Search and Replace in Writer with Delphi
First of all, download and open Delphi OOo, an excellent toolbox to use Delphi with BrOffice.org, LibreOffice or OpenOffice.org. 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:\template.ott');
fileProp3:= CreateProperties(['AsTemplate', true]);
myTemplate := StarDesktop.LoadComponentFromURL(myFile3, '_blank', 0, fileProp3);
oReplace := myTemplate.createReplaceDescriptor;
oReplace.setSearchString('field1');
oReplace.setReplaceString('New content!');
myTemplate.ReplaceAll(oReplace);
fileProp4:= CreateProperties(['FilterName', 'writer_pdf_Export']);
myFile4:= convertToURL('C:\new_document.pdf');
myTemplate.storeToURL(myfile4, fileProp4);
Delphi 7, BrOffice.org/OpenOffice.org 3.2.1, Windows XP SP 3.
- Blog de gbpacheco
- 3374 leituras
