You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by spiritkill <ga...@gmail.com> on 2011/07/22 12:06:40 UTC

problem with the methode "replaceText()" and with save HWPFDocument

Hello everyone,

I have two problem with Poi api 3.7 and 3.8 (I tried both):

1) When I save a word document with poi, the fonts are not the same as the
original document.
I use this code:

            File iFile = new File("D:/empty.doc");
            File oFile = new File("D:/doc.doc");
            InputStream fis = new FileInputStream(iFile);
            POIFSFileSystem fs = null;
            HWPFDocument doc = null;
            try {
                fs = new POIFSFileSystem(fis);
            } finally {
                fis.close();
            }
            doc = new HWPFDocument(fs);

            OutputStream out = new FileOutputStream(oFile);
            try {
                doc.write(out);
                out.flush();
            } finally {
                out.close();
            }

The empty.doc file is:
http://apache-poi.1045710.n5.nabble.com/file/n4622539/empty.jpg 

The doc.doc file is:
http://apache-poi.1045710.n5.nabble.com/file/n4622539/doc.jpg 

The fonts are not same.


2) The method "replaceText(String,String)" has corrupted the Word file.
I use this code:

            File iFile = new File("D:/empty.doc");
            File oFile = new File("D:/doc.doc");
            InputStream fis = new FileInputStream(iFile);
            POIFSFileSystem fs = null;
            HWPFDocument doc = null;
            try {
                fs = new POIFSFileSystem(fis);
            } finally {
                fis.close();
            }
            doc = new HWPFDocument(fs);
            Range r = doc.getRange();
            *
            System.out.println("original text : " + r.text());
            r.replaceText("<NOM>", "Moi");
            System.out.println("modified text : " + r.text());
            *
            OutputStream out = new FileOutputStream(oFile);
            try {
                doc.write(out);
                out.flush();
            } finally {
                out.close();
            }

The empty.doc file is the same and the doc.doc file is corrupted.

The "println()" method give me that:

run:
original text : Mr <NOM>Mr <NOM>
modified text : Mr MoiMr Moi
BUILD SUCCESSFUL (total time: 1 second)

And when I try to open the doc.doc file, I have this error:
http://apache-poi.1045710.n5.nabble.com/file/n4622539/error.jpg 


Thanks for your help.

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/problem-with-the-methode-replaceText-and-with-save-HWPFDocument-tp4622539p4622539.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: problem with the methode "replaceText()" and with save HWPFDocument

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 22 Jul 2011, spiritkill wrote:
> I have two problem with Poi api 3.7 and 3.8 (I tried both):

I'd suggest you re-try with a recent nightly build - HWPF has been having 
a log of work done to it by Sergey recently

Nick

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