You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Brian Rosenberger <BR...@serena.com> on 2011/07/27 19:03:42 UTC
AW: AW: Replacing placeholder to a Table.
Hi Nick,
meanwhile I've created a small test class that indicates the problem. I have a table between two paragraphs and I simply would like to re-sort those IBodyElements, so that the table is first - followed by two paragraphs.
When I simply try to resort the list or to replace it, I get an UnmodifiableCollection Exception.
Against TAG REL_3_8_BETA3:
package net.brutex.msd2docx;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.xwpf.usermodel.*;
public class Test {
static String outputfile = "c:/temp/testdoc.docx";
public static void main(String[] args) {
try {
//Create an XWPFDoc and put a table between two
//paragraphs
XWPFDocument d = new XWPFDocument();
XWPFParagraph p1 = d.createParagraph();
XWPFRun r1= p1.createRun();
r1.setText("Paragraph 1, Run 1.");
XWPFTable t1 = d.createTable(4, 3);
t1.getRow(0).getCell(0).setText("Table 1");
XWPFParagraph p2 = d.createParagraph();
XWPFRun r2= p2.createRun();
r2.setText("Paragraph 2, Run 2.");
//Howto move table t1 to another position,
//i.e. above p1 ?
//Just list the IBodyElement List
List<IBodyElement> list = d.getBodyElements();
int i=0;
for ( IBodyElement e : list ) {
System.out.println(i + ": " + e.getElementType().name());
i++;
}
d.write(new FileOutputStream(outputfile));
} catch (Exception e) {
e.printStackTrace();
}
}
}
Cheers
Brian
Von: Nick Burch [mailto:nick.burch@alfresco.com]
Gesendet: Montag, 27. Juni 2011 12:38
I think we should be maintaining a list with both paragraphs and tables in it though, with relative ordering preserved. On XWPFDocument there's
List<IBodyElement> bodyElements
for example, which is built by doing a child walk and storing the entries in the order they occur
I'd look at extending that to suit your needs
Nick