> cellDataList, Cell cell, Head head,
Integer relativeRowIndex, Boolean isHead) {
boolean needSetWidth = relativeRowIndex != null && (isHead || relativeRowIndex == 0);
if (!needSetWidth) {
diff --git a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
index 1010163e..d248de13 100644
--- a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
+++ b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
@@ -4,14 +4,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.poi.ss.usermodel.Cell;
-
import com.alibaba.excel.enums.CellDataTypeEnum;
-import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.excel.metadata.Head;
+import com.alibaba.excel.metadata.data.WriteCellData;
+import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.poi.ss.usermodel.Cell;
+
/**
* Take the width of the longest column as the width.
*
@@ -24,10 +25,11 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty
private static final int MAX_COLUMN_WIDTH = 255;
- private Map> cache = new HashMap>(8);
+ private final Map> cache = MapUtils.newHashMapWithExpectedSize(8);
@Override
- protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List> cellDataList, Cell cell, Head head,
+ protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List> cellDataList, Cell cell,
+ Head head,
Integer relativeRowIndex, Boolean isHead) {
boolean needSetWidth = isHead || !CollectionUtils.isEmpty(cellDataList);
if (!needSetWidth) {
@@ -52,11 +54,11 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty
}
}
- private Integer dataLength(List> cellDataList, Cell cell, Boolean isHead) {
+ private Integer dataLength(List> cellDataList, Cell cell, Boolean isHead) {
if (isHead) {
return cell.getStringCellValue().getBytes().length;
}
- CellData cellData = cellDataList.get(0);
+ WriteCellData> cellData = cellDataList.get(0);
CellDataTypeEnum type = cellData.getType();
if (type == null) {
return -1;
diff --git a/src/main/java/com/alibaba/excel/write/style/row/AbstractRowHeightStyleStrategy.java b/src/main/java/com/alibaba/excel/write/style/row/AbstractRowHeightStyleStrategy.java
index 303c8180..6c908eb6 100644
--- a/src/main/java/com/alibaba/excel/write/style/row/AbstractRowHeightStyleStrategy.java
+++ b/src/main/java/com/alibaba/excel/write/style/row/AbstractRowHeightStyleStrategy.java
@@ -1,46 +1,25 @@
package com.alibaba.excel.write.style.row;
-import org.apache.poi.ss.usermodel.Row;
-
-import com.alibaba.excel.event.NotRepeatExecutor;
import com.alibaba.excel.write.handler.RowWriteHandler;
-import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
-import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
+import com.alibaba.excel.write.handler.context.RowWriteHandlerContext;
+
+import org.apache.poi.ss.usermodel.Row;
/**
* Set the row height strategy
*
* @author Jiaju Zhuang
*/
-public abstract class AbstractRowHeightStyleStrategy implements RowWriteHandler, NotRepeatExecutor {
-
- @Override
- public String uniqueValue() {
- return "RowHighStyleStrategy";
- }
-
- @Override
- public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer rowIndex,
- Integer relativeRowIndex, Boolean isHead) {
-
- }
-
- @Override
- public void afterRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
- Integer relativeRowIndex, Boolean isHead) {
-
- }
-
+public abstract class AbstractRowHeightStyleStrategy implements RowWriteHandler {
@Override
- public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
- Integer relativeRowIndex, Boolean isHead) {
- if (isHead == null) {
+ public void afterRowDispose(RowWriteHandlerContext context) {
+ if (context.getHead() == null) {
return;
}
- if (isHead) {
- setHeadColumnHeight(row, relativeRowIndex);
+ if (context.getHead()) {
+ setHeadColumnHeight(context.getRow(), context.getRelativeRowIndex());
} else {
- setContentColumnHeight(row, relativeRowIndex);
+ setContentColumnHeight(context.getRow(), context.getRelativeRowIndex());
}
}
diff --git a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataListener.java b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataListener.java
index 3108f97a..6971c076 100644
--- a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataListener.java
+++ b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataListener.java
@@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.core.celldata;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Assert;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
+import org.junit.Assert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* @author Jiaju Zhuang
*/
@@ -31,7 +31,7 @@ public class CellDataDataListener extends AnalysisEventListener {
Assert.assertEquals(cellDataData.getDate().getStringValue(), "2020年01月01日");
Assert.assertEquals((long)cellDataData.getInteger1().getData(), 2L);
Assert.assertEquals((long)cellDataData.getInteger2(), 2L);
- Assert.assertEquals(cellDataData.getFormulaValue().getFormulaValue(), "B2+C2");
+ Assert.assertEquals(cellDataData.getFormulaValue().getFormulaData().getFormulaValue(), "B2+C2");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
}
}
diff --git a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java
index fdedb1ef..61d2809c 100644
--- a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java
+++ b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java
@@ -5,19 +5,20 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.CellData;
+import com.alibaba.excel.metadata.data.FormulaData;
+import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.util.DateUtils;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
/**
- *
* @author Jiaju Zhuang
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -50,15 +51,16 @@ public class CellDataDataTest {
private List data() throws Exception {
List list = new ArrayList();
CellDataData cellDataData = new CellDataData();
- cellDataData.setDate(new CellData<>(DateUtils.parseDate("2020-01-01 01:01:01")));
+ cellDataData.setDate(new WriteCellData<>(DateUtils.parseDate("2020-01-01 01:01:01")));
CellData integer1 = new CellData();
integer1.setType(CellDataTypeEnum.NUMBER);
integer1.setNumberValue(BigDecimal.valueOf(2L));
cellDataData.setInteger1(integer1);
cellDataData.setInteger2(2);
- CellData formulaValue = new CellData();
- formulaValue.setFormula(Boolean.TRUE);
- formulaValue.setFormulaValue("B2+C2");
+ WriteCellData> formulaValue = new WriteCellData<>();
+ FormulaData formulaData = new FormulaData();
+ formulaValue.setFormulaData(formulaData);
+ formulaData.setFormulaValue("B2+C2");
cellDataData.setFormulaValue(formulaValue);
list.add(cellDataData);
return list;
diff --git a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityData.java b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityData.java
deleted file mode 100644
index c0d9d89f..00000000
--- a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityData.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.alibaba.easyexcel.test.core.compatibility;
-
-import com.alibaba.excel.annotation.ExcelProperty;
-
-import lombok.Data;
-
-/**
- * @author Jiaju Zhuang
- */
-@Data
-public class CompatibilityData extends BaseRowModel {
- @ExcelProperty("字符串标题0")
- private String string0;
- @ExcelProperty("字符串标题1")
- private String string1;
-}
diff --git a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataListener.java b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataListener.java
deleted file mode 100644
index 29774ba9..00000000
--- a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataListener.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.alibaba.easyexcel.test.core.compatibility;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Assert;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.alibaba.easyexcel.test.core.annotation.AnnotationDataListener;
-import com.alibaba.excel.context.AnalysisContext;
-import com.alibaba.excel.event.AnalysisEventListener;
-import com.alibaba.fastjson.JSON;
-
-/**
- * @author Jiaju Zhuang
- */
-public class CompatibilityDataListener extends AnalysisEventListener> {
- private static final Logger LOGGER = LoggerFactory.getLogger(AnnotationDataListener.class);
- List> list = new ArrayList>();
-
- @Override
- public void invoke(List data, AnalysisContext context) {
- list.add(data);
- }
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- Assert.assertEquals(list.size(), 10);
- List data = list.get(0);
- Assert.assertEquals(data.get(0), "字符串00");
- LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
- }
-}
diff --git a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataTest.java
deleted file mode 100644
index 87edf636..00000000
--- a/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityDataTest.java
+++ /dev/null
@@ -1,157 +0,0 @@
-package com.alibaba.easyexcel.test.core.compatibility;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.alibaba.easyexcel.test.util.TestFileUtil;
-import com.alibaba.excel.EasyExcel;
-import com.alibaba.excel.ExcelReader;
-import com.alibaba.excel.ExcelWriter;
-import com.alibaba.excel.metadata.Font;
-import com.alibaba.excel.parameter.AnalysisParam;
-import com.alibaba.excel.parameter.GenerateParam;
-
-/**
- *
- * @author Jiaju Zhuang
- */
-public class CompatibilityDataTest {
-
- private static File file07;
- private static File file03;
-
- @BeforeClass
- public static void init() {
- file07 = TestFileUtil.createNewFile("compatibility07.xlsx");
- file03 = TestFileUtil.createNewFile("compatibility03.xls");
- }
-
- @Test
- public void t01ReadAndWrite07() throws Exception {
- readAndWrite(file07);
- }
-
- @Test
- public void t02ReadAndWrite03() throws Exception {
- readAndWrite(file03);
- }
-
- private void readAndWrite(File file) throws Exception {
- OutputStream out = new FileOutputStream(file);
- GenerateParam generateParam = new GenerateParam("", null, out);
- generateParam.setSheetName("");
- generateParam.setOutputStream(out);
- generateParam.setClazz(null);
- ExcelWriter writer = new ExcelWriter(generateParam);
- // sheet1 width,string head,string data
- Sheet sheet1 = new Sheet(1, 3);
- sheet1.setSheetName("第一个sheet");
- Map columnWidth = new HashMap();
- columnWidth.put(0, 10000);
- columnWidth.put(1, 50000);
- sheet1.setColumnWidthMap(columnWidth);
- sheet1.setHead(head());
- writer.write1(listData(), sheet1);
-
- // sheet2 style,class head
- Sheet sheet2 = new Sheet(2, 3, CompatibilityData.class, "第二个sheet", null);
- sheet2.setStartRow(5);
- sheet2.setTableStyle(style());
- writer.write(data(), sheet2);
- writer.merge(8, 8, 0, 1);
-
- // sheet3 table
- Sheet sheet3 = new Sheet(3, 0);
- sheet3.setSheetName("第三个sheet");
-
- Table table1 = new Table(1);
- table1.setHead(head());
- writer.write1(listData(), sheet3, table1);
-
- Table table2 = new Table(2);
- table2.setClazz(CompatibilityData.class);
- writer.write(data(), sheet3, table2);
-
- writer.finish();
- out.close();
-
- InputStream inputStream = new FileInputStream(file);
- List