chenfeng1029 发表于 2019-11-15 13:19:55

报表导出问题

1、有没有好的办法,可以不进行预览直接进行报表导出excel或者pdf
2、3张不同的报表,是否可以合并在一起,一起套打。
3、有什么demo,是否可以借鉴下。

KearneyKang 发表于 2019-11-15 16:00:35

你是C/S端项目,还是B/S端项目。C/S端项目是可以的实现静默的导出和打印的,B/S 端暂时实现不了这样的需求

chenfeng1029 发表于 2019-11-15 16:47:00

我是用c/s

KearneyKang 发表于 2019-11-15 17:42:29

那你可以直接写一个导出的按钮,然后导出的代码如下,通过直接点击导出来实现报表的导出跟报表展示就没有关系了,但是这个实际上也就是没有执行那个Viewer显示的特性// Provide the page report you want to render.
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);

// Create an output directory.
System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyExcel");
outputDirectory.Create();

// Provide settings for your rendering output.
GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls;
GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension excelRenderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));

// Overwrite output file if it already exists.
outputProvider.OverwriteOutputFile = true;

reportDocument.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
// Provide the page report you want to render.
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();
GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);

// Create an output directory.
System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyWord");
outputDirectory.Create();

// Provide settings for your rendering output.
GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = new GrapeCity.ActiveReports.Export.Word.Page.Settings();

// Set the FileFormat property to .OOXML.
wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML;

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));

// Overwrite output file if it already exists.
outputProvider.OverwriteOutputFile = true;

reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting);      

chenfeng1029 发表于 2019-11-18 13:23:16

我本地已经做好了rdlx报表,是否可以直接导出。而不通过view方式在导出

KearneyKang 发表于 2019-11-18 13:32:41

就是我上面给你的代码那样导出,这是后台导出的代码

chenfeng1029 发表于 2019-11-18 13:37:19

我的意思是。我rdlx报表在本地,加载后。直接导出呀。我试了下,只是导出一个空白的

chenfeng1029 发表于 2019-11-18 14:15:25

我把代码调整了下
Private Function P_Exportword() As Integer
      Dim intsuc As Integer = - 2
      Try
            Dim strFileName As String = System.Environment.CurrentDirectory + "\report\dz_bgd.rdlx"
            Dim report As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(new system.io.FileInfo(strFileName))
            AddHandler report.Document.LocateDataSource, AddressOf OnLocateDataSource '添加动态数据源事件,进行事件加载
            Dim reportDocument As GrapeCity.ActiveReports.Document.PageDocument = New GrapeCity.ActiveReports.Document.PageDocument(report)
            
            Dim outputDirectory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("C:\myword")
            outputDirectory.Create()
            Dim wordSetting AsGrapeCity.ActiveReports.Export.Word.Page.Settings = New GrapeCity.ActiveReports.Export.Word.Page.Settings()
            wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML
            Dim wordRenderingExtension As GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension = New GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension()
            Dim outputProvider As GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider = New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))
            outputProvider.OverwriteOutputFile = True
            

            reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting)
            intsuc = 1
      Catch ex As Exception
            MsgBox(ex.Message, , "错误")
      End Try
      Return intsuc
    End Function

   Private Sub OnLocateDataSource(ByVal sender As Object, ByVal args As GrapeCity.ActiveReports.LocateDataSourceEventArgs)

      '   If args.DataSourceName = "binbin" Then

      '            Dim vConnection As New GrapeCity.ActiveReports.PageReportModel.ConnectionProperties
      '            vConnection.ConnectString = _nConnection1

      '    If args.DataSetName = "DataSet1" Then
      'args.Data = _nMainDataSource1

      '   End If
      '   End If
      if P_ReturnReportData.Tables.Count>0 then
            _nDataSource1=P_ReturnReportData.Copy()
      End If
      If _nDataSource1.Tables.Count = 1 Then
            If LCase(Convert.ToString(args.DataSetName)) = "master" Then
                args.Data = _nDataSource1.Tables(0)
            End If
            If LCase(Convert.ToString(args.DataSetName)) = "detail" Then
                args.Data = _nDataSource1.Tables(1)
            End If
      ElseIf _nDataSource1.Tables.Count = 2 Then
            If LCase(Convert.ToString(args.DataSetName)) = "master" Then
                args.Data = _nDataSource1.Tables(0)
            End If
            If LCase(Convert.ToString(args.DataSetName)) = "detail" Then'Detail
                args.Data = _nDataSource1.Tables(1)
            End If
      End If


    End Sub
不过导出报表,提示无法加载数据源。
我把报表的数据源改为dataset provider
最后提示,无法加载数据源。

chenfeng1029 发表于 2019-11-18 14:17:46

chenfeng1029 发表于 2019-11-18 14:35:49

问题已经解决了。我把代码修改了下
Private Function P_Exportword() As Integer
      Dim intsuc As Integer = - 2
      Try
            Dim strFileName As String = System.Environment.CurrentDirectory + "\report\dz_bgd.rdlx"
            Dim report As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(new system.io.FileInfo(strFileName))
       '   AddHandler report.Document.LocateDataSource, AddressOf OnLocateDataSource '添加动态数据源事件,进行事件加载
            Dim reportDocument As GrapeCity.ActiveReports.Document.PageDocument = New GrapeCity.ActiveReports.Document.PageDocument(report)
            AddHandler reportdocument.LocateDataSource, AddressOf OnLocateDataSource '添加动态数据源事件,进行事件加载
            Dim outputDirectory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("C:\myword")
            outputDirectory.Create()
            Dim wordSetting AsGrapeCity.ActiveReports.Export.Word.Page.Settings = New GrapeCity.ActiveReports.Export.Word.Page.Settings()
            wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML
            Dim wordRenderingExtension As GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension = New GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension()
            Dim outputProvider As GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider = New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))
            outputProvider.OverwriteOutputFile = True
            

            reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting)
            intsuc = 1
      Catch ex As Exception
            MsgBox(ex.Message, , "错误")
      End Try
      Return intsuc
    End Function
页: [1] 2
查看完整版本: 报表导出问题