Forums Register Login

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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Welcome to JavaRanch.

How, exactly, are you appending the second document to the first?
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
"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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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..
+Pie Number of slices to send: Send
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..
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
"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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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..
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Lal can you please post the code for concatenating Ranges thanks.
+Pie Number of slices to send: Send
Hi lalitha devi,
Any success in merging 2 documents or replacing text with POI?
please post the code.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Welcome to Javaranch gl rao !
+Pie Number of slices to send: Send
Hi
Can anybody post code for merging 2 documents with POI?
+Pie Number of slices to send: Send
Hi som sekhar, welcome to the ranch !
If you have a question, please make your own thread. (UseOneThreadPerQuestion)
+Pie Number of slices to send: Send
hi! how to wtite jtable to ms word program i try this but i didn't help me.
+Pie Number of slices to send: Send
Hi there and welcome to Javaranch! You might be best off asking your question in a new thread .
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 14731 times.
Similar Threads
HWPF POI
apache POI - HWPF search & replace
HWPF
insert header and footer with POI HWPF?
HWPF Mail Merging
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:06:27.