Hi,
I have a .docx documents which contains a table with Bookmark “WI”.
When i upload the documents, i want to replace the entire table with new table while remaining the same bookmark . I tried below code, but the bookmark is gone after save. Could you please help on this?
String templateUrl = "C://TEST";
Document doc = new Document(templateUrl);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToBookmark("WI");
Table newTable = builder.startTable();
Bookmark bookmark = doc.getRange().getBookmarks().get("WI");
Table table = (Table) bookmark.getBookmarkStart().getAncestor(NodeType.TABLE);
builder.insertCell();
builder.startBookmark("WI");
/// continue insert content
builder.endRow();
builder.endTable();
builder.endBookmark("WI");
table.getParentNode().insertBefore(newTable, table);
table.remove();
String fileName = woNum + "_" + sdf.format(today)+ ".docx";
String exportDir = tempFolder + fileName ;
doc.save(exportDir);