zoukankan      html  css  js  c++  java
  • Java Excel

    /**
    * Excel上传
    * */
    @RequestMapping(value = "/xxx.do")
    public void excelBatch(@RequestParam("file") MultipartFile file,
    HttpServletResponse response, HttpServletRequest request)
    throws Exception {
    ByteArrayInputStream is = null;
    try {
    //读取流文件
    is = new ByteArrayInputStream(file.getBytes());
    // 打开文件
    Workbook book = Workbook.getWorkbook(is);
    // 得到第一个工作表对象
    Sheet sheet = book.getSheet(0);
    // 得到第一个工作表中的总行数
    int rowCount = sheet.getRows();
    Map<String, String> map = new HashMap<String, String>();
    if (rowCount > 1) {
    // 循环取出Excel中的内容
    for (int i = 1; i < rowCount; i++) {
    Cell[] cells = sheet.getRow(i);
    String col1 = cells[0].getContents();//数据1
    String col2 = cells[1].getContents();//数据2
    String col3 = cells[2].getContents();//数据3
    // 保存到数据库...
    }
    map.put("flag", "success");
    writerJson(response, map);
    }
    } catch (BiffException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    is.close();
    }
    }

  • 相关阅读:
    多线程
    IO
    Collections工具类
    File类
    Map
    List与Set接口
    如何把数学作为一种工具
    包装类
    异常
    内部类
  • 原文地址:https://www.cnblogs.com/MyBlog-/p/11909610.html
Copyright © 2011-2022 走看看