快速學會使用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),咱們很高興爲您提供查詢和諮詢

相關文章
相關標籤/搜索