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

Free Support Forum - aspose.com

Use of insertRows() or insertRow()


I try to insert a row in an excel file, and I don’t suceed…
The number of rows is always the same before and after calling insertRow() (or insertRows()).
Is something wrong in my code ?

I tried with 8.6.2 and 8.6.3 Aspose jar library.



Thanks for your template file and sample code.

Well, Cells.getRows().getCount() attribute would give you rows count but, the rows with standard (default) settings / formatting are not included to be counted. Since you insert a blank row in the sheet with default formatting, so it will not be counted but surely the row is inserted as you may see the blank row(s) are there before your data in the output file, you may confirm this by opening the output file into Ms Excel manually. For your information, the RowCollection.getCount() and ColumnCollection.getCount() are mainly useful if you want to retrieve the number of rows / columns which are initialized / used in a worksheet.
Please use Cells.getMaxDataRow() and Cells.getMaxDataColumn() attributes to get the farthest row and column indexes (zero based). Please see the updated code segment for your reference:
Sample code:

// First sheet
Worksheet sheet = null;

sheet = workbook.getWorksheets().get(1);

int avant = sheet.getCells().getRows().getCount();
System.out.println("Rows number before insert row = "+avant);
int maxRows = sheet.getCells().getMaxDataRow() + 1;
System.out.println("Rows number after insert row = "+maxRows);

Kindly let us know if you still need some clarifications, we would be happy to help you.

Thank you.