user3709485
user3709485

Reputation: 29

Edit or add a new row in excel file using apache POI

I know how to write data in to a row in excel android. But how can I add a new row on it without missing old rows.(I rewrite old rows but it will take a long time). Thanks.

Upvotes: 0

Views: 2048

Answers (1)

Sankumarsingh
Sankumarsingh

Reputation: 10079

To add rows in between multiple rows, you need to shift all the rows below it down by one row, and create a new row: for example if you need to add another row in 5th position, and the sheet contains 10 rows just shift 5 to 10 rows by one step down

    sheet.shiftRows(5, 10, 1);

and add new row in 5th position

    sheet.createRow(5);

You can use shiftRows to delete as well, in that case you just need to pass the third argument in minus. You can see here as well

NOTE: Delete first row carefully... In proper handling may corrupt your excel file.

Upvotes: 1

Related Questions