lxl921 发表于 2019-9-13 22:17:21

winform导出PDF只有格式没有数据

AR13.1,VS2017C#
在winform中viewer控件,页面报表,预览数据正常,通过代码增加PDF导出,生成的PDF文件,只有格式,无数据。另能否在导出时可以选文件路径及进度条。谢谢!
代码如下:
      public void tsbPDF_Click(object sender, EventArgs e)
      {
            // Provide the page report you want to render.
            System.IO.FileInfo rptPath = new System.IO.FileInfo(@"..\..\装箱单.rdlx");
            GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath);
            // Create an output directory.
            System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"D:\MyPDF");
            outputDirectory.Create();
            // Provide settings for your rendering output.
            GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
            // Reduce the report size and report generation time.
            pdfSetting.OptimizeStatic = true;
            // Set the rendering extension and render the report.
            GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
            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;
            pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
      }

KearneyKang 发表于 2019-9-16 09:09:42

您好,你的报表的数据源绑定数动态数据源绑定还是怎么的,执行导出PDF的时候是否进行了一个数据源的绑定

lxl921 发表于 2019-9-16 13:48:10

KearneyKang 发表于 2019-9-16 09:09
您好,你的报表的数据源绑定数动态数据源绑定还是怎么的,执行导出PDF的时候是否进行了一个数据源的绑定

报表的数据源是固定在报表上的,没有动态绑定。执行导出PDF时,不知道在哪里绑定。

KearneyKang 发表于 2019-9-16 15:42:05

那么导出Word或者导出Excel数据都能正常的展示吗?

lxl921 发表于 2019-9-16 15:45:52

KearneyKang 发表于 2019-9-16 15:42
那么导出Word或者导出Excel数据都能正常的展示吗?

没有导出过word或是excel,现在就增加了一个导出PDF

KearneyKang 发表于 2019-9-16 18:28:55

本帖最后由 KearneyKang 于 2019-9-20 08:57 编辑

你试试别得格式看看,要不就是你写一个简单的demo发给我我给看看具体什么原因

lxl921 发表于 2019-9-16 23:12:24

KearneyKang 发表于 2019-9-16 18:28
你试试逼得格式看看,要不就是你写一个简单的demo发给我我给看看具体什么原因

已发窗体代码到QQ

KearneyKang 发表于 2019-9-17 09:12:12

好的:)

lxl921 发表于 2019-9-19 21:53:22

经与康工反复沟通调试,问题得以解决,现分享原因。之前的贴出的代码是导出模板数据,但我报表上有参数,需要选择参数后,报表才装载数据,但导出PDF没有这步操作,所以导出的是空格式,没有数据。正确代码如下,供参考。
      private void button1_Click(object sender, EventArgs e)
      {
            System.IO.FileInfo rptPath = new System.IO.FileInfo(@"装箱单.rdlx");
            GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath);
            // Create an output directory.
            System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"D:\MyPDF");
            outputDirectory.Create();
            // Provide settings for your rendering output.
            GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
            // Reduce the report size and report generation time.
            pdfSetting.OptimizeStatic = true;
            // Set the rendering extension and render the report.
            GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
            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;
            pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);

      }

KearneyKang 发表于 2019-9-20 08:59:21

谢谢你的分享,这个主要的解决思路就定义一个全局变量的报表,然后都调用这个报表就不会出现这个问题
页: [1]
查看完整版本: winform导出PDF只有格式没有数据