Hey. Thank you for your answer. I've tried aspose.words.15.2 and I've still got the same issue.
Here is a little sample code to see what I need :
public static void main(String[] args) throws Exception {
String fileName = "D:\\ASPOSETEST\\blankmodel.docx";
// String fileName = "D:\\ASPOSETEST\\manuallyfilledmodel.docx";
// String fileName = "D:\\ASPOSETEST\\asposefilledmodel.docx";
Document doc = new Document(fileName);
readSdtTypes(doc);
// replacePlaceHolderText(doc);
}
public static void readSdtTypes(Document doc) {
NodeCollection sdtNodes = doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true);
Iterator it = sdtNodes.iterator();
while (it.hasNext()) {
StructuredDocumentTag sdt = (StructuredDocumentTag) it.next();
Iterator subIt = sdt.iterator();
while (subIt.hasNext()) {
Node subNode = subIt.next();
System.out.println(subNode.getNodeType());
}
}
}
public static void replacePlaceHolderText(Document doc) throws Exception {
String destFile = "D:\\ASPOSETEST\\asposefilledmodel.docx";
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection sdtNodes = doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true);
Iterator it = sdtNodes.iterator();
while (it.hasNext()) {
StructuredDocumentTag sdt = (StructuredDocumentTag) it.next();
Run run = (Run) sdt.getChild(NodeType.RUN, 0, true);
if (run != null) {
run.setText("Hello");
}
}
doc.save(destFile);
}
I have attached 3 files :
blankmodel.docx which is the empty file with just a content control.
manuallyfilledmodel.docx which is the blankmodel with something written manually into it via Word 2010.
asposefilledmodel.docx which is the blankmodel filled with the code above (replacePlaceHolderText).
(the password is rmsdoc if you need the authorization).
If you run the readSdtTypes with the 3 files, you'll have 21 for blankmodel and asposefilledmodel, and 21, 9, 10, 21 for the manuallyfilledmodel.
You can see that the difference between the files is that in the manually filled file, you can select any letter and click anywhere in the content control. I'm pretty sure that it's because of the 9 and 10 NodeTypes, the editable ranges.
So what I want is to be able to produce a manuallyfilledmodel.docx using my replacePlaceHolderText method. How can I add these EditableRangeStart and End nodes to my run to obtain the same editable field that I have in the manuallyfilledmodel.docx ? I'm not able to do it because these NodeTypes can't be instantiated. Is there any method to do that ?
I hope you understand what I mean and come up with a solution. Thank you !