当前位置: 首页 > news >正文

hutool ExcelUtil 导出导入excel

引入依赖

  <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.15</version></dependency>

文件导入

public void savelist(String filepath,String keyname){ExcelReader reader = ExcelUtil.getReader(FileUtil.file(filepath), 0);List<Map<String, Object>> sheetRowsMap = reader.readAll();String host = "192.168.1.80";int port = 6379;Jedis jedis = new  Jedis(host, port);for (Map<String, Object> stringObjectMap : sheetRowsMap) {TemplateVo vo =  JwfsStdPopRealPopNewTemplateVo.builder().addressDetail(String.valueOf(stringObjectMap.get("户籍地址(校验后)"))).popName(String.valueOf(stringObjectMap.get("姓名"))).popPhone(String.valueOf(stringObjectMap.get("电话"))).build();log.info(vo);}}

文件导出

 public static void export(List<JwfsStdPopRealPopNewTemplateVo> data, String path, String fileName, JwfsStdPopRealPopNewTemplateVo excelData) throws IOException {log.info("开始导出");ExcelWriter writer = ExcelUtil.getWriter();List<Map> fieldAnnotation = getFieldAnnotation(excelData);for(Map<String,String> map:fieldAnnotation){for(String key:map.keySet()){String value = map.get(key);writer.addHeaderAlias(key,value);}}//第1列40px宽//writer.setColumnWidth(0, 40);//第2列15px 宽//writer.setColumnWidth(1, 15);//对齐方式,水平左对齐,垂直中间对齐writer.getStyleSet().setAlign(HorizontalAlignment.LEFT, VerticalAlignment.CENTER);//标题样式CellStyle headCellStyle = writer.getHeadCellStyle();//设置背景色headCellStyle.setFillForegroundColor(IndexedColors.WHITE1.getIndex());//必须设置 否则背景色不生效headCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//创建标题字体Font headFont = writer.createFont();headFont.setFontName("宋体");//大小headFont.setFontHeightInPoints((short) 11);//加粗headFont.setBold(true);headCellStyle.setFont(headFont);writer.setColumnWidth(-1, 30);writer.setRowHeight(-1,20);//保存路径FileOutputStream output = new FileOutputStream(path+fileName+".xls");// 一次性写出内容writer.write(data);//自适应列宽int columnCount = writer.getColumnCount();for (int i = 0; i < columnCount; ++i) {double width = SheetUtil.getColumnWidth(writer.getSheet(), i, false);if (width != -1.0D) {width *= 256.0D;//此处可以适当调整,调整列空白处宽度width += 220D;writer.setColumnWidth(i, Math.toIntExact(Math.round(width / 256D)));}}writer.flush(output,true);// 关闭writer,释放内存writer.close();}JwfsStdPopRealPopNewTemplateVo jwfsStdPopRealPopNewTemplateVo = JwfsStdPopRealPopNewTemplateVo.builder().build();export(list,"C:\\Users\\Administrator\\Desktop\\1\\",filename,jwfsStdPopRealPopNewTemplateVo);
http://www.lryc.cn/news/396350.html

相关文章:

  • 打卡第7天-----哈希表
  • 【Linux】WEB网站网络防火墙(WAF软件)Fail2ban:保护服务器免受恶意攻击的必备工具
  • 妙笔生词智能写歌词软件:创新助力还是艺术之殇?
  • 力扣hot100-普通数组
  • 深入浅出Transformer:大语言模型的核心技术
  • MacOS隐藏文件打开指南
  • grafana数据展示
  • 53-4 内网代理6 - frp搭建三层代理
  • SQLite 命令行客户端 + HTA 实现简易UI
  • TikTok小店推出“百万英镑俱乐部”,实力宠卖家!
  • 路径规划 | 基于蚁群算法的三维无人机航迹规划(Matlab)
  • .Net C#执行JavaScript脚本
  • 企业应对策略:全面防御.DevicData-P-xxxxxx勒索病毒
  • 记一次mysql导出到达梦数据库
  • 2024年高压电工证考试题库及高压电工试题解析
  • 完美解决ImportError: cannot import name ‘idnadata‘的正确解决方法,亲测有效!!!
  • 完美解决windows开机时,系统提示此windows副本不是正版的正确解决方法,亲测有效!!!
  • 树莓派采集系统
  • ListView
  • gptoolbox matlab工具箱cmake 调试笔记
  • Python面试题:请编写一个函数,计算一个字符串中每个字符的出现频率
  • MacOS如何切换shell类型
  • Qt QSettings 使用详解:跨平台的配置管理
  • 确定适合您需求的负载组
  • Xubuntu24.04之设置高性能模式两种方式(二百六十一)
  • 【自适应滤波系列五】基于LMS算法的回声消除(Acoustic Echo Cancellation, AEC)
  • matlab 卷积和多项式乘法
  • 数据跨境传输法规日趋完善,企业如何规避合规风险?
  • 工业机床CNC设备如何上云?
  • Android C++系列:Linux进程间关系