曹超 发表于 2015-5-12 09:33:00

WinForm导出excel和pdf的代码

回复 13楼frank.zhang的帖子

这个导出excel和pdf的代码可不可以给段WinForm的代码

frank.zhang 发表于 2015-5-12 11:10:00

您好,
在WinForm下,只是改变了输出的方式。
// 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 a output directory
System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyPDF");
outputDirectory.Create();
// Provide settings for your rendering output.
GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new
GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = pdfSetting;
//Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension =
new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new
GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory,
System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
reportDocument.Render(pdfRenderingExtension, outputProvider, pdfSetting);

// 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());

参考文档:http://arhelp.grapecity.com/webhelp/AR9/index.html#Rendering.html

曹超 发表于 2015-5-12 13:14:00

非常感谢,初用AR9,多多学习

frank.zhang 发表于 2015-5-12 13:43:00

感谢反馈。
页: [1]
查看完整版本: WinForm导出excel和pdf的代码