Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JODF
>
Tutorial
> Set bookmark text
The following example shows you how to update bookmark content.
import java.util.List; import com.independentsoft.office.odf.Bookmark; import com.independentsoft.office.odf.BookmarkStart; import com.independentsoft.office.odf.IParagraphContent; import com.independentsoft.office.odf.Paragraph; import com.independentsoft.office.odf.Text; import com.independentsoft.office.odf.TextDocument; public class Example { public static void main(String[] args) { try { TextDocument doc = new TextDocument("c:\\test\\input.odt"); List
paragraphs = doc.getParagraphs(); for (int i = 0; i < paragraphs.size(); i++) { for (IParagraphContent paragraphElement : paragraphs.get(i).getContent()) { if (paragraphElement instanceof Bookmark) { Bookmark bookmark = (Bookmark)paragraphElement; if (bookmark.getName().indexOf("BookmarkName") > -1) { for (IParagraphContent bookmarkElement : bookmark.getContent()) { if (bookmarkElement instanceof Text) { Text text = (Text)bookmarkElement; text.setValue("New Bookmark text"); } } } } else if (paragraphElement instanceof BookmarkStart) { BookmarkStart bookmarkStart = (BookmarkStart)paragraphElement; for (IParagraphContent bookmarkElement : bookmarkStart.getContent()) { if (bookmarkElement instanceof Text) { Text text = (Text)bookmarkElement; text.setValue("New Bookmark text"); } } } } } doc.save("c:\\test\\output.odt", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*