业务场景:
在VB.NET 程序中生成 Datatable,然后加载到 rdlx报表中显示出来(正常),点击按钮导出Excel(报错);
问题:
(1)把 datatable加载到 rdlx报表的时候可以正常加载并显示;
(2)但是生成excel报表的时候,系统报错“未设置数据,请指定一个数据集”
我的测试代码如下:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim f = "I:\Ex\test_ar18\test_ar18\bin\Debug\net8.0-windows\report\1.rdlx"
Dim finfo As New IO.FileInfo(f)
' Provide the page report you want to render.
report = New GrapeCity.ActiveReports.PageReport(finfo)
' 下面的代码加载 datatable:正常
AddHandler report.Document.LocateDataSource, AddressOf Document_LocateDataSource
' 显示报表:正常
Me.Viewer1.LoadDocument(report.Document)
Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report)
' Create an output directory.
Dim outputDirectory As New IO.DirectoryInfo("C:\MyExcel")
outputDirectory.Create()
' Provide settings for your rendering output.
Dim excelSetting As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings
excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls
Dim setting As GrapeCity.ActiveReports.Extensibility.Rendering.ISettings = excelSetting
' Set the rendering extension and render the report.
Dim excelRenderingExtension As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension
Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))
' Overwrite output file if it already exists.
outputProvider.OverwriteOutputFile = True
' 这里生成电子表格的时候报错了: 未设置数据,请指定一个数据集
reportDocument.Render(excelRenderingExtension, outputProvider, setting.GetSettings)
Catch ex As Exception
Text = ex.Message
End Try
End Sub
|