activeReport17 加载datatable正常, 导出Excel报错
业务场景:在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
这个问题解决了;我的自定义按钮是加载了LocateDataSource事件的,只是这个事件是用来显示报表用的,当导出电子表格的时候,还需要再次针对reportDocument 对象触发LocateDataSource事件实现针对导出电子表格事件的数据加载;在我的测试中不需要 run()就可以,添加上也不会报错; 自定义导出按钮没有加载LocateDataSource事件,也没有调用下Report.Run();有兴趣可以加我QQ546962925 谢谢网友 wengMQ的回复 ! 大佬解决了就好
:hjyzw:
给您奖励金币
页:
[1]