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

网站建设明细标价表网站报价详情

网站建设明细标价表,网站报价详情,美容营销型网站,网站建设的运营计划书通过easyexcel导出列表数据 根据列表内容自适应宽高。 文件名冲突#xff0c;修改文件名递增设置。 依赖 dependencygroupIdcom.alibaba/groupIdartifactIdeasyexcel/artifactIdversion${easyexcel.version}/version修改文件名递增设置。 依赖 dependencygroupIdcom.alibaba/groupIdartifactIdeasyexcel/artifactIdversion${easyexcel.version}/version/dependencydependencygroupIdcom.alibaba/groupIdartifactIdeasyexcel-core/artifactIdversion${easyexcel.version}/versionscopecompile/scope/dependency easyexcel.version3.3.2/easyexcel.version 具体实现 public void export() {//获取列表集合根据自己业务逻辑获取ListApi list this.list();String fileName 服务发布.xlsx;String filePath getUniqueFilePath(fileName);EasyExcel.write(filePath, ApiExcel.class) .registerWriteHandler(new CustomCellWriteWidthConfig()) //.registerWriteHandler(new CustomCellWriteHeightConfig()) .sheet(服务发布列表).doWrite(list);} 判断文件是否存在。 private static String getUniqueFilePath(String baseFileName) {File file new File(baseFileName);int counter 1;while (file.exists()) {String newFileName String.format(%s(%d).xlsx, baseFileName.replace(.xlsx, ), counter);file new File(newFileName);counter;}return file.getAbsolutePath();} 自适应列宽类 package com.cait.fm.console.common;import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Sheet; import java.util.HashMap; import java.util.List; import java.util.Map;/*** author: jg* date: 2024-12-06* description:*/ public class CustomCellWriteWidthConfig extends AbstractColumnWidthStyleStrategy {private final MapInteger, MapInteger, Integer CACHE new HashMap();Overrideprotected void setColumnWidth(WriteSheetHolder writeSheetHolder, ListWriteCellData? cellDataList, Cell cell, Head head, Integer integer,Boolean isHead) {boolean needSetWidth isHead || !cellDataList.isEmpty();if (needSetWidth) {MapInteger, Integer maxColumnWidthMap CACHE.computeIfAbsent(writeSheetHolder.getSheetNo(), k - new HashMap());Integer columnWidth this.dataLength(cellDataList, cell, isHead);if (columnWidth 0) {if (columnWidth 10 columnWidth 20) {columnWidth 20;} else if (columnWidth 10) {columnWidth 10;}Integer maxColumnWidth maxColumnWidthMap.get(cell.getColumnIndex());if (maxColumnWidth null || columnWidth maxColumnWidth) {maxColumnWidthMap.put(cell.getColumnIndex(), columnWidth);Sheet sheet writeSheetHolder.getSheet();sheet.setColumnWidth(cell.getColumnIndex(), 256 * columnWidth 184);}}}}private Integer dataLength(ListWriteCellData? cellDataList, Cell cell, Boolean isHead) {if (isHead) {return cell.getStringCellValue().getBytes().length;} else {CellData? cellData cellDataList.get(0);CellDataTypeEnum type cellData.getType();if (type null) {return -1;} else {switch (type) {case STRING:// 换行符数据需要提前解析好String stringValue cellData.getStringValue();if (stringValue.contains(\n)) {int index stringValue.indexOf(\n);return index ! -1 ? stringValue.substring(0, index).getBytes().length 1 : stringValue.getBytes().length 1;} else if (stringValue.contains(()) {return stringValue.getBytes().length;} else {return stringValue.getBytes().length;}case BOOLEAN:return cellData.getBooleanValue().toString().getBytes().length;case NUMBER:return cellData.getNumberValue().toString().getBytes().length;default:return -1;}}}}}自适应行高 public class CustomCellWriteHeightConfig extends AbstractRowHeightStyleStrategy {/*** 默认高度*/private static final Integer DEFAULT_HEIGHT 300;Overrideprotected void setHeadColumnHeight(Row row, int relativeRowIndex) {}Overrideprotected void setContentColumnHeight(Row row, int relativeRowIndex) {IteratorCell cellIterator row.cellIterator();if (!cellIterator.hasNext()) {return;}// 默认为 1 行高度int maxHeight 1;while (cellIterator.hasNext()) {Cell cell cellIterator.next();if (cell.getCellType() CellType.STRING) {String value cell.getStringCellValue();for (int i 0; i value.length(); i 10) {if (i 10 value.length()) {value value.substring(0, i) \n value.substring(i, i 10) value.substring(i 10);} else {value value.substring(0, i) \n value.substring(i);}}if (value.contains(\n)) {int length value.split(\n).length;maxHeight Math.max(maxHeight, length);}}}row.setHeight((short) (maxHeight * DEFAULT_HEIGHT));}Overridepublic void afterRowDispose(RowWriteHandlerContext context) {if (context.getHead() ! null) {if(ObjectUtils.isEmpty(context.getRelativeRowIndex())){return;}if (Boolean.TRUE.equals(context.getHead())) {this.setHeadColumnHeight(context.getRow(), context.getRelativeRowIndex());} else {this.setContentColumnHeight(context.getRow(), context.getRelativeRowIndex());}}} }
http://www.pierceye.com/news/648796/

相关文章:

  • 营销型网站 易网拓德阳做网站
  • 网站建设seo虾哥网络购物网站技术实施方案
  • 门户网站框架下载陕西省建设工会网站
  • 网站有信心做的更好做外贸到什么网站上发布比较好
  • wex5做网站wordpress页面的设置
  • 绍兴市建设银行网站网站建设的基本术语
  • 建筑企业网站模板免费下载seo 网站换程序
  • wordpress怎么做排名seo怎么样
  • 电商网站开发平台哪家好百度运营怎么做
  • 门户网站 源码网站建设推广公司范围
  • 网站字体大小wordpress用户登录页面
  • 影院禁止18岁以下观众入内宿迁新站seo
  • 龙岗网站设计机构网站开发开始阶段的主要任务包括( )。
  • 宿州公司网站建设教做世界美食的网站
  • 网站建设价格很 好乐云seo免费自学编程
  • 网站哪家做的好公共资源交易中心级别
  • html5网站开发工具自己做微信电影网站怎么做
  • 学院网站制度建设成品大香伊煮蕉免费在线
  • 做网站的域名和空间是什么意思佛山建站专
  • 网站是哪个公司做wordpress 底部修改插件
  • 嘉兴网站推广优化印度vps
  • 网站seo诊断分析和优化方案青岛网站制作方案
  • 发布个人免费网站的一般流程图宣传广告
  • php学什么可以做网站po wordpress
  • 875网站建设怎么样网站设计高端网站设计
  • qq钓鱼网站怎么制作扬州网站建设哪个好薇
  • 域名和网站空间怎么做解析南阳seo网站推广费用
  • 烟台企业网站建设国内ui网站有哪些
  • 手机网站建设选 朗创营销电商运营的核心公式
  • seo网站排名软件飞机网页设计实训报告