本帖最后由 KearneyKang 于 2018-7-25 11:37 编辑
1、导出WPF的view里是没有导出按钮的,你可以通过添加一个导出的按钮,然后通过按钮触发导出的操作。具体的导出后台实现的方向,导出Word:
- <pre>GrapeCity.ActiveReports.PageReport report = <span style="COLOR: #0000ff">new</span> GrapeCity.ActiveReports.PageReport();
- GrapeCity.ActiveReports.Document.PageDocument reportDocument = <span style="COLOR: #0000ff">new</span> GrapeCity.ActiveReports.Document.PageDocument(report);
- <span style="COLOR: #008000">// Create an output directory.
- </span>System.IO.DirectoryInfo outputDirectory = <span style="COLOR: #0000ff">new</span> System.IO.DirectoryInfo(<span style="COLOR: #800000">@"C:\MyWord"</span>);
- outputDirectory.Create();
- <span style="COLOR: #008000">// Provide settings for your rendering output.
- </span>GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = <span style="COLOR: #0000ff">new</span> GrapeCity.ActiveReports.Export.Word.Page.Settings();
- <span style="COLOR: #008000">// Set the FileFormat property to .OOXML.
- </span>wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML;
- <span style="COLOR: #008000">// Set the rendering extension and render the report.
- </span>GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension = <span style="COLOR: #0000ff">new</span> GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
- GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = <span style="COLOR: #0000ff">new</span> GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
- <span style="COLOR: #008000">// Overwrite output file if it already exists.
- </span>outputProvider.OverwriteOutputFile = <span style="COLOR: #0000ff">true</span>;
- reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting); </pre>
复制代码
导出Excel
- 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());
复制代码 第二个问题,如果需要自定义按钮事件的话,你就直接添加对应的按钮,因为你用的是动态数据源,参数的传递,您就可以通过文本框的形式传递,然后通过自己添加的按钮触发对应的操作。也就是我们说的自定义一些文本输入框和按钮,最后在后台把筛选好的数据绑定给报表,报表只做一个数据的展示就行。
第三个问题,如果你的子表用的是向下钻取的话,你可以根据表达式来控制跳转到对应的报表,但是没办法做的你说的数据不存在不跳转,因为我在报表端没办法做到怎样判断返回的数据是否不存在,因为你的数据是后台动态绑定的。你可以参考这个博客看看:https://www.grapecity.com.cn/blo ... -without-showing-it
用页面报表的特性来解决,当数据不存在时,不显示。那你的子表就需要用页面报表
|