java - Reading from excel file with blank cells to 2d array -


i have following code reads logins , passwords xls file starting second row(it skips column names) , writes 2d array. works if sheet doesn't have blank cells in of rows. should make work empty cells?

private static object[][] getusersfromxls(string sheetname) {          final file excelfile = new file("src//resources//testdata.xls");          fileinputstream fileinputstream;            try {              fileinputstream = new fileinputstream(excelfile);              workbook = new hssfworkbook(fileinputstream);          } catch (ioexception e) {              e.printstacktrace();          }            sheet = workbook.getsheet(sheetname);            final int numberofrows = sheet.getlastrownum();          final int numberofcolumns = sheet.getrow(0).getlastcellnum();            final string[][] xlsdata = new string[numberofrows][numberofcolumns];          string cellvalue;            (int = 1; <= numberofrows; i++) {              final hssfrow row = sheet.getrow(i);                (int j = 0; j < numberofcolumns; j++) {                  final hssfcell cell = row.getcell(j);                  final int celltype = cell.getcelltype();                    if (celltype == hssfcell.cell_type_formula) {                      throw new runtimeexception("cannot process formula. please change field result of formula.");                  } else {                      cellvalue = string.valueof(cell);                      xlsdata[i - 1][j] = cellvalue;                  }              }          }          return xlsdata;      }


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -