Free Support Forum - aspose.com

How to remove specific row from table using Java

Dear Team,



I have a requirement to delete an row from a table. Here the row can sometimes hold data and sometimes it is empty. In either case I need to delete the row.



I am attaching the sample document for my requirement. In that sample document in first table need to delete the rows 5 and 6 and in second table the last two rows.



Kindly help me in providing some inputs to achieve the functionality.



Thanks and Regards

Pradeep

Hi Pradeep,

Thanks for your inquiry. Please use Row.remove method to remove the row. Following code example shows how to remove the row from table. Hope this helps you. Please let us know if you have any more queries.

Document doc = **new** Document( *MyDir* + "Test+Docment.docx");

//Get the first table

Table table = (Table)doc.getChild(NodeType. *TABLE* , 0, **true** );

table.getRows().get(5).remove();

//Get the second table

table = (Table)doc.getChild(NodeType. *TABLE* , 1, **true** );

table.getLastRow().remove();

doc.save( *MyDir* + "Out.docx");