浩子

在.NET的世界里徜徉

导航

ASP.NET 页面中水晶报表导出

一大段代码,看看吧。

string sDestFile = Path.GetTempFileName();

   string sExportFormatType = text_export.SelectedItem.Text;

   if (sExportFormatType == "")
    return;

   DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
   diskOpts.DiskFileName = sDestFile;

   oRpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

   switch (sExportFormatType)
   {
    case "Mircrosoft Word 文档":
    {
     oRpt.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows;
     break;
    }
    case "Mircrosoft Excel 文档":
    {
     oRpt.ExportOptions.ExportFormatType = ExportFormatType.Excel;
     break;
    }
    case "Adobe PDF 文档":
    {
     oRpt.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
     break;
    }
   }

   oRpt.ExportOptions.DestinationOptions = diskOpts;

   oRpt.Export();

   Response.ClearContent();
   Response.ClearHeaders();

   switch (sExportFormatType)
   {
    case "Mircrosoft Word 文档":
    {
     Response.ContentType = "application/msword";
     break;
    }
    case "Mircrosoft Excel 文档":
    {
     Response.ContentType = "application/vnd.ms-excel";
     break;
    }
    case "Adobe PDF 文档":
    {
     Response.ContentType = "application/pdf";
     break;
    }
   }

   Response.WriteFile(sDestFile);
   Response.Flush();
   Response.Close();

   File.Delete(sDestFile);

posted on 2004-11-22 16:44  浩子  阅读(3314)  评论(8编辑  收藏  举报