| | |
| | | import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
| | | import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | |
| | | public class CustomerHandler extends AbstractColumnWidthStyleStrategy { |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { |
| | | protected void setColumnWidth(WriteSheetHolder writeSheetHolder, |
| | | List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, |
| | | Boolean isHead) { |
| | | boolean needSetWidth = isHead || !CollectionUtils.isEmpty(cellDataList); |
| | | if (needSetWidth) { |
| | | Map<Integer, Integer> maxColumnWidthMap = (Map) CACHE.get(writeSheetHolder.getSheetNo()); |
| | | Map<Integer, Integer> maxColumnWidthMap = (Map) CACHE.get( |
| | | writeSheetHolder.getSheetNo()); |
| | | if (maxColumnWidthMap == null) { |
| | | maxColumnWidthMap = new HashMap(16); |
| | | CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); |
| | |
| | | } |
| | | } |
| | | |
| | | Integer maxColumnWidth = (Integer) ((Map) maxColumnWidthMap).get(cell.getColumnIndex()); |
| | | Integer maxColumnWidth = (Integer) ((Map) maxColumnWidthMap).get( |
| | | cell.getColumnIndex()); |
| | | if (maxColumnWidth == null || columnWidth > maxColumnWidth) { |
| | | ((Map) maxColumnWidthMap).put(cell.getColumnIndex(), columnWidth); |
| | | writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), columnWidth * 256); |
| | | writeSheetHolder.getSheet() |
| | | .setColumnWidth(cell.getColumnIndex(), columnWidth * 256); |
| | | } |
| | | } |
| | | } |