66 lines
1.6 KiB
Java
66 lines
1.6 KiB
Java
package com.imyeyu.api.util;
|
|
|
|
import com.imyeyu.api.modules.user.bean.Gender;
|
|
import com.imyeyu.java.TimiJava;
|
|
import org.apache.poi.ss.usermodel.CellStyle;
|
|
import org.apache.poi.ss.usermodel.Font;
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
///
|
|
///
|
|
/// @author 夜雨
|
|
/// @since 2026-08-04 15:57
|
|
public abstract class BaseXSSFBuilder<T> {
|
|
|
|
public abstract byte[] build(List<T> list) throws IOException;
|
|
|
|
protected CellStyle createTitleStyle(Workbook workbook) {
|
|
CellStyle style = workbook.createCellStyle();
|
|
Font font = workbook.createFont();
|
|
font.setBold(true);
|
|
font.setFontHeightInPoints((short) 14);
|
|
style.setFont(font);
|
|
return style;
|
|
}
|
|
|
|
protected CellStyle createHeaderStyle(Workbook workbook) {
|
|
CellStyle style = workbook.createCellStyle();
|
|
Font font = workbook.createFont();
|
|
font.setBold(true);
|
|
style.setFont(font);
|
|
return style;
|
|
}
|
|
|
|
protected void appendRow(Sheet sheet, int rowIndex, CellStyle style, String... values) {
|
|
Row row = sheet.createRow(rowIndex);
|
|
for (int index = 0; index < values.length; index++) {
|
|
row.createCell(index).setCellValue(values[index]);
|
|
if (style != null) {
|
|
row.getCell(index).setCellStyle(style);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected String text(Object obj) {
|
|
if (obj == null) {
|
|
return "";
|
|
}
|
|
return TimiJava.defaultIfEmpty(obj.toString(), "");
|
|
}
|
|
|
|
protected String gender(Gender gender) {
|
|
if (gender == null) {
|
|
return "";
|
|
}
|
|
return switch (gender) {
|
|
case MALE -> "男";
|
|
case FEMALE -> "女";
|
|
};
|
|
}
|
|
}
|