快速学会使用FastReport VCL从Delphi / Lazarus将报表导出到Excel XML

报表生成器FastReport VCL是用于在软件中集成商务智能的现代解决方案。它提供了可视化模板设计器,能够访问最受欢迎的数据源,报告引擎,预览,将过滤器导出为30多种格式,并能够部署到云,Web,电子邮件和打印中。程序员

近日,FastReport VCL更新至v6.7,在新版本中,添加了对最新版本IDE的支持,简化了用于付款标准的条形码的建立,新增从预览窗口直接编辑RichView的功能,同时修复了多个Bug问题。欢迎下载体验。(点击下载数据库

XML是一项旨在管理结构化数据并将该数据显示为人类可读的文本文件的技术。XML符合行业标准,能够被许多数据库和应用程序处理。使用XML,许多开发人员能够建立本身的自定义标签,数据结构和架构。一般,XML极大地促进了各类数据库,应用程序和组织中数据的定义,传输,验证和解释。数据结构

可是,若是微软传统上不尝试制做“拥有二十一点和单元的本身的XML”,那微软就不会成为本身。所以,Excel实际上不是使用一种(!)XML标准来存储Excel电子表格,而是一种(较旧的和更正确的)XML标准。多线程

正如屡次提到的,FastReport容许以各类格式保存来自Delphi和Lazarus的文档、报告和数据。惟一想指出的是,咱们须要观察对象的对齐方式,以便生成的电子表格具备吸引力和质量。所以,Fastreport为Excel XML提供了两个不一样的(!)导出过滤器。架构

可视化报告生成器FastReport VCL功能指南:从Delphi / Lazarus将报表导出到Excel XML

很明显,程序员历来不会作任何“仅仅由于他想作”的事情——用户才是真正想作什么的人。那么,从用户的角度来看,当他想从应用程序得到Excel电子表格时,这两种格式有什么不一样呢?ide

对于用户来讲,这种差别与没有任何图片的rtf和成熟的MS Word文档之间的差别大体相同——第一个差别在现实生活中不多出现。在一个简单的XML文件中没有样式或图片—只有一个XML表。工具

FastReport工具可帮助选择将文档的哪些页面发送到Excel,某些页面或范围。 导出设置:与原始版本(WYSIWYG)更好的视觉对应,分页符和跳过页眉和页脚的连续文档。this

结果:不要拆分,使用报告页面,在父级上使用打印-报告模板中的每一个TrfxReportPage都对应于该书的一张纸(假设TfrxReportPage.PrintOnParent = False)或按特殊数量拆分行。导出后打开:导出后,Microsoft Excel将当即打开结果文件(或由与XLSX文件关联的任何其余软件)打开。url

可视化报告生成器FastReport VCL功能指南:从Delphi / Lazarus将报表导出到Excel XML

能够将生成的XML / XLSX保存为本地存储中带有.xml扩展名的文件,发送到FTP,经过电子邮件发送或上传到其中一个云存储(Dropbox,OneDrive,Box.com,GoogleDrive)。spa

比较生成的XLSX和Excel XML文件

可视化报告生成器FastReport VCL功能指南:从Delphi / Lazarus将报表导出到Excel XML 可视化报告生成器FastReport VCL功能指南:从Delphi / Lazarus将报表导出到Excel XML

第一个屏幕截图是保存为XLSX格式的结果,而且咱们能够看到,该格式不支持比纯文本更复杂的数据。可是第二张屏幕截图向咱们展现了XML格式的全部可能性,例如彻底支持图像和条形码。说到文件的重量,结果是能够预料的:XLSX-48,0kB,XML-40,0kB。

可视化报告生成器FastReport VCL功能指南:从Delphi / Lazarus将报表导出到Excel XML

让咱们进一步了解为何XLSX比XML更重要。这些美丽的鱼被做为基础。这份文件包含了大量的文本、表格数据和30张照片。为了更清楚地说明问题,让咱们将其与未老化的Excel 97进行比较,咱们在另外一篇文章中讨论过它。

可视化报告生成器FastReport VCL功能指南:从Delphi / Lazarus将报表导出到Excel XML
可视化报告生成器FastReport VCL功能指南:从Delphi / Lazarus将报表导出到Excel XML

Excel 97 –它是二进制格式(biff8),没有任何压缩,所以文件很大。与后来的XML格式不一样,Excel 97支持各类图像。Excel table(XML)– XLSX的早期版本,其中的数据存储为简单,单个,总体的XML文件,与OOXML和MS Office传统二进制格式相比,它们很是大。

Excel 97 –它是二进制格式(biff8),没有任何压缩,所以文件很大。与后来的XML格式不一样,Excel 97支持各类图像。Excel table(XML)– XLSX的早期版本,其中的数据存储为简单,单个,总体的XML文件,与OOXML和MS Office传统二进制格式相比,它们很是大。

XLSX Excel 2007格式的有限功能和可能的限制

列数从256增长到16 384,工做表中的行数从65 536增长到1,048576。因为Excel 2007支持多个处理器和多线程芯片组,所以具备许多公式的大工做表计算得以加速。

如何直接从Delphi / Lazarus中保存到XLSX和XML Excel中

导出到XML

procedure TForm1.Button1Click(Sender: TObject);
begin
 {Generate a report. The report must be generated before exporting}
 frxReport1.PrepareReport();
 {Set the range of pages to export. By default, all pages of the generated report are exported}
 frxXMLExport1.PageNumbers := '2-3';
 {Set whether to generate a continuous document which skips headers and footers.
  Enabling this option disables TfrxXMLExport.ExportPageBreaks}
 frxXMLExport1.SuppressPageHeadersFooters := True;
 {Set whether to export the page breaks within the sheet of the book so that when printing the pages correspond to the pages of the generated report}
 frxXMLExport1.ExportPageBreaks := True;
 {Set WYSIWYG}
 frxXMLExport1.Wysiwyg := True;
 {Set the document splitting order using Split property which can take the following values:
  ssNotSplit – create a continuous document;
  ssRPages – each sheet of the generated report corresponds to the sheet of the book;
  ssPrintOnPrev – each sheet of TfrxReportPage in the report template corresponds to a sheet of the book (provided that TfrxReportPage.PrintOnParent = False);
  ssRowsCount - each sheet will have the number of rows specified in the TfrxXMLExport.RowsCount property.}
 frxXMLExport1.Split := ssNotSplit;
 {Set whether to open the resulting file after export}
 frxXMLExport1.OpenAfterExport := False;
 {Set whether to display export progress
  (show which page is currently being exported)}
 frxXMLExport1.ShowProgress := False;
 {Set whether to display a dialog box with export filter settings}
 frxXMLExport1.ShowDialog := False;
 {Set the name of the resulting file.}
 {Please note that if you do not set the file name and disable the export filter dialog box,}
 {the file name selection dialog will still be displayed}
 frxXMLExport1.FileName := 'C:\Output\test.xls';
 {Export the report}
 frxReport1.Export(frxXMLExport1);
end;

导出到XLSX

procedure TForm1.Button2Click(Sender: TObject);
begin
 {Generate a report. The report must be generated before exporting}
 frxReport1.PrepareReport();
 {Set the range of pages to export. By default, all pages of the generated report are exported}
 frxXLSXExport1.PageNumbers := '2-3';
 {Set whether to generate a continuous document which skips empty rows, headers and footers (with EmptyLines = False).
  With EmptyLines = True the report will be exported as it was generated. Without skipping the empty rows, headers and footers.
  Enabling this option disables TfrxXLSXExport.SuppressPageHeadersFooters and vice versa)
  frxXLSXExport1.EmptyLines := True;
  {Set whether to export the page breaks within the sheet of the book so that when printing the pages correspond to the pages of the generated report}
 frxXLSXExport1.ExportPageBreaks := True;
 {Set WYSIWYG}
 frxXLSXExport1.Wysiwyg := True;
 {Set whether to export only the content of data bands}
 frxXLSXExport1.DataOnly := False;
 {Set the document splitting order:
  with the SingleSheet option on, all pages of the document will be located on one sheet
  frxXLSXExport1.SingleSheet := True;
  If you set the value to ChunkSize, each sheet will have a specified number of rows.
  In this case SingleSheet should be set to False
  frxXLSXExport1.ChunkSize := 50;
  We will set the default order when each sheet of the generated report corresponds to a sheet of the book}
 frxXLSXExport1.SingleSheet := False;
 frxXLSXExport1.ChunkSize := 0;
 {Set whether to open the resulting file after export}
 frxXLSXExport1.OpenAfterExport := False;
 {Set whether to display export progress
  (show which page is currently being exported)}
 frxXLSXExport1.ShowProgress := False;
 {Set whether to display a dialog box with export filter settings}
 frxXLSXExport1.ShowDialog := False;
 {Set the name of the resulting file.}
 {Please note that if you do not set the file name and disable the export filter dialog box,}
 {the file name selection dialog will still be displayed}
 frxXLSXExport1.FileName := 'C:\Output\test.xlsx';
 {Export the report}
 frxReport1.Export(frxXLSXExport1);
end;

若是您有任何疑问或需求,请随时加入FastReport技术交流群(783996712),咱们很高兴为您提供查询和咨询

相关文章
相关标签/搜索