You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
48 lines
1.6 KiB
package com.ruoyi.system.utils;
|
|
|
|
import com.alibaba.excel.metadata.Head;
|
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|
import com.alibaba.excel.write.style.AbstractCellStyleStrategy;
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class CellStyleStrategy extends AbstractCellStyleStrategy {
|
|
|
|
private WriteCellStyle headWriteCellStyle;
|
|
private List<WriteCellStyle> contentWriteCellStyleList;
|
|
|
|
private CellStyle headCellStyle;
|
|
private List<CellStyle> contentCellStyleList;
|
|
|
|
public CellStyleStrategy(WriteCellStyle headWriteCellStyle,
|
|
List<WriteCellStyle> contentWriteCellStyleList) {
|
|
this.headWriteCellStyle = headWriteCellStyle;
|
|
this.contentWriteCellStyleList = contentWriteCellStyleList;
|
|
}
|
|
|
|
public CellStyleStrategy(WriteCellStyle headWriteCellStyle, WriteCellStyle contentWriteCellStyle) {
|
|
this.headWriteCellStyle = headWriteCellStyle;
|
|
contentWriteCellStyleList = new ArrayList<WriteCellStyle>();
|
|
contentWriteCellStyleList.add(contentWriteCellStyle);
|
|
}
|
|
|
|
@Override
|
|
protected void setHeadCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
|
|
if (headCellStyle == null) {
|
|
return;
|
|
}
|
|
cell.setCellStyle(headCellStyle);
|
|
}
|
|
|
|
@Override
|
|
protected void setContentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
|
|
if (contentCellStyleList == null || contentCellStyleList.isEmpty()) {
|
|
return;
|
|
}
|
|
cell.setCellStyle(contentCellStyleList.get(0));
|
|
}
|
|
|
|
}
|