日期:2014-05-20 浏览次数:20953 次
public static void main(String[] args) throws Exception {
Workbook book = null;
book = Workbook.getWorkbook(new File("C:\\Documents and Settings\\pKF58059\\桌面\\tab.xls"));
//获取sheet
Sheet sheet = book.getSheet(0);
int rows = sheet.getRows();
int cols = sheet.getColumns();
int[][][] tab = new int[rows][cols][];
for(int r = 0; r < rows; r++){
Cell[] rowCells = sheet.getRow(r);
for(int c = 0; c < cols; c++){
Cell cell = rowCells[c];
String value = cell.getContents();
String[] items = value.split(",");
int[] values = new int[items.length];
for(int i = 0; i < items.length; i++){
values[i] = Integer.parseInt(items[i]);
}
tab[r][c] = values;
}
}
for(int x = 0; x < tab.length; x++){
for(int y = 0; y < tab[x].length; y++){
for(int z = 0; z < tab[x][y].length; z++){
System.out.println("第" + x + "行,第" + y +"列的第" + z + "个数据是:" + tab[x][y][z]);
}
}
}
}
------解决方案--------------------
String value = cell.getContents();
value.replaceAll("\\s+", "");
if(value.equals("")){
continue;
}
String[] items = value.split(",");