AbstractHeadColumnWidthStyleStrategy.java
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.taover.easyexcel.write.style.column;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import com.taover.easyexcel.metadata.CellData;
import com.taover.easyexcel.metadata.Head;
import com.taover.easyexcel.write.metadata.holder.WriteSheetHolder;
/**
* Returns the column width according to each column header
*
* @author Jiaju Zhuang
*/
public abstract class AbstractHeadColumnWidthStyleStrategy extends AbstractColumnWidthStyleStrategy {
@Override
protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<CellData> cellDataList, Cell cell, Head head,
Integer relativeRowIndex, Boolean isHead) {
boolean needSetWidth = relativeRowIndex != null && (isHead || relativeRowIndex == 0);
if (!needSetWidth) {
return;
}
Integer width = columnWidth(head, cell.getColumnIndex());
if (width != null) {
width = width * 256;
writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), width);
}
}
/**
* Returns the column width corresponding to each column head.
*
* <p>
* if return null,ignore
*
* @param head
* Nullable.
* @param columnIndex
* Not null.
* @return
*/
protected abstract Integer columnWidth(Head head, Integer columnIndex);
}