You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by magicsmacks <cl...@hotmail.com> on 2012/11/25 14:52:01 UTC

Copy a simple docx file

Hello,

I am trying to copy a docx file with XWPF into an other dock file.
But when I did it, all the organization (fonts, size, return...) of the file
was lost.
Could you help me ?
This is my code :
                                    FileInputStream fis = new
FileInputStream(file);
        		            org.apache.poi.xwpf.extractor.XWPFWordExtractor
oleTextExtractor =
        		            new XWPFWordExtractor(new XWPFDocument(fis));
        		            System.out.print(oleTextExtractor.getText());      
        		            
        		            XWPFDocument document = new XWPFDocument(); 
        		            XWPFParagraph tmpParagraph =
document.createParagraph(); 
        		            XWPFRun tmpRun = tmpParagraph.createRun(); 
        		            tmpRun.setText(oleTextExtractor.getText()); 
        		            document.write(new FileOutputStream(new
File("/Users/output.docx")));
Thank you for your help.

Magicsmacks



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Copy-a-simple-docx-file-tp5711538.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: Copy a simple docx file

Posted by magicsmacks <cl...@hotmail.com>.
Thank you for your help



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Copy-a-simple-docx-file-tp5711538p5711557.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: Copy a simple docx file

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Sorry, cannot help you there. You will need to wait for someone else to
respond. Might even be worth posting with a title that asks how to search
for and replace text in an OOXML format Word file.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Copy-a-simple-docx-file-tp5711538p5711553.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: Copy a simple docx file

Posted by magicsmacks <cl...@hotmail.com>.
Thank you for your answer!
Indeed, I will want to modify this text later.
For a .doc file with HWPF I used the range.replaceText() function.
But for a .docx, Is there any function which allows to replace a specific
text like with a HWPF? And Could I use the same code before ?
Thank you for your help.

Magicsmacks



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Copy-a-simple-docx-file-tp5711538p5711550.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: Copy a simple docx file

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Do you just want to copy the document or are you going to make changes to it
later?

Assuming all you want to do is copy it, then simply use Java's streaming
capabilities (FileInputStream and FileOutputStream) to do so. Even if you do
still want to use XWPF, then all you need to do is create a new XWPFDocument
and then call the write method supplying a stream that links to the new
location of the file;

 FileInputStream fis = new FileInputStream(file);
 XWPFDocument document = new XWPFDocument(fs);
 document.write(new FileOutputStream(new File("/Users/output.docx"))); 

and that ought to copy the file for you.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Copy-a-simple-docx-file-tp5711538p5711546.html
Sent from the POI - User mailing list archive at Nabble.com.

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