java - How to read first n lines of a HUGE excel file -


so i'm trying write program scans specific pattern in row of excel file. namely n followed letter, s or t (with each letter occupying single cell).

the problem is, excel file i'm using absolutely massive, 3000 rows , 1000 columns. i'm trying search pattern in first 60 rows in order reduce java heap space. how can suit algorithm this? i'm still getting out of memory exceptions.

my code follows:

import java.awt.list; import java.io.file; import java.io.fileinputstream; import java.io.ioexception; import java.util.arraylist;  import org.apache.poi.encrypteddocumentexception; import org.apache.poi.openxml4j.exceptions.invalidformatexception; import org.apache.poi.ss.usermodel.workbook; import org.apache.poi.ss.usermodel.workbookfactory; import org.apache.poi.xssf.usermodel.xssfcell; import org.apache.poi.xssf.usermodel.xssfrow; import org.apache.poi.xssf.usermodel.xssfsheet; import org.apache.poi.xssf.usermodel.xssfworkbook;  public class excelreader {      public int reader(file file) throws ioexception, encrypteddocumentexception, invalidformatexception {         fileinputstream fis = new fileinputstream(file);         string filepath = file.getpath();         workbook wb = workbookfactory.create(new file(filepath));         xssfsheet sheet = (xssfsheet) wb.getsheetat(0);         xssfrow row;         xssfcell cell;         arraylist<integer> list = new arraylist<integer>();          int rows;         int cols = 0;         int temp = 0;         rows = sheet.getphysicalnumberofrows();          (int = 0; < 10 || < 60; i++) {             row = sheet.getrow(i);             if (row != null) {                 temp = sheet.getrow(i).getphysicalnumberofcells();                 if (temp > cols)                     cols = temp;             }         }         (int r = 0; r <= 60; r++) {             row = sheet.getrow(r);             if (row != null) {                 (int c = 0; c <= cols; c++) {                     int numblanks = 0;                     cell = row.getcell((short) c);                     if (cell != null) {                         //system.out.print(cell + "\t\t");                     } else {                         //system.out.print("\t\t");                     }                     if (cell != null && cell.getcelltype() == xssfcell.cell_type_string) {                         if ("n".equals(cell.getstringcellvalue())) {                             (int k = c; k <= cols; k++) {                                 if ("-".equals(row.getcell(k).getstringcellvalue())) {                                     numblanks++;                                     continue;                                 }                                 if ("s".equals(row.getcell(c + 2 + numblanks).getstringcellvalue())                                         || "t".equals(row.getcell(c + 2 + numblanks).getstringcellvalue())) {                                     list.add((int) sheet.getrow(1).getcell(c).getnumericcellvalue());                                     break;                                 }                             }                         }                     }                 }                 system.out.println();             }         }         system.out.println();         system.out.println("rows: " + rows);         system.out.println("columns: " + cols);         system.out.println(list);         return temp;     } } 


Comments

Popular posts from this blog

ios - UITEXTFIELD InputView Uipicker not working in swift -

Hatching array of circles in AutoCAD using c# -