Activereports 12 新特性(3)—新增JSON和CSV导出

发布时间:2017/11/27 00:11 发布者:KearneyKang

返回博客中心

 

这是一个令人兴奋的消息! 最新发布的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产品更多特性:

/developer/activereports

下载产品体验产品功能:

/download/?pid=16


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网