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
So, quickly and easily we can make our application to generate modern global format files.