在使用Aspose.Words for Java过程中,我想把这个一个大单元格分成两行三列的小单元格,请问用程序怎么进行控制?6371670204337_.pic.png (84.1 KB)
@silence_chen, 请考虑以下示例:
Document doc = new Document("in.docx");
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
// Get the row we need to split.
Row row = table.getRows().get(1);
// Get the cell we need to split.
Cell cell = row.getCells().get(0);
// Clone the cell without contents.
Cell newCell1 = (Cell)cell.deepClone(false);
Cell newCell2 = (Cell)cell.deepClone(false);
// Set the new cell width.
double width = cell.getCellFormat().getWidth();
cell.getCellFormat().setWidth(width / 3);
newCell1.getCellFormat().setWidth(width / 3);
newCell2.getCellFormat().setWidth(width / 3);
// Insert the new cells.
cell.getParentNode().insertAfter(newCell1, cell);
cell.getParentNode().insertAfter(newCell2, newCell1);
// Clone the row with contents
Row newRow = (Row)row.deepClone(true);
// Set the new row height.
double height = row.getRowFormat().getHeight();
row.getRowFormat().setHeight(height / 2);
newRow.getRowFormat().setHeight(height / 2);
// Insert the new row.
row.getParentNode().insertAfter(newRow, row);
// Autofit the table to the column width.
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
doc.save("in.split.docx");
in.docx (12.3 KB)
in.split.docx (10.1 KB)
请检查以下文档链接: