本帖最后由 人生就是修炼 于 2023-5-8 14:24 编辑
官方文档是无参的示例,注释为英文,这里注释为中文,并且导出的报表是有参数的格式
官方文档:https://help.grapecity.com.cn/pages/viewpage.action?pageId=47647535
示例基于SQLite数据库
- //定义报表的路径和名称
- string file_name = @"询问笔录.rdlx"; //报表格式为:页面报表(pageReport)
- // 提供页面报表到你想要的状态 Provide the page report you want to render.
- GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name)); //简写方式 var pageReport = new PageReport(new System.IO.FileInfo(file_name));
- GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
- // 定义页面报表(Rdlx)的数据库连接参数
- pageReport.Report.DataSources[0].DataSourceReference = "";
- pageReport.Report.DataSources[0].ConnectionProperties.DataProvider = "ODBC";
- pageReport.Report.DataSources[0].ConnectionProperties.ConnectString = @"DRIVER=SQLITE3 ODBC DRIVER;DATABASE=data\YiFa.db";
- pageReport.Report.ReportParameters[0].DefaultValue.Values.Clear();
- pageReport.Report.ReportParameters[0].DefaultValue.Values.Add(this.uiTextBox询问号.Text.Trim());
- pageReport.Report.ReportParameters[1].DefaultValue.Values.Clear();
- pageReport.Report.ReportParameters[1].DefaultValue.Values.Add(this.uiTextBox年度.Text.Trim());
- // 创建输入目录 Create an output directory.
- System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"D:\易罚Word导出");
- outputDirectory.Create();
- // 为您的渲染输出提供设置 Provide settings for your rendering output.
- GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = new GrapeCity.ActiveReports.Export.Word.Page.Settings();
- // 将FileFormat属性设置为.OOXML 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);
- MessageBox.Show("导出Word成功!");
复制代码
|