diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/handlers/RowTagHandler.java b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/handlers/RowTagHandler.java index 37965254..51c192ca 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/handlers/RowTagHandler.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/handlers/RowTagHandler.java @@ -4,8 +4,10 @@ import java.util.LinkedHashMap; import com.alibaba.excel.constant.ExcelXmlConstants; import com.alibaba.excel.context.xlsx.XlsxReadContext; +import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.enums.RowTypeEnum; import com.alibaba.excel.metadata.Cell; +import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.read.metadata.holder.ReadRowHolder; import com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; import com.alibaba.excel.util.PositionUtils; @@ -41,6 +43,24 @@ public class RowTagHandler extends AbstractXlsxTagHandler { public void endElement(XlsxReadContext xlsxReadContext, String name) { XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); RowTypeEnum rowType = MapUtils.isEmpty(xlsxReadSheetHolder.getCellMap()) ? RowTypeEnum.EMPTY : RowTypeEnum.DATA; + // It's possible that all of the cells in the row are empty + if (rowType == RowTypeEnum.DATA) { + boolean hasData = false; + for (Cell cell : xlsxReadSheetHolder.getCellMap().values()) { + if (!(cell instanceof ReadCellData)) { + hasData = true; + break; + } + ReadCellData readCellData = (ReadCellData)cell; + if (readCellData.getType() != CellDataTypeEnum.EMPTY) { + hasData = true; + break; + } + } + if (!hasData) { + rowType = RowTypeEnum.EMPTY; + } + } xlsxReadContext.readRowHolder(new ReadRowHolder(xlsxReadSheetHolder.getRowIndex(), rowType, xlsxReadSheetHolder.getGlobalConfiguration(), xlsxReadSheetHolder.getCellMap())); xlsxReadContext.analysisEventProcessor().endRow(xlsxReadContext); diff --git a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java index 031e5114..322891da 100644 --- a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java +++ b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java @@ -24,7 +24,7 @@ public class LockTest { @Test public void test() throws Exception { List list = - EasyExcel.read(new FileInputStream("/Users/zhuangjiaju/test/pic.xls")).doReadAllSync(); + EasyExcel.read(new FileInputStream("/Users/zhuangjiaju/Downloads/test.xlsx")).useDefaultListener(false).doReadAllSync(); for (Object data : list) { LOGGER.info("返回数据:{}", JSON.toJSONString(data)); } diff --git a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/write/TempWriteData.java b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/write/TempWriteData.java new file mode 100644 index 00000000..b26ce4b6 --- /dev/null +++ b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/write/TempWriteData.java @@ -0,0 +1,17 @@ +package com.alibaba.easyexcel.test.temp.write; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ContentStyle; +import com.alibaba.excel.annotation.write.style.HeadStyle; +import com.alibaba.excel.enums.BooleanEnum; + +import lombok.Data; + +@Data +public class TempWriteData { + + @ExcelProperty(" 换行\r\n \\ \r\n的名字") + @HeadStyle(wrapped = BooleanEnum.TRUE) + @ContentStyle(wrapped = BooleanEnum.TRUE) + private String name; +} diff --git a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/write/TempWriteTest.java b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/write/TempWriteTest.java new file mode 100644 index 00000000..0f218e45 --- /dev/null +++ b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/write/TempWriteTest.java @@ -0,0 +1,22 @@ +package com.alibaba.easyexcel.test.temp.write; + +import com.alibaba.easyexcel.test.util.TestFileUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.util.ListUtils; + +import org.junit.Ignore; +import org.junit.Test; + +@Ignore +public class TempWriteTest { + + @Test + public void write() { + TempWriteData tempWriteData = new TempWriteData(); + tempWriteData.setName("zs\r\n \\ \r\n t4"); + EasyExcel.write(TestFileUtil.getPath() + "TempWriteTest" + System.currentTimeMillis() + ".xlsx", + TempWriteData.class) + .sheet() + .doWrite(ListUtils.newArrayList(tempWriteData)); + } +} diff --git a/update.md b/update.md index f6831f4b..57cced3c 100644 --- a/update.md +++ b/update.md @@ -1,5 +1,6 @@ # 3.1.0 -* 去除cglib&asm依赖,改成重新拷贝一份 [Issue #2240](https://github.com/alibaba/easyexcel/issues/2240) +* 支持jdk17,去除cglib&asm依赖,改成重新拷贝一份 [Issue #2240](https://github.com/alibaba/easyexcel/issues/2240) +* 有样式没有数据的情况下也算空行 [Issue #2294](https://github.com/alibaba/easyexcel/issues/2294) # 3.0.5 * 修复`ReadListener` 转换异常不抛出的问题