public class TableOrder {
private static WordprocessingMLPackage wordMLPackage;
private static ObjectFactory factory;
public static void main (String args[]) throws Exception {
String tableDOCXFilePath = "C:\\TableOrder\\table.docx";
WordprocessingMLPackage tableDOCX = DOCXHelper.getInput(tableDOCXFilePath);
List<Object> tableList = DOCXHelper.getAllElementFromObject(tableDOCX.getMainDocumentPart(), Tbl.class);
Tbl table = (Tbl)tableList.get(0);
List<Object> rowList = DOCXHelper.getAllElementFromObject(table, Tr.class);
wordMLPackage = WordprocessingMLPackage.createPackage();
factory = Context.getWmlObjectFactory();
Tbl newTable = factory.createTbl();
newTable.getContent().add(rowList.get(3));
newTable.getContent().add(rowList.get(1));
newTable.getContent().add(rowList.get(2));
newTable.getContent().add(rowList.get(0));
wordMLPackage.getMainDocumentPart().addObject(newTable);
wordMLPackage.save(new java.io.File("C:\\TableOrder\\tableNew.docx"));
}
}
Users browsing this forum: No registered users and 92 guests