extraReadSet;
/**
* The default is all excel objects.Default is true.
*
@@ -212,4 +220,12 @@ public class ReadWorkbook extends ReadBasicParameter {
public void setUseDefaultListener(Boolean useDefaultListener) {
this.useDefaultListener = useDefaultListener;
}
+
+ public Set getExtraReadSet() {
+ return extraReadSet;
+ }
+
+ public void setExtraReadSet(Set extraReadSet) {
+ this.extraReadSet = extraReadSet;
+ }
}
diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadRowHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadRowHolder.java
index 24079f7..9916015 100644
--- a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadRowHolder.java
+++ b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadRowHolder.java
@@ -3,10 +3,6 @@ package com.alibaba.excel.read.metadata.holder;
import com.alibaba.excel.enums.HolderEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.Holder;
-import com.alibaba.excel.util.CollectionUtils;
-
-import java.util.HashMap;
-import java.util.Map;
/**
* sheet holder
@@ -28,34 +24,6 @@ public class ReadRowHolder implements Holder {
*/
private GlobalConfiguration globalConfiguration;
- /**
- * Return row comments
- * key: col index
- * value: comments
- */
- private Map rowComments;
-
- public Map getRowComments() {
- return rowComments;
- }
-
- public void setRowComments(Map rowComments) {
- this.rowComments = rowComments;
- }
-
- public void addComments(Integer index, String comments) {
- this.rowComments = this.rowComments == null ? new HashMap(8) : this.rowComments;
- this.rowComments.put(index, comments);
- }
-
- public String getComments(Integer index) {
- if (CollectionUtils.isEmpty(rowComments)) {
- return null;
- } else {
- return rowComments.get(index);
- }
- }
-
public ReadRowHolder(Integer rowIndex, GlobalConfiguration globalConfiguration) {
this.rowIndex = rowIndex;
this.globalConfiguration = globalConfiguration;
diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
index cbda93f..c03edf2 100644
--- a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
+++ b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
@@ -16,6 +16,7 @@ import com.alibaba.excel.cache.selector.EternalReadCacheSelector;
import com.alibaba.excel.cache.selector.ReadCacheSelector;
import com.alibaba.excel.cache.selector.SimpleReadCacheSelector;
import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.enums.ExtraReadEnum;
import com.alibaba.excel.enums.HolderEnum;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelAnalysisException;
@@ -96,6 +97,12 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
* @see SAXParserFactory#newInstance(String, ClassLoader)
*/
private String xlsxSAXParserFactoryName;
+ /**
+ * Read some additional fields. None are read by default.
+ *
+ * @see ExtraReadEnum
+ */
+ private Set extraReadSet;
/**
* The default is all excel objects.if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a
* field. if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed.
@@ -155,9 +162,7 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
this.autoCloseStream = readWorkbook.getAutoCloseStream();
}
- // The type of excel is read according to the judgment.Because encrypted XLSX needs to be specified as XLS to
- // properly parse.
- this.excelType = ExcelTypeEnum.valueOf(file, inputStream, readWorkbook.getExcelType());
+ this.excelType = readWorkbook.getExcelType();
if (ExcelTypeEnum.XLS == excelType && getGlobalConfiguration().getUse1904windowing() == null) {
getGlobalConfiguration().setUse1904windowing(Boolean.FALSE);
@@ -186,6 +191,11 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
this.defaultReturnMap = readWorkbook.getDefaultReturnMap();
}
this.xlsxSAXParserFactoryName = readWorkbook.getXlsxSAXParserFactoryName();
+ if (readWorkbook.getExtraReadSet() == null) {
+ this.extraReadSet = new HashSet();
+ } else {
+ this.extraReadSet = readWorkbook.getExtraReadSet();
+ }
this.hasReadSheet = new HashSet();
this.ignoreRecord03 = Boolean.FALSE;
this.password = readWorkbook.getPassword();
@@ -343,6 +353,14 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
this.xlsxSAXParserFactoryName = xlsxSAXParserFactoryName;
}
+ public Set getExtraReadSet() {
+ return extraReadSet;
+ }
+
+ public void setExtraReadSet(Set extraReadSet) {
+ this.extraReadSet = extraReadSet;
+ }
+
@Override
public HolderEnum holderType() {
return HolderEnum.WORKBOOK;
diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/read/DemoCellCommentsListener.java b/src/test/java/com/alibaba/easyexcel/test/demo/read/DemoCellCommentsListener.java
index 733005c..e7d8def 100644
--- a/src/test/java/com/alibaba/easyexcel/test/demo/read/DemoCellCommentsListener.java
+++ b/src/test/java/com/alibaba/easyexcel/test/demo/read/DemoCellCommentsListener.java
@@ -1,16 +1,16 @@
package com.alibaba.easyexcel.test.demo.read;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelDataConvertException;
-import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.fastjson.JSON;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
/**
* 读取单元格的批注
@@ -37,7 +37,7 @@ public class DemoCellCommentsListener extends AnalysisEventListener {
public void onException(Exception exception, AnalysisContext context) {
LOGGER.error("解析失败,但是继续解析下一行:{}", exception.getMessage());
if (exception instanceof ExcelDataConvertException) {
- ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
+ ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception;
LOGGER.error("第{}行,第{}列解析异常", excelDataConvertException.getRowIndex(),
excelDataConvertException.getColumnIndex());
}
@@ -50,15 +50,7 @@ public class DemoCellCommentsListener extends AnalysisEventListener {
* @param context
*/
@Override
- public void invokeHeadMap(Map headMap, AnalysisContext context) {
- Map rowComments = context.readRowHolder().getRowComments();
- LOGGER.info("解析到一条头数据:{}", JSON.toJSONString(headMap));
- if (!CollectionUtils.isEmpty(rowComments)) {
- for (Integer i : rowComments.keySet()) {
- LOGGER.info("解析到头数据低{}列包含批注:{}", i, rowComments.get(i));
- }
- }
- }
+ public void invokeHeadMap(Map headMap, AnalysisContext context) {}
@Override
public void invoke(DemoData data, AnalysisContext context) {
diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/read/CommentTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/read/CommentTest.java
new file mode 100644
index 0000000..bcb1d99
--- /dev/null
+++ b/src/test/java/com/alibaba/easyexcel/test/temp/read/CommentTest.java
@@ -0,0 +1,34 @@
+package com.alibaba.easyexcel.test.temp.read;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.metadata.CellData;
+import com.alibaba.fastjson.JSON;
+
+/**
+ * 临时测试
+ *
+ * @author Jiaju Zhuang
+ **/
+@Ignore
+public class CommentTest {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CommentTest.class);
+
+ @Test
+ public void comment() throws Exception {
+ File file = new File("D:\\test\\comment.xls");
+ List