MS Word 2016 Shows Warning Message when EditableRange is used using Java

Hi,
We had previously a problem ( WORDSNET-18693) with locked documents when Document Header was protected with password.
We do see now that we are getting a new problem when merging Docx documents, which leaves two section breaks :frowning:
Code is basically unchanged (workaround to unlock document is still in place).After conversion.png (2.3 KB)
Before conversion.png (1.7 KB)

@jkrauseno

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi again,
Sorry for late reply, didn’t manage to do anything during the weekend :frowning: Files.zip (339.5 KB)

See attached documents and java source code (compiled with Java 1.7).

I’ve been testing this with 19.5 code base as well as 20.8, which apparently is the last one I can use according to current license(?!).

Jørg

@jkrauseno

You are using Document.appendDocument method in your code. We suggest you please use DocumentBuilder.insertDocument method as shown below to remove the section break at the start of document. Hope this helps you.

// Headers are still here, let's remove them
System.out.println("Number of headers after removeAllChildren: "
        + newDocument.getFirstSection().getHeadersFooters().getCount());
builder.moveToDocumentStart();
builder.insertDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);
/*doc.getFirstSection().getPageSetup()
        .setSectionStart(SectionStart.CONTINUOUS);
newDocument
        .appendDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);
newDocument.getSections().get(1).getHeadersFooters()
        .linkToPrevious(true);
*/
System.out.println("Source document appended");

Hi,

thanks for your valuable input. I checked it with both 19.5 and 20.8, and the additional section break is NOT inserted any longer.

Remains to handle the issue with the license…

Jørg

Hi again,
We have now installed the modification at the client, and running into a weird problem when they’re opening their converted documents, unfortunately.

Getting a message box (only available in Norwegian I’m afraid), but basically is says

“some of the regions you can edit overlap, and it’s not possible to show them at the same time.”

We’ve been testing this all sorts of ways, but we don’t get this message in our environment (Word 365). The customer is using Word 2016 though, but I’m struggling to see the relevance.

The code is exactly the same, and I’m adding source, target and template file as usual. Unfortunately, I don’t have any CPUs running Word 2013 or 2016, so I can’t check this.

Hopefully you’ll be able to see anything?

Documents.zip (112.7 KB)

@jkrauseno

Yes, we noticed this message using MS Word 2016.

Please create a simple Java application (source code without compilation errors) that generates the problematic output. We will investigate the issue and provide you more information on it.

Hi, it’s the same application as before? Do you still have it?

Jørg

AsposeTest.zip (2.6 KB)

In case you don’t find :slight_smile:

@jkrauseno

We have logged this problem in our issue tracking system as WORDSNET-21906. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@jkrauseno

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-21906) as ‘Not a Bug’.

Please use the following code example to get the desired output. Hope this helps you.

Document doc = new Document(MyDir + "Source.docx");

System.out.println("Opening template document in Aspose");
Document docTemplate = new Document(MyDir + "Template.docx");
Document newDocument = docTemplate.deepClone();

DocumentBuilder builder = new DocumentBuilder(newDocument);
builder.moveToDocumentStart();
builder.insertDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);

for(EditableRangeStart start : (Iterable<EditableRangeStart>)newDocument.getChildNodes(NodeType.EDITABLE_RANGE_START, true))
    start.getEditableRange().remove();

newDocument.protect(ProtectionType.READ_ONLY);

newDocument.save(MyDir + "Target with new header.docx",com.aspose.words.SaveFormat.DOCX);