| | |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import com.alibaba.excel.annotation.write.style.*; |
| | | import com.alibaba.excel.converters.Converter; |
| | | import com.alibaba.excel.converters.WriteConverterContext; |
| | | import com.alibaba.excel.enums.BooleanEnum; |
| | | import com.alibaba.excel.enums.CellDataTypeEnum; |
| | | import com.alibaba.excel.enums.poi.BorderStyleEnum; |
| | | import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum; |
| | | import com.alibaba.excel.enums.poi.VerticalAlignmentEnum; |
| | | import com.alibaba.excel.metadata.GlobalConfiguration; |
| | | import com.alibaba.excel.metadata.data.ImageData; |
| | | import com.alibaba.excel.metadata.data.WriteCellData; |
| | | import com.alibaba.excel.metadata.property.ExcelContentProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | //参考: https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write |
| | | @Data |
| | |
| | | horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER, |
| | | borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN, borderBottom = BorderStyleEnum.THIN, |
| | | leftBorderColor = 8, rightBorderColor = 8, topBorderColor = 8, bottomBorderColor = 8) //IndexedColors.BLACK |
| | | @ContentRowHeight(100) //设置内容高度 |
| | | @ContentFontStyle(fontName="宋体", fontHeightInPoints = 14) |
| | | @ContentRowHeight(30) //设置内容高度 |
| | | @ContentFontStyle(fontName="宋体", fontHeightInPoints = 11) |
| | | @ContentStyle(wrapped = BooleanEnum.TRUE, shrinkToFit = BooleanEnum.TRUE, |
| | | horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER, |
| | | borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN, borderBottom = BorderStyleEnum.THIN, |
| | | leftBorderColor = 8, rightBorderColor = 8, topBorderColor = 8, bottomBorderColor = 8) //IndexedColors.BLACK |
| | | @ColumnWidth(16) //设置列宽 |
| | | public class ExcelVo implements Converter<byte[]> { |
| | | @ColumnWidth(40) |
| | | // @ContentLoopMerge(eachRow=2) |
| | | @ColumnWidth(0)//设置列宽为0,不显示 |
| | | @ExcelProperty("ID") |
| | | public String id ; |
| | | |
| | | @ColumnWidth(15) |
| | | @ExcelProperty("用户名") |
| | | public String userName ; |
| | | |
| | | @ColumnWidth(40) |
| | | @ColumnWidth(20) |
| | | @ExcelProperty("排班日期") |
| | | // @ContentLoopMerge(eachRow=2) |
| | | public String scheduleDate ; |
| | | |
| | | @ColumnWidth(40) |
| | | @ColumnWidth(28) |
| | | @ExcelProperty("创建时间") |
| | | // @ContentLoopMerge(eachRow=2) |
| | | public Date dt ; |
| | | |
| | | @ColumnWidth(40) |
| | |
| | | @ColumnWidth(40) |
| | | @ExcelProperty({"排班内容","工作内容"}) |
| | | public String workDetails ; |
| | | |
| | | public WriteCellData<?> convertToExcelData(byte[] value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
| | | WriteCellData cellData = new WriteCellData() ; |
| | | if(value != null && value.length >0){ |
| | | List<ImageData> list = new ArrayList<>(); |
| | | ImageData imd = new ImageData(); |
| | | imd.setImage(value); |
| | | imd.setImageType(ImageData.ImageType.PICTURE_TYPE_PICT); |
| | | imd.setLeft(10); |
| | | imd.setTop(10); |
| | | imd.setRight(10); |
| | | imd.setBottom(10); |
| | | list.add(imd) ; |
| | | cellData.setImageDataList(list); |
| | | cellData.setType(CellDataTypeEnum.EMPTY); |
| | | }else{ |
| | | cellData.setStringValue(""); |
| | | cellData.setType(CellDataTypeEnum.STRING); |
| | | } |
| | | return cellData; |
| | | } |
| | | |
| | | public WriteCellData<?> convertToExcelData(WriteConverterContext<byte[]> context) throws Exception { |
| | | return this.convertToExcelData(context.getValue(), context.getContentProperty(), context.getWriteContext().currentWriteHolder().globalConfiguration()); |
| | | } |
| | | |
| | | } |