这是一个令人兴奋的消息! 最新发布的ActiveReports 12推出了两种新的导出模式 JSON和CSV, 这些导出功能类似于我们的其他接口,如PDF,Doc,Docx和HTML,只需要几行代码,就可以实现。
一、 导出JSON
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。JSON采用完全独立于语言的文本格式,这些特性使JSON成为理想的数据交换语言
1、在报表设计器中导出JSON模式,具体操作如下:
2、代码中实现:
// 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:\MyJSON"); outputDirectory.Create(); // Provide settings for your rendering output. GrapeCity.ActiveReports.Export.Text.Page.JsonRenderingExtension.Settings jsonSettings = new GrapeCity.ActiveReports.Export.Text.Page.JsonRenderingExtension.Settings(); jsonSettings.Formatted = true; // Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Text.Page.JsonRenderingExtension jsonRenderingExtension = new GrapeCity.ActiveReports.Export.Text.Page.JsonRenderingExtension(); 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(jsonRenderingExtension, outputProvider, jsonSettings);
二、 导出CSV
CSV逗号分隔值文件(Comma Separated value),是一种用来存储数据的纯文本文件格式。CSV是一种通用的文件格式,它可以非常容易的被导入各种PC表格及数据库中,CSV文件中的一行即就是数据表中的一行。
1、在报表设计器中导出CSV模式,具体操作如下:
2、代码中实现:
// 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:\MyCSV"); outputDirectory.Create(); // Provide settings for your rendering output. GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension.Settings csvSettings = new GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension.Settings(); csvSettings.ColumnsDelimiter = ","; csvSettings.RowsDelimiter = "\r\n"; csvSettings.QuotationSymbol = '"'; csvSettings.Encoding = Encoding.UTF8; // Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension csvRenderingExtension = new GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension(); 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(csvRenderingExtension, outputProvider, csvSettings);
了解ActiveReports产品更多特性:
下载产品体验产品功能: