WINSOFT components and applications

Libre

Libre

Delphi library for automating LibreOffice.
Download Libre 3.5 trial version
Download demo example
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)
Order Winsoft Component Package

FAQ

How can I close a spreadsheet or text document?

const Closeable: XCloseable = CoXCloseable.Create(SpreadsheetDocument);
Closeable.close(False);

const Closeable: XCloseable = CoXCloseable.Create(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.Create(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.Create(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.Create(SpreadsheetDocument);
const SelectionSupplier: XSelectionSupplier = CoXSelectionSupplier.Create(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.Create(CellRange);
const Column = ColumnRowRange.getColumns.getByIndex(0);

const PropertySet: XPropertySet = CoXPropertySet.Create(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 select text?

const Libre: ILibre = CoLibre.Create;
const TextDocument = Libre.OpenTextDocument('C:\document.odt');
const Model: XModel = CoXModel.Create(TextDocument);

const TextViewCursorSupplier: XTextViewCursorSupplier = CoXTextViewCursorSupplier.Create(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.Create(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.Create(TextDocument);
const Bookmarks = BookmarksSupplier.getBookmarks;
const Element = Bookmarks.getByName(Bookmarks.getElementNames[0]); // the first bookmark
const TextContent: XTextContent = CoXTextContent.Create(Element);

const Model: XModel = CoXModel.Create(TextDocument);
const TextViewCursorSupplier: XTextViewCursorSupplier = CoXTextViewCursorSupplier.Create(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.Create(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.Create(TextDocument.getCurrentController.getFrame.getContainerWindow);
const Toolkit: XToolkit2 = CoXToolkit2.Create(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: PropertyValue = CoPropertyValue.Create(Libre.IdlReflection);
FilterName.Name := 'FilterName';
FilterName.Value := 'writer_pdf_Export';

const FilterOptions: PropertyValue = CoPropertyValue.Create(Libre.IdlReflection);
FilterOptions.Name := 'FilterOptions';
FilterOptions.Value := '{"PageRange": {"type": "string", "value": "1-2"}}';

const Storable: XStorable = CoXStorable.Create(TextDocument);
Storable.storeToURL(ToFileUrl('C:\document.pdf'), VarArrayOf([FilterName.ComObject, FilterOptions.ComObject]));

Useful Links

Icon Professional Delphi Library for Automating the LibreOffice

Icon Direct Office
Icon Office Component Suite
Icon Office XML

Icon LibreOffice
Icon LibreOffice API Documentation
Icon LibreOffice Programming
Icon Automation Bridge