肯定要知道的是,poi支持Excel2007的版本,2003的版本并不支持
String fileName = file.getOriginalFilename();
String fileType = "";
List<PmoRegulationDetail> regulationList = new ArrayList<PmoRegulationDetail>();
try {
XSSFWorkbook wb = null;
wb = new XSSFWorkbook(file.getInputStream());
XSSFSheet sheet = wb.getSheetAt(0);
for(int i=sheet.getFirstRowNum()+1,size=sheet.getLastRowNum();i<=size;i++){
XSSFRow row = sheet.getRow(i);
int x = row.getFirstCellNum();
PmoRegulationDetail detial = new PmoRegulationDetail();
detial.setAgentName(row.getCell(x).toString().trim());
detial.setAmount(row.getCell(x+1).toString().trim());
detial.setMonth(row.getCell(x+2).toString().trim());
detial.setIdentifier(row.getCell(x+3).toString().trim());
detial.setRegulationRemark(row.getCell(x+4).toString().trim());
regulationList.add(detial);
}
logger.debug("last row = "+sheet.getLastRowNum());
} catch (Exception e) {
e.printStackTrace();}
XSSFWorkbook wb = new XSSFWorkbook();//创建一个新的工作薄,读取的时候是读取工作薄
XSSFSheet sheet = wb.getSheetAt(0);//得到第一个工作薄的电子表格
XSSFRow row = sheet.getRow(i);//获取电子表格的第i行
row.getCell(X)//获取该行第x列的值,有很多获取不同数据格式的获取方式,暂时没有了解
String test = new String(" abc ");
String testB = test.trim();//b = abc 去掉字符串中的开头和结尾的空格符