|
@@ -9,7 +9,9 @@ package cn.com.qmth.examcloud.core.print.common.utils;
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
+import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -27,16 +29,22 @@ import java.util.List;
|
|
|
public class ExcelUtils {
|
|
|
private static Logger log = LoggerFactory.getLogger(ExcelUtils.class);
|
|
|
|
|
|
+ public static <T> void toExcelFile(Class<T> clazz, List<T> list, File excelFile) {
|
|
|
+ toExcelFile(clazz, list, excelFile, null);
|
|
|
+ }
|
|
|
+
|
|
|
public static <T> void toExcelFile(Class<T> clazz, List<T> list, File excelFile, String title) {
|
|
|
if (excelFile == null) {
|
|
|
log.warn("excelFile must be not null.");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isBlank(title)) {
|
|
|
- title = "";
|
|
|
+ ExportParams params = new ExportParams();
|
|
|
+ params.setType(ExcelType.XSSF);
|
|
|
+ //params.setColor(IndexedColors.AQUA.getIndex());
|
|
|
+ if (StringUtils.isNotBlank(title)) {
|
|
|
+ params.setTitle(title);
|
|
|
}
|
|
|
- ExportParams params = new ExportParams(title, title);
|
|
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(excelFile);
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(params, clazz, list);) {
|