true
make all content visible within a
* cell by displaying it on multiple lines
*
*/
- boolean wrapped();
+ boolean wrapped() default false;
/**
* Set the type of vertical alignment for the cell
*/
- VerticalAlignment verticalAlignment();
+ VerticalAlignment verticalAlignment() default VerticalAlignment.CENTER;
/**
* Set the degree of rotation for the text in the cell.
@@ -70,39 +70,39 @@ public @interface ContentStyle {
* getter is returning values in the range mandated by the current type of Excel file-format that this CellStyle is
* applied to.
*/
- short rotation();
+ short rotation() default -1;
/**
* Set the number of spaces to indent the text in the cell
*/
- short indent();
+ short indent() default -1;
/**
* Set the type of border to use for the left border of the cell
*/
- BorderStyle borderLeft();
+ BorderStyle borderLeft() default BorderStyle.NONE;
/**
* Set the type of border to use for the right border of the cell
*/
- BorderStyle borderRight();
+ BorderStyle borderRight() default BorderStyle.NONE;
/**
* Set the type of border to use for the top border of the cell
*/
- BorderStyle borderTop();
+ BorderStyle borderTop() default BorderStyle.NONE;
/**
* Set the type of border to use for the bottom border of the cell
*/
- BorderStyle borderBottom();
+ BorderStyle borderBottom() default BorderStyle.NONE;
/**
* Set the color to use for the left border
*
* @see IndexedColors
*/
- short leftBorderColor();
+ short leftBorderColor() default -1;
/**
* Set the color to use for the right border
@@ -110,7 +110,7 @@ public @interface ContentStyle {
* @see IndexedColors
*
*/
- short rightBorderColor();
+ short rightBorderColor() default -1;
/**
* Set the color to use for the top border
@@ -118,7 +118,7 @@ public @interface ContentStyle {
* @see IndexedColors
*
*/
- short topBorderColor();
+ short topBorderColor() default -1;
/**
* Set the color to use for the bottom border
@@ -126,14 +126,14 @@ public @interface ContentStyle {
* @see IndexedColors
*
*/
- short bottomBorderColor();
+ short bottomBorderColor() default -1;
/**
* Setting to one fills the cell with the foreground color... No idea about other values
*
* @see FillPatternType#SOLID_FOREGROUND
*/
- FillPatternType fillPatternType();
+ FillPatternType fillPatternType() default FillPatternType.NO_FILL;
/**
* Set the background fill color.
@@ -141,7 +141,7 @@ public @interface ContentStyle {
* @see IndexedColors
*
*/
- short fillBackgroundColor();
+ short fillBackgroundColor() default -1;
/**
* Set the foreground fill color Note: Ensure Foreground color is set prior to background color.
@@ -149,11 +149,11 @@ public @interface ContentStyle {
* @see IndexedColors
*
*/
- short fillForegroundColor();
+ short fillForegroundColor() default -1;
/**
* Controls if the Cell should be auto-sized to shrink to fit if the text is too long
*/
- boolean shrinkToFit();
+ boolean shrinkToFit() default false;
}
diff --git a/src/main/java/com/alibaba/excel/annotation/write/style/HeadFontStyle.java b/src/main/java/com/alibaba/excel/annotation/write/style/HeadFontStyle.java
index 907a44b..957e50f 100644
--- a/src/main/java/com/alibaba/excel/annotation/write/style/HeadFontStyle.java
+++ b/src/main/java/com/alibaba/excel/annotation/write/style/HeadFontStyle.java
@@ -16,7 +16,7 @@ import org.apache.poi.ss.usermodel.IndexedColors;
*
* @author Jiaju Zhuang
*/
-@Target({ElementType.FIELD})
+@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HeadFontStyle {
@@ -24,12 +24,12 @@ public @interface HeadFontStyle {
/**
* The name for the font (i.e. Arial)
*/
- String fontName();
+ String fontName() default "宋体";
/**
* Height in the familiar unit of measure - points
*/
- short fontHeightInPoints() default -1;
+ short fontHeightInPoints() default 14;
/**
* Whether to use italics or not
@@ -85,5 +85,5 @@ public @interface HeadFontStyle {
/**
* Bold
*/
- boolean bold() default false;
+ boolean bold() default true;
}
diff --git a/src/main/java/com/alibaba/excel/annotation/write/style/HeadStyle.java b/src/main/java/com/alibaba/excel/annotation/write/style/HeadStyle.java
index 10252a7..d882da8 100644
--- a/src/main/java/com/alibaba/excel/annotation/write/style/HeadStyle.java
+++ b/src/main/java/com/alibaba/excel/annotation/write/style/HeadStyle.java
@@ -19,7 +19,7 @@ import org.apache.poi.ss.usermodel.VerticalAlignment;
*
* @author Jiaju Zhuang
*/
-@Target({ElementType.FIELD})
+@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HeadStyle {
@@ -36,7 +36,7 @@ public @interface HeadStyle {
/**
* Set the cell's using this style to be locked
*/
- boolean locked() default false;
+ boolean locked() default true;
/**
* Turn on or off "Quote Prefix" or "123 Prefix" for the style, which is used to tell Excel that the thing which
@@ -48,19 +48,19 @@ public @interface HeadStyle {
/**
* Set the type of horizontal alignment for the cell
*/
- HorizontalAlignment horizontalAlignment();
+ HorizontalAlignment horizontalAlignment() default HorizontalAlignment.CENTER;
/**
* Set whether the text should be wrapped. Setting this flag to true
make all content visible within a
* cell by displaying it on multiple lines
*
*/
- boolean wrapped() default false;
+ boolean wrapped() default true;
/**
* Set the type of vertical alignment for the cell
*/
- VerticalAlignment verticalAlignment();
+ VerticalAlignment verticalAlignment() default VerticalAlignment.CENTER;
/**
* Set the degree of rotation for the text in the cell.
@@ -80,22 +80,22 @@ public @interface HeadStyle {
/**
* Set the type of border to use for the left border of the cell
*/
- BorderStyle borderLeft();
+ BorderStyle borderLeft() default BorderStyle.THIN;
/**
* Set the type of border to use for the right border of the cell
*/
- BorderStyle borderRight();
+ BorderStyle borderRight() default BorderStyle.THIN;
/**
* Set the type of border to use for the top border of the cell
*/
- BorderStyle borderTop();
+ BorderStyle borderTop() default BorderStyle.THIN;
/**
* Set the type of border to use for the bottom border of the cell
*/
- BorderStyle borderBottom();
+ BorderStyle borderBottom() default BorderStyle.THIN;
/**
* Set the color to use for the left border
@@ -133,7 +133,7 @@ public @interface HeadStyle {
*
* @see FillPatternType#SOLID_FOREGROUND
*/
- FillPatternType fillPatternType();
+ FillPatternType fillPatternType() default FillPatternType.SOLID_FOREGROUND;
/**
* Set the background fill color.
diff --git a/src/main/java/com/alibaba/excel/converters/DefaultConverterLoader.java b/src/main/java/com/alibaba/excel/converters/DefaultConverterLoader.java
index 77e8b59..0182255 100644
--- a/src/main/java/com/alibaba/excel/converters/DefaultConverterLoader.java
+++ b/src/main/java/com/alibaba/excel/converters/DefaultConverterLoader.java
@@ -48,56 +48,12 @@ public class DefaultConverterLoader {
private static Maptrue
make all content visible within a
+ * cell by displaying it on multiple lines
+ *
+ */
+ private Boolean wrapped;
+ /**
+ * Set the type of vertical alignment for the cell
+ */
+ private VerticalAlignment verticalAlignment;
+ /**
+ * Set the degree of rotation for the text in the cell.
+ *
+ * Note: HSSF uses values from -90 to 90 degrees, whereas XSSF uses values from 0 to 180 degrees. The
+ * implementations of this method will map between these two value-ranges accordingly, however the corresponding
+ * getter is returning values in the range mandated by the current type of Excel file-format that this CellStyle is
+ * applied to.
+ */
+ private Short rotation;
+ /**
+ * Set the number of spaces to indent the text in the cell
+ */
+ private Short indent;
+ /**
+ * Set the type of border to use for the left border of the cell
+ */
+ private BorderStyle borderLeft;
+ /**
+ * Set the type of border to use for the right border of the cell
+ */
+ private BorderStyle borderRight;
+ /**
+ * Set the type of border to use for the top border of the cell
+ */
+ private BorderStyle borderTop;
+
+ /**
+ * Set the type of border to use for the bottom border of the cell
+ */
+ private BorderStyle borderBottom;
+ /**
+ * Set the color to use for the left border
+ *
+ * @see IndexedColors
+ */
+ private Short leftBorderColor;
+
+ /**
+ * Set the color to use for the right border
+ *
+ * @see IndexedColors
+ *
+ */
+ private Short rightBorderColor;
+
+ /**
+ * Set the color to use for the top border
+ *
+ * @see IndexedColors
+ *
+ */
+ private Short topBorderColor;
+ /**
+ * Set the color to use for the bottom border
+ *
+ * @see IndexedColors
+ *
+ */
+ private Short bottomBorderColor;
+ /**
+ * Setting to one fills the cell with the foreground color... No idea about other values
+ *
+ * @see FillPatternType#SOLID_FOREGROUND
+ */
+ private FillPatternType fillPatternType;
+
+ /**
+ * Set the background fill color.
+ *
+ * @see IndexedColors
+ *
+ */
+ private Short fillBackgroundColor;
+
+ /**
+ * Set the foreground fill color Note: Ensure Foreground color is set prior to background color.
+ *
+ * @see IndexedColors
+ *
+ */
+ private Short fillForegroundColor;
+ /**
+ * Controls if the Cell should be auto-sized to shrink to fit if the text is too long
+ */
+ private Boolean shrinkToFit;
+
+ public static StyleProperty build(HeadStyle headStyle) {
+ if (headStyle == null) {
+ return null;
+ }
+ StyleProperty styleProperty = new StyleProperty();
+ styleProperty.setDataFormat(headStyle.dataFormat());
+ styleProperty.setHidden(headStyle.hidden());
+ styleProperty.setLocked(headStyle.locked());
+ styleProperty.setQuotePrefix(headStyle.quotePrefix());
+ styleProperty.setHorizontalAlignment(headStyle.horizontalAlignment());
+ styleProperty.setWrapped(headStyle.wrapped());
+ styleProperty.setVerticalAlignment(headStyle.verticalAlignment());
+ styleProperty.setRotation(headStyle.rotation());
+ styleProperty.setIndent(headStyle.indent());
+ styleProperty.setBorderLeft(headStyle.borderLeft());
+ styleProperty.setBorderRight(headStyle.borderRight());
+ styleProperty.setBorderTop(headStyle.borderTop());
+ styleProperty.setBorderBottom(headStyle.borderBottom());
+ styleProperty.setLeftBorderColor(headStyle.leftBorderColor());
+ styleProperty.setRightBorderColor(headStyle.rightBorderColor());
+ styleProperty.setTopBorderColor(headStyle.topBorderColor());
+ styleProperty.setBottomBorderColor(headStyle.bottomBorderColor());
+ styleProperty.setFillPatternType(headStyle.fillPatternType());
+ styleProperty.setFillBackgroundColor(headStyle.fillBackgroundColor());
+ styleProperty.setFillForegroundColor(headStyle.fillForegroundColor());
+ styleProperty.setShrinkToFit(headStyle.shrinkToFit());
+ return styleProperty;
+ }
+
+ public static StyleProperty build(ContentStyle contentStyle) {
+ if (contentStyle == null) {
+ return null;
+ }
+ StyleProperty styleProperty = new StyleProperty();
+ styleProperty.setDataFormat(contentStyle.dataFormat());
+ styleProperty.setHidden(contentStyle.hidden());
+ styleProperty.setLocked(contentStyle.locked());
+ styleProperty.setQuotePrefix(contentStyle.quotePrefix());
+ styleProperty.setHorizontalAlignment(contentStyle.horizontalAlignment());
+ styleProperty.setWrapped(contentStyle.wrapped());
+ styleProperty.setVerticalAlignment(contentStyle.verticalAlignment());
+ styleProperty.setRotation(contentStyle.rotation());
+ styleProperty.setIndent(contentStyle.indent());
+ styleProperty.setBorderLeft(contentStyle.borderLeft());
+ styleProperty.setBorderRight(contentStyle.borderRight());
+ styleProperty.setBorderTop(contentStyle.borderTop());
+ styleProperty.setBorderBottom(contentStyle.borderBottom());
+ styleProperty.setLeftBorderColor(contentStyle.leftBorderColor());
+ styleProperty.setRightBorderColor(contentStyle.rightBorderColor());
+ styleProperty.setTopBorderColor(contentStyle.topBorderColor());
+ styleProperty.setBottomBorderColor(contentStyle.bottomBorderColor());
+ styleProperty.setFillPatternType(contentStyle.fillPatternType());
+ styleProperty.setFillBackgroundColor(contentStyle.fillBackgroundColor());
+ styleProperty.setFillForegroundColor(contentStyle.fillForegroundColor());
+ styleProperty.setShrinkToFit(contentStyle.shrinkToFit());
+ return styleProperty;
+ }
+
+ 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/util/WriteHandlerUtils.java b/src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java
index b303a31..06dcc72 100644
--- a/src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java
+++ b/src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java
@@ -123,6 +123,21 @@ public class WriteHandlerUtils {
}
}
+ public static void afterCellDataConverted(WriteContext writeContext, CellData cellData, Cell cell, Head head,
+ Integer relativeRowIndex, Boolean isHead) {
+ List+ * 由于是流式读取,没法在读取到单元格数据的时候直接读取到额外信息,所以只能最后通知哪些单元格有哪些额外信息 * *
- * 1. 创建excel对应的实体对象 参照{@link DemoData} + * 1. 创建excel对应的实体对象 参照{@link DemoExtraData} *
- * 2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoHeadDataListener} + * 2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoExtraListener} *
* 3. 直接读即可
*/
@Test
- public void commentsRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
+ public void extraRead() {
+ String fileName = TestFileUtil.getPath() + "demo" + File.separator + "extra.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet
- EasyExcel.read(fileName, DemoData.class, new DemoCellCommentsListener()).sheet().doRead();
+ EasyExcel.read(fileName, DemoExtraData.class, new DemoExtraListener())
+ // 需要读取批注 默认不读取
+ .extraRead(CellExtraTypeEnum.COMMENT)
+ // 需要读取超链接 默认不读取
+ .extraRead(CellExtraTypeEnum.HYPERLINK)
+ // 需要读取合并单元格信息 默认不读取
+ .extraRead(CellExtraTypeEnum.MERGE).sheet().doRead();
}
/**
@@ -233,7 +242,7 @@ public class ReadTest {
}
/**
- * 不创建对象的读,不是特别推荐使用,都用String接收对日期的支持不是很好
+ * 不创建对象的读
*/
@Test
public void noModleRead() {
diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomCellWriteHandler.java b/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomCellWriteHandler.java
index b92d44a..b1bcb7d 100644
--- a/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomCellWriteHandler.java
+++ b/src/test/java/com/alibaba/easyexcel/test/demo/write/CustomCellWriteHandler.java
@@ -6,13 +6,12 @@ import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Hyperlink;
-import org.apache.poi.ss.usermodel.Row;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
-import com.alibaba.excel.write.handler.CellWriteHandler;
+import com.alibaba.excel.write.handler.AbstractCellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
@@ -21,22 +20,10 @@ import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
*
* @author Jiaju Zhuang
*/
-public class CustomCellWriteHandler implements CellWriteHandler {
+public class CustomCellWriteHandler extends AbstractCellWriteHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomCellWriteHandler.class);
- @Override
- public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
- Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
-
- }
-
- @Override
- public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell,
- Head head, Integer relativeRowIndex, Boolean isHead) {
-
- }
-
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
List
+ * 1. 创建excel对应的实体对象 参照{@link DemoStyleData}
+ *
+ * 3. 直接写即可
+ */
+ @Test
+ public void annotationStyleWrite() {
+ String fileName = TestFileUtil.getPath() + "annotationStyleWrite" + System.currentTimeMillis() + ".xlsx";
+ // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
+ EasyExcel.write(fileName, DemoStyleData.class).sheet("模板").doWrite(data());
+ }
+
+ /**
+ * 拦截器形式自定义样式
*
* 1. 创建excel对应的实体对象 参照{@link DemoData}
*
@@ -279,8 +293,8 @@ public class WriteTest {
* 3. 直接写即可
*/
@Test
- public void styleWrite() {
- String fileName = TestFileUtil.getPath() + "styleWrite" + System.currentTimeMillis() + ".xlsx";
+ public void handlerStyleWrite() {
+ String fileName = TestFileUtil.getPath() + "handlerStyleWrite" + System.currentTimeMillis() + ".xlsx";
// 头的策略
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// 背景设置为红色
@@ -310,7 +324,7 @@ public class WriteTest {
/**
* 合并单元格
*
- * 1. 创建excel对应的实体对象 参照{@link DemoData}
+ * 1. 创建excel对应的实体对象 参照{@link DemoData} {@link DemoMergeData}
*
* 2. 创建一个merge策略 并注册
*
@@ -318,7 +332,14 @@ public class WriteTest {
*/
@Test
public void mergeWrite() {
+ // 方法1 注解
String fileName = TestFileUtil.getPath() + "mergeWrite" + System.currentTimeMillis() + ".xlsx";
+ // 在DemoStyleData里面加上ContentLoopMerge注解
+ // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
+ EasyExcel.write(fileName, DemoMergeData.class).sheet("模板").doWrite(data());
+
+ // 方法2 自定义合并单元格策略
+ fileName = TestFileUtil.getPath() + "mergeWrite" + System.currentTimeMillis() + ".xlsx";
// 每隔2行会合并 把eachColumn 设置成 3 也就是我们数据的长度,所以就第一列会合并。当然其他合并策略也可以自己写
LoopMergeStrategy loopMergeStrategy = new LoopMergeStrategy(2, 0);
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
@@ -414,6 +435,23 @@ public class WriteTest {
.registerWriteHandler(new CustomCellWriteHandler()).sheet("模板").doWrite(data());
}
+ /**
+ * 可变标题处理(包括标题国际化等)
+ *
+ * 简单的说用List
+ * 1. 创建excel对应的实体对象 参照{@link ConverterData}
+ *
+ * 2. 直接写即可
+ */
+ @Test
+ public void variableTitleWrite() {
+ // 写法1
+ String fileName = TestFileUtil.getPath() + "variableTitleWrite" + System.currentTimeMillis() + ".xlsx";
+ // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
+ EasyExcel.write(fileName, ConverterData.class).head(variableTitleHead()).sheet("模板").doWrite(data());
+ }
+
/**
* 不创建对象的写
*/
@@ -437,6 +475,20 @@ public class WriteTest {
return list;
}
+ private List>的标题 但是还支持注解
+ *
> variableTitleHead() {
+ List
> list = new ArrayList
>();
+ List
> head() {
List
> list = new ArrayList
>();
List
>`和`class`的head,会通过index去匹配注解
+* 修复读取转换器的并发问题
+*
# 2.1.4
* 新增参数`useDefaultListener` 可以排除默认对象转换