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这个包