您好,
程序详见附件。
- private void button1_Click(object sender, EventArgs e)
- {
- // Provide the page report you want to render.
- GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));
- GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
- pageReport.Report.DataSources[0].DataSourceReference = "";
- pageReport.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
- pageReport.Report.DataSources[0].ConnectionProperties.ConnectString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", db_name);
- pageReport.Report.ReportParameters[0].DefaultValue.Values.Add(productId);
- // 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));
- pageDocument.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
- }
复制代码
|