Skip to content

Unable to replace paragraph in ODF Text Document #235

Description

@rsoika

I need to replace a text fragment of a ODT Text Document with a new text.
My code looks something like this:

	private void replaceODFTextFragment(OdfTextDocument doc, String pattern, String replace)
			throws InvalidNavigationException {
		TextNavigation searchPattern = new TextNavigation(pattern, doc);
		while (searchPattern.hasNext()) {
			logger.info("..found match "+pattern + "    -----> Replace: "+replace);
			TextSelection textSelection = (TextSelection) searchPattern.getCurrentItem();
			textSelection.replaceWith(replace);
			break;
		}

	}

But this is not working.
The OdfTextDocument is not updated at all.

Also it is not possible to navigate to the next element as stated in the documentation [here](https://odftoolkit.org/api/odfdom/org/odftoolkit/odfdom/incubator/search/Navigation.html#getNextMatchElement(org.w3c.dom.Node).

There is no getNextMatchElement method in version 0.11.0 of this project.

Can anybody help me out here.

I use the library successful for OdfSpreadsheetDocument objects and this works well.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions