POI 操作excel图标

   @Override
    public void excelExport(HttpServletResponse response, String orgzCode,
                            String periodId,
                            String systemCode) throws IOException {

        /**
         * @description: 读取文件
         **/
        Resource resource = new ClassPathResource("information/图.xlsx");

        InputStream inputStream = resource.getInputStream();
        //String path = resource.getFile().getPath();

        XSSFWorkbook wb = new XSSFWorkbook(inputStream);
        XSSFSheet sheet = wb.getSheetAt(0);
        int startRow = 2;
        XSSFRow row = sheet.getRow(startRow);
        XSSFCell cellA1 = row.createCell(1);
        cellA1.setCellValue(11);
        XSSFCell cellA2 = row.createCell(2);
        cellA2.setCellValue(22);
        XSSFCell cellA3 = row.createCell(3);
        cellA3.setCellValue(33);
        XSSFCell cellA4 = row.createCell(4);
        cellA4.setCellValue(44);

        wb.setForceFormulaRecalculation(true);
        String excelName = "导出数据.xlsx";
        response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(excelName, "UTF-8"));
        response.setContentType("application/x-msdownload;charset=UTF-8");
        ServletOutputStream os = response.getOutputStream();
        wb.write(os);
        //释放资源
        os.flush();
        os.close();
        wb.close();
        //return excelName;
    }
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容