問題:
在ASP.NET中可否直接匯出,不需產生檔案或暫存檔?
答案:
如下程式可直接將報表匯出成PDF格式給使用者瀏覽,不會產生檔案。
Dim crExportOptions As CrystalDecisions.Shared.ExportOptions
Dim RptDoc as New ReportDocument
dim rptFile as String =Server.MapPath("AsiaCustomers.rpt")
RptDoc.Load ( rptFile )
RptDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
RptDoc.ExportOptions.FormatOptions = New PdfRtfWordFormatOptions()
Dim req As New ExportRequestContext()
req.ExportInfo = RptDoc.ExportOptions
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Dim s As System.IO.Stream
s = RptDoc.FormatEngine.ExportToStream(req)
s.Seek(0,IO.SeekOrigin.Begin )
Dim buffer(s.Length) As Byte
s.Read(buffer, 0, s.Length)
Response.BinaryWrite(buffer)
Response.End()
' Saved From URL: http://www.netmag.com.tw/member/netmag_hot/NHot00029.aspx