Search and Replace in Writer with Delphi

postado em 28 de nov. de 2011 05:58 por Gustavo Pacheco

First of all, download and open Delphi OOo, an excellent toolbox to use Delphi with LibreOffice. You can find Delphi OOo here.

Then, use this piece of code to open a template, search and replace text and generate a PDF file:


fileProp3, fileProp4, oReplace, myTemplate: Variant;

myFile3, myFile4: String;


myFile3:= convertToURL('D:\');

fileProp3:= CreateProperties(['AsTemplate', true]);

myTemplate := StarDesktop.LoadComponentFromURL(myFile3, '_blank', 0, fileProp3);

oReplace := myTemplate.createReplaceDescriptor;


oReplace.setReplaceString('New content!');


fileProp4:= CreateProperties(['FilterName', 'writer_pdf_Export']);

myFile4:= convertToURL('C:\new_document.pdf');

myTemplate.storeToURL(myfile4, fileProp4);

Delphi 7,  LibreOffice 3.4.2, Windows XP SP 3.