Search and Replace

From Apache OpenOffice Wiki
Jump to: navigation, search

The cell range interface is derived from providing search and replacement of text.

  • The method createReplaceDescriptor() creates a new descriptor that contains all data for the replace action. It returns the interface of this descriptor.
  • The method replaceAll() performs a replacement in all cells according to the passed replace descriptor.

The following example replaces all occurrences of "cell" with "text":

 // --- Replace text in all cells. --- xReplace = (
     UnoRuntime.queryInterface(, xCellRange); xReplaceDesc = xReplace.createReplaceDescriptor();
 // property SearchWords searches for whole cells!
 xReplaceDesc.setPropertyValue("SearchWords", new Boolean(false));
 int nCount = xReplace.replaceAll(xReplaceDesc);
 System.out.println("Search text replaced " + nCount + " times.");  
Documentation note.png The property SearchWords has a different meaning in spreadsheets: If true, only cells containing the whole search text and nothing else is found. If false, cells containing the search string as a substring is found.
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages