报表界面显示时有一些样式,导出Excel时客户不想要,又做了一个ProcurementVolumeExcel.rdlx报表用于导出
数据库采用动态连接方式,ProcurementVolume.rdlx用于界面显示,两张报表的DataSource和DataSet名称设置相同
导出代码是从以下博客中复制
https://www.grapecity.com.cn/blogs/activereports-export
标红行NWind_CHS_Access.rdsx是什么,在我的代码里应该怎么改
程序具体代码如下,
''' <summary>
''' 查询
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Protected Sub btnQuery_Click(sender As Object, e As EventArgs) Handles btnQuery.Click
Dim rpt As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("ProcurementVolume.rdlx")))
AddHandler rpt.Document.LocateDataSource, AddressOf Me.runtime_LocateDataSource
Me.WebViewer1.Report = rpt
End Sub
Sub runtime_LocateDataSource(sender As Object, args As GrapeCity.ActiveReports.LocateDataSourceEventArgs)
If args.DataSet.Query.DataSourceName = "DataSource1" Then
If args.DataSet.Name = "ProcurementVolume" Then
args.Data = CreateProcurementVolume()
End If
End If
End Sub
Private Function CreateProcurementVolume() As DataTable
Dim db As DbHelper = New DbHelper()
Dim dt As DataTable = Nothing
Dim sql As String = "SELECT * FROM tb"
dt = db.ExecuteDataTable(sql)
Return dt
End Function
''' <summary>
''' 导出
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Protected Sub BtExcel_Click(sender As Object, e As EventArgs) Handles BtExcel.Click
Dim _reportDef As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("ProcurementVolumeExcel.rdlx")))
_reportDef.Report.DataSources(0).DataSourceReference = Server.MapPath("../Data/NWind_CHS_Access.rdsx")
Dim _reportRuntime As New GrapeCity.ActiveReports.Document.PageDocument(_reportDef)
Dim XlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport()
Dim ms As New System.IO.MemoryStream()
XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx
XlsExport1.Export(_reportRuntime, ms)
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=" + "ProcurementVolume.xlsx"))
Response.BinaryWrite(ms.ToArray())
Response.End()
End Sub
|
|