Re: Split Word Cell Horizontally

I face the same problem. I need to clone the last row of table with splitting cell as shown in above figure. How can I clone last row of table with split cell? Please provide java based solution.

I use the below program to solve program .

Document doc = new Document(MyDir + “CAPSHEET.docx”);
// Retrieve the first table in the document.
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);

// Clone the last row in the table.
Row clonedRow = (Row)table.getLastRow().deepClone(true);

// Remove all content from the cloned row’s cells. This makes the row ready for
// new content to be inserted into.
for (Cell cell: clonedRow.getCells())
{

cell.getFirstParagraph().getRuns().clear();
cell.getFirstParagraph().appendChild(new Run(doc,“hello text”));
}
// Add the row to the end of the table.
table.appendChild(clonedRow);



From the above code I got only last row of table cloned.


But, I need to clone last row of table with splited cell for dynamic populating of data.

Hi Tikaraj,


Thanks for your inquiry. Please attach the following resources here for testing:

  • Your input Word document
  • Aspose.Words generated output document showing the undesired behavior.
  • Please attach your expected document here for our reference. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document using Microsoft Word. We will then provide you code to achieve the same using Aspose.Words.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

Hi Awais,


I have attached the word docoment. Please see attached file.

Hi Tikaraj,


Thanks for your inquiry. Please use the following simple code to achieve this:
Document doc = new Document(getMyDir() + “TestTemplate.docx”);
Table tab = doc.getFirstSection().getBody().getTables().get(0);
Table clone = (Table)tab.deepClone(true);
clone.getFirstRow().remove();
clone.getFirstRow().remove();
tab.getParentNode().insertAfter(clone, tab);
doc.save(getMyDir() + “15.9.0.docx”);
Hope, this helps.

Best regards,