How to Search and Replace in calc (ods) OpenOffice document

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
liste
Posts: 2
Joined: Thu Nov 13, 2014 12:47 pm

How to Search and Replace in calc (ods) OpenOffice document

Post by liste »

I am using Delphi Vcl and I want to use Search&Replace command in openoffice or libreoffice calc program. there is one example in here (http://stackoverflow.com/questions/7806 ... e-document ) but it is work in only odt file. I need for ods (calc) Find&Replace code for pascal or delphi
thanks for helps
OpenOffice 4.1 on Windows 7
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: How to Search and Replace in calc (ods) OpenOffice docum

Post by karolus »

Hallo

In Case of Calc-files the Method ..createReplaceDescriptor is available on Ranges like single sheets.

Code: Select all

...
sheet : = StarDocument.Sheets.getByIndex(0);
FileReplace := sheet.CreateReplaceDescriptor;
....

sheet.ReplaceAll(FileReplace); 
Karolus
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: How to Search and Replace in calc (ods) OpenOffice docum

Post by Charlie Young »

I would add that there is one poorly documented property of the SearchDescriptor which is specific to Calc:

SearchType (not included in API-reference ) integer - Determines if the search should be done in cell formulas (0) values (1) or notes (2). [Calc only]
Apache OpenOffice 4.1.1
Windows XP
liste
Posts: 2
Joined: Thu Nov 13, 2014 12:47 pm

Re: How to Search and Replace in calc (ods) OpenOffice docum

Post by liste »

hi Karolus

Thanks for answer. I try to test that code but there is no Create Replace Descriptor event on sheet object can you send me small sample?
karolus wrote:Hallo

In Case of Calc-files the Method ..createReplaceDescriptor is available on Ranges like single sheets.

Code: Select all

...
sheet : = StarDocument.Sheets.getByIndex(0);
FileReplace := sheet.CreateReplaceDescriptor;
....

sheet.ReplaceAll(FileReplace);
Karolus
OpenOffice 4.1 on Windows 7
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: How to Search and Replace in calc (ods) OpenOffice docum

Post by karolus »

I'm only tell you what I've inspected with the Help ofMRI
Use the tool by yourself!
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: How to Search and Replace in calc (ods) OpenOffice docum

Post by Charlie Young »

liste wrote:hi Karolus

Thanks for answer. I try to test that code but there is no Create Replace Descriptor event on sheet object can you send me small sample?
karolus wrote:Hallo

In Case of Calc-files the Method ..createReplaceDescriptor is available on Ranges like single sheets.

Code: Select all

...
sheet : = StarDocument.Sheets.getByIndex(0);
FileReplace := sheet.CreateReplaceDescriptor;
....

sheet.ReplaceAll(FileReplace); 
Karolus
These things are case sensitive, try createReplaceDescriptor.
Apache OpenOffice 4.1.1
Windows XP
Post Reply