java读取excel 支持所有版本
来源:互联网 发布:java中重载的意义 编辑:程序博客网 时间:2024/06/05 17:38
springmvc 写的一个小例子 读取excel里的数据 并且保存 需要的jar包 为dom4j-1.6.1.jar poi-3.9-20121203.jar poi-examples-3.9-20121203.jar poi-excelant-3.9-20121203.jar poi-ooxml-3.9-20121203.jar poi-ooxml-schemas-3.9-20121203.jar poi-scratchpad-3.9-20121203.jar xmlbeans-2.6.0.jar
@RequestMapping(value = "/word/file", method = RequestMethod.POST)
public String fileWord(@RequestParam(value=("file"),required=false) MultipartFile file) throws IOException {
try {
String filepath = "E:\\" + file.getOriginalFilename();
FileUtils.writeByteArrayToFile(new File(filepath), file.getBytes());
String fileType = filepath.substring(filepath.lastIndexOf(".")+1);
Workbook workbook = null;
InputStream is = new FileInputStream(filepath);
if (fileType.equalsIgnoreCase("xlsx")) {
workbook = new XSSFWorkbook(is);
}else if(fileType.equalsIgnoreCase("xls")){
workbook = new HSSFWorkbook(is);
}else {
throw new Exception("暂时只支持xlsx和xls格式的excel读取");
}
// 循环工作表Sheet
for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
Sheet sheetAt = workbook.getSheetAt(numSheet);
if (sheetAt == null) {
continue;
}
// 循环行Row
for (int rowNum = 1; rowNum <= sheetAt.getLastRowNum(); rowNum++) {
Row row = sheetAt.getRow(rowNum);
if (row != null) {
Words words = new Words();
words.setMerchantNumber(row.getCell(0)+"");
words.setMerchantName(row.getCell(1)+"");
words.setShopNumber(row.getCell(2)+"");
words.setShopName(row.getCell(3)+"");
words.setOrderNumber(row.getCell(4)+"");
words.setMoney(Double.parseDouble(row.getCell(5)+""));
words.setState(row.getCell(6)+"");
String parseExcel = parseExcel(row.getCell(7));
words.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(parseExcel));
words.setNeeded(row.getCell(8)+"");
wordsService.saveWord(words);
}
}
}
File file2 = new File(filepath);
file2.delete();
} catch (Exception e) {
System.out.println("在读取word格式的文件时出现了未知错位,错位在wordsController类中");
e.printStackTrace();
}
return "forward:/word/words/1";
}
- java读取excel 支持所有版本
- 纯js读取excel文件内容,支持所有刘浏览器
- 读取RSS(支持目前所有RSS版本)
- 读取RSS(支持目前所有RSS版本).net
- java读取Excel读取
- vs2017支持所有版本VC
- POI 读取 Excel 转 HTML 支持 03xls 和 07xlsx 版本 包含样式,03xls07xlsx
- excel逐列读取excel所有数据
- java利用POI实现Excel导入导出详解-支持97-2013版本以及2017版本
- Java读取Excel方式
- java读取excel文件
- java读取excel 文件
- JAVA读取EXCEL
- java读取excel
- java读取excel文件
- Java读取Excel文件
- java读取Excel文件
- java读取 excel 文本
- js 中的for in 与标准for循环遍历数组
- UITablerView(表视图基础)
- 访问系统的相册
- 彻底解决:Keil编译提示“File has been changed outside the editor, reload?”提示!
- Areas on the Cross-Section Diagram
- java读取excel 支持所有版本
- [CFF认证]201509-3模板生成系统(C++)
- yii-basic(一)安装及简介
- 第十四周项目2-二叉树排序树中查找的路径
- mysql实现ORACLE 中ROWNUM函数
- java线程
- es6 javascript的 class 类的基本语法
- 网络数据传输的原理,理解各站点间数据是如何传输的
- 2016 年哪些互联网技术开始变得流行,哪些过时了?