Difference between revisions of "Documentation/DevGuide/Spreadsheets/Search and Replace"
From Apache OpenOffice Wiki
< Documentation | DevGuide
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Spreadsheet Documents) |
m |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 6: | Line 6: | ||
|NextPage=Documentation/DevGuide/Spreadsheets/Sorting | |NextPage=Documentation/DevGuide/Spreadsheets/Sorting | ||
}} | }} | ||
− | {{DISPLAYTITLE:Search and Replace}} | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}} |
+ | {{DISPLAYTITLE:Search and Replace}} | ||
<!--<idltopic>com.sun.star.util.XReplaceable</idltopic>--> | <!--<idltopic>com.sun.star.util.XReplaceable</idltopic>--> | ||
The cell range interface <idl>com.sun.star.util.XReplaceable</idl> is derived from <idl>com.sun.star.util.XSearchable</idl> providing search and replacement of text. | The cell range interface <idl>com.sun.star.util.XReplaceable</idl> is derived from <idl>com.sun.star.util.XSearchable</idl> providing search and replacement of text. | ||
* The method <code>createReplaceDescriptor()</code> creates a new descriptor that contains all data for the replace action. It returns the interface <idl>com.sun.star.util.XReplaceDescriptor</idl> of this descriptor. | * The method <code>createReplaceDescriptor()</code> creates a new descriptor that contains all data for the replace action. It returns the interface <idl>com.sun.star.util.XReplaceDescriptor</idl> of this descriptor. | ||
− | * The method <code>replaceAll()</code> performs a replacement in all cells according to the passed | + | * The method <code>replaceAll()</code> performs a replacement in all cells according to the passed replacedescriptor. |
The following example replaces all occurrences of "cell" with "text": | The following example replaces all occurrences of "cell" with "text": | ||
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]--> | <!--[SOURCE:Spreadsheet/SpreadsheetSample.java]--> | ||
− | + | <syntaxhighlight lang="java"> | |
// --- Replace text in all cells. --- | // --- Replace text in all cells. --- | ||
com.sun.star.util.XReplaceable xReplace = (com.sun.star.util.XReplaceable) | com.sun.star.util.XReplaceable xReplace = (com.sun.star.util.XReplaceable) | ||
Line 26: | Line 27: | ||
int nCount = xReplace.replaceAll(xReplaceDesc); | int nCount = xReplace.replaceAll(xReplaceDesc); | ||
System.out.println("Search text replaced " + nCount + " times."); | System.out.println("Search text replaced " + nCount + " times."); | ||
− | + | </syntaxhighlight> | |
− | {{ | + | {{Note|The property <tt>SearchWords</tt> 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.}} |
{{PDL1}} | {{PDL1}} | ||
− | [[Category:Documentation/ | + | [[Category:Documentation/Developer's Guide/Spreadsheet Documents]] |
Latest revision as of 13:23, 5 March 2021
The cell range interface com.sun.star.util.XReplaceable is derived from com.sun.star.util.XSearchable 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 com.sun.star.util.XReplaceDescriptor of this descriptor. - The method
replaceAll()
performs a replacement in all cells according to the passed replacedescriptor.
The following example replaces all occurrences of "cell" with "text":
// --- Replace text in all cells. --- com.sun.star.util.XReplaceable xReplace = (com.sun.star.util.XReplaceable) UnoRuntime.queryInterface(com.sun.star.util.XReplaceable.class, xCellRange); com.sun.star.util.XReplaceDescriptor xReplaceDesc = xReplace.createReplaceDescriptor(); xReplaceDesc.setSearchString("cell"); xReplaceDesc.setReplaceString("text"); // 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.");
Content on this page is licensed under the Public Documentation License (PDL). |