so look!!!
i'm reading a document
- Code: Select all
WordprocessingMLPackage.load(new File("C://model.docx"));
after this i'm creating an ArrayList of each elements on the body, because i need to identify where the tables are, to put a image. Up here is everything ok.
but before save the new document i'm using the header's model.docx to create my own like this:
- Code: Select all
HashMap<Integer, String> map = new HashMap<Integer, String>();
//here the map record each elements of body
map = inspectDocument(wordMLPackage);
ObjectFactory factory = new ObjectFactory();
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
Document wmlDocumentEl = documentPart.getJaxbElement();
//after to discoverer and map each elements of body i create a new body object to poputale
Body body = factory.createBody();
int i = 0;
while (i < map.size()) {
if (map.get(i).contains("inserir foto")) {
body.getEGBlockLevelElts().add(createTableWithPicture(ctg.getFotos(), wordMLPackage));
}
else if (map.get(i).equals("P")) {
body.getEGBlockLevelElts().add(wmlDocumentEl.getBody().getEGBlockLevelElts().get(i));
}
else if (map.get(i).equals("Tbl")) {
body.getEGBlockLevelElts().add(wmlDocumentEl.getBody().getEGBlockLevelElts().get(i));
}
i++;
}
SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
//and before to save the document i fill body's properties with model.docx
body.setSectPr(wmlDocumentEl.getBody().getSectPr());
body.setParent(wmlDocumentEl.getBody().getParent());
saver.save("C:\\relatório.docx");
but when i save the document, and try open it, the image on header was substitute with the others image there i had add on document.
i know that the error is :
- Code: Select all
body.setSectPr(wmlDocumentEl.getBody().getSectPr());
body.setParent(wmlDocumentEl.getBody().getParent());
but i don't know how to copy the header with the image and others attributes to add in my new document or change the name of the header's image in /word/media to solve the conflict.