How to read one row at a time from excel file using aspose in java

2k views Asked by At

I have an excel file with 1000's of rows and I want read each row at a time in Java using aspose API's. I want to convert each row into a String array. Can anyone help me with this?

Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
2

There are 2 answers

0
Amjad Sahi On

Aspose.Cells provides the LightCells API, mainly designed to read/ write cell's data one by one without building a complete data model block (using the Cell collection etc.) into memory. It works in an event-driven mode. I think you may try it. When reading template files, the component parses every cell and provides their value one by one. Please see the document for your reference here.

I am developer evangelist at Aspose.

1
nitin mudgal On
Cells cells = worksheet.getCells();
Range range = cells.getMaxDisplayRange();
int totalColumns = range.getColumnCount();
int totalRows = range.getRowCount();
RowCollection rows = cells.getRows();

for (int i = 1; i < rows.getCount(); i++) {
    for (int j = 0; j < totalColumns; j++) {
        System.out.print(cells.get(i, j).getValue() + "\t");
    }
    System.out.println("");
}