You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Doppelhofer Andreas <An...@salomon.at> on 2010/01/19 13:49:21 UTC

Microsoft Word error after opening previous generated doc file

Hi all,
Following code creates a new doc file from an existing empty doc file.
The generation terminates without error, but after opening the new
"sample2.doc" file with Microsoft Word (2003 SP3) and trying to
edit/add/remove the text, Microsoft Word ist getting "no response" and
the only way to close Word is to kill it from Task Manager.
I tried to open the file with OpenOffice (3.1) and there only the "H"
from "Hello World!" is displayed. In OpenOffice i can add/remove... some
text.

What's the error? I'm using poi-bin-3.6-20091214 on Windows. The
"empty.doc" file is a doc file without any text or something in it. Just
"create new file" and save it.

Thx dops

--
public static void main(String[] args) throws IOException {

 File file = new File("empty.doc");
 POIFSFileSystem fs1 = new POIFSFileSystem(new FileInputStream(file));
 HWPFDocument doc = new HWPFDocument(fs1);

 Range range = doc.getRange();
 CharacterRun run = range.insertAfter("Hello World!");

 OutputStream out = new FileOutputStream(new File("sample2.doc"));
 doc.write(out);
 out.flush();
 out.close();

}
--

-- 


Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
Sitz der Gesellschaft: Friesach bei Graz
UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
Firmenbuchgericht: Landesgericht fur Zivilrechtssachen Graz


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


AW: Microsoft Word error after opening previous generated doc file

Posted by Doppelhofer Andreas <An...@salomon.at>.
Any idea? 

> -----Ursprüngliche Nachricht-----
> Von: Doppelhofer Andreas [mailto:Andreas.Doppelhofer@salomon.at] 
> Gesendet: Dienstag, 19. Januar 2010 13:49
> An: user@poi.apache.org
> Betreff: Microsoft Word error after opening previous 
> generated doc file
> 
> Hi all,
> Following code creates a new doc file from an existing empty doc file.
> The generation terminates without error, but after opening 
> the new "sample2.doc" file with Microsoft Word (2003 SP3) and 
> trying to edit/add/remove the text, Microsoft Word ist 
> getting "no response" and the only way to close Word is to 
> kill it from Task Manager.
> I tried to open the file with OpenOffice (3.1) and there only the "H"
> from "Hello World!" is displayed. In OpenOffice i can 
> add/remove... some text.
> 
> What's the error? I'm using poi-bin-3.6-20091214 on Windows. 
> The "empty.doc" file is a doc file without any text or 
> something in it. Just "create new file" and save it.
> 
> Thx dops
> 
> --
> public static void main(String[] args) throws IOException {
> 
>  File file = new File("empty.doc");
>  POIFSFileSystem fs1 = new POIFSFileSystem(new 
> FileInputStream(file));  HWPFDocument doc = new HWPFDocument(fs1);
> 
>  Range range = doc.getRange();
>  CharacterRun run = range.insertAfter("Hello World!");
> 
>  OutputStream out = new FileOutputStream(new 
> File("sample2.doc"));  doc.write(out);  out.flush();  out.close();
> 
> }
> --

-- 


Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
Sitz der Gesellschaft: Friesach bei Graz
UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
Firmenbuchgericht: Landesgericht für Zivilrechtssachen Graz


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


Re: AW: AW: Microsoft Word error after opening previous generated doc file

Posted by MSB <ma...@tiscali.co.uk>.
Sorry Andreas, I have not had the opportunity to run my old test code yet
against the more recent versions of POI, but it does seem as though there
may be problems with those later releases as other users have posted
questions regarding code that worked with, for example, version 3.2.

If you can, it may be best to revert to that earlier version and use it.

Yours

Mark B.


Doppelhofer Andreas wrote:
> 
>> -----Ursprüngliche Nachricht-----
>> Von: MSB [mailto:markbrdsly@tiscali.co.uk] 
>> Gesendet: Montag, 25. Januar 2010 09:51
>> An: user@poi.apache.org
>> Betreff: Re: AW: Microsoft Word error after opening previous 
>> generated doc file
>> 
>> 
>> Cannot imagine that there will be any difference but what 
>> about running Word, opening a new blank document and then 
>> saving that away to disk? This is what I have always done 
>> just so that I can be certain about what is happening in the 
>> background.
> 
> The same like 
> 2) Right click @ explorer -> Create new Word Document... 
>    -> open file and save it (filesize 24kb)
> and this works but only in 3.2
> 
>> 
>> Must admit that I cannot be 100% certain whether I have used 
>> HWPF to create a brand new document since version 3.2 but I 
>> am confident that I have. When I get back from work later 
>> today, I will try some of my earlier code examples just to 
>> see what happens for there have been changes to the way the 
>> API works IMO.
> 
> Thx dops
> 
>> 
>> Yours
>> 
>> Mark B
>> 
>> 
>> Doppelhofer Andreas wrote:
>> > 
>> > I tried this sample with 3.2 of poi and it works!! 
>> > Only this works...
>> >> 2) Right click @ explorer -> Create new Word Document... 
>> -> open file 
>> >> and save it (filesize 24kb)
>> > 
>> >> -----Ursprüngliche Nachricht-----
>> >> Von: Doppelhofer Andreas [mailto:Andreas.Doppelhofer@salomon.at]
>> >> Gesendet: Montag, 25. Januar 2010 08:51
>> >> An: POI Users List
>> >> Betreff: AW: Microsoft Word error after opening previous generated 
>> >> doc file
>> >> 
>> >> I used this sample to get started with HWPF but this 
>> sample creates 
>> >> an corrupt doc file.
>> >> I tried 2 way's creating an empty.doc (both doesnt work at the end)
>> >> 
>> >> 1) Right click @ explorer -> Create new Word Document.. 
>> >> (filesize 11kb)
>> >>    Then execute app, after opening the new doc no text in it, but 
>> >> file seems to be ok.
>> >> 2) Right click @ explorer -> Create new Word Document... 
>> -> open file 
>> >> and save it (filesize 24kb)
>> >>    Then execute app, open new file, text exists in doc 
>> without style 
>> >> info, trying to edit/select something, word "hangs"
>> >> 
>> >> What do i wrong, or is this a bug? I tried this sample with
>> >> 3.5 and 3.6 of poi but no difference, both create corrupt files...
>> >> 
>> >> Thx dops
>> >> 
>> >> > -----Ursprüngliche Nachricht-----
>> >> > Von: MSB [mailto:markbrdsly@tiscali.co.uk]
>> >> > Gesendet: Freitag, 22. Januar 2010 15:30
>> >> > An: user@poi.apache.org
>> >> > Betreff: Re: Microsoft Word error after opening previous
>> >> generated doc
>> >> > file
>> >> > 
>> >> > 
>> >> > Well, one thought is that you are trying to insert a 
>> CharacterRun 
>> >> > rather than a Paragraph object. Have a look at this
>> >> example, I seem to
>> >> > remember that it worked successfully;
>> >> > 
>> >> > http://faq.javaranch.com/java/CreateWordDocument
>> >> > 
>> >> > Remember Andreas that HWPF is very immature and if you try
>> >> to use it
>> >> > for anything really complex it may well fail you. For
>> >> example, I have
>> >> > run into problems setting more than one attribute for a
>> >> CharacterRun;
>> >> > it is possible to set the text emboldened or underlined but
>> >> not both. 
>> >> > Would you be willing to contribute toward developing HWPF? 
>> >> If so, then
>> >> > visit this page http://poi.apache.org/hwpf/index.html 
>> and see about 
>> >> > becoming involved please.
>> >> > 
>> >> > Yours
>> >> > 
>> >> > Mark B
>> >> > 
>> >> > 
>> >> > Doppelhofer Andreas wrote:
>> >> > > 
>> >> > > Hi all,
>> >> > > Following code creates a new doc file from an existing
>> >> > empty doc file.
>> >> > > The generation terminates without error, but after
>> >> opening the new
>> >> > > "sample2.doc" file with Microsoft Word (2003 SP3) and 
>> trying to 
>> >> > > edit/add/remove the text, Microsoft Word ist getting "no
>> >> > response" and
>> >> > > the only way to close Word is to kill it from Task Manager.
>> >> > > I tried to open the file with OpenOffice (3.1) and there
>> >> > only the "H"
>> >> > > from "Hello World!" is displayed. In OpenOffice i can
>> >> add/remove... 
>> >> > > some text.
>> >> > > 
>> >> > > What's the error? I'm using poi-bin-3.6-20091214 on 
>> Windows. The 
>> >> > > "empty.doc" file is a doc file without any text or
>> >> something in it.
>> >> > > Just "create new file" and save it.
>> >> > > 
>> >> > > Thx dops
>> >> > > 
>> >> > > --
>> >> > > public static void main(String[] args) throws IOException {
>> >> > > 
>> >> > >  File file = new File("empty.doc");  POIFSFileSystem fs1 = new 
>> >> > > POIFSFileSystem(new
>> >> > FileInputStream(file));
>> >> > > HWPFDocument doc = new HWPFDocument(fs1);
>> >> > > 
>> >> > >  Range range = doc.getRange();
>> >> > >  CharacterRun run = range.insertAfter("Hello World!");
>> >> > > 
>> >> > >  OutputStream out = new FileOutputStream(new
>> >> File("sample2.doc"));
>> >> > > doc.write(out);  out.flush();  out.close();
>> >> > > 
>> >> > > }
>> >> > > --
>> >> 
>> >> --
>> >> 
>> >> 
>> >> Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei 
>> >> Graz Sitz der Gesellschaft: Friesach bei Graz UID-NR:ATU28654300 - 
>> >> Firmenbuchnummer: 49324 K
>> >> Firmenbuchgericht: Landesgericht für Zivilrechtssachen Graz
>> >> 
>> >> 
>> >> 
>> ---------------------------------------------------------------------
>> >> 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
>> > 
>> > 
>> > 
>> 
>> --
>> View this message in context: 
>> http://old.nabble.com/Microsoft-Word-error-after-opening-previ
> ous-generated-doc-file-tp27225280p27303581.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
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Microsoft-Word-error-after-opening-previous-generated-doc-file-tp27225280p27325962.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


AW: AW: Microsoft Word error after opening previous generated doc file

Posted by Doppelhofer Andreas <An...@salomon.at>.
> -----Ursprüngliche Nachricht-----
> Von: MSB [mailto:markbrdsly@tiscali.co.uk] 
> Gesendet: Montag, 25. Januar 2010 09:51
> An: user@poi.apache.org
> Betreff: Re: AW: Microsoft Word error after opening previous 
> generated doc file
> 
> 
> Cannot imagine that there will be any difference but what 
> about running Word, opening a new blank document and then 
> saving that away to disk? This is what I have always done 
> just so that I can be certain about what is happening in the 
> background.

The same like 
2) Right click @ explorer -> Create new Word Document... 
   -> open file and save it (filesize 24kb)
and this works but only in 3.2

> 
> Must admit that I cannot be 100% certain whether I have used 
> HWPF to create a brand new document since version 3.2 but I 
> am confident that I have. When I get back from work later 
> today, I will try some of my earlier code examples just to 
> see what happens for there have been changes to the way the 
> API works IMO.

Thx dops

> 
> Yours
> 
> Mark B
> 
> 
> Doppelhofer Andreas wrote:
> > 
> > I tried this sample with 3.2 of poi and it works!! 
> > Only this works...
> >> 2) Right click @ explorer -> Create new Word Document... 
> -> open file 
> >> and save it (filesize 24kb)
> > 
> >> -----Ursprüngliche Nachricht-----
> >> Von: Doppelhofer Andreas [mailto:Andreas.Doppelhofer@salomon.at]
> >> Gesendet: Montag, 25. Januar 2010 08:51
> >> An: POI Users List
> >> Betreff: AW: Microsoft Word error after opening previous generated 
> >> doc file
> >> 
> >> I used this sample to get started with HWPF but this 
> sample creates 
> >> an corrupt doc file.
> >> I tried 2 way's creating an empty.doc (both doesnt work at the end)
> >> 
> >> 1) Right click @ explorer -> Create new Word Document.. 
> >> (filesize 11kb)
> >>    Then execute app, after opening the new doc no text in it, but 
> >> file seems to be ok.
> >> 2) Right click @ explorer -> Create new Word Document... 
> -> open file 
> >> and save it (filesize 24kb)
> >>    Then execute app, open new file, text exists in doc 
> without style 
> >> info, trying to edit/select something, word "hangs"
> >> 
> >> What do i wrong, or is this a bug? I tried this sample with
> >> 3.5 and 3.6 of poi but no difference, both create corrupt files...
> >> 
> >> Thx dops
> >> 
> >> > -----Ursprüngliche Nachricht-----
> >> > Von: MSB [mailto:markbrdsly@tiscali.co.uk]
> >> > Gesendet: Freitag, 22. Januar 2010 15:30
> >> > An: user@poi.apache.org
> >> > Betreff: Re: Microsoft Word error after opening previous
> >> generated doc
> >> > file
> >> > 
> >> > 
> >> > Well, one thought is that you are trying to insert a 
> CharacterRun 
> >> > rather than a Paragraph object. Have a look at this
> >> example, I seem to
> >> > remember that it worked successfully;
> >> > 
> >> > http://faq.javaranch.com/java/CreateWordDocument
> >> > 
> >> > Remember Andreas that HWPF is very immature and if you try
> >> to use it
> >> > for anything really complex it may well fail you. For
> >> example, I have
> >> > run into problems setting more than one attribute for a
> >> CharacterRun;
> >> > it is possible to set the text emboldened or underlined but
> >> not both. 
> >> > Would you be willing to contribute toward developing HWPF? 
> >> If so, then
> >> > visit this page http://poi.apache.org/hwpf/index.html 
> and see about 
> >> > becoming involved please.
> >> > 
> >> > Yours
> >> > 
> >> > Mark B
> >> > 
> >> > 
> >> > Doppelhofer Andreas wrote:
> >> > > 
> >> > > Hi all,
> >> > > Following code creates a new doc file from an existing
> >> > empty doc file.
> >> > > The generation terminates without error, but after
> >> opening the new
> >> > > "sample2.doc" file with Microsoft Word (2003 SP3) and 
> trying to 
> >> > > edit/add/remove the text, Microsoft Word ist getting "no
> >> > response" and
> >> > > the only way to close Word is to kill it from Task Manager.
> >> > > I tried to open the file with OpenOffice (3.1) and there
> >> > only the "H"
> >> > > from "Hello World!" is displayed. In OpenOffice i can
> >> add/remove... 
> >> > > some text.
> >> > > 
> >> > > What's the error? I'm using poi-bin-3.6-20091214 on 
> Windows. The 
> >> > > "empty.doc" file is a doc file without any text or
> >> something in it.
> >> > > Just "create new file" and save it.
> >> > > 
> >> > > Thx dops
> >> > > 
> >> > > --
> >> > > public static void main(String[] args) throws IOException {
> >> > > 
> >> > >  File file = new File("empty.doc");  POIFSFileSystem fs1 = new 
> >> > > POIFSFileSystem(new
> >> > FileInputStream(file));
> >> > > HWPFDocument doc = new HWPFDocument(fs1);
> >> > > 
> >> > >  Range range = doc.getRange();
> >> > >  CharacterRun run = range.insertAfter("Hello World!");
> >> > > 
> >> > >  OutputStream out = new FileOutputStream(new
> >> File("sample2.doc"));
> >> > > doc.write(out);  out.flush();  out.close();
> >> > > 
> >> > > }
> >> > > --
> >> 
> >> --
> >> 
> >> 
> >> Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei 
> >> Graz Sitz der Gesellschaft: Friesach bei Graz UID-NR:ATU28654300 - 
> >> Firmenbuchnummer: 49324 K
> >> Firmenbuchgericht: Landesgericht für Zivilrechtssachen Graz
> >> 
> >> 
> >> 
> ---------------------------------------------------------------------
> >> 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
> > 
> > 
> > 
> 
> --
> View this message in context: 
> http://old.nabble.com/Microsoft-Word-error-after-opening-previ
ous-generated-doc-file-tp27225280p27303581.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
> 
> 

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


Re: AW: Microsoft Word error after opening previous generated doc file

Posted by MSB <ma...@tiscali.co.uk>.
Cannot imagine that there will be any difference but what about running Word,
opening a new blank document and then saving that away to disk? This is what
I have always done just so that I can be certain about what is happening in
the background.

Must admit that I cannot be 100% certain whether I have used HWPF to create
a brand new document since version 3.2 but I am confident that I have. When
I get back from work later today, I will try some of my earlier code
examples just to see what happens for there have been changes to the way the
API works IMO.

Yours

Mark B


Doppelhofer Andreas wrote:
> 
> I tried this sample with 3.2 of poi and it works!! 
> Only this works...
>> 2) Right click @ explorer -> Create new Word Document... -> 
>> open file and save it (filesize 24kb)
> 
>> -----Ursprüngliche Nachricht-----
>> Von: Doppelhofer Andreas [mailto:Andreas.Doppelhofer@salomon.at] 
>> Gesendet: Montag, 25. Januar 2010 08:51
>> An: POI Users List
>> Betreff: AW: Microsoft Word error after opening previous 
>> generated doc file
>> 
>> I used this sample to get started with HWPF but this sample 
>> creates an corrupt doc file.
>> I tried 2 way's creating an empty.doc (both doesnt work at the end)
>> 
>> 1) Right click @ explorer -> Create new Word Document.. 
>> (filesize 11kb)
>>    Then execute app, after opening the new doc no text in it, 
>> but file seems to be ok. 
>> 2) Right click @ explorer -> Create new Word Document... -> 
>> open file and save it (filesize 24kb)
>>    Then execute app, open new file, text exists in doc 
>> without style info, trying to edit/select something, word "hangs"
>> 
>> What do i wrong, or is this a bug? I tried this sample with 
>> 3.5 and 3.6 of poi but no difference, both create corrupt files...
>> 
>> Thx dops
>> 
>> > -----Ursprüngliche Nachricht-----
>> > Von: MSB [mailto:markbrdsly@tiscali.co.uk]
>> > Gesendet: Freitag, 22. Januar 2010 15:30
>> > An: user@poi.apache.org
>> > Betreff: Re: Microsoft Word error after opening previous 
>> generated doc 
>> > file
>> > 
>> > 
>> > Well, one thought is that you are trying to insert a CharacterRun 
>> > rather than a Paragraph object. Have a look at this 
>> example, I seem to 
>> > remember that it worked successfully;
>> > 
>> > http://faq.javaranch.com/java/CreateWordDocument
>> > 
>> > Remember Andreas that HWPF is very immature and if you try 
>> to use it 
>> > for anything really complex it may well fail you. For 
>> example, I have 
>> > run into problems setting more than one attribute for a 
>> CharacterRun; 
>> > it is possible to set the text emboldened or underlined but 
>> not both. 
>> > Would you be willing to contribute toward developing HWPF? 
>> If so, then 
>> > visit this page http://poi.apache.org/hwpf/index.html and see about 
>> > becoming involved please.
>> > 
>> > Yours
>> > 
>> > Mark B
>> > 
>> > 
>> > Doppelhofer Andreas wrote:
>> > > 
>> > > Hi all,
>> > > Following code creates a new doc file from an existing
>> > empty doc file.
>> > > The generation terminates without error, but after 
>> opening the new 
>> > > "sample2.doc" file with Microsoft Word (2003 SP3) and trying to 
>> > > edit/add/remove the text, Microsoft Word ist getting "no
>> > response" and
>> > > the only way to close Word is to kill it from Task Manager.
>> > > I tried to open the file with OpenOffice (3.1) and there
>> > only the "H"
>> > > from "Hello World!" is displayed. In OpenOffice i can 
>> add/remove... 
>> > > some text.
>> > > 
>> > > What's the error? I'm using poi-bin-3.6-20091214 on Windows. The 
>> > > "empty.doc" file is a doc file without any text or 
>> something in it.
>> > > Just "create new file" and save it.
>> > > 
>> > > Thx dops
>> > > 
>> > > --
>> > > public static void main(String[] args) throws IOException {
>> > > 
>> > >  File file = new File("empty.doc");
>> > >  POIFSFileSystem fs1 = new POIFSFileSystem(new
>> > FileInputStream(file));
>> > > HWPFDocument doc = new HWPFDocument(fs1);
>> > > 
>> > >  Range range = doc.getRange();
>> > >  CharacterRun run = range.insertAfter("Hello World!");
>> > > 
>> > >  OutputStream out = new FileOutputStream(new 
>> File("sample2.doc")); 
>> > > doc.write(out);  out.flush();  out.close();
>> > > 
>> > > }
>> > > --
>> 
>> -- 
>> 
>> 
>> Salomon Automation GmbH - Friesachstrasse 15 - A-8114 
>> Friesach bei Graz Sitz der Gesellschaft: Friesach bei Graz 
>> UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
>> Firmenbuchgericht: Landesgericht für Zivilrechtssachen Graz
>> 
>> 
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Microsoft-Word-error-after-opening-previous-generated-doc-file-tp27225280p27303581.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


AW: Microsoft Word error after opening previous generated doc file

Posted by Doppelhofer Andreas <An...@salomon.at>.
I tried this sample with 3.2 of poi and it works!! 
Only this works...
> 2) Right click @ explorer -> Create new Word Document... -> 
> open file and save it (filesize 24kb)

> -----Ursprüngliche Nachricht-----
> Von: Doppelhofer Andreas [mailto:Andreas.Doppelhofer@salomon.at] 
> Gesendet: Montag, 25. Januar 2010 08:51
> An: POI Users List
> Betreff: AW: Microsoft Word error after opening previous 
> generated doc file
> 
> I used this sample to get started with HWPF but this sample 
> creates an corrupt doc file.
> I tried 2 way's creating an empty.doc (both doesnt work at the end)
> 
> 1) Right click @ explorer -> Create new Word Document.. 
> (filesize 11kb)
>    Then execute app, after opening the new doc no text in it, 
> but file seems to be ok. 
> 2) Right click @ explorer -> Create new Word Document... -> 
> open file and save it (filesize 24kb)
>    Then execute app, open new file, text exists in doc 
> without style info, trying to edit/select something, word "hangs"
> 
> What do i wrong, or is this a bug? I tried this sample with 
> 3.5 and 3.6 of poi but no difference, both create corrupt files...
> 
> Thx dops
> 
> > -----Ursprüngliche Nachricht-----
> > Von: MSB [mailto:markbrdsly@tiscali.co.uk]
> > Gesendet: Freitag, 22. Januar 2010 15:30
> > An: user@poi.apache.org
> > Betreff: Re: Microsoft Word error after opening previous 
> generated doc 
> > file
> > 
> > 
> > Well, one thought is that you are trying to insert a CharacterRun 
> > rather than a Paragraph object. Have a look at this 
> example, I seem to 
> > remember that it worked successfully;
> > 
> > http://faq.javaranch.com/java/CreateWordDocument
> > 
> > Remember Andreas that HWPF is very immature and if you try 
> to use it 
> > for anything really complex it may well fail you. For 
> example, I have 
> > run into problems setting more than one attribute for a 
> CharacterRun; 
> > it is possible to set the text emboldened or underlined but 
> not both. 
> > Would you be willing to contribute toward developing HWPF? 
> If so, then 
> > visit this page http://poi.apache.org/hwpf/index.html and see about 
> > becoming involved please.
> > 
> > Yours
> > 
> > Mark B
> > 
> > 
> > Doppelhofer Andreas wrote:
> > > 
> > > Hi all,
> > > Following code creates a new doc file from an existing
> > empty doc file.
> > > The generation terminates without error, but after 
> opening the new 
> > > "sample2.doc" file with Microsoft Word (2003 SP3) and trying to 
> > > edit/add/remove the text, Microsoft Word ist getting "no
> > response" and
> > > the only way to close Word is to kill it from Task Manager.
> > > I tried to open the file with OpenOffice (3.1) and there
> > only the "H"
> > > from "Hello World!" is displayed. In OpenOffice i can 
> add/remove... 
> > > some text.
> > > 
> > > What's the error? I'm using poi-bin-3.6-20091214 on Windows. The 
> > > "empty.doc" file is a doc file without any text or 
> something in it.
> > > Just "create new file" and save it.
> > > 
> > > Thx dops
> > > 
> > > --
> > > public static void main(String[] args) throws IOException {
> > > 
> > >  File file = new File("empty.doc");
> > >  POIFSFileSystem fs1 = new POIFSFileSystem(new
> > FileInputStream(file));
> > > HWPFDocument doc = new HWPFDocument(fs1);
> > > 
> > >  Range range = doc.getRange();
> > >  CharacterRun run = range.insertAfter("Hello World!");
> > > 
> > >  OutputStream out = new FileOutputStream(new 
> File("sample2.doc")); 
> > > doc.write(out);  out.flush();  out.close();
> > > 
> > > }
> > > --
> 
> -- 
> 
> 
> Salomon Automation GmbH - Friesachstrasse 15 - A-8114 
> Friesach bei Graz Sitz der Gesellschaft: Friesach bei Graz 
> UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
> Firmenbuchgericht: Landesgericht für Zivilrechtssachen Graz
> 
> 
> ---------------------------------------------------------------------
> 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


AW: Microsoft Word error after opening previous generated doc file

Posted by Doppelhofer Andreas <An...@salomon.at>.
I used this sample to get started with HWPF but this sample creates an corrupt doc file.
I tried 2 way's creating an empty.doc (both doesnt work at the end)

1) Right click @ explorer -> Create new Word Document.. (filesize 11kb)
   Then execute app, after opening the new doc no text in it, but file seems to be ok. 
2) Right click @ explorer -> Create new Word Document... -> open file and save it (filesize 24kb)
   Then execute app, open new file, text exists in doc without style info, trying to edit/select something, word "hangs"

What do i wrong, or is this a bug? I tried this sample with 3.5 and 3.6 of poi but no difference, both create corrupt files...

Thx dops

> -----Ursprüngliche Nachricht-----
> Von: MSB [mailto:markbrdsly@tiscali.co.uk] 
> Gesendet: Freitag, 22. Januar 2010 15:30
> An: user@poi.apache.org
> Betreff: Re: Microsoft Word error after opening previous 
> generated doc file
> 
> 
> Well, one thought is that you are trying to insert a 
> CharacterRun rather than a Paragraph object. Have a look at 
> this example, I seem to remember that it worked successfully;
> 
> http://faq.javaranch.com/java/CreateWordDocument
> 
> Remember Andreas that HWPF is very immature and if you try to 
> use it for anything really complex it may well fail you. For 
> example, I have run into problems setting more than one 
> attribute for a CharacterRun; it is possible to set the text 
> emboldened or underlined but not both. Would you be willing 
> to contribute toward developing HWPF? If so, then visit this 
> page http://poi.apache.org/hwpf/index.html and see about 
> becoming involved please.
> 
> Yours
> 
> Mark B
> 
> 
> Doppelhofer Andreas wrote:
> > 
> > Hi all,
> > Following code creates a new doc file from an existing 
> empty doc file.
> > The generation terminates without error, but after opening the new 
> > "sample2.doc" file with Microsoft Word (2003 SP3) and trying to 
> > edit/add/remove the text, Microsoft Word ist getting "no 
> response" and 
> > the only way to close Word is to kill it from Task Manager.
> > I tried to open the file with OpenOffice (3.1) and there 
> only the "H"
> > from "Hello World!" is displayed. In OpenOffice i can add/remove... 
> > some text.
> > 
> > What's the error? I'm using poi-bin-3.6-20091214 on Windows. The 
> > "empty.doc" file is a doc file without any text or something in it. 
> > Just "create new file" and save it.
> > 
> > Thx dops
> > 
> > --
> > public static void main(String[] args) throws IOException {
> > 
> >  File file = new File("empty.doc");
> >  POIFSFileSystem fs1 = new POIFSFileSystem(new 
> FileInputStream(file));  
> > HWPFDocument doc = new HWPFDocument(fs1);
> > 
> >  Range range = doc.getRange();
> >  CharacterRun run = range.insertAfter("Hello World!");
> > 
> >  OutputStream out = new FileOutputStream(new File("sample2.doc"));  
> > doc.write(out);  out.flush();  out.close();
> > 
> > }
> > --

-- 


Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
Sitz der Gesellschaft: Friesach bei Graz
UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
Firmenbuchgericht: Landesgericht für Zivilrechtssachen Graz


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


Re: Microsoft Word error after opening previous generated doc file

Posted by MSB <ma...@tiscali.co.uk>.
Well, one thought is that you are trying to insert a CharacterRun rather than
a Paragraph object. Have a look at this example, I seem to remember that it
worked successfully;

http://faq.javaranch.com/java/CreateWordDocument

Remember Andreas that HWPF is very immature and if you try to use it for
anything really complex it may well fail you. For example, I have run into
problems setting more than one attribute for a CharacterRun; it is possible
to set the text emboldened or underlined but not both. Would you be willing
to contribute toward developing HWPF? If so, then visit this page
http://poi.apache.org/hwpf/index.html and see about becoming involved
please.

Yours

Mark B


Doppelhofer Andreas wrote:
> 
> Hi all,
> Following code creates a new doc file from an existing empty doc file.
> The generation terminates without error, but after opening the new
> "sample2.doc" file with Microsoft Word (2003 SP3) and trying to
> edit/add/remove the text, Microsoft Word ist getting "no response" and
> the only way to close Word is to kill it from Task Manager.
> I tried to open the file with OpenOffice (3.1) and there only the "H"
> from "Hello World!" is displayed. In OpenOffice i can add/remove... some
> text.
> 
> What's the error? I'm using poi-bin-3.6-20091214 on Windows. The
> "empty.doc" file is a doc file without any text or something in it. Just
> "create new file" and save it.
> 
> Thx dops
> 
> --
> public static void main(String[] args) throws IOException {
> 
>  File file = new File("empty.doc");
>  POIFSFileSystem fs1 = new POIFSFileSystem(new FileInputStream(file));
>  HWPFDocument doc = new HWPFDocument(fs1);
> 
>  Range range = doc.getRange();
>  CharacterRun run = range.insertAfter("Hello World!");
> 
>  OutputStream out = new FileOutputStream(new File("sample2.doc"));
>  doc.write(out);
>  out.flush();
>  out.close();
> 
> }
> --
> 
> -- 
> 
> 
> Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
> Sitz der Gesellschaft: Friesach bei Graz
> UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
> Firmenbuchgericht: Landesgericht fur Zivilrechtssachen Graz
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Microsoft-Word-error-after-opening-previous-generated-doc-file-tp27225280p27273998.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