Public List ReadExcel2010(String sFilename)
{
List SheetData = new ArrayList();
InputStream fs = new FileInputStream(filename);
XSSFWorkbook wb = new XSSFWorkbook(fs);
XSSFSheet sheet = wb.getSheetAt(0);
try
{
Header header = sheet.getHeader();
int rowsCount = sheet.getLastRowNum();
System.out.println("Total Number of Rows: " + (rowsCount + 1));
for (int i = 0; i <= rowsCount; i++) {
List data = new ArrayList();
Row row = sheet.getRow(i);
int colCounts = row.getLastCellNum();
System.out.println("Total Number of Cols: " + colCounts);
for (int j = 0; j < colCounts; j++) {
Cell cell = row.getCell(j);
data.add(cell );
System.out.println("[" + i + "," + j + "]=" + cell.getStringCellValue());
}
Sheetdata.add(data);
}
} catch (Exception ex) {
java.util.logging.Logger.getLogger(FieldController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
fs.close();
} catch (IOException ex) {
java.util.logging.Logger.getLogger(FieldController.class.getName()).log(Level.SEVERE, null, ex);
}
}
return Sheetdata;
}
{
List SheetData = new ArrayList();
InputStream fs = new FileInputStream(filename);
XSSFWorkbook wb = new XSSFWorkbook(fs);
XSSFSheet sheet = wb.getSheetAt(0);
try
{
Header header = sheet.getHeader();
int rowsCount = sheet.getLastRowNum();
System.out.println("Total Number of Rows: " + (rowsCount + 1));
for (int i = 0; i <= rowsCount; i++) {
List data = new ArrayList();
Row row = sheet.getRow(i);
int colCounts = row.getLastCellNum();
System.out.println("Total Number of Cols: " + colCounts);
for (int j = 0; j < colCounts; j++) {
Cell cell = row.getCell(j);
data.add(cell );
System.out.println("[" + i + "," + j + "]=" + cell.getStringCellValue());
}
Sheetdata.add(data);
}
} catch (Exception ex) {
java.util.logging.Logger.getLogger(FieldController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
fs.close();
} catch (IOException ex) {
java.util.logging.Logger.getLogger(FieldController.class.getName()).log(Level.SEVERE, null, ex);
}
}
return Sheetdata;
}
No comments:
Post a Comment