|
@@ -3,6 +3,7 @@ package cn.tr.module.excel.core.utils;
|
|
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|
|
import com.alibaba.excel.write.metadata.style.WriteFont;
|
|
import com.alibaba.excel.write.metadata.style.WriteFont;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @ClassName : StyleUtils
|
|
* @ClassName : StyleUtils
|
|
@@ -12,22 +13,27 @@ import org.apache.poi.ss.usermodel.*;
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
public class StyleUtils {
|
|
public class StyleUtils {
|
|
|
|
|
+ public static WriteCellStyle getNotNullHeadStyle(){
|
|
|
|
|
+ WriteCellStyle headStyle = getHeadStyle();
|
|
|
|
|
+ WriteFont writeFont = headStyle.getWriteFont();
|
|
|
|
|
+ writeFont.setColor(IndexedColors.RED.getIndex());
|
|
|
|
|
+ return headStyle;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static WriteCellStyle getHeadStyle(){
|
|
public static WriteCellStyle getHeadStyle(){
|
|
|
// 头的策略
|
|
// 头的策略
|
|
|
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
|
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
|
|
// 背景颜色
|
|
// 背景颜色
|
|
|
- headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
|
|
|
|
|
|
+ headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
|
|
|
headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
|
|
headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
|
|
|
- headWriteCellStyle.setLocked(true);
|
|
|
|
|
-
|
|
|
|
|
// 字体
|
|
// 字体
|
|
|
WriteFont headWriteFont = new WriteFont();
|
|
WriteFont headWriteFont = new WriteFont();
|
|
|
//设置字体名字
|
|
//设置字体名字
|
|
|
- headWriteFont.setFontName("黑体");
|
|
|
|
|
- //斜体
|
|
|
|
|
- headWriteFont.setItalic(true);
|
|
|
|
|
|
|
+ headWriteFont.setFontName("宋体");
|
|
|
|
|
+// //斜体
|
|
|
|
|
+// headWriteFont.setItalic(true);
|
|
|
//设置字体大小
|
|
//设置字体大小
|
|
|
- headWriteFont.setFontHeightInPoints((short)12);
|
|
|
|
|
|
|
+ headWriteFont.setFontHeightInPoints((short)9);
|
|
|
//字体加粗
|
|
//字体加粗
|
|
|
headWriteFont.setBold(true);
|
|
headWriteFont.setBold(true);
|
|
|
|
|
|
|
@@ -56,7 +62,6 @@ public class StyleUtils {
|
|
|
//设置自动换行
|
|
//设置自动换行
|
|
|
headWriteCellStyle.setWrapped(true);
|
|
headWriteCellStyle.setWrapped(true);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
//设置水平对齐的样式为居中对齐
|
|
//设置水平对齐的样式为居中对齐
|
|
|
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
|
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
|
|
//设置垂直对齐的样式为居中对齐
|
|
//设置垂直对齐的样式为居中对齐
|
|
@@ -69,7 +74,6 @@ public class StyleUtils {
|
|
|
return headWriteCellStyle;
|
|
return headWriteCellStyle;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public static WriteCellStyle getContentStyle(){
|
|
public static WriteCellStyle getContentStyle(){
|
|
|
// 内容的策略
|
|
// 内容的策略
|
|
|
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
|
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
|
@@ -80,10 +84,7 @@ public class StyleUtils {
|
|
|
contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
|
|
contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
|
|
|
|
// 设置字体
|
|
// 设置字体
|
|
|
- WriteFont contentWriteFont = new WriteFont();
|
|
|
|
|
- contentWriteFont.setFontHeightInPoints((short) 9);//设置字体大小
|
|
|
|
|
- contentWriteFont.setFontName("宋体"); //设置字体名字
|
|
|
|
|
- contentWriteCellStyle.setWriteFont(contentWriteFont);//在样式用应用设置的字体;
|
|
|
|
|
|
|
+ contentWriteCellStyle.setWriteFont(getDefaultFont());;
|
|
|
|
|
|
|
|
//设置样式;
|
|
//设置样式;
|
|
|
contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
|
|
contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
|
|
@@ -104,4 +105,11 @@ public class StyleUtils {
|
|
|
return contentWriteCellStyle;
|
|
return contentWriteCellStyle;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static WriteFont getDefaultFont(){
|
|
|
|
|
+ // 设置字体
|
|
|
|
|
+ WriteFont contentWriteFont = new WriteFont();
|
|
|
|
|
+ contentWriteFont.setFontHeightInPoints((short) 9);//设置字体大小
|
|
|
|
|
+ contentWriteFont.setFontName("宋体"); //设置字体名字
|
|
|
|
|
+ return contentWriteFont;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|