找回密码
 立即注册

QQ登录

只需一步,快速开始

[已处理] 报表导出问题

chenfeng1029
金牌服务用户   /  发表于:2019-11-15 13:19  /   查看:6822  /  回复:10
1金币
1、有没有好的办法,可以不进行预览直接进行报表导出excel或者pdf
2、3张不同的报表,是否可以合并在一起,一起套打。
3、有什么demo,是否可以借鉴下。

10 个回复

倒序浏览
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显示的特性
  1. // Provide the page report you want to render.
  2. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);

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

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

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

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

  15. reportDocument.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
复制代码
  1. // Provide the page report you want to render.
  2. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();
  3. GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);

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

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

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

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

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

  16. reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting);      
复制代码


回复 使用道具 举报
chenfeng1029
金牌服务用户   /  发表于:2019-11-18 13:23:16
5#
我本地已经做好了rdlx报表,是否可以直接导出。而不通过view方式在导出
回复 使用道具 举报
KearneyKang讲师达人认证 悬赏达人认证
超级版主   /  发表于:2019-11-18 13:32:41
6#
就是我上面给你的代码那样导出,这是后台导出的代码
回复 使用道具 举报
chenfeng1029
金牌服务用户   /  发表于:2019-11-18 13:37:19
7#
我的意思是。我rdlx报表在本地,加载后。直接导出呀。我试了下,只是导出一个空白的
回复 使用道具 举报
chenfeng1029
金牌服务用户   /  发表于:2019-11-18 14:15:25
8#
我把代码调整了下
  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 As  GrapeCity.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
9#

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
chenfeng1029
金牌服务用户   /  发表于:2019-11-18 14:35:49
10#
问题已经解决了。我把代码修改了下
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 As  GrapeCity.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
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部