I was able to do what I needed using jopendocument and xpath. Here is a
quick summary.
0. ODSingleXMLDocument xmldoc = new ODPackage(new
File("input.odt")).toSingle();
1. use xpath.selectNodes to find the elements: tables are:
".//table:table"
and other elements are: ".//text:p|.//text:span|.//text:h"
e.g.
xmldoc.getXPath(".//text:p").selectNodes(xmldoc.getDocument().getRootEle
ment());
2. for each table t returned by the xpath query:
Int rowCount = t.getRowCount();
Int colCount = t.getColumnCount();
MutableCell<ODSingleXMLDocument> cell = t.getCellAt (col, row);
Cell.replaceBy(old, new);
Also
t.duplicateRows(row, 1, duplicateCount) as necessary if you need to
expand the table.
3. for each element e returned by the xpath query:
e.setText(e.getText().replace (old, new))
4. xmldoc.saveAs(File f)
My imports look like this:
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.xpath.XPath;
import org.jopendocument.dom.ODPackage;
import org.jopendocument.dom.ODSingleXMLDocument;
import org.jopendocument.dom.spreadsheet.MutableCell;
import org.jopendocument.dom.spreadsheet.Table;
import org.jopendocument.model.OpenDocument;
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Arun
Sent: Thursday, February 10, 2011 9:07 AM
To: jOpenDocument
Subject: [jopendocument] Re: simple ODT manipulation
Please send the files to me also.
Expecting reply at the earliest,