Creating an Open Document Text (ODT) file from Delphi

Creating an Open Document Text (ODT) file from Delphi

The ODT file extension is used for Open Document text files, which are usually created using the OpenOffice or LibreOffice word processor apps. This document format is based on the XML markup language and therefore easy to convert.

To understand what kind of format it is, it’s enough to see the open standard OpenDocument Format (created by the OASIS community), directly associated with ODT. Since ODF can store and exchange office documents, it also includes the Open Document Text file extension, which contains various reports, notes, books and so on. We talked more about the ODF format in this article.

The ODT files became especially popular not long ago, in 2014, when the Google Docs web applications, along with Sheet and Slides, started supporting the ODF standard, so users had the opportunity to save text documents in the .odt format and this file extension started becoming more and more popular. These files are easy to open and thanks to the XML markup language you can easily convert them to other formats using the appropriate utilities.

To correctly open a file with the ODT extension, you need to use the office suites such as LibreOffice, StarOffice, OpenOffice – they allow you to freely convert and edit files of this format. If the user tries to open an ODT file using the Microsoft Office application, he will need to install the ODF Sun Plugin for MS Office. Many PC owners open ODT files using Corel WordPerfect Office, there are also NeoOffice and Lotus Symphony. In my opinion, the choice is wide!

Saving in ODT format from Delphi using FastReport

Why FastReport? Because it is designed for generating documents! First of all, we should already have a compiled project with FastReport implemented with the Export to Open Documents Text component, as well as the generated report (there is a separate article on creating reports). Run the application and call export from the preview window (at the end of this article there is a way how to save the .ODT 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 ODT files.

Code for saving in Open Document Text format directly from Delphi / Lazarus

Saving in ODT
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.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}
 frxODTExport1.PageNumbers := '2-3';
 {Set whether to generate a continuous document}
 frxODTExport1.SingleSheet := False;
 {Set whether to export the page breaks so that when printing the pages correspond to the pages of the generated report}
 frxODTExport1.ExportPageBreaks := True;
 {Set WYSIWYG}
 frxODTExport1.Wysiwyg := True;
 {Set whether to export the background}
 frxODTExport1.Background := True;
 {Set whether to open the resulting file after export}
 frxODTExport1.OpenAfterExport := False;
 {Set whether to display export progress (show which page is currently being exported)}
 frxODTExport1.ShowProgress := False;
 {Set whether to display the export filter dialog box}
 frxODTExport1.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}
 frxODTExport1.FileName := 'C:\Output\test.odt';
 {Export the report}
 frxReport1.Export(frxODTExport1);
end;

Comparison of Microsoft Word 2007 XML and Open Document Text

So what is better to use? Let’s learn about their base. Both of them are based on the XML markup language. XML is a technology designed to manage structured data and display that data as a human-readable text file. XML conforms to industry standards and can be processed by many databases and applications. Using XML, many developers can create their own customized tags, data structures, and schemas. In general, XML greatly facilitates the definition, transfer, validation, and interpretation of data in various databases, applications, and organizations. This means that both files are zip archives renamed as .docs / .odt.

Let’s talk about the features and functionality. Attaching your comments to specific parts of a document makes your feedback more clear; there is a “Notes” function for this. When you save the document in .odt format and open it again in Word 2007, comments about a group of words becomes a single point. The single point is usually indicated at the end of the group of words. Tables are not supported in comments. The contents of the table are maintained in the comment but the structure is lost.

Speaking about the documents and data protection, we should remember about the “Document Protection” and “Information rights management (IRM)” functions. When you save a Word 2007 document in ODT format, this function is deleted; you cannot open such files.

Though everyone’s favorite correction function, which saved many of us, will not work in ODT or rather all changes are accepted and your information may suffer. References and headers are converted to plain text, and footnotes simply disappear.

Frames are partially supported. When saving a Word 2007 document in ODT format frames are converted to text fields; bindings to some field areas are not supported. If unsupported content is present, the frame is deleted, but not the content itself. This includes tables, auto shapes, text fields, frames, and SmartArt graphics.

When you save the Word 2007 document in .odt format, continuous section breaks might lose some properties, such as top/bottom margins, headers/footers, borders, and line numbering.

Tables are partially Supported. ODT format doesn’t support tables with more than 64 columns and theme formatting is converted to cell level formatting. Text boxes cannot be nested and text orientation in a table cell is not supported.

Speaking about graphic elements, something works in any format but something is not supported at all. Word does not support groups of objects so when you open an OpenDocument file, the objects are ungrouped. This applies to all objects grouped with a diagram, as well as to drawings grouped with a figure, caption or OLE object. The visibility of objects may change. Invisible objects become visible after saving the file in .odt and opening again in Word.

I can go on and on, but just highlighted the most interesting functions. You can find a detailed comparison table here


There is not much difference in file size. A Word document is a bit bigger because of encryption support; and ODT file doesn’t support it. We used these fish as an example; this document has a lot of text, tabular data and 30 photographs. See screenshots for clarity:

Let’s sum things up. Both formats are modern, open (which is important), supported by many text editors. The advantage of ODT is open source and OASIS community support, while DOCX is supported by Microsoft only which has now turned to Open Source initiatives. The choice is up to you and your customer – anyways, you can count on the creation of high-quality documents that support FastReport standards. 

Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314

© 1998-2024 Fast Reports Inc.
Trustpilot