• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Apache POI -HWPF Word Document not appending using document.write(stream)

 
lal dev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am working for Apache POI, HWPF Documents
Used to concatenate 2 word documents.

I am able to concatenate 2 word documents and display result in 3rd document.
But, as i am concatenating, the font type, size, bold are not coming in result document

When i read one word document, and update result document, everything is coming fine.
ie result document has all font size, bold format is correct

But, try to open existing word document in append mode and updating other documents,
the result document is resulting only with first document, not updating 2nd document.

Can you please suggest.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

How, exactly, are you appending the second document to the first?
 
lal dev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am reading new document as follows:

FileInputStream fileInputStream = new FileInputStream(new File(Infilename));
BufferedInputStream buffInputStream = new BufferedInputStream(fileInputStream);
HWPFDocument document = new HWPFDocument(buffInputStream);
range = new Range(0,document.characterLength(),document);
range.insertBefore(pos+". ");

File outfile = new File(Outfilename);
FileOutputStream fileOutputStream =new FileOutputStream(outfile,true);
BufferedOutputStream buffOutputStream = new BufferedOutputStream(fileOutputStream);
document.write(buffOutputStream);

i am adding some text to the range of new document and writing the new document.
I am opening the FileOutputStream in append mode, ie true..
so, i think it will append the existing file.

Can you please suggest...
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Lalitha Devi G" please check your private messages for an important administrative matter. You can see them by clicking the My Private Messages link above.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DOC is a structure document format. You can't append one document to another by writing two DOC file streams into a single file. You'll need to open the other file as an HWPF document as well, and then insert the text range of the first file into it.
 
lal dev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we can open HWPf word document with input stream as input parameter.
so, i am opening HWPF word document as inputfile.

can you please explain "and then insert the text range of the first file into it".

can you please suggest..
 
lal dev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the point, i had Range say bigRange with all contents of all documents, but how can we set this range to a particular document...

can you please suggest..
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, please change your screen name according to the JavaRanch naming policy - a first name and a last name are required.

You need to open both files as HWPF documents, and then get a Range object of the document you want to append. Then you can insert that behind the Range object of the document you want to append to. You already have most of that code in the snippet you posted before.
 
lal dev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I had a range with all concatenated word documents, but... not able to set this range to a HWPF Document.

Can you please suggest...
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"gld", please read the policy on screen names: http://www.javaranch.com/name.jsp A valid screen name is not optional - accounts without it are generally closed. To avoid this, please fix yours before your next post.

I'm not sure how exactly to accomplish appending documents, but I'm sure it has something to with what's mentioned in "Changing text" in http://poi.apache.org/hwpf/quick-guide.html
 
lal dev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not able to create HWPF empty document. and not able to set range to a HWPF Document.

I am glad to see responses, thank you sir, but can you please suggest how to create a new HWPF Document and set range..

Can you please suggest....

Thanks in advance..

i have changed the name as "lal dev". my name is Lalitha Devi, so is this name fine... to continue... please suggest.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your screen name is fine now.

An empty document can be created by "new HWPFDocument(new POIFSFileSystem())". How are you trying to append the files? Post the code, and we may be able to help.
 
lal dev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting text of document as range and concatenating all ranges into Bigrange as follows:


Bigr.insertAfter(range.text());

range is one documents range..

but facing problem for DocumentSummary inforamtion:
Error getting property set with name DocumentSummaryInformation

here i am not able to set document information for individual documents...
Can you please suggest..
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The line of code you posted doesn't do anything with DocumentSummaryInformation; where is that error message coming from? If you post code, seeing more than a single line would be helpful.
 
Naga Varadharaju
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lal can you please post the code for concatenating Ranges thanks.
 
gl rao
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi lalitha devi,
Any success in merging 2 documents or replacing text with POI?
please post the code.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some discussion of replacing text using HWPF can be found at http://mail-archives.apache.org/mod_mbox/poi-user/200812.mbox/browser in the discussion "POI - HWPFDocument". The code that goes with it is at http://test.javaranch.com/ulf/ParagraphText.java and http://test.javaranch.com/ulf/InsertText.java
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch gl rao !
 
som sekhar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Can anybody post code for merging 2 documents with POI?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi som sekhar, welcome to the ranch !
If you have a question, please make your own thread. (UseOneThreadPerQuestion)
 
emrecan polatkan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi! how to wtite jtable to ms word program i try this but i didn't help me.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there and welcome to Javaranch! You might be best off asking your question in a new thread .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic