Browse Source

优化写入样式代码

pull/2079/head
Jiaju Zhuang 3 years ago
parent
commit
5b37ec243f
  1. 14
      src/main/java/com/alibaba/excel/constant/OrderConstant.java
  2. 6
      src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
  3. 2
      src/main/java/com/alibaba/excel/write/style/DefaultStyle.java

14
src/main/java/com/alibaba/excel/constant/OrderConstant.java

@ -7,6 +7,16 @@ package com.alibaba.excel.constant;
*/ */
public class OrderConstant { public class OrderConstant {
/**
* The system's own style
*/
public static int DEFAULT_DEFINE_STYLE = -70000;
/**
* Annotation style definition
*/
public static int ANNOTATION_DEFINE_STYLE = -60000;
/** /**
* Define style. * Define style.
*/ */
@ -15,10 +25,10 @@ public class OrderConstant {
/** /**
* default order. * default order.
*/ */
public static final int DEFAULT_ORDER = 0; public static int DEFAULT_ORDER = 0;
/** /**
* Sorting of styles written to cells. * Sorting of styles written to cells.
*/ */
public static final int FILL_STYLE = 50000; public static int FILL_STYLE = 50000;
} }

6
src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java

@ -9,6 +9,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import com.alibaba.excel.constant.OrderConstant;
import com.alibaba.excel.converters.Converter; import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ConverterKeyBuild; import com.alibaba.excel.converters.ConverterKeyBuild;
import com.alibaba.excel.converters.DefaultConverterLoader; import com.alibaba.excel.converters.DefaultConverterLoader;
@ -235,6 +236,11 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
private void dealStyle(List<WriteHandler> handlerList) { private void dealStyle(List<WriteHandler> handlerList) {
WriteHandler styleStrategy = new AbstractVerticalCellStyleStrategy() { WriteHandler styleStrategy = new AbstractVerticalCellStyleStrategy() {
@Override
public int order() {
return OrderConstant.ANNOTATION_DEFINE_STYLE;
}
@Override @Override
protected WriteCellStyle headCellStyle(Head head) { protected WriteCellStyle headCellStyle(Head head) {
return WriteCellStyle.build(head.getHeadStyleProperty(), head.getHeadFontProperty()); return WriteCellStyle.build(head.getHeadStyleProperty(), head.getHeadFontProperty());

2
src/main/java/com/alibaba/excel/write/style/DefaultStyle.java

@ -19,7 +19,7 @@ public class DefaultStyle extends HorizontalCellStyleStrategy {
@Override @Override
public int order() { public int order() {
return OrderConstant.DEFINE_STYLE - 1; return OrderConstant.DEFAULT_DEFINE_STYLE;
} }
public DefaultStyle() { public DefaultStyle() {

Loading…
Cancel
Save