You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Edward J. Lyons Jr." <ed...@netnumina.com> on 2004/04/08 15:27:43 UTC

Help combining word documents

Hi Guys - 

( I sent this yesterday, but it didn't get through )

I need to load in two simple word documents, combine them into one and output them.  How can I do this?  Without documentation or examples, I don't understand the API.  How do I insert stuff from one document to the end of another?  If HWPF doesn't do this, please give me a clue and I'll fix it and contribute the source back (I'm actually a decent Java programmer).  

Thanks very much!

Sincerely,

Ed Lyons
ed AT netnumina DOT com

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


Re: Help combining word documents

Posted by Ryan Ackley <sa...@cfl.rr.com>.
What you want to do is somewhat complex. I would suggest you pay me to do it
for you :-) I will give you the basics and since you are a decent Java
programmer you may be able to connect the dots.

To walk a document tree:

HWPFDocument doc = new HWPFDocument(in);
Range r = doc.getRange();

for (int x = 0; x < r.numSections(); x++)
{
  Section s = r.getSection(x);
  for (int y = 0; y < s.numParagraphs(); y++)
  {
    Paragraph p = s.getParagraph(y);
    for (int z = 0; z < p.numCharacterRuns(); z++)
    {
      CharacterRun run = p.getCharacterRun(z);
    }
  }
}

As you can see you have three main Classes. Sections, Paragraphs and
CharacterRuns. each one extends Range.

Range defines methods for adding content. insertAfter and insertBefore. They
are overloaded for different content types.

So I would suggest you read the content from one Word document and add it to
the other.

It gets real complex because there are data structures that each Word
document has that its sections, paragraphs, and character runs are dependent
on. So you can't just transfer stuff from one file to another without doing
some type of merge of these data structures. You will need a deep
understanding of the file format to accomplish that.

It would probably take me a month to do this in my spare time. I am guessing
for you it would probably take 2-3 months working full time. Some people
have more time than money though. I am happy to help as long as you
contribute steadily. I have helped people in the past while waiting for
their incredible contribution and then they disappear.

-Ryan



----- Original Message ----- 
From: "Edward J. Lyons Jr." <ed...@netnumina.com>
To: <po...@jakarta.apache.org>
Sent: Thursday, April 08, 2004 9:27 AM
Subject: Help combining word documents


Hi Guys -

( I sent this yesterday, but it didn't get through )

I need to load in two simple word documents, combine them into one and
output them.  How can I do this?  Without documentation or examples, I don't
understand the API.  How do I insert stuff from one document to the end of
another?  If HWPF doesn't do this, please give me a clue and I'll fix it and
contribute the source back (I'm actually a decent Java programmer).

Thanks very much!

Sincerely,

Ed Lyons
ed AT netnumina DOT com

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


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