jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
47
48
49
50
51
52
53
package com.bstek.bdf2.export.excel.style;
 
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Workbook;
 
public abstract class AbstractStyleBuilder {
 
    public CellStyle createBorderCellStyle(Workbook workbook, boolean showBorder) {
        CellStyle style = workbook.createCellStyle();
        if (showBorder) {
            style.setBorderRight(CellStyle.BORDER_THIN);
            style.setRightBorderColor(IndexedColors.BLACK.getIndex());
            style.setBorderBottom(CellStyle.BORDER_THIN);
            style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
            style.setBorderLeft(CellStyle.BORDER_THIN);
            style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
            style.setBorderTop(CellStyle.BORDER_THIN);
            style.setTopBorderColor(IndexedColors.BLACK.getIndex());
        }
        return style;
    }
 
    public void setCellStyleFont(Workbook workbook, CellStyle style, int i) {
        Font font = workbook.createFont();
        if (i == 0) {
            // 正常
        } else if (i == 4) {
            // 下划线
            font.setUnderline(Font.U_SINGLE);
            style.setFont(font);
        } else if (i == 2) {
            // 倾斜
            font.setItalic(true);
            style.setFont(font);
        } else if (i == 1) {
            // 加粗
            font.setBoldweight(Font.BOLDWEIGHT_BOLD);
            style.setFont(font);
        }
    }
 
    public void setCellStyleAligment(CellStyle style, int i) {
        if (i == 0) {
            style.setAlignment(CellStyle.ALIGN_LEFT);
        } else if (i == 1) {
            style.setAlignment(CellStyle.ALIGN_CENTER);
        } else if (i == 2) {
            style.setAlignment(CellStyle.ALIGN_RIGHT);
        }
    }
}