Tha*_*nha 7 vb.net visual-studio-2010 crystal-reports
我在其功能下面的代码是使用CrystalReports从屏幕上的报表加载数据.
Dim strExportFile As String
strExportFile = "ReportReajustesAplicados.pdf"
Dim s As System.IO.MemoryStream = relat.ExportToStream(ExportFormatType.PortableDocFormat)
With HttpContext.Current.Response
.ClearContent()
.ClearHeaders()
.ContentType = "application/pdf"
.AddHeader("Content-Disposition", "inline; filename=" & strExportFile)
.BinaryWrite(s.ToArray)
.End()
End With
Run Code Online (Sandbox Code Playgroud)
当我提取数据时.
我有以下错误
无法将类型为"FileStreamDeleteOnClose"的对象强制转换为"System.IO.MemoryStream".
我尝试使用System.IO.Stream,提取工作,但不显示屏幕上的数据,因为".BinaryWrite(s.ToArray)"不接受方法ToArray.
注意:我放的时候
#if DEBUG Then
CrystalReportViewer1.ReportSource = relat
CrystalReportViewer1.DataBind ()
Exit Sub
If #End
Run Code Online (Sandbox Code Playgroud)
作品
我需要这个才能工作,但是在发布模式下.
帮我
我找到了解决方案:
https://archive.sap.com/discussions/thread/3322762
正如SAP所说:"这是设计,我们从未完全支持导出到MemoryStream.唯一的选择是不使用MemoryStream,这不会被改变."
所以解决方案是用Stream替换MemoryStream并将其发送到Byte数组中,如下所示:
Dim strExportFile As String
strExportFile = "ReportReajustesAplicados.pdf"
Dim s As System.IO.Stream = relat.ExportToStream(ExportFormatType.PortableDocFormat)
Dim b(s.Length) As Byte
s.Read(b, 0, CInt(s.Length))
With HttpContext.Current.Response
.ClearContent()
.ClearHeaders()
.ContentType = "application/pdf"
.AddHeader("Content-Disposition", "inline; filename=" & strExportFile)
.BinaryWrite(b)
.Flush()
.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
End With
Run Code Online (Sandbox Code Playgroud)
您可以替换.BinaryWrite(s.ToArray)为.BinaryWrite(CType(Session("myCrystalReport"), IO.MemoryStream).ToArray()).
我在下面写了一个例子,我不确定这是否是你想要的,但我希望它可以帮助你。这对我有用,让用户使用 PDF 格式下载/查看 Crystal Reports。
Dim fileName As String = "ReportReajustesAplicados.pdf"
Response.ContentType = "application/pdf"
Response.Clear()
Response.Buffer = True
Response.AddHeader("Content-Disposition", "filename=" + fileName)
Response.BinaryWrite(CType(Session("myCrystalReport"), IO.MemoryStream).ToArray())
Response.End()
Run Code Online (Sandbox Code Playgroud)
我将水晶报表放入带有这些选项的会话中(rpt 是我的水晶报表):
Dim options = rpt.ExportOptions
options.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
Session!myCrystalReport= rpt.FormatEngine.ExportToStream(New CrystalDecisions.Shared.ExportRequestContext With {
.ExportInfo = options
})
rpt.Dispose()
Run Code Online (Sandbox Code Playgroud)
如果我的答案不清楚或不是您想要的,请告诉我,我会尽快更新。