Mark, 

I did what you suggested: 
1 - I created a very simple file and saved it as dotx and docx formats. 
2- I changed their formats to zip and then unzipped them and compared the
contents. 
3- There was a difference in contentType at "[Content_Types].xml" file (for
this part: PartName="/word/document.xml"). Also there were very few
differences in some other xml files which I think are not so important.

So I tried to change the contentType of the generated file. I ran your
program and passed a template having few bookmarks (.dotx template file),
then I called the following method after calling your save method. And now
word can open the file without any problem: 

private void changeContentType(String filename) {
        try{
    OPCPackage opcPackage = OPCPackage.open(new FileInputStream(filename));
        opcPackage.replaceContentType(
        
"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml",
        
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"
                );                      
        opcPackage.save(new FileOutputStream(filename));
    } catch (InvalidFormatException e) {
                e.printStackTrace();            
    } catch (IOException e) {
                e.printStackTrace();
        }
}       

I tried to change the contentType using the document object itself but it
did not work. That's why I had to create a new method and do another process
on the generated file! So, the question is that how can we modify the code
in a way that works with OPCPackage in first place? This way working with
templates will be pretty easy!

P.S: I am going to test the same for .dotm file(which has binary data as
well) and see what will happen!  I will update this comment and let you know
if it works. 


Thank you for your help,
Regards





--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/How-to-read-the-value-of-bookmarks-docx-tp5710184p5710754.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to