Libre
Delphi library for automating LibreOffice.
- Supports the complete LibreOffice API
- Compatible with Delphi versions 7 - 13
- Source code included with registered version
- Royalty-free distribution in applications
Order Libre license $120 USD (license for one developer)
Order Libre multi-license $360 USD (license for all developers in the company)
Order Libre year upgrades $60 USD (registered users only)
Order Libre year upgrades multi-license $180 USD (registered multi-license users only)
FAQ
How can I close a spreadsheet or text document?
const Closeable: XCloseable = CoXCloseable.Wrap(SpreadsheetDocument); Closeable.close(False); const Closeable: XCloseable = CoXCloseable.Wrap(TextDocument); Closeable.close(False);
How can I create, modify, or delete spreadsheets?
const Libre: ILibre = CoLibre.Create;
const Spreadsheets = Libre.CreateSpreadsheetDocument.getSheets;
// create new spreadsheets
Spreadsheets.insertNewByName('MySpreadsheet1', 0);
Spreadsheets.insertNewByName('MySpreadsheet2', 0);
// modify content of spreadsheet
const Spreadsheet: XSpreadsheet = CoXSpreadsheet.Wrap(Spreadsheets.getByName('MySpreadsheet1'));
const Cell = Spreadsheet.getCellByPosition(2, 2);
Cell.setFormula('Hello, world!');
// delete spreadsheet
Spreadsheets.removeByName('MySpreadsheet1');
How can I set cell properties?
const Cell = Spreadsheet.getCellByPosition(2, 2);
Cell.setFormula('Hello, world!');
const PropertySet: XPropertySet = CoXPropertySet.Wrap(Cell);
PropertySet.setPropertyValue('CharColor', $003399);
PropertySet.setPropertyValue('CharHeight', 20);
PropertySet.setPropertyValue('ParaLeftMargin', 500);
PropertySet.setPropertyValue('IsCellBackgroundTransparent', False);
PropertySet.setPropertyValue('CellBackColor', $99CCFF);
How can I select cells?
const Model: XModel = CoXModel.Wrap(SpreadsheetDocument);
const SelectionSupplier: XSelectionSupplier = CoXSelectionSupplier.Wrap(Model.getCurrentController);
const CellRange = Spreadsheet.getCellRangeByName('A1:C3');
SelectionSupplier.select(CellRange.ComObject);
How can I set the column width?
const CellRange = Spreadsheet.getCellRangeByName('C1');
const ColumnRowRange: XColumnRowRange = CoXColumnRowRange.Wrap(CellRange);
const Column = ColumnRowRange.getColumns.getByIndex(0);
const PropertySet: XPropertySet = CoXPropertySet.Wrap(Column);
PropertySet.setPropertyValue('Width', 5000);
How can I retrieve service names?
const Libre: ILibre = CoLibre.Create; for var ServiceName in Libre.MultiServiceFactory.getAvailableServiceNames do ShowMessage(ServiceName);
How can I retrieve available filters?
const Libre: ILibre = CoLibre.Create; for var FilterName in Libre.FilterFactory.getElementNames do ShowMessage(FilterName);
How can I select text?
const Libre: ILibre = CoLibre.Create;
const TextDocument = Libre.OpenTextDocument('C:\document.odt');
const Model: XModel = CoXModel.Wrap(TextDocument);
const TextViewCursorSupplier: XTextViewCursorSupplier = CoXTextViewCursorSupplier.Wrap(Model.getCurrentController);
const TextViewCursor = TextViewCursorSupplier.getViewCursor;
TextViewCursor.gotoStart(False);
TextViewCursor.gotoEnd(True);
How can I retrieve bookmarks?
const Libre: ILibre = CoLibre.Create;
const TextDocument = Libre.OpenTextDocument('C:\document.odt');
const BookmarksSupplier: XBookmarksSupplier_2 = CoXBookmarksSupplier_2.Wrap(TextDocument);
for var ElementName in BookmarksSupplier.getBookmarks.getElementNames do
ShowMessage(ElementName);
How can I move the cursor to a bookmark?
const Libre: ILibre = CoLibre.Create;
const TextDocument = Libre.OpenTextDocument('C:\document.odt');
const BookmarksSupplier: XBookmarksSupplier_2 = CoXBookmarksSupplier_2.Wrap(TextDocument);
const Bookmarks = BookmarksSupplier.getBookmarks;
const Element = Bookmarks.getByName(Bookmarks.getElementNames[0]); // the first bookmark
const TextContent: XTextContent = CoXTextContent.Wrap(Element);
const Model: XModel = CoXModel.Wrap(TextDocument);
const TextViewCursorSupplier: XTextViewCursorSupplier = CoXTextViewCursorSupplier.Wrap(Model.getCurrentController);
TextViewCursorSupplier.getViewCursor.gotoRange(TextContent.getAnchor, False);
How can I hide or disable the Writer window?
const Libre: ILibre = CoLibre.Create; const TextDocument = Libre.CreateTextDocument; const Window = TextDocument.getCurrentController.getFrame.getContainerWindow; Window.setEnable(False); // disable window Window.setVisible(False); // hide window Window.setEnable(True); // enable window Window.setVisible(True); // show window
How can I minimize or maximize the Writer window?
const Libre: ILibre = CoLibre.Create; const TextDocument = Libre.CreateTextDocument; const TopWindow: XTopWindow2 = CoXTopWindow2.Wrap(TextDocument.getCurrentController.getFrame.getContainerWindow); TopWindow.IsMinimized := True; // minimize TopWindow.IsMaximized := True; // maximize
How can I create and show a message box?
const Libre: ILibre = CoLibre.Create; const TextDocument = Libre.CreateTextDocument; const WindowPeer: XWindowPeer = CoXWindowPeer.Wrap(TextDocument.getCurrentController.getFrame.getContainerWindow); const Toolkit: XToolkit2 = CoXToolkit2.Wrap(WindowPeer.getToolkit); const MessageBox = Toolkit.XMessageBoxFactory.createMessageBox(WindowPeer, MessageBoxType_INFOBOX, MessageBoxButtons_BUTTONS_OK, 'Title', 'Message'); MessageBox.execute;
How can I specify the page range for PDF export?
const Libre: ILibre = CoLibre.Create;
const TextDocument = Libre.OpenTextDocument('C:\document.odt', True, False, True);
const FilterName = Libre.CreatePropertyValue('FilterName', 'writer_pdf_Export');
const FilterOptions = Libre.CreatePropertyValue('FilterOptions', '{"PageRange": {"type": "string", "value": "1-2"}}');
const Storable: XStorable = CoXStorable.Wrap(TextDocument);
Storable.storeToURL(ToFileUrl('C:\document.pdf'), VarArrayOf([FilterName, FilterOptions]));
How can I create bold text?
const TextCursor = Text.createTextCursor;
const PropertySet: XPropertySet = CoXPropertySet.Wrap(TextCursor);
PropertySet.setPropertyValue('CharWeight', Double(FontWeight_BOLD));
TextCursor.setString('Hello, world!');
How can I open a text document from memory?
const Libre: ILibre = CoLibre.Create; const Data = TFile.ReadAllBytes(GetCurrentDir + '\hello.odt'); const TextDocument = CoXTextDocument.Wrap(Libre.OpenDocument(Data));
How can I create a text document using string data?
const Libre: ILibre = CoLibre.Create;
const Data = TEncoding.UTF8.GetBytes('Hello, world!');
const TextDocument = CoXTextDocument.Wrap(Libre.OpenDocument(Data));
How can I store the text document to memory?
const Data = Libre.SaveDocumentData(CoXComponent.Wrap(TextDocument));