简体   繁体   中英

Apache POI - multiple columns in a Word (docx) document

I'm trying to create a word document with multiple columns. The reason for doing this (rather than using tables) is that the data will span multiple pages and only with columns I can fill the whole page before adding to a new one.

Can it be done with Apache POI ? Thanks!

How about using previously created empty document with multiple columns? Like this:

    XWPFDocument document = new XWPFDocument(PoiTest.class.getResourceAsStream("twocolumn.docx"));
    XWPFParagraph tmpParagraph = document.getParagraphs().get(0);

    for (int i = 0; i < 100; i++) {
        XWPFRun tmpRun = tmpParagraph.createRun();
        tmpRun.setText("LALALALAALALAAAA");
        tmpRun.setFontSize(18);
    }
    document.write(new FileOutputStream(new File("C:\\temp\\poi.docx")));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM