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();
        }
    
  • 相关阅读:
    DGL学习(六): GCN实现
    DGL学习(五): DGL构建异质图
    DGL学习(四): 图分类教程
    LuoGuP2495:[SDOI2011]消耗战
    LuoGuP1121:环状最大两段子段和
    LuoGuP3177:[HAOI2015]树上染色
    LuoGuP2607:[ZJOI2008]骑士
    HDU4283:You Are the One
    LuoGuP4294:[WC2008]游览计划
    LuoGuP4127:[AHOI2009]同类分布
  • 原文地址:https://www.cnblogs.com/ideaAI/p/14757728.html
Copyright © 2011-2022 走看看