Question

I'm thinking about including the Apache POI into my application. Main goal is to output RTF document, but DOC would be nice, too. But the documentation is not very detailed about writing a HWPFDocument and everything I found on the web isn't helpful at all.

I can read DOC files, that's working without any problem. But I really can't see how I write a document. Maybe someone can give me a short code example?

Thanks a lot!

Was it helpful?

Solution

If you want to do RTF, These are text files and they are support in all versions of Word.

you can use itext for simple stuff http://itextdocs.lowagie.com/tutorial/rtf/index.php

ro

you can export them the hard way

//-- save as example.doc -------------

{
\rtf1
\ansi
\ansicpg1252
\deff0
\deflang1033
  {\fonttbl
    {\f0
     \fswiss
     \fcharset0 Arial;
    }
  }
  {
  \*
  \generator Msftedit 5.41.21.2500;
  }
  \viewkind4
  \uc1
  \pard
  \f0
  \fs20 

  Hello World

  \par
}

OTHER TIPS

Well,

It has been a long time since the last time I used POI. I read that the HWPFDocument is now orphaned (read on apache POI website). I would recommend using the WordML specification released by Microsoft instead.

http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats

I have used this method before. The easiest way is to create a WordML template and just replace the values using XPATH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top