wuliao5945 发表于 2020-4-27 08:48:32

ar13导出Excel,后台导出与界面显示不同的另一张报表

报表界面显示时有一些样式,导出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

KearneyKang 发表于 2020-4-27 09:23:48

您好,那里面使用了.rdsx的这个后缀文件,这是使用了共享数据源,然后数据源的链接匹配信息是放在该文件夹下的。
具体的报表导出实现的代码你可以参考这个:https://www.grapecity.com/activereports/docs/v14/online/overview.html

wuliao5945 发表于 2020-4-27 12:28:47

我用的ar13, 这个代码也一样好用吗,我把代码复制到按钮事件下,结果导出一个空的报表,代码必须要在load事件中吗,而且我不要导出界面显示的报表,导出我想导出另一个rdlx

wuliao5945 发表于 2020-4-27 12:31:58

我的代码中如果不用共享数据源,具体要怎么设置

KearneyKang 发表于 2020-4-27 14:27:35

您好,导出只能导出Word、Excel和PDF等格式不能导出RDLX,还有就是你说的导出为空白就是没有数据,那原因是你使用了动态数据源绑定,导出的时候了没有进行数据集的绑定,导出的内容就是空白的,
对于空白的问题:
第一种办法是导出前进行数据源 的绑定
第二种办法是定义一个报表的全局变量,项目load的时候就进行数据源绑定,然后后面导出的时候聚使用这个报表,这样道春就是有数据的

wuliao5945 发表于 2020-4-28 08:47:29

我想表达的是我要导出的和界面显示的是两个rdlx
我导出按钮的代码如下:断点跟踪,_reportRuntime 结果显示计算超时,图片放最下面
''' <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")))

         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

Lenka.Guo 发表于 2020-4-28 10:16:20

您好
看您的错误信息,应该是报表是动态数据源链接, 所以您在对报表导出时,也需要进行一次数据绑定   Dim rptPath As New FileInfo("..\..\Invoice2.rdlx")
      Dim definition As New PageReport(rptPath)
      AddHandler definition.Document.LocateDataSource, AddressOf OnLocateDataSource



   然后再调用导出方法。

wuliao5945 发表于 2020-4-28 11:36:30

啊,我贴出的代码误删了一行,数据绑定程序里是有的
      Dim _reportDef As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("ProcurementVolumeExcel.rdlx")))
      AddHandler _reportDef.Document.LocateDataSource, AddressOf Me.runtime_LocateDataSource
      'Me.WebViewer1.Report = _reportDef
      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()
报的错误如下图中所显示,断点跟踪的话,_reportRuntime结果就不正确了,像我上面贴的 printer“计算超时”,如果放开Me.WebViewer1.Report = _reportDef这句,下面不执行,页面上报表显示是正常的

KearneyKang 发表于 2020-4-28 18:35:31

您好,还是有点不是很了解你目前遇到的问题,方便电话沟通不。到时候我们在电话上,进行一个详细的沟通
页: [1]
查看完整版本: ar13导出Excel,后台导出与界面显示不同的另一张报表