Creating an Open Documents Spreadsheet from Delphi / C++Builder / Lazarus

Summary of ODS and ODF

ODS is an open format for spreadsheets made in accordance with the OpenDocument Format (ODF) standard. This format is distributed free of charge and uses the standards of the International Organization for Standardization. The standard was developed by OASIS technical committee and was based on the XML format; it was approved for release as an ISO and IEC International Standard under the name ISO/IEC 26300 on May 1, 2006. NATO made the Open Document Format (ODF) standard mandatory to support interoperability among the various national governments. Many countries have adopted ODF as a state standard.

ODF spreadsheets (one of the varieties of ODS) are simple, interactive files objects used to analyze, organize, and store all kinds of spreadsheet-based data.

ODS resources can be opened with any modern office suite, OpenOffice, LibreOffice Suite and MS Office (since 2007).

Since 2014, the ODF standard has been added to the Google Docs, Sheets, and Slides web applications. Now you can open, edit and save files with the .odt (text documents), .ods (spreadsheets) and .odp (presentations) extensions. On Android phones and tablets, the most comprehensive support of ods files is implemented in the AndrOpen Office application.

Each ODF document is stored in a zip archive, therefore, to open this document, it is enough to rename its extension to .zip and open it with any zip archiver. After that we will see at least five .xml files and several directories.

There is so-called metadata in these xml files, in addition to the actual content of the document. It is the additional data that allows you to set specific parameters for the text. For example, font type and size, text position on the page, print or display options.

The XML metadata description standard (eXtend Markup Language) is gaining the most popularity nowadays. The main requirement of this standard is being user-friendly: xml documents should be easily readable using the simplest word processors and xml-markup should be simple to understand by a person.

ODF is one of numerous implementations of the XML standard. Therefore, after opening the ODF document as a ZIP archive, it won’t be a big deal to understand the structure of files and folders by their names. Especially for those who at least once in their life created html pages, at least at the same level of “Hello, World!” stuff. Content.xml is the main content file and style.xml contains the style information. Folders can contain multimedia files: pictures, audio and video. In general, the ODF document is something like a web site from the times of static html pages.

Now we learned about the format itself, but how do we save a report with the .ods extension? In fact, it’s extremely easy. We can create the simplest document and unzip it, as mentioned above. Let me remind you that the standard is open. Or… we can do it our favorite way!

Saving in .ODS format from Delphi using FastReport

Before saving an .ods file, you should already have a compiled project with FastReport implemented with the Export to Open Documents Spreadsheet component, as well as the generated report (there is a separate article on creating repots). Let me remind you again – yes, you can use internal sources of the application and databases as a data source for your report. Run the application and call export from the preview window (at the end of this article there is a way how to save the .ODS file directly from the code), a settings window will appear:

  

FastReport tools allow you to choose which pages of our document to export, certain pages or a range.

Export settings – whether to set a better visual correspondence with the original version (WYSIWYG), use page breaks, export as a continuous document that skips headers and footers, or export a background – graphic objects, that are used as a background of the report page.

As usual, you can specify where to save your file (in the local storage, send as E-mail, upload to FTP or cloud storage).

Open after export - the resulting file will be opened immediately after export by any software associated with ODS files.

Full code for saving in Open Document Spreadsheet format directly from Delphi / Lazarus

Saving to ODS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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}
 frxODSExport1.PageNumbers := '2-3';
 {Set whether to generate a continuous document}
 frxODSExport1.SingleSheet := False;
 {Set whether to export the page breaks so that when printing the pages correspond to the pages of the generated report}
 frxODSExport1.ExportPageBreaks := True;
 {Set WYSIWYG}
 frxODSExport1.Wysiwyg := True;
 {Set whether to export the background}
 frxODSExport1.Background := True;
 {Set whether to open the resulting file after export}
 frxODSExport1.OpenAfterExport := False;
 {Set whether to display export progress (show which page is currently being exported)}
 frxODSExport1.ShowProgress := False;
 {Set whether to display the export filter dialog box}
 frxODSExport1.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}
 frxODSExport1.FileName := 'C:\Output\test.ods';
 {Export the report}
 frxReport1.Export(frxODSExport1);
end;

So, quickly and easily we can make our application to generate modern global format files. 

Fast Reports
  • 800-985-8986 (Englisch, die USA)
  • +4930568373928 (Deutsch)
  • +55 19 98147-8148 (Portugiesisch)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314

© 1998-2024 Fast Reports Inc.
Trustpilot