Free Support Forum - aspose.com

How to split one cell? aspose word for java

How to split one cell? aspose word for java Image_2018-02-23 20-06-14.png (26.1 KB)

@yunpat81,

Thanks for your inquiry. The Row class represents a table row and Cell class represents a table cell. Please use CompositeNode.InsertAfter method to insert the Cell node immediately after the specified reference Cell node. Please use the same method to insert the multiple Cell nodes into the Row node according to your requirement.

We suggest you please read about Aspose.Words’ document object model from here:
Aspose.Words Document Object Model

@yunpat81,

Following code example shows how to split a table’s cell into three cell. We have attached the input and output document for your kind reference. Docs.zip (18.2 KB). Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

// Get cell we need to split (lets split first cell for 3 cells)
Row row1 = doc.getFirstSection().getBody().getTables().get(0).getFirstRow();
Cell cell1 = row1.getFirstCell();

// Create two new cells
Cell cell11 = new Cell(doc);
Cell cell12 = new Cell(doc);

// Set widht (it will be original cell width / 3)
double newCellWidth = cell1.getCellFormat().getWidth() / 3;
cell1.getCellFormat().setWidth(newCellWidth);
cell11.getCellFormat().setWidth(newCellWidth);
cell12.getCellFormat().setWidth(newCellWidth);

// Insert new cells
row1.insertAfter(cell11, cell1);
row1.insertAfter(cell12, cell11);

doc.save(MyDir + "out.docx");

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan