if you think this library has been useful, feel free to give any help. Don't be shy.

Click here to lend your support to: Java2word, coding for fun! and make a donation at !

Friday, February 10, 2012

huge ms word documents with java2word

Someone a while ago asked if Java2word can generate huge MS Word documents. I guess the limit is on the MS Word itself and space on your hard-disk.

Take a look at the screenshot:

There are 187 pages on this document. I also opened on Word Viewer running on Linux Ubuntu via Wine.

This is the code that generates this document:

        IDocument myDoc = new Document2004();
        TableV2 tbl = new TableV2();
        tbl.addRow( TableRow.with("Table Header in all Pages", "Usefull for reports").withStyle().repeatTableHeaderOnEveryPage().create() );
        tbl.addRow( TableRow.with("Simple String cell", "Another simple String cell") ); 
        tbl.addRow( TableRow.with( TableCell.with(Paragraph.with("TableCell- Style to the whole cell, Par").create()), "Simple String" ).withStyle().bold().create() );
        tbl.addRow( TableRow.with("Style to the whole cell, Str", "String").withStyle().bold().create() );
        tbl.addRow( TableRow.with( TableCell.with(Paragraph.with("TableRowV2 with merge").create()).withStyle().gridSpan(2).create() ).withStyle().bold().create() );
        tbl.addRow( TableRow.with( TableCell.with(Paragraph.withPieces( ParagraphPiece.with("Paragraph with Style inside TableCell").withStyle().bold().fontSize("20").create() ).create()).withStyle().bgColor("00FFFF").create(), "String"  ));
        String img = Image.from_WEB_URL("").setHeight("100").setWidth("300").create().getContent();
        tbl.addRow( TableRow.with("this google logo: ", "Image here: "+ img + " == image before") );
        for (int i = 0; i < 8000; i++) {
            tbl.addRow( TableRow.with("111 ", "222") );            
        tbl.addRow( TableRow.with("LAST", "LAST") );            

By the way this is the new Table V2 (coming soon, thanks Fabio Cordeiro) where you'll be able to apply style and do a lot more with it.


Leonardo Correa

Wednesday, February 1, 2012

java2word version 3.1 released

============= Version 3.1 - 01-Feb-2012  =============

Applied patch for Identation and hiperlinks by whoahbot, Added some comments on methods, work in progress for special characters in

    - Issue 70: Created a method on Utils.class called replaceSpecialCharacters. This is under experiments.
    - Issue 82: Alternative for those who want to use paragraphs in table.
              Now you can NOT pass null to a table cell, which doens't make sense anyway. You have to pass "".
    - Issue 46:   Adding indentation
    - Issue 45:   Adding hyperlinks to the document
    - Removed all deprecated methods

Upgrade steps:
    - download this version or checkout the latest code and build your own jar file.

Download it here:

Leonardo Correa