本帖最后由 KearneyKang 于 2017-12-13 17:07 编辑
您好,数据源的绑定跟您其它动态数据源绑定一样。如下是导出Excel并且绑定动态数据源的代码
- private void tsbExcel_Click(object sender, EventArgs e)
- {
- string file_name = @"..\..\RdlReport1.rdlx";
- //GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"123.rdlx"));
- //GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
- GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));
- pageReport.Document.LocateDataSource += new LocateDataSourceEventHandler(LocateData);
- this._document = pageReport.Document;
-
- System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"D:\MyExcel");
- outputDirectory.Create();
-
- GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
- excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls;
- excelSetting.MultiSheet = false;
- GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;
- 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));
- outputProvider.OverwriteOutputFile = false;
- _document.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
- }
复制代码 导出word的代码- // 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);
复制代码
|