We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to delete last row from csv file

Hi Team,

Can you please share some sample code to delete last row of any csv file.

E.g. Following is my file content and i want to delete last row (1|2|3) from it.

a|b|c|d
e|f|g|h
i|j|k|l
1|2|3

Thanks,
Sachin Dagar

Hi,

Thanks for your query.

See the following sample code to accomplish your task for your reference:
e.g
Sample code:

TxtLoadOptions opts = new TxtLoadOptions(LoadFormat.CSV);

Workbook workbook = new Workbook("Book1.csv", opts);

//Get the last data row in the sheet.

int maxdatarow = workbook.getWorksheets().get(0).getCells().getMaxDataRow();

//Delete the row.

workbook.getWorksheets().get(0).getCells().deleteRow(maxdatarow);

workbook.save(“out1.csv”,
SaveFormat.CSV);


Hope, this helps a bit.

Thank you.

Thank you for your quick help !

Hi,


Good to know that your issue is sorted out by the suggested code. Let us know if you have any issue or queries, we will be happy to assist you soon.

Thank you.