0

im developing one tool for uploading excel and validate it, but excel file is large and the row count is about 65536.

here is my code used for uploading and reading the excel sheet values

    int firstColNo = 1;
    int rowcount = sheet.getRows();
    int colCount = sheet.getColumns();
    int row = 0;
    String comp = "";
    for (row = 1; row < rowcount; row++) {
        if (labelCell != null) {
            cell = sheet.getCell(firstColNo, row);
            if (cell.getContents() != null && cell.getContents().length() > 0){
                String compoundId = cell.getContents();               
                System.out.println(compoundId);
            } else {
                System.out.println("-");
            }
        }
    }

by reading the row values it takes more to time to read, is there any way to make it faster else any code modifications need to be done in my code?

can anybody help me to overcome this issue.

Marcos
  • 4,643
  • 7
  • 33
  • 60
user2405204
  • 1
  • 1
  • 2

1 Answers1

0

Here is an example for you

 HSSFWorkbook workbook = new HSSFWorkbook(file);

    //Get first sheet from the workbook
    HSSFSheet sheet = workbook.getSheetAt(0);

    //Iterate through each rows from first sheet
    Iterator<Row> rowIterator = sheet.iterator();
    while(rowIterator.hasNext()) {
        Row row = rowIterator.next();

        //For each row, iterate through each columns
        Iterator<Cell> cellIterator = row.cellIterator();
        while(cellIterator.hasNext()) {

            Cell cell = cellIterator.next();

            switch(cell.getCellType()) {
                case Cell.CELL_TYPE_BOOLEAN:
                    System.out.print(cell.getBooleanCellValue() + "\t\t");
                    break;
                case Cell.CELL_TYPE_NUMERIC:
                    System.out.print(cell.getNumericCellValue() + "\t\t");
                    break;
                case Cell.CELL_TYPE_STRING:
                    System.out.print(cell.getStringCellValue() + "\t\t");
                    break;
            }
        }
        System.out.println("");
    }
Shreyas Dave
  • 3,815
  • 3
  • 28
  • 57