Hi,

Can anyone help? I am not sure if it's possible to append two Word documents 
using POI, I really appreciate if anyone could point me to the right direction?

Kind regards,
ShuiChen

--- On Tue, 1/17/12, Shuichen Zhang <[email protected]> wrote:

> From: Shuichen Zhang <[email protected]>
> Subject: POI XWPF: how to copy a picture from one XWPFDocument to another
> To: "POI Users List" <[email protected]>
> Date: Tuesday, January 17, 2012, 1:53 PM
> Hello,
> 
> I want to append one XWPF document to another main document.
> I am going through all BodyElements in the document and
> copying every BodyELement to the main document. 
> 
> The problem with my current approach is that the
> getElementType() only returns "PARAGRAPH" or "TABLE".  If a
> pragraph contains a picture (PNG), it seems that the the
> picture cannot be copied over using setParagraph() method
> (please see my code block in below).
> 
> Would anyone advise how to copy a picture from one
> XWPFDocument to another? I am new to the XWPF API, or is
> there any better way to append one document to
> another?  Thanks in advance.
> 
> Best regards,
> ShuiChen
> 
> // start of code block
> XWPFDocument doc = new XWPFDocument(new
> FileInputStream(appFile));
> XWPFDocument maindDoc = new XWPFDocument(new
> FileInputStream(mainFile));
> 
> List elementList = doc.getBodyElements();    
> List paragraphList = doc.getParagraphs();
> List tableList = doc.getTables();        
>         
> for (int i = 0; i < elementList.size(); i++){
>   IBodyElement element = (IBodyElement)
> elementList.get(i);
>   if
> (element.getElementType().toString().equals("PARAGRAPH")) {
> 
>     // copying the paragraph to the main document 
>     paragraph = mainDoc.createParagraph();
>     paragraph = (XWPFParagraph)
> paragraphList.get(doc.getParagraphPos(i));
>     mainDoc.setParagraph(paragraph,
> doc.getParagraphPos(i));
> 
>   } else if
> (element.getElementType().toString().equals("TABLE")) {
>     XWPFTable table = (XWPFTable)
> tableList.get(doc.getTablePos(i));
>                 
>     // copying the table to the main document
>     table = mainDoc.createTable(); 
>     table = (XWPFTable)
> tableList.get(doc.getTablePos(i));
>     mainDoc.setTable(doc.getTablePos(i), table);
> 
>   }
> }
> // end of code block
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
>

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

Reply via email to