zoukankan      html  css  js  c++  java
  • Excel处理写入(SpringBoot Mybatis-Plus)

    gradle

    compile group: 'org.apache.poi', name: 'poi', version: '3.9';
    compile group: 'org.apache.poi', name: 'poi-excelant', version: '3.9';
    compile group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.9';
    

    demo

    @PostMapping(value = "/excelWrite")
        @ResponseBody
        public HttpResult excelWrite(@RequestParam("file") MultipartFile multipartFile) throws IOException {
            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
            HSSFSheet sheet = hssfWorkbook.createSheet();
            Row row0 = sheet.createRow(0);
            int columnIndex = 0;
            row0.createCell(columnIndex).setCellValue("");
            row0.createCell(++columnIndex).setCellValue("名称");
            row0.createCell(++columnIndex).setCellValue("规格");
            row0.createCell(++columnIndex).setCellValue("单位");
            row0.createCell(++columnIndex).setCellValue("数量");
            row0.createCell(++columnIndex).setCellValue("单价");
            row0.createCell(++columnIndex).setCellValue("总额");
    
            for (int i = 0; i < productList.size(); i++) {
                Product product = productList.get(i);
                Row row = sheet.createRow(i + 1);
                for (int j = 0; j < columnIndex + 1; j++) {
                    row.createCell(j);
                }
                columnIndex = 0;
    //            row.getCell(columnIndex).setCellValue(i + 1);
                row.getCell(++columnIndex).setCellValue(product.getName());
                row.getCell(++columnIndex).setCellValue(product.getType());
                row.getCell(++columnIndex).setCellValue(product.getNum());
            }
    
    
            FileOutputStream out = new FileOutputStream("D:\汇总.xls");
            hssfWorkbook.write(out);
            out.flush();
    
            return HttpResult.ok();
        }
    
  • 相关阅读:
    Next Permutation
    SpringMVC配置信息
    Servlet详解(转载)
    Length of Last Word
    Maximum Subarray**
    Divide Two Integers
    Generate Parentheses***
    http解码-2
    编码-1
    扫描工具对比
  • 原文地址:https://www.cnblogs.com/ideaAI/p/14757728.html
Copyright © 2011-2022 走看看