| | |
| | | package com.zy.asrs.wms.utils; |
| | | |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.wms.asrs.entity.MatField; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Created by vincent on 2/17/2024 |
| | |
| | | } |
| | | |
| | | public static <T> Workbook create(List<T> list, Class<T> clz) { |
| | | return create(list, clz, null); |
| | | } |
| | | |
| | | public static <T> Workbook create(List<T> list, Class<T> clz, List<MatField> dynamicFields) { |
| | | HSSFWorkbook workbook = new HSSFWorkbook(); |
| | | Sheet sheet = workbook.createSheet(clz.getSimpleName()); |
| | | |
| | |
| | | } |
| | | header.createCell(headerIdx).setCellValue(memo); |
| | | headerIdx++; |
| | | } |
| | | |
| | | //动态字段 |
| | | if(dynamicFields != null){ |
| | | for (MatField field : dynamicFields) { |
| | | header.createCell(headerIdx).setCellValue(field.getDescribe()); |
| | | headerIdx++; |
| | | } |
| | | } |
| | | |
| | | int rowIndex = 1; |
| | |
| | | } |
| | | cellIndex++; |
| | | } |
| | | |
| | | //动态字段 |
| | | if(dynamicFields != null){ |
| | | for (Field field : fields) { |
| | | if (field.getName().equals("dynamicFields")) { |
| | | try { |
| | | Map<String, Object> map = (Map<String, Object>) field.get(t); |
| | | for (MatField matField : dynamicFields) { |
| | | Object value = map.get(matField.getName()); |
| | | if(value != null){ |
| | | row.createCell(cellIndex).setCellValue(value.toString()); |
| | | cellIndex++; |
| | | } |
| | | } |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | for (int i = 0; i <= fields.length; i++) { |