标签:io ar os java for sp 数据 on bs
/**
* 处理excel数据的方法
*/
public static Hashtable<String, Vector<Vector<String>>> readExcel(
String filePath) throws Exception {
Hashtable<String, Vector<Vector<String>>> datas = new Hashtable<String, Vector<Vector<String>>>();
InputStream is = null;
try {
is = new FileInputStream(filePath);
WorkbookSettings wkbkSet = new WorkbookSettings();
wkbkSet.setSuppressWarnings(true);
Workbook rwb = Workbook.getWorkbook(is, wkbkSet);
Sheet st[] = rwb.getSheets();
for (int a = 0; a < st.length; a++) {
String sheetName = st[a].getName().trim();
Vector<Vector<String>> sheetDatas = new Vector<Vector<String>>();
for (int i = 0; i < st[a].getRows(); i++) {
Vector<String> rowDatas = new Vector<String>();
for (int j = 0; j < st[a].getColumns(); j++) {
Cell c = st[a].getCell(j, i);
String content = c.getContents().trim();
rowDatas.add(content);
}
sheetDatas.add(rowDatas);
}
datas.put(sheetName, sheetDatas);
}
rwb.close();
} catch (Exception e) {
throw e;
} finally {
try {
if (is != null) {
is.close();
}
} catch (Exception e) {
}
}
return datas;
}
public static void main(String[] args) throws Exception {
Hashtable<String, Vector<Vector<String>>> datas = readExcel("E:\\123.xls");
System.out.println(datas.get("Sheet1"));
}
标签:io ar os java for sp 数据 on bs
原文地址:http://my.oschina.net/pzxzj/blog/341388