We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How can I add EditableRangeStart and EditableRangeEnd to a StructuredDocumentTag?

Hi,

I am generating documents from a word template that contains Content controls. In the template the document has the default placeholder text (click here to input text), I can edit it manually and then read the document with aspose. The authorizations are limited and you can only edit or delete what's inside the content controls.

The content control has these nodes :

EditableRangeStart (nodetype 11)

Run (nodetype 21)

EditableRangeEnd (nodetype 12)

If I read the document with aspose and try to modify the default placerholder text with the following code :

Run run = (Run) node.getChild(NodeType.RUN,0,true);

run.setText("text");

It works but then my content control only has a run and no editable range. It is then impossible to edit the text directly in the document (you can only delete it, like when you got the default placeholder text) and you can't modify the paragraph format options either.

I tried adding the editable range in my StructuredDocumentTag but I can't instantiate those classes. Are there any methods to do that ?

I am currently working with aspose.words-14.5.0.

Thank you for your help !

Hi David,


Thanks for your inquiry. Please try using Aspose.Words for Java 15.2.0 and see how it goes on your end. I hope, this helps.

In case the problem still remains, please attach your input/output Word documents here for testing. We will investigate the issue on our end and provide you more information.

Best regards,

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 !


Hi David,

Thanks for the additional information.

The problem occurs even when you save "blankmodel.docx" to .docx format using Aspose.Words 15.2.0 using the following two lines of code.

Document doc = new Document(getMyDir() + "blankmodel.docx");
doc.save(getMyDir() + "out.docx");

I have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-11701.

Secondly, currently EditableRangeStart, EditableRangeEnd and EditableRange classes don't have any public constructors which can be used to define new Editable ranges. This problem will be addressed by WORDSNET-9000.

Your thread has been linked to the appropriate issues and you will be notified as soon as they are resolved. Sorry for the inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-11701) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as WORDSNET-9000) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(7)