Browse Source

修改完成部分图片等导入

developing
Jiaju Zhuang 4 years ago
parent
commit
de4ec6d400
  1. 2
      lombok.config
  2. 6
      src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java
  3. 4
      src/main/java/com/alibaba/excel/exception/ExcelDataConvertException.java
  4. 19
      src/main/java/com/alibaba/excel/metadata/AbstractCell.java
  5. 45
      src/main/java/com/alibaba/excel/metadata/AbstractHolder.java
  6. 103
      src/main/java/com/alibaba/excel/metadata/CellData.java
  7. 139
      src/main/java/com/alibaba/excel/metadata/ClientAnchorData.java
  8. 28
      src/main/java/com/alibaba/excel/metadata/CommentData.java
  9. 20
      src/main/java/com/alibaba/excel/metadata/DataFormat.java
  10. 16
      src/main/java/com/alibaba/excel/metadata/FormulaData.java
  11. 10
      src/main/java/com/alibaba/excel/metadata/HyperlinkData.java
  12. 58
      src/main/java/com/alibaba/excel/metadata/ImageData.java
  13. 13
      src/main/java/com/alibaba/excel/metadata/ReadCellData.java
  14. 59
      src/main/java/com/alibaba/excel/metadata/RichTextStringData.java
  15. 42
      src/main/java/com/alibaba/excel/metadata/WriteCellData.java
  16. 78
      src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
  17. 27
      src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
  18. 4
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
  19. 4
      src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
  20. 6
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java
  21. 4
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java
  22. 186
      src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java
  23. 74
      src/main/java/com/alibaba/excel/write/metadata/style/WriteFont.java

2
lombok.config

@ -0,0 +1,2 @@
lombok.toString.callSuper = CALL
lombok.equalsAndHashCode.callSuper= CALL

6
src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java

@ -37,13 +37,17 @@ public enum CellDataTypeEnum {
*/ */
ERROR, ERROR,
/** /**
* Images are currently supported only when writing * image. Support only when writing.
*/ */
IMAGE, IMAGE,
/** /**
* date.Support only when writing. * date.Support only when writing.
*/ */
DATE, DATE,
/**
* rich text string.Support only when writing.
*/
RICH_TEXT_STRING,
; ;
private static final Map<String, CellDataTypeEnum> TYPE_ROUTING_MAP = new HashMap<String, CellDataTypeEnum>(16); private static final Map<String, CellDataTypeEnum> TYPE_ROUTING_MAP = new HashMap<String, CellDataTypeEnum>(16);

4
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.metadata.property.ExcelContentProperty;
import com.alibaba.excel.write.builder.ExcelWriterBuilder; import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -12,8 +13,7 @@ import lombok.Setter;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Getter @Data
@Setter
public class ExcelDataConvertException extends RuntimeException { public class ExcelDataConvertException extends RuntimeException {
/** /**
* NotNull. * NotNull.

19
src/main/java/com/alibaba/excel/metadata/AbstractCell.java

@ -1,10 +1,13 @@
package com.alibaba.excel.metadata; package com.alibaba.excel.metadata;
import lombok.Data;
/** /**
* cell * cell
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Data
public class AbstractCell implements Cell { public class AbstractCell implements Cell {
/** /**
* Row index * Row index
@ -14,20 +17,4 @@ public class AbstractCell implements Cell {
* Column index * Column index
*/ */
private Integer columnIndex; 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;
}
} }

45
src/main/java/com/alibaba/excel/metadata/AbstractHolder.java

@ -6,11 +6,16 @@ import java.util.Map;
import com.alibaba.excel.converters.Converter; import com.alibaba.excel.converters.Converter;
import lombok.Data;
import lombok.NoArgsConstructor;
/** /**
* Write/read holder * Write/read holder
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Data
@NoArgsConstructor
public abstract class AbstractHolder implements ConfigurationHolder { public abstract class AbstractHolder implements ConfigurationHolder {
/** /**
* Record whether it's new or from cache * 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<List<String>> getHead() {
return head;
}
public void setHead(List<List<String>> 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<String, Converter<?>> getConverterMap() {
return converterMap;
}
public void setConverterMap(Map<String, Converter<?>> converterMap) {
this.converterMap = converterMap;
}
@Override @Override
public Map<String, Converter<?>> converterMap() { public Map<String, Converter<?>> converterMap() {
return getConverterMap(); return getConverterMap();

103
src/main/java/com/alibaba/excel/metadata/CellData.java

@ -1,14 +1,18 @@
package com.alibaba.excel.metadata; package com.alibaba.excel.metadata;
import java.math.BigDecimal; import java.math.BigDecimal;
import com.alibaba.excel.annotation.write.style.ImagePosition;
import java.util.Date; import java.util.Date;
import com.alibaba.excel.annotation.write.style.ImagePosition;
import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.property.ImagePositionProperty; import com.alibaba.excel.metadata.property.ImagePositionProperty;
import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.util.StringUtils;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import lombok.Getter; import lombok.Data;
import lombok.Setter; 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. * Excel internal cell data.
@ -17,8 +21,7 @@ import lombok.Setter;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Getter @Data
@Setter
public class CellData<T> extends AbstractCell { public class CellData<T> extends AbstractCell {
private CellDataTypeEnum type; private CellDataTypeEnum type;
/** /**
@ -33,52 +36,20 @@ public class CellData<T> extends AbstractCell {
* {@link CellDataTypeEnum#BOOLEAN} * {@link CellDataTypeEnum#BOOLEAN}
*/ */
private Boolean booleanValue; 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. * formula
*/
private Boolean useImagePositionProperty = false;
/**
* Support only when writing.
*/
private Date dateValue;
/**
* The number formatting.
*/
private Short dataFormat;
/**
* The string of number formatting.
*/ */
private String dataFormatString; private FormulaData formulaData;
/** /**
* The resulting converted data. * data format
*/ */
private T data; private DataFormat dataFormat;
public CellData(CellData<T> 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());
}
public CellData() {} public CellData() {}
@ -86,12 +57,6 @@ public class CellData<T> extends AbstractCell {
this.data = data; this.data = data;
} }
public CellData(T data, String formulaValue) {
this.data = data;
this.formula = Boolean.TRUE;
this.formulaValue = formulaValue;
}
public CellData(String stringValue) { public CellData(String stringValue) {
this(CellDataTypeEnum.STRING, stringValue); this(CellDataTypeEnum.STRING, stringValue);
} }
@ -105,7 +70,6 @@ public class CellData<T> extends AbstractCell {
} }
this.type = type; this.type = type;
this.stringValue = stringValue; this.stringValue = stringValue;
this.formula = Boolean.FALSE;
} }
public CellData(BigDecimal numberValue) { public CellData(BigDecimal numberValue) {
@ -114,7 +78,6 @@ public class CellData<T> extends AbstractCell {
} }
this.type = CellDataTypeEnum.NUMBER; this.type = CellDataTypeEnum.NUMBER;
this.numberValue = numberValue; this.numberValue = numberValue;
this.formula = Boolean.FALSE;
} }
public CellData(byte[] imageValue) { public CellData(byte[] imageValue) {
@ -123,7 +86,6 @@ public class CellData<T> extends AbstractCell {
} }
this.type = CellDataTypeEnum.IMAGE; this.type = CellDataTypeEnum.IMAGE;
this.imageValue = imageValue; this.imageValue = imageValue;
this.formula = Boolean.FALSE;
} }
public CellData(byte[] imageValue, ImagePosition imagePosition) { public CellData(byte[] imageValue, ImagePosition imagePosition) {
@ -146,7 +108,6 @@ public class CellData<T> extends AbstractCell {
} }
this.type = CellDataTypeEnum.BOOLEAN; this.type = CellDataTypeEnum.BOOLEAN;
this.booleanValue = booleanValue; this.booleanValue = booleanValue;
this.formula = Boolean.FALSE;
} }
public CellData(Date dateValue) { public CellData(Date dateValue) {
@ -158,7 +119,6 @@ public class CellData<T> extends AbstractCell {
this.formula = Boolean.FALSE; this.formula = Boolean.FALSE;
} }
public CellData(CellDataTypeEnum type) { public CellData(CellDataTypeEnum type) {
if (type == null) { if (type == null) {
throw new IllegalArgumentException("Type can not be null"); throw new IllegalArgumentException("Type can not be null");
@ -230,39 +190,4 @@ public class CellData<T> extends AbstractCell {
return cellData; 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;
}
}
} }

139
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}:
* <ol>
* <li> {@link ClientAnchor.AnchorType#DONT_MOVE_AND_RESIZE} == absolute top-left coordinates and width/height, no
* cell references
* <li> {@link ClientAnchor.AnchorType#MOVE_DONT_RESIZE} == fixed top-left cell reference, absolute width/height
* <li> {@link ClientAnchor.AnchorType#MOVE_AND_RESIZE} == fixed top-left and bottom-right cell references, dynamic
* width/height
* </ol>
* 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)
* <p>
* 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)
* </p>
*/
MOVE_AND_RESIZE(0),
/**
* Don't Move but do Resize With Anchor Cells (1)
* <p>
* 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.
* </p>
* 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)
* <p>
* 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.
* </p>
* <p>
* 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.
* </p>
*/
MOVE_DONT_RESIZE(2),
/**
* Do Not Move or Resize With Underlying Rows/Columns (3)
* <p>
* Specifies that the current start and end positions shall
* be maintained with respect to the distances from the
* absolute start point of the worksheet.
* </p>
* <p>
* If additional rows/columns are added before the
* drawing, the drawing shall move its anchors as needed
* to maintain this same absolute position.
* </p>
*/
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];
}
}
}

28
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;
}

20
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;
}

16
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;
}

10
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 {
}

58
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;
}
}
}

13
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<T> extends CellData<T>{
}

59
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<IntervalFont> 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;
}
}

42
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<T> extends CellData<T> {
/**
* 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;
}

78
src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java

@ -1,19 +1,13 @@
package com.alibaba.excel.metadata.property; package com.alibaba.excel.metadata.property;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; 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.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat; import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.format.NumberFormat; 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.util.StringUtils;
import com.alibaba.excel.write.metadata.holder.AbstractWriteHolder; 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 * Define the header attribute of excel
* *
* @author jipengfei * @author jipengfei
*/ */
@Data
public class ExcelHeadProperty { public class ExcelHeadProperty {
private static final Logger LOGGER = LoggerFactory.getLogger(ExcelHeadProperty.class); private static final Logger LOGGER = LoggerFactory.getLogger(ExcelHeadProperty.class);
@ -64,7 +64,7 @@ public class ExcelHeadProperty {
*/ */
private Map<String, Field> ignoreMap; private Map<String, Field> ignoreMap;
public ExcelHeadProperty(Holder holder, Class headClazz, List<List<String>> head, Boolean convertAllField) { public ExcelHeadProperty(Holder holder, Class headClazz, List<List<String>> head, Boolean convertAllFiled) {
this.headClazz = headClazz; this.headClazz = headClazz;
headMap = new TreeMap<Integer, Head>(); headMap = new TreeMap<Integer, Head>();
contentPropertyMap = new TreeMap<Integer, ExcelContentProperty>(); contentPropertyMap = new TreeMap<Integer, ExcelContentProperty>();
@ -87,7 +87,7 @@ public class ExcelHeadProperty {
headKind = HeadKindEnum.STRING; headKind = HeadKindEnum.STRING;
} }
// convert headClazz to head // convert headClazz to head
initColumnProperties(holder, convertAllField); initColumnProperties(holder, convertAllFiled);
initHeadRowNumber(); initHeadRowNumber();
if (LOGGER.isDebugEnabled()) { 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) { if (headClazz == null) {
return; return;
} }
@ -124,9 +124,9 @@ public class ExcelHeadProperty {
Map<Integer, Field> indexFiledMap = new TreeMap<Integer, Field>(); Map<Integer, Field> indexFiledMap = new TreeMap<Integer, Field>();
boolean needIgnore = (holder instanceof AbstractWriteHolder) && ( 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).getExcludeColumnIndexes()) || !CollectionUtils
.isEmpty(((AbstractWriteHolder) holder).getIncludeColumnFiledNames()) || !CollectionUtils .isEmpty(((AbstractWriteHolder) holder).getIncludeColumnFieldNames()) || !CollectionUtils
.isEmpty(((AbstractWriteHolder) holder).getIncludeColumnIndexes())); .isEmpty(((AbstractWriteHolder) holder).getIncludeColumnIndexes()));
ClassUtils.declaredFields(headClazz, sortedAllFiledMap, indexFiledMap, ignoreMap, convertAllFiled, needIgnore, ClassUtils.declaredFields(headClazz, sortedAllFiledMap, indexFiledMap, ignoreMap, convertAllFiled, needIgnore,
holder); holder);
@ -134,6 +134,7 @@ public class ExcelHeadProperty {
for (Map.Entry<Integer, Field> entry : sortedAllFiledMap.entrySet()) { for (Map.Entry<Integer, Field> entry : sortedAllFiledMap.entrySet()) {
initOneColumnProperty(entry.getKey(), entry.getValue(), indexFiledMap.containsKey(entry.getKey())); initOneColumnProperty(entry.getKey(), entry.getValue(), indexFiledMap.containsKey(entry.getKey()));
} }
headKind = HeadKindEnum.CLASS;
} }
/** /**
@ -182,63 +183,8 @@ public class ExcelHeadProperty {
fieldNameContentPropertyMap.put(field.getName(), excelContentProperty); 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() { public boolean hasHead() {
return headKind != HeadKindEnum.NONE; return headKind != HeadKindEnum.NONE;
} }
public int getHeadRowNumber() {
return headRowNumber;
}
public void setHeadRowNumber(int headRowNumber) {
this.headRowNumber = headRowNumber;
}
public Map<Integer, Head> getHeadMap() {
return headMap;
}
public void setHeadMap(Map<Integer, Head> headMap) {
this.headMap = headMap;
}
public Map<Integer, ExcelContentProperty> getContentPropertyMap() {
return contentPropertyMap;
}
public void setContentPropertyMap(Map<Integer, ExcelContentProperty> contentPropertyMap) {
this.contentPropertyMap = contentPropertyMap;
}
public Map<String, ExcelContentProperty> getFieldNameContentPropertyMap() {
return fieldNameContentPropertyMap;
}
public void setFieldNameContentPropertyMap(Map<String, ExcelContentProperty> fieldNameContentPropertyMap) {
this.fieldNameContentPropertyMap = fieldNameContentPropertyMap;
}
public Map<String, Field> getIgnoreMap() {
return ignoreMap;
}
public void setIgnoreMap(Map<String, Field> ignoreMap) {
this.ignoreMap = ignoreMap;
}
} }

27
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.read.metadata.property.ExcelReadHeadProperty;
import com.alibaba.excel.util.ListUtils; import com.alibaba.excel.util.ListUtils;
import org.slf4j.Logger; import lombok.Data;
import org.slf4j.LoggerFactory;
/** /**
* Read Holder * Read Holder
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Data
public abstract class AbstractReadHolder extends AbstractHolder implements ReadHolder { public abstract class AbstractReadHolder extends AbstractHolder implements ReadHolder {
/** /**
* Count the number of added heads when read sheet. * Count the number of added heads when read sheet.
@ -112,29 +112,6 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
} }
} }
public List<ReadListener> getReadListenerList() {
return readListenerList;
}
public void setReadListenerList(List<ReadListener> 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 @Override
public List<ReadListener> readListenerList() { public List<ReadListener> readListenerList() {

4
src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java

@ -179,9 +179,9 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
} }
WriteWorkbookHolder writeWorkbookHolder = writeContext.writeWorkbookHolder(); WriteWorkbookHolder writeWorkbookHolder = writeContext.writeWorkbookHolder();
boolean needIgnore = boolean needIgnore =
!CollectionUtils.isEmpty(writeWorkbookHolder.getExcludeColumnFiledNames()) || !CollectionUtils !CollectionUtils.isEmpty(writeWorkbookHolder.getExcludeColumnFieldNames()) || !CollectionUtils
.isEmpty(writeWorkbookHolder.getExcludeColumnIndexes()) || !CollectionUtils .isEmpty(writeWorkbookHolder.getExcludeColumnIndexes()) || !CollectionUtils
.isEmpty(writeWorkbookHolder.getIncludeColumnFiledNames()) || !CollectionUtils .isEmpty(writeWorkbookHolder.getIncludeColumnFieldNames()) || !CollectionUtils
.isEmpty(writeWorkbookHolder.getIncludeColumnIndexes()); .isEmpty(writeWorkbookHolder.getIncludeColumnIndexes());
ClassUtils.declaredFields(clazz, sortedAllFiledMap, ClassUtils.declaredFields(clazz, sortedAllFiledMap,
writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled(), needIgnore, writeWorkbookHolder); writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled(), needIgnore, writeWorkbookHolder);

4
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.Set;
import java.util.TreeMap; import java.util.TreeMap;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.IndexedColors;
@ -50,6 +52,8 @@ import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Data
@NoArgsConstructor
public abstract class AbstractWriteHolder extends AbstractHolder implements WriteHolder { public abstract class AbstractWriteHolder extends AbstractHolder implements WriteHolder {
/** /**
* Need Head * Need Head

6
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.util.StringUtils;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
@ -20,8 +22,8 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Getter @Data
@Setter @NoArgsConstructor
public class WriteSheetHolder extends AbstractWriteHolder { public class WriteSheetHolder extends AbstractWriteHolder {
/** /**
* current param * current param

4
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.util.StringUtils;
import com.alibaba.excel.write.metadata.WriteWorkbook; import com.alibaba.excel.write.metadata.WriteWorkbook;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@ -33,8 +34,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Getter @Data
@Setter
public class WriteWorkbookHolder extends AbstractWriteHolder { 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 * Current poi Workbook.This is only for writing, and there may be no data in version 07 when template data needs to

186
src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java

@ -1,5 +1,10 @@
package com.alibaba.excel.write.metadata.style; 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.BorderStyle;
import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.ss.usermodel.FillPatternType; 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.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment; 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 * Cell style when writing
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Data
public class WriteCellStyle { public class WriteCellStyle {
/** /**
* Set the data format (must be a valid format). Built in formats are defined at {@link BuiltinFormats}. * 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; 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;
}
} }

74
src/main/java/com/alibaba/excel/write/metadata/style/WriteFont.java

@ -1,5 +1,6 @@
package com.alibaba.excel.write.metadata.style; package com.alibaba.excel.write.metadata.style;
import lombok.Data;
import org.apache.poi.common.usermodel.fonts.FontCharset; import org.apache.poi.common.usermodel.fonts.FontCharset;
import org.apache.poi.hssf.usermodel.HSSFPalette; import org.apache.poi.hssf.usermodel.HSSFPalette;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
@ -10,6 +11,7 @@ import org.apache.poi.ss.usermodel.IndexedColors;
* *
* @author jipengfei * @author jipengfei
*/ */
@Data
public class WriteFont { public class WriteFont {
/** /**
* The name for the font (i.e. Arial) * The name for the font (i.e. Arial)
@ -68,76 +70,4 @@ public class WriteFont {
* Bold * Bold
*/ */
private Boolean 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;
}
} }

Loading…
Cancel
Save