Excel読み込みJXL
以下はJXLでExcelをリストに読み込むプログラムです
/**
* jxl Excel .
* @author sakyone
*/
public class JxlExcelReader {
/**
* @return String[]
*/
public List readExcel(InputStream in) {
List lt = new ArrayList();
Workbook wb = null;
try {
wb = Workbook.getWorkbook(in);
Sheet[] sheets = wb.getSheets(); //
for (int i = 0; i < sheets.length; i++) {
Sheet sheet = sheets[i];
System.err.println("----------sheet"+i+" "+sheet.getRows()+" ------------");
for (int j = 0; j < sheet.getRows(); j++) {
Cell[] cells = sheet.getRow(j); //
if (cells != null && cells.length > 0) { //
// System.err.println("----------- "+cells.length+" ------------");
String[] dataCells = new String[cells.length];
for (int k = 0; k < cells.length; k++) {
dataCells[k] = "" + cells[k].getContents(); //
}//column
lt.add(dataCells);
}
}//one sheet
}//xls file
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (wb != null) {
wb.close();
}
}
return lt;
}