Page tree
Skip to end of metadata
Go to start of metadata

Microsoft Excel是可以使用ExcelRenderingExtension呈现报告的格式之一。 您可以两种格式导出Excel文件,即Xls和Xlsx。

以下步骤提供了以Microsoft Excel格式呈现报告的示例。

1、创建一个新的Visual Studio项目。

2、在出现的“新建项目”对话框中,选择“ ActiveReports 14页面报表应用程序”,然后在“名称”字段中指定项目的名称。

3、单击“确定”创建一个新的ActiveReports 14页面报表应用程序。 默认情况下,页面报告将添加到项目中。

4、在项目中添加对GrapeCity.ActiveReports.Export.Excel包的引用。

5、在打开的Form.cs或Form.vb上,双击标题栏以创建Form_Load事件。

6、在Form_Load事件中添加以下代码。

Visual Basic.NET代码。 粘贴到Form Load事件中。


' Provide the page report you want to render.
Dim report As New GrapeCity.ActiveReports.PageReport()
Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report)

' Create an output directory.
Dim outputDirectory As New System.IO.DirectoryInfo("C:\MyExcel")
outputDirectory.Create()

' Provide settings for your rendering output.
Dim excelSetting As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings()
excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls
Dim setting As GrapeCity.ActiveReports.Extensibility.Rendering.ISettings = excelSetting

' Set the rendering extension and render the report.
Dim excelRenderingExtension As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension()
Dim outputProvider As 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(excelRenderingExtension, outputProvider, setting.GetSettings())

C#代码。 粘贴到Form Load事件中。


// 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:\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));

// Overwrite output file if it already exists.
outputProvider.OverwriteOutputFile = true;

reportDocument.Render(excelRenderingExtension, outputProvider, setting.GetSettings());







相关资源:


注意

如需寻求在线帮助,请访问 ActiveReports 求助中心

如需了解更多ActiveReports产品特性,请访问 ActiveReports 官方网站

ActiveReports 官方技术交流群:109783140

下载产品体验产品功能:http://www.gcpowertools.com.cn/products/download.aspx?pid=16

  • No labels