How to add a table to header or footer?

后端 未结 2 1758
悲哀的现实
悲哀的现实 2021-01-24 15:29

I\'m having serious trouble adding a new, simple XWPFTable to an XWPFHeader (or Footer). Unfortunately there seems to be only one guy having the same problem (https://bz.apache.

2条回答
  •  被撕碎了的回忆
    2021-01-24 16:08

    Create table in docx document footer with Apache POI:

        XWPFHeaderFooterPolicy policy = document.getHeaderFooterPolicy();
        if (policy == null)
          policy = document.createHeaderFooterPolicy();
    
        XWPFHeaderFooter footer = policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
    
        XWPFParagraph p = footer.createParagraph();
        p.createRun().setText("My First Footer");
    
        XWPFTable t = footer.createTable(1, 3);
        XWPFTableRow r = t.getRow(0);
        r.createCell().setText("Uno");
        r.createCell().setText("Dos");
        r.createCell().setText("Tres");
    

提交回复
热议问题