您好,
导出excel、pdf解决的思路是自定义一个button,然后添加到Toolbar上。在这个button上增加一个点击触发的方法。在这个方法里面实现导出。
- //Add a new button to the end of the tool strip with the caption "Print."
- ToolStripButton tsbPrint = new ToolStripButton("Print");
- viewer1.Toolbar.ToolStrip.Items.Add(tsbPrint);
- //Create a click event handler for the button.
- tsbPrint.Click += new EventHandler(tsbPrint_Click);
复制代码
- //Call the custom dialog from the new button's click event.
- private void tsbPrint_Click(object sender, EventArgs e)
- {
- this.CustomPrint();
- }
- //Call the custom print dialog.
- private void CustomPrint()
- {
- frmPrintDlg _printForm = new frmPrintDlg();
- _printForm.ShowDialog(this);
- }
复制代码
导出excel代码参考
- // Provide the page report you want to render.
- GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"C:\Sample_PageReport.rdlx"));
- 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));
- reportDocument.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
复制代码 |