From de4ec6d40013e2d12b5aa43d36973cca2f035c71 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Tue, 13 Apr 2021 23:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=8C=E6=88=90=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=9B=BE=E7=89=87=E7=AD=89=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lombok.config | 2 + .../alibaba/excel/enums/CellDataTypeEnum.java | 6 +- .../exception/ExcelDataConvertException.java | 4 +- .../alibaba/excel/metadata/AbstractCell.java | 19 +- .../excel/metadata/AbstractHolder.java | 45 +---- .../com/alibaba/excel/metadata/CellData.java | 103 ++-------- .../excel/metadata/ClientAnchorData.java | 139 +++++++++++++ .../alibaba/excel/metadata/CommentData.java | 28 +++ .../alibaba/excel/metadata/DataFormat.java | 20 ++ .../alibaba/excel/metadata/FormulaData.java | 16 ++ .../alibaba/excel/metadata/HyperlinkData.java | 10 + .../com/alibaba/excel/metadata/ImageData.java | 58 ++++++ .../alibaba/excel/metadata/ReadCellData.java | 13 ++ .../excel/metadata/RichTextStringData.java | 59 ++++++ .../alibaba/excel/metadata/WriteCellData.java | 42 ++++ .../metadata/property/ExcelHeadProperty.java | 78 ++------ .../metadata/holder/AbstractReadHolder.java | 27 +-- .../write/executor/ExcelWriteAddExecutor.java | 4 +- .../metadata/holder/AbstractWriteHolder.java | 4 + .../metadata/holder/WriteSheetHolder.java | 6 +- .../metadata/holder/WriteWorkbookHolder.java | 4 +- .../write/metadata/style/WriteCellStyle.java | 186 +----------------- .../excel/write/metadata/style/WriteFont.java | 74 +------ 23 files changed, 450 insertions(+), 497 deletions(-) create mode 100644 lombok.config create mode 100644 src/main/java/com/alibaba/excel/metadata/ClientAnchorData.java create mode 100644 src/main/java/com/alibaba/excel/metadata/CommentData.java create mode 100644 src/main/java/com/alibaba/excel/metadata/DataFormat.java create mode 100644 src/main/java/com/alibaba/excel/metadata/FormulaData.java create mode 100644 src/main/java/com/alibaba/excel/metadata/HyperlinkData.java create mode 100644 src/main/java/com/alibaba/excel/metadata/ImageData.java create mode 100644 src/main/java/com/alibaba/excel/metadata/ReadCellData.java create mode 100644 src/main/java/com/alibaba/excel/metadata/RichTextStringData.java create mode 100644 src/main/java/com/alibaba/excel/metadata/WriteCellData.java diff --git a/lombok.config b/lombok.config new file mode 100644 index 00000000..50dfe616 --- /dev/null +++ b/lombok.config @@ -0,0 +1,2 @@ +lombok.toString.callSuper = CALL +lombok.equalsAndHashCode.callSuper= CALL \ No newline at end of file diff --git a/src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java b/src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java index 6220340a..a7a667f0 100644 --- a/src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java +++ b/src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java @@ -37,13 +37,17 @@ public enum CellDataTypeEnum { */ ERROR, /** - * Images are currently supported only when writing + * image. Support only when writing. */ IMAGE, /** * date.Support only when writing. */ DATE, + /** + * rich text string.Support only when writing. + */ + RICH_TEXT_STRING, ; private static final Map TYPE_ROUTING_MAP = new HashMap(16); diff --git a/src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java b/src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java index 7231afd9..3cd9077b 100644 --- a/src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java +++ b/src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java @@ -4,6 +4,7 @@ import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.write.builder.ExcelWriterBuilder; +import lombok.Data; import lombok.Getter; import lombok.Setter; @@ -12,8 +13,7 @@ import lombok.Setter; * * @author Jiaju Zhuang */ -@Getter -@Setter +@Data public class ExcelDataConvertException extends RuntimeException { /** * NotNull. diff --git a/src/main/java/com/alibaba/excel/metadata/AbstractCell.java b/src/main/java/com/alibaba/excel/metadata/AbstractCell.java index 5cea37cf..6647cf0c 100644 --- a/src/main/java/com/alibaba/excel/metadata/AbstractCell.java +++ b/src/main/java/com/alibaba/excel/metadata/AbstractCell.java @@ -1,10 +1,13 @@ package com.alibaba.excel.metadata; +import lombok.Data; + /** * cell * * @author Jiaju Zhuang **/ +@Data public class AbstractCell implements Cell { /** * Row index @@ -14,20 +17,4 @@ public class AbstractCell implements Cell { * Column index */ private Integer columnIndex; - - public Integer getRowIndex() { - return rowIndex; - } - - public void setRowIndex(Integer rowIndex) { - this.rowIndex = rowIndex; - } - - public Integer getColumnIndex() { - return columnIndex; - } - - public void setColumnIndex(Integer columnIndex) { - this.columnIndex = columnIndex; - } } diff --git a/src/main/java/com/alibaba/excel/metadata/AbstractHolder.java b/src/main/java/com/alibaba/excel/metadata/AbstractHolder.java index 548503d0..d8b4ec43 100644 --- a/src/main/java/com/alibaba/excel/metadata/AbstractHolder.java +++ b/src/main/java/com/alibaba/excel/metadata/AbstractHolder.java @@ -6,11 +6,16 @@ import java.util.Map; import com.alibaba.excel.converters.Converter; +import lombok.Data; +import lombok.NoArgsConstructor; + /** * Write/read holder * * @author Jiaju Zhuang */ +@Data +@NoArgsConstructor public abstract class AbstractHolder implements ConfigurationHolder { /** * Record whether it's new or from cache @@ -71,46 +76,6 @@ public abstract class AbstractHolder implements ConfigurationHolder { } - public Boolean getNewInitialization() { - return newInitialization; - } - - public void setNewInitialization(Boolean newInitialization) { - this.newInitialization = newInitialization; - } - - public List> getHead() { - return head; - } - - public void setHead(List> head) { - this.head = head; - } - - public Class getClazz() { - return clazz; - } - - public void setClazz(Class clazz) { - this.clazz = clazz; - } - - public GlobalConfiguration getGlobalConfiguration() { - return globalConfiguration; - } - - public void setGlobalConfiguration(GlobalConfiguration globalConfiguration) { - this.globalConfiguration = globalConfiguration; - } - - public Map> getConverterMap() { - return converterMap; - } - - public void setConverterMap(Map> converterMap) { - this.converterMap = converterMap; - } - @Override public Map> converterMap() { return getConverterMap(); diff --git a/src/main/java/com/alibaba/excel/metadata/CellData.java b/src/main/java/com/alibaba/excel/metadata/CellData.java index 5621ed6e..604df146 100644 --- a/src/main/java/com/alibaba/excel/metadata/CellData.java +++ b/src/main/java/com/alibaba/excel/metadata/CellData.java @@ -1,14 +1,18 @@ package com.alibaba.excel.metadata; import java.math.BigDecimal; -import com.alibaba.excel.annotation.write.style.ImagePosition; import java.util.Date; + +import com.alibaba.excel.annotation.write.style.ImagePosition; import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.metadata.property.ImagePositionProperty; import com.alibaba.excel.util.StringUtils; +import com.alibaba.excel.write.metadata.style.WriteCellStyle; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; +import org.apache.poi.ss.usermodel.Comment; +import org.apache.poi.ss.usermodel.Hyperlink; +import org.apache.poi.ss.usermodel.RichTextString; /** * Excel internal cell data. @@ -17,8 +21,7 @@ import lombok.Setter; * * @author Jiaju Zhuang */ -@Getter -@Setter +@Data public class CellData extends AbstractCell { private CellDataTypeEnum type; /** @@ -33,52 +36,20 @@ public class CellData extends AbstractCell { * {@link CellDataTypeEnum#BOOLEAN} */ private Boolean booleanValue; - private Boolean formula; - private String formulaValue; - private byte[] imageValue; /** - * Keep the information of image position in annotation. + * The resulting converted data. */ - private ImagePositionProperty imagePositionProperty; + private T data; /** - * It will be set true when using annotation to set the image's position. - */ - private Boolean useImagePositionProperty = false; - /** - * Support only when writing. - */ - private Date dateValue; - /** - * The number formatting. - */ - private Short dataFormat; - /** - * The string of number formatting. + * formula */ - private String dataFormatString; + private FormulaData formulaData; /** - * The resulting converted data. + * data format */ - private T data; - - public CellData(CellData other) { - this.type = other.type; - this.numberValue = other.numberValue; - this.stringValue = other.stringValue; - this.booleanValue = other.booleanValue; - this.formula = other.formula; - this.formulaValue = other.formulaValue; - this.imageValue = other.imageValue; - this.imagePositionProperty = other.imagePositionProperty; - this.useImagePositionProperty = other.useImagePositionProperty; - this.dataFormat = other.dataFormat; - this.dataFormatString = other.dataFormatString; - this.data = other.data; - setRowIndex(other.getRowIndex()); - setColumnIndex(other.getColumnIndex()); - } + private DataFormat dataFormat; public CellData() {} @@ -86,12 +57,6 @@ public class CellData extends AbstractCell { this.data = data; } - public CellData(T data, String formulaValue) { - this.data = data; - this.formula = Boolean.TRUE; - this.formulaValue = formulaValue; - } - public CellData(String stringValue) { this(CellDataTypeEnum.STRING, stringValue); } @@ -105,7 +70,6 @@ public class CellData extends AbstractCell { } this.type = type; this.stringValue = stringValue; - this.formula = Boolean.FALSE; } public CellData(BigDecimal numberValue) { @@ -114,7 +78,6 @@ public class CellData extends AbstractCell { } this.type = CellDataTypeEnum.NUMBER; this.numberValue = numberValue; - this.formula = Boolean.FALSE; } public CellData(byte[] imageValue) { @@ -123,7 +86,6 @@ public class CellData extends AbstractCell { } this.type = CellDataTypeEnum.IMAGE; this.imageValue = imageValue; - this.formula = Boolean.FALSE; } public CellData(byte[] imageValue, ImagePosition imagePosition) { @@ -146,7 +108,6 @@ public class CellData extends AbstractCell { } this.type = CellDataTypeEnum.BOOLEAN; this.booleanValue = booleanValue; - this.formula = Boolean.FALSE; } public CellData(Date dateValue) { @@ -158,7 +119,6 @@ public class CellData extends AbstractCell { this.formula = Boolean.FALSE; } - public CellData(CellDataTypeEnum type) { if (type == null) { throw new IllegalArgumentException("Type can not be null"); @@ -230,39 +190,4 @@ public class CellData extends AbstractCell { return cellData; } - @Override - public String toString() { - if (type == null) { - return StringUtils.EMPTY; - } - switch (type) { - case NUMBER: - if (numberValue == null) { - return StringUtils.EMPTY; - } - return numberValue.toString(); - case BOOLEAN: - if (booleanValue == null) { - return StringUtils.EMPTY; - } - return booleanValue.toString(); - case DIRECT_STRING: - case STRING: - case ERROR: - return stringValue; - case DATE: - if (dateValue == null) { - return StringUtils.EMPTY; - } - return dateValue.toString(); - case IMAGE: - if (imageValue == null) { - return StringUtils.EMPTY; - } - return "image[" + imageValue.length + "]"; - default: - return StringUtils.EMPTY; - } - } - } diff --git a/src/main/java/com/alibaba/excel/metadata/ClientAnchorData.java b/src/main/java/com/alibaba/excel/metadata/ClientAnchorData.java new file mode 100644 index 00000000..cf215e6f --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/ClientAnchorData.java @@ -0,0 +1,139 @@ +package com.alibaba.excel.metadata; + +import lombok.Data; +import org.apache.poi.ss.usermodel.ClientAnchor; +import org.apache.poi.util.Internal; + +/** + * A client anchor is attached to an excel worksheet. It anchors against + * absolute coordinates, a top-left cell and fixed height and width, or + * a top-left and bottom-right cell, depending on the {@link ClientAnchorData.AnchorType}: + *
    + *
  1. {@link ClientAnchor.AnchorType#DONT_MOVE_AND_RESIZE} == absolute top-left coordinates and width/height, no + * cell references + *
  2. {@link ClientAnchor.AnchorType#MOVE_DONT_RESIZE} == fixed top-left cell reference, absolute width/height + *
  3. {@link ClientAnchor.AnchorType#MOVE_AND_RESIZE} == fixed top-left and bottom-right cell references, dynamic + * width/height + *
+ * Note this class only reports the current values for possibly calculated positions and sizes. + * If the sheet row/column sizes or positions shift, this needs updating via external calculations. + * + * @author Jiaju Zhuang + */ +@Data +public class ClientAnchorData { + + /** + * The x coordinate within the first cell. + */ + private int dx1; + + /** + * The y coordinate within the first cell. + */ + private int dy1; + + /** + * The x coordinate within the second cell. + */ + private int dx2; + + /** + * The y coordinate within the second cell + */ + private int dy2; + + /** + * 0-based column of the first cell. + */ + private short col1; + + /** + * 0-based row of the first cell. + */ + private int row1; + + /** + * 0-based column of the second cell. + */ + private short col2; + + /** + * 0-based row of the second cell. + */ + private int row2; + /** + * anchor type + */ + private AnchorType anchorType; + + public enum AnchorType { + /** + * Move and Resize With Anchor Cells (0) + *

+ * Specifies that the current drawing shall move and + * resize to maintain its row and column anchors (i.e. the + * object is anchored to the actual from and to row and column) + *

+ */ + MOVE_AND_RESIZE(0), + + /** + * Don't Move but do Resize With Anchor Cells (1) + *

+ * Specifies that the current drawing shall not move with its + * row and column, but should be resized. This option is not normally + * used, but is included for completeness. + *

+ * Note: Excel has no setting for this combination, nor does the ECMA standard. + */ + DONT_MOVE_DO_RESIZE(1), + + /** + * Move With Cells but Do Not Resize (2) + *

+ * Specifies that the current drawing shall move with its + * row and column (i.e. the object is anchored to the + * actual from row and column), but that the size shall remain absolute. + *

+ *

+ * If additional rows/columns are added between the from and to locations of the drawing, + * the drawing shall move its to anchors as needed to maintain this same absolute size. + *

+ */ + MOVE_DONT_RESIZE(2), + + /** + * Do Not Move or Resize With Underlying Rows/Columns (3) + *

+ * Specifies that the current start and end positions shall + * be maintained with respect to the distances from the + * absolute start point of the worksheet. + *

+ *

+ * If additional rows/columns are added before the + * drawing, the drawing shall move its anchors as needed + * to maintain this same absolute position. + *

+ */ + DONT_MOVE_AND_RESIZE(3); + + public final short value; + + // disallow non-sequential enum instance creation + private AnchorType(int value) { + this.value = (short)value; + } + + /** + * return the AnchorType corresponding to the code + * + * @param value the anchor type code + * @return the anchor type enum + */ + @Internal + public static ClientAnchorData.AnchorType byId(int value) { + return values()[value]; + } + } +} diff --git a/src/main/java/com/alibaba/excel/metadata/CommentData.java b/src/main/java/com/alibaba/excel/metadata/CommentData.java new file mode 100644 index 00000000..94c1b675 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/CommentData.java @@ -0,0 +1,28 @@ +package com.alibaba.excel.metadata; + +import lombok.Data; + +/** + * TODO + * + * @author Jiaju Zhuang + */ +@Data +public class CommentData { + /** + * Row index + */ + private Integer rowIndex; + /** + * Column index + */ + private Integer columnIndex; + /** + * Name of the original comment author + */ + private String author; + /** + * rich text string + */ + private RichTextStringData richTextStringData; +} diff --git a/src/main/java/com/alibaba/excel/metadata/DataFormat.java b/src/main/java/com/alibaba/excel/metadata/DataFormat.java new file mode 100644 index 00000000..fdaa5236 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/DataFormat.java @@ -0,0 +1,20 @@ +package com.alibaba.excel.metadata; + +import lombok.Data; + +/** + * data format + * + * @author Jiaju Zhuang + */ +@Data +public class DataFormat { + /** + * index + */ + private Short index; + /** + * format + */ + private String format; +} diff --git a/src/main/java/com/alibaba/excel/metadata/FormulaData.java b/src/main/java/com/alibaba/excel/metadata/FormulaData.java new file mode 100644 index 00000000..8f3c4f15 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/FormulaData.java @@ -0,0 +1,16 @@ +package com.alibaba.excel.metadata; + +import lombok.Data; + +/** + * formula + * + * @author Jiaju Zhuang + */ +@Data +public class FormulaData { + /** + * formula + */ + private String formulaValue; +} diff --git a/src/main/java/com/alibaba/excel/metadata/HyperlinkData.java b/src/main/java/com/alibaba/excel/metadata/HyperlinkData.java new file mode 100644 index 00000000..f3453c64 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/HyperlinkData.java @@ -0,0 +1,10 @@ +package com.alibaba.excel.metadata; + +/** + * TODO + * + * @author Jiaju Zhuang + */ +public class HyperlinkData { + +} diff --git a/src/main/java/com/alibaba/excel/metadata/ImageData.java b/src/main/java/com/alibaba/excel/metadata/ImageData.java new file mode 100644 index 00000000..e1bb30fa --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/ImageData.java @@ -0,0 +1,58 @@ +package com.alibaba.excel.metadata; + +import lombok.Data; + +/** + * image + * + * @author Jiaju Zhuang + */ +@Data +public class ImageData extends ClientAnchorData { + + /** + * image + */ + private byte[] image; + + /** + * image type + */ + private ImageType imageType; + + public enum ImageType { + /** + * Extended windows meta file + */ + PICTURE_TYPE_EMF(2), + /** + * Windows Meta File + */ + PICTURE_TYPE_WMF(3), + /** + * Mac PICT format + */ + PICTURE_TYPE_PICT(4), + /** + * JPEG format + */ + PICTURE_TYPE_JPEG(5), + /** + * PNG format + */ + PICTURE_TYPE_PNG(6), + /** + * Device independent bitmap + */ + PICTURE_TYPE_DIB(7), + + ; + + public final int value; + + ImageType(int value) { + this.value = value; + } + } + +} diff --git a/src/main/java/com/alibaba/excel/metadata/ReadCellData.java b/src/main/java/com/alibaba/excel/metadata/ReadCellData.java new file mode 100644 index 00000000..cf9ad233 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/ReadCellData.java @@ -0,0 +1,13 @@ +package com.alibaba.excel.metadata; + +import lombok.Data; + +/** + * TODO + * + * @author Jiaju Zhuang + */ +@Data +public class ReadCellData extends CellData{ + +} diff --git a/src/main/java/com/alibaba/excel/metadata/RichTextStringData.java b/src/main/java/com/alibaba/excel/metadata/RichTextStringData.java new file mode 100644 index 00000000..eabb85c3 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/RichTextStringData.java @@ -0,0 +1,59 @@ +package com.alibaba.excel.metadata; + +import java.util.List; + +import com.alibaba.excel.util.ListUtils; +import com.alibaba.excel.write.metadata.style.WriteFont; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * TODO + * + * @author Jiaju Zhuang + */ +@Data +@NoArgsConstructor +public class RichTextStringData { + private String textString; + private WriteFont writeFont; + private List intervalFontList; + + public RichTextStringData(String textString) { + this.textString = textString; + } + + @Data + @AllArgsConstructor + public static class IntervalFont { + private Integer startIndex; + private Integer endIndex; + private WriteFont writeFont; + } + + /** + * Applies a font to the specified characters of a string. + * + * @param startIndex The start index to apply the font to (inclusive) + * @param endIndex The end index to apply to font to (exclusive) + * @param writeFont The font to use. + */ + public void applyFont(int startIndex, int endIndex, WriteFont writeFont) { + if (intervalFontList == null) { + intervalFontList = ListUtils.newArrayList(); + } + intervalFontList.add(new IntervalFont(startIndex, endIndex, writeFont)); + } + + /** + * Sets the font of the entire string. + * + * @param writeFont The font to use. + */ + public void applyFont(WriteFont writeFont) { + this.writeFont = writeFont; + } + +} diff --git a/src/main/java/com/alibaba/excel/metadata/WriteCellData.java b/src/main/java/com/alibaba/excel/metadata/WriteCellData.java new file mode 100644 index 00000000..901aa916 --- /dev/null +++ b/src/main/java/com/alibaba/excel/metadata/WriteCellData.java @@ -0,0 +1,42 @@ +package com.alibaba.excel.metadata; + +import java.util.Date; + +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.write.metadata.style.WriteCellStyle; + +import lombok.Data; + +/** + * TODO + * + * @author Jiaju Zhuang + */ +@Data +public class WriteCellData extends CellData { + /** + * Support only when writing.{@link CellDataTypeEnum#DATE} + */ + private Date dateValue; + /** + * {@link CellDataTypeEnum#IMAGE} + */ + private ImageData imageDataValue; + /** + * rich text.{@link CellDataTypeEnum#RICH_TEXT_STRING} + */ + private RichTextStringData richTextStringDataValue; + + /** + * comment + */ + private CommentData commentData; + /** + * hyper link + */ + private HyperlinkData hyperlinkData; + /** + * sytle + */ + private WriteCellStyle writeCellStyle; +} diff --git a/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java b/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java index 5915cf06..34c9d4d0 100644 --- a/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java +++ b/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java @@ -1,19 +1,13 @@ package com.alibaba.excel.metadata.property; import java.lang.reflect.Field; -import java.util.AbstractMap; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; -import org.apache.commons.collections4.CollectionUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.format.DateTimeFormat; import com.alibaba.excel.annotation.format.NumberFormat; @@ -27,11 +21,17 @@ import com.alibaba.excel.util.ClassUtils; import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.write.metadata.holder.AbstractWriteHolder; +import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Define the header attribute of excel * * @author jipengfei */ +@Data public class ExcelHeadProperty { private static final Logger LOGGER = LoggerFactory.getLogger(ExcelHeadProperty.class); @@ -64,7 +64,7 @@ public class ExcelHeadProperty { */ private Map ignoreMap; - public ExcelHeadProperty(Holder holder, Class headClazz, List> head, Boolean convertAllField) { + public ExcelHeadProperty(Holder holder, Class headClazz, List> head, Boolean convertAllFiled) { this.headClazz = headClazz; headMap = new TreeMap(); contentPropertyMap = new TreeMap(); @@ -87,7 +87,7 @@ public class ExcelHeadProperty { headKind = HeadKindEnum.STRING; } // convert headClazz to head - initColumnProperties(holder, convertAllField); + initColumnProperties(holder, convertAllFiled); initHeadRowNumber(); if (LOGGER.isDebugEnabled()) { @@ -115,7 +115,7 @@ public class ExcelHeadProperty { } } - private void initColumnProperties(Holder holder, Boolean convertAllField) { + private void initColumnProperties(Holder holder, Boolean convertAllFiled) { if (headClazz == null) { return; } @@ -124,9 +124,9 @@ public class ExcelHeadProperty { Map indexFiledMap = new TreeMap(); boolean needIgnore = (holder instanceof AbstractWriteHolder) && ( - !CollectionUtils.isEmpty(((AbstractWriteHolder) holder).getExcludeColumnFiledNames()) || !CollectionUtils + !CollectionUtils.isEmpty(((AbstractWriteHolder) holder).getExcludeColumnFieldNames()) || !CollectionUtils .isEmpty(((AbstractWriteHolder) holder).getExcludeColumnIndexes()) || !CollectionUtils - .isEmpty(((AbstractWriteHolder) holder).getIncludeColumnFiledNames()) || !CollectionUtils + .isEmpty(((AbstractWriteHolder) holder).getIncludeColumnFieldNames()) || !CollectionUtils .isEmpty(((AbstractWriteHolder) holder).getIncludeColumnIndexes())); ClassUtils.declaredFields(headClazz, sortedAllFiledMap, indexFiledMap, ignoreMap, convertAllFiled, needIgnore, holder); @@ -134,6 +134,7 @@ public class ExcelHeadProperty { for (Map.Entry entry : sortedAllFiledMap.entrySet()) { initOneColumnProperty(entry.getKey(), entry.getValue(), indexFiledMap.containsKey(entry.getKey())); } + headKind = HeadKindEnum.CLASS; } /** @@ -182,63 +183,8 @@ public class ExcelHeadProperty { fieldNameContentPropertyMap.put(field.getName(), excelContentProperty); } - public Class getHeadClazz() { - return headClazz; - } - - public void setHeadClazz(Class headClazz) { - this.headClazz = headClazz; - } - - public HeadKindEnum getHeadKind() { - return headKind; - } - - public void setHeadKind(HeadKindEnum headKind) { - this.headKind = headKind; - } - public boolean hasHead() { return headKind != HeadKindEnum.NONE; } - public int getHeadRowNumber() { - return headRowNumber; - } - - public void setHeadRowNumber(int headRowNumber) { - this.headRowNumber = headRowNumber; - } - - public Map getHeadMap() { - return headMap; - } - - public void setHeadMap(Map headMap) { - this.headMap = headMap; - } - - public Map getContentPropertyMap() { - return contentPropertyMap; - } - - public void setContentPropertyMap(Map contentPropertyMap) { - this.contentPropertyMap = contentPropertyMap; - } - - public Map getFieldNameContentPropertyMap() { - return fieldNameContentPropertyMap; - } - - public void setFieldNameContentPropertyMap(Map fieldNameContentPropertyMap) { - this.fieldNameContentPropertyMap = fieldNameContentPropertyMap; - } - - public Map getIgnoreMap() { - return ignoreMap; - } - - public void setIgnoreMap(Map ignoreMap) { - this.ignoreMap = ignoreMap; - } } diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java index 95bf6f89..396fa55a 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java +++ b/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java @@ -15,14 +15,14 @@ import com.alibaba.excel.read.metadata.ReadWorkbook; import com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty; import com.alibaba.excel.util.ListUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.Data; /** * Read Holder * * @author Jiaju Zhuang */ +@Data public abstract class AbstractReadHolder extends AbstractHolder implements ReadHolder { /** * Count the number of added heads when read sheet. @@ -112,29 +112,6 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH } } - public List getReadListenerList() { - return readListenerList; - } - - public void setReadListenerList(List readListenerList) { - this.readListenerList = readListenerList; - } - - public ExcelReadHeadProperty getExcelReadHeadProperty() { - return excelReadHeadProperty; - } - - public void setExcelReadHeadProperty(ExcelReadHeadProperty excelReadHeadProperty) { - this.excelReadHeadProperty = excelReadHeadProperty; - } - - public Integer getHeadRowNumber() { - return headRowNumber; - } - - public void setHeadRowNumber(Integer headRowNumber) { - this.headRowNumber = headRowNumber; - } @Override public List readListenerList() { diff --git a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java index 4d96e8c4..c4b3e45e 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -179,9 +179,9 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { } WriteWorkbookHolder writeWorkbookHolder = writeContext.writeWorkbookHolder(); boolean needIgnore = - !CollectionUtils.isEmpty(writeWorkbookHolder.getExcludeColumnFiledNames()) || !CollectionUtils + !CollectionUtils.isEmpty(writeWorkbookHolder.getExcludeColumnFieldNames()) || !CollectionUtils .isEmpty(writeWorkbookHolder.getExcludeColumnIndexes()) || !CollectionUtils - .isEmpty(writeWorkbookHolder.getIncludeColumnFiledNames()) || !CollectionUtils + .isEmpty(writeWorkbookHolder.getIncludeColumnFieldNames()) || !CollectionUtils .isEmpty(writeWorkbookHolder.getIncludeColumnIndexes()); ClassUtils.declaredFields(clazz, sortedAllFiledMap, writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled(), needIgnore, writeWorkbookHolder); diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java index e7132481..54c31245 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java @@ -9,6 +9,8 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import lombok.Data; +import lombok.NoArgsConstructor; import org.apache.commons.collections4.CollectionUtils; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.IndexedColors; @@ -50,6 +52,8 @@ import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy; * * @author Jiaju Zhuang */ +@Data +@NoArgsConstructor public abstract class AbstractWriteHolder extends AbstractHolder implements WriteHolder { /** * Need Head diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java index afae52b8..57f13584 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java @@ -8,7 +8,9 @@ import com.alibaba.excel.enums.WriteLastRowTypeEnum; import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.write.metadata.WriteSheet; +import lombok.Data; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.ss.usermodel.Sheet; @@ -20,8 +22,8 @@ import org.apache.poi.xssf.usermodel.XSSFSheet; * * @author Jiaju Zhuang */ -@Getter -@Setter +@Data +@NoArgsConstructor public class WriteSheetHolder extends AbstractWriteHolder { /** * current param diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java index 19e4622b..671b96f7 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java @@ -20,6 +20,7 @@ import com.alibaba.excel.util.MapUtils; import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.write.metadata.WriteWorkbook; +import lombok.Data; import lombok.Getter; import lombok.Setter; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -33,8 +34,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; * * @author Jiaju Zhuang */ -@Getter -@Setter +@Data public class WriteWorkbookHolder extends AbstractWriteHolder { /*** * Current poi Workbook.This is only for writing, and there may be no data in version 07 when template data needs to diff --git a/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java b/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java index 81c85e83..330aa51a 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java +++ b/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java @@ -1,5 +1,10 @@ package com.alibaba.excel.write.metadata.style; +import com.alibaba.excel.metadata.property.FontProperty; +import com.alibaba.excel.metadata.property.StyleProperty; +import com.alibaba.excel.util.StringUtils; + +import lombok.Data; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.FillPatternType; @@ -8,15 +13,12 @@ import org.apache.poi.ss.usermodel.IgnoredErrorType; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.VerticalAlignment; -import com.alibaba.excel.metadata.property.FontProperty; -import com.alibaba.excel.metadata.property.StyleProperty; -import com.alibaba.excel.util.StringUtils; - /** * Cell style when writing * * @author Jiaju Zhuang */ +@Data public class WriteCellStyle { /** * Set the data format (must be a valid format). Built in formats are defined at {@link BuiltinFormats}. @@ -213,180 +215,4 @@ public class WriteCellStyle { return writeCellStyle; } - - public Short getDataFormat() { - return dataFormat; - } - - public void setDataFormat(Short dataFormat) { - this.dataFormat = dataFormat; - } - - public WriteFont getWriteFont() { - return writeFont; - } - - public void setWriteFont(WriteFont writeFont) { - this.writeFont = writeFont; - } - - public Boolean getHidden() { - return hidden; - } - - public void setHidden(Boolean hidden) { - this.hidden = hidden; - } - - public Boolean getLocked() { - return locked; - } - - public void setLocked(Boolean locked) { - this.locked = locked; - } - - public Boolean getQuotePrefix() { - return quotePrefix; - } - - public void setQuotePrefix(Boolean quotePrefix) { - this.quotePrefix = quotePrefix; - } - - public HorizontalAlignment getHorizontalAlignment() { - return horizontalAlignment; - } - - public void setHorizontalAlignment(HorizontalAlignment horizontalAlignment) { - this.horizontalAlignment = horizontalAlignment; - } - - public Boolean getWrapped() { - return wrapped; - } - - public void setWrapped(Boolean wrapped) { - this.wrapped = wrapped; - } - - public VerticalAlignment getVerticalAlignment() { - return verticalAlignment; - } - - public void setVerticalAlignment(VerticalAlignment verticalAlignment) { - this.verticalAlignment = verticalAlignment; - } - - public Short getRotation() { - return rotation; - } - - public void setRotation(Short rotation) { - this.rotation = rotation; - } - - public Short getIndent() { - return indent; - } - - public void setIndent(Short indent) { - this.indent = indent; - } - - public BorderStyle getBorderLeft() { - return borderLeft; - } - - public void setBorderLeft(BorderStyle borderLeft) { - this.borderLeft = borderLeft; - } - - public BorderStyle getBorderRight() { - return borderRight; - } - - public void setBorderRight(BorderStyle borderRight) { - this.borderRight = borderRight; - } - - public BorderStyle getBorderTop() { - return borderTop; - } - - public void setBorderTop(BorderStyle borderTop) { - this.borderTop = borderTop; - } - - public BorderStyle getBorderBottom() { - return borderBottom; - } - - public void setBorderBottom(BorderStyle borderBottom) { - this.borderBottom = borderBottom; - } - - public Short getLeftBorderColor() { - return leftBorderColor; - } - - public void setLeftBorderColor(Short leftBorderColor) { - this.leftBorderColor = leftBorderColor; - } - - public Short getRightBorderColor() { - return rightBorderColor; - } - - public void setRightBorderColor(Short rightBorderColor) { - this.rightBorderColor = rightBorderColor; - } - - public Short getTopBorderColor() { - return topBorderColor; - } - - public void setTopBorderColor(Short topBorderColor) { - this.topBorderColor = topBorderColor; - } - - public Short getBottomBorderColor() { - return bottomBorderColor; - } - - public void setBottomBorderColor(Short bottomBorderColor) { - this.bottomBorderColor = bottomBorderColor; - } - - public FillPatternType getFillPatternType() { - return fillPatternType; - } - - public void setFillPatternType(FillPatternType fillPatternType) { - this.fillPatternType = fillPatternType; - } - - public Short getFillBackgroundColor() { - return fillBackgroundColor; - } - - public void setFillBackgroundColor(Short fillBackgroundColor) { - this.fillBackgroundColor = fillBackgroundColor; - } - - public Short getFillForegroundColor() { - return fillForegroundColor; - } - - public void setFillForegroundColor(Short fillForegroundColor) { - this.fillForegroundColor = fillForegroundColor; - } - - public Boolean getShrinkToFit() { - return shrinkToFit; - } - - public void setShrinkToFit(Boolean shrinkToFit) { - this.shrinkToFit = shrinkToFit; - } } diff --git a/src/main/java/com/alibaba/excel/write/metadata/style/WriteFont.java b/src/main/java/com/alibaba/excel/write/metadata/style/WriteFont.java index 6ed4c2a7..38c65539 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/style/WriteFont.java +++ b/src/main/java/com/alibaba/excel/write/metadata/style/WriteFont.java @@ -1,5 +1,6 @@ package com.alibaba.excel.write.metadata.style; +import lombok.Data; import org.apache.poi.common.usermodel.fonts.FontCharset; import org.apache.poi.hssf.usermodel.HSSFPalette; import org.apache.poi.ss.usermodel.Font; @@ -10,6 +11,7 @@ import org.apache.poi.ss.usermodel.IndexedColors; * * @author jipengfei */ +@Data public class WriteFont { /** * The name for the font (i.e. Arial) @@ -68,76 +70,4 @@ public class WriteFont { * Bold */ private Boolean bold; - - public String getFontName() { - return fontName; - } - - public void setFontName(String fontName) { - this.fontName = fontName; - } - - public Short getFontHeightInPoints() { - return fontHeightInPoints; - } - - public void setFontHeightInPoints(Short fontHeightInPoints) { - this.fontHeightInPoints = fontHeightInPoints; - } - - public Boolean getItalic() { - return italic; - } - - public void setItalic(Boolean italic) { - this.italic = italic; - } - - public Boolean getStrikeout() { - return strikeout; - } - - public void setStrikeout(Boolean strikeout) { - this.strikeout = strikeout; - } - - public Short getColor() { - return color; - } - - public void setColor(Short color) { - this.color = color; - } - - public Short getTypeOffset() { - return typeOffset; - } - - public void setTypeOffset(Short typeOffset) { - this.typeOffset = typeOffset; - } - - public Byte getUnderline() { - return underline; - } - - public void setUnderline(Byte underline) { - this.underline = underline; - } - - public Integer getCharset() { - return charset; - } - - public void setCharset(Integer charset) { - this.charset = charset; - } - - public Boolean getBold() { - return bold; - } - - public void setBold(Boolean bold) { - this.bold = bold; - } }