You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by gummadi krishna <kr...@yahoo.co.in> on 2010/11/03 17:32:41 UTC

Construct xwpfDocument from existing body

Hi ,

 I have a case where from a exisiting docx file i extract the document and save the document which is in xml format to DB like below :

    XWPFDocument olddoc = new XWPFDocument(fis);
     String strXml = olddoc.getDocument().toString();
	
 Now i want to open a new XWPFDocument with the existing body . So i did the below :
 XWPFDocument newPoiDoc = new XWPFDocument();
XmlObject xmlObj=XmlObject.Factory.parse(strXml);
 newPoiDoc.getDocument().addNewBody().set(xmlObj);

 newPoiDoc.save(os) ;

By doing this iam able to save a new doc file but when i open the file i am not able to see any images which were there in old file and formatting is also lost . How can i make sure not to loose fromatting and the images as in the old file

	



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Construct xwpfDocument from existing body

Posted by David Fisher <df...@jmlafferty.com>.
Hi,

Images are in a different part of the file.

I suggest that you take the .docx file make a copy with your filesystem and cahnge the suffix to .zip. You can then unzip the file and inspect the various parts of the OOXML.

If you do this you will better understand where those images are.

Regards,
Dave

On Nov 3, 2010, at 9:32 AM, gummadi krishna wrote:

> Hi ,
> 
> I have a case where from a exisiting docx file i extract the document and save the document which is in xml format to DB like below :
> 
>    XWPFDocument olddoc = new XWPFDocument(fis);
>     String strXml = olddoc.getDocument().toString();
> 	
> Now i want to open a new XWPFDocument with the existing body . So i did the below :
> XWPFDocument newPoiDoc = new XWPFDocument();
> XmlObject xmlObj=XmlObject.Factory.parse(strXml);
> newPoiDoc.getDocument().addNewBody().set(xmlObj);
> 
> newPoiDoc.save(os) ;
> 
> By doing this iam able to save a new doc file but when i open the file i am not able to see any images which were there in old file and formatting is also lost . How can i make sure not to loose fromatting and the images as in the old file
> 
> 	
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org