|
@@ -0,0 +1,81 @@
|
|
|
+/*
|
|
|
+ * *************************************************
|
|
|
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
|
|
|
+ * Created by Deason on 2018-11-22 10:01:09.
|
|
|
+ * *************************************************
|
|
|
+ */
|
|
|
+
|
|
|
+package cn.com.qmth.examcloud.core.print.common.utils;
|
|
|
+
|
|
|
+import cn.afterturn.easypoi.excel.export.styler.AbstractExcelExportStyler;
|
|
|
+import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Excel导出默认样式
|
|
|
+ *
|
|
|
+ * @author: fengdesheng
|
|
|
+ * @since: 2018/11/22
|
|
|
+ */
|
|
|
+public class ExcelStyle extends AbstractExcelExportStyler implements IExcelExportStyler {
|
|
|
+ private final short fontHeightInPoints = 16;
|
|
|
+
|
|
|
+ public ExcelStyle(Workbook workbook) {
|
|
|
+ super.createStyles(workbook);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CellStyle getHeaderStyle(short headerColor) {
|
|
|
+ CellStyle headerStyle = this.workbook.createCellStyle();
|
|
|
+ Font font = this.workbook.createFont();
|
|
|
+ font.setBold(true);
|
|
|
+ font.setFontHeightInPoints(fontHeightInPoints);
|
|
|
+ headerStyle.setFont(font);
|
|
|
+ //headerStyle.setFillForegroundColor(headerColor);
|
|
|
+ //headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ headerStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ return headerStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setDataFormat(STRING_FORMAT);
|
|
|
+ if (isWarp) {
|
|
|
+ cellStyle.setWrapText(true);
|
|
|
+ }
|
|
|
+ return cellStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ public CellStyle getTitleStyle(short color) {
|
|
|
+ CellStyle titleStyle = this.workbook.createCellStyle();
|
|
|
+ Font font = this.workbook.createFont();
|
|
|
+ font.setBold(true);
|
|
|
+ font.setColor(IndexedColors.WHITE.getIndex());
|
|
|
+ titleStyle.setFont(font);
|
|
|
+ titleStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
|
|
+ titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ titleStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ titleStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ titleStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ titleStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ titleStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ titleStyle.setWrapText(true);
|
|
|
+ return titleStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
|
|
|
+ return isWarp ? this.stringNoneWrapStyle : this.stringNoneStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|