当前位置: 代码迷 >> J2EE >> poi读取2003一般,为什么读取不到2007的
  详细解决方案

poi读取2003一般,为什么读取不到2007的

热度:68   发布时间:2016-04-17 23:29:07.0
poi读取2003正常,为什么读取不到2007的
controller

/**
 * 读者批导入EXCEL接收
 * @param model
 * @return
 * @throws IOException 
 * @throws FileNotFoundException 
 * @throws InvalidFormatException 
 */
@RequestMapping("/upload")
public String upload(@RequestParam("file") MultipartFile file , Model model) throws InvalidFormatException, FileNotFoundException, IOException{
try {
String filePath = Config.parseFilePath(
"window.bookSellerReceive.file",
"window.bookSellerReceive.file", file);
excelImp.initWorkbook(new FileInputStream(new File(filePath)));
Map<String,String> map = excelImp.readerTitle(0).getTitles();
model.addAttribute("sheetNameInfos", map);
model.addAttribute("filePath", filePath);
return MANA_PATH + "readerupload/sheetUpload";
} catch (BusinessException e) {
model.addAttribute(Constant.MESSAGE_ERROR, e.getMessage());
e.printStackTrace();
return list(model);

}

excel工具类

/**
 * <p>
 * description:创建工作本
 * </p>
 * 
 * @param inp
 * @return
 * @throws InvalidFormatException
 * @throws IOException
 * @return Workbook
 * @date 2012-7-2
 */
public void initWorkbook(InputStream inp) throws InvalidFormatException,
IOException {
workbook = WorkbookFactory.create(inp);
}

readerTitle

public ExcelTitle readerTitle(int sheetNumber) {
return readerTitle(sheetNumber, null);
}


debug是在

excelImp.initWorkbook(new FileInputStream(new File(filePath)));

看半天看不出哪有问题2003接收正常 2007就失败了
------解决思路----------------------
我来帮你顶下 兄弟
------解决思路----------------------
我来帮你顶下 兄弟
------解决思路----------------------
2003和2007的API是不一样的
------解决思路----------------------
WorkbookFactory.create(inp);
既可创建HSSFWorkbook(.xls),也可创建XSSFWorkbook(.xlsx)。你具体报什么错?
------解决思路----------------------
应该是版本问题吧,对2003的操作和2007的操作是不一样的
------解决思路----------------------
删除xbean-2.1.0.jar这个包
  相关解决方案