zoukankan      html  css  js  c++  java
  • Java 导入excel获取表格信息

    public ResponseFindPage<Student> findPage(@RequestParam("file") MultipartFile file) {
    ResponseFindPage<Student> rfp = new ResponseFindPage<Student>();
    String fileName = file.getOriginalFilename();
    System.out.println(fileName);

    Workbook workbook = null;
    try {
    InputStream in = file.getInputStream();
    workbook = new XSSFWorkbook(in);
    //workbook = WorkbookFactory.create(new File(String.valueOf(file)));
    } catch (IOException e) {
    e.printStackTrace();
    }
    //获取一张表
    Sheet sheet = workbook.getSheetAt(0);
    for (int i = 1; i <= sheet.getLastRowNum(); i++) {//跳过第一行,取得其他行数据
    Row row = sheet.getRow(i);//取得第i行数据
    Student student = new Student();
    for (int j = 0; j < row.getLastCellNum(); j++) {
    Cell cell = row.getCell(j);//取得第j列数据
    cell.setCellType(CellType.STRING);
    String value = cell.getStringCellValue();
    System.out.print(i + " " + j + " " + value + " ");
    }
    if (StringUtils.isNotBlank(student.getPhone())) {
    students.add(student);
    }
    }
    rfp.setData(students);
    return rfp;
    }
  • 相关阅读:
    VUE常用传值方式、父传子、子传父、非父子组件传值
    ios10中禁止用户缩放页面
    TCP MSS
    C++11 之 override
    unordered_set
    c++Lambda
    QUIC实现代码分析
    C++11新特性之十:enable_shared_from_this
    c++11 atomic
    How to Write a QUIC Endpoint Program
  • 原文地址:https://www.cnblogs.com/xiaobug/p/14550985.html
Copyright © 2011-2022 走看看