Take the 2-minute tour ×

In my grails application i need to urgently create a file in current system in which i need to save information fetched from table in database.

I have created file as,

File file=new File("file name.txt")


then i have wrote values of mysql db table fields in it as,


it stores data like continous text but i want to have a .doc file in which data should get stored in table.On googling i found APACHE'S POI for creating doc file but i am not getting how it works and how i should use it.

With advance thanks, Laxmi.p

share|improve this question
Do you need a .doc, or would something like .rtf or .docx work equally well? –  Gagravarr Jul 25 '11 at 16:57

1 Answer 1

It is complicated to the point of it not being worth any persons effort to make tables (that do not randomly break) in HWPF. If you can use docx then the XWPF packages are easy to achieve this with.

import org.apache.poi.xwpf.*

class DocumentUtil {

    public static XWPFDocument makeDocument(metaData, tableData) {
        //make document and apply metadata, like regular text, headings bla bla
        def doc = new XWPFDocument()
        def table = doc.createTable(metaData.rows, metaData.cols)
        table = popuLateTable(table, tableData) //implement this part yourself

        return doc

If you cant use docx, I'd reccomend going for an excel document(HSSFWorkbook, even easier) or just a simple rtf (which is basically text with annotations for styling).

Edit: Which I see has been mentioned in a comment further up here.

share|improve this answer

Your Answer


