embulk-parser-poi_excel 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -0
  3. data/build.gradle +1 -1
  4. data/classpath/embulk-parser-poi_excel-0.1.2.jar +0 -0
  5. data/src/main/java/org/embulk/parser/poi_excel/PoiExcelColumnValueType.java +2 -3
  6. data/src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java +34 -50
  7. data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java +300 -0
  8. data/src/main/java/org/embulk/parser/poi_excel/{visitor → bean}/PoiExcelColumnIndex.java +44 -27
  9. data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelSheetBean.java +102 -0
  10. data/src/main/java/org/embulk/parser/poi_excel/visitor/AbstractPoiExcelCellAttributeVisitor.java +15 -13
  11. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellCommentVisitor.java +2 -2
  12. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellFontVisitor.java +2 -2
  13. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellStyleVisitor.java +2 -2
  14. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java +52 -31
  15. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelClientAnchorVisitor.java +2 -2
  16. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java +30 -29
  17. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorFactory.java +4 -0
  18. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorValue.java +10 -21
  19. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/BooleanCellVisitor.java +5 -0
  20. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/CellVisitor.java +30 -0
  21. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/DoubleCellVisitor.java +13 -1
  22. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/LongCellVisitor.java +13 -1
  23. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/StringCellVisitor.java +5 -0
  24. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/TimestampCellVisitor.java +30 -8
  25. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin.java +0 -1
  26. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellError.java +184 -0
  27. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_columnNumber.java +3 -5
  28. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_constant.java +54 -0
  29. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_convertError.java +113 -0
  30. data/src/test/resources/org/embulk/parser/poi_excel/test1.xls +0 -0
  31. metadata +9 -4
  32. data/classpath/embulk-parser-poi_excel-0.1.1.jar +0 -0
@@ -1,4 +1,4 @@
1
- package org.embulk.parser.poi_excel.visitor;
1
+ package org.embulk.parser.poi_excel.bean;
2
2
 
3
3
  import java.text.MessageFormat;
4
4
  import java.util.LinkedHashMap;
@@ -7,7 +7,6 @@ import java.util.Map;
7
7
 
8
8
  import org.apache.poi.ss.util.CellReference;
9
9
  import org.embulk.parser.poi_excel.PoiExcelColumnValueType;
10
- import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
11
10
  import org.embulk.parser.poi_excel.PoiExcelParserPlugin.PluginTask;
12
11
  import org.embulk.spi.Column;
13
12
  import org.embulk.spi.Exec;
@@ -21,48 +20,66 @@ public class PoiExcelColumnIndex {
21
20
 
22
21
  protected final Map<String, Integer> indexMap = new LinkedHashMap<>();
23
22
 
24
- public void initializeColumnIndex(PluginTask task, List<ColumnOptionTask> columnOptions) {
23
+ public void initializeColumnIndex(PluginTask task, List<PoiExcelColumnBean> beanList) {
25
24
  int index = -1;
26
25
  indexMap.clear();
27
26
 
28
27
  Schema schema = task.getColumns().toSchema();
29
28
  for (Column column : schema.getColumns()) {
30
- ColumnOptionTask option = columnOptions.get(column.getIndex());
31
-
32
- String type = option.getValueType().trim();
33
- int n = type.indexOf('.');
34
- if (n >= 0) {
35
- String suffix = type.substring(n + 1).trim();
36
- option.setValueTypeSuffix(suffix);
37
- type = type.substring(0, n).trim();
38
- }
39
-
40
- PoiExcelColumnValueType valueType;
41
- try {
42
- valueType = PoiExcelColumnValueType.valueOf(type.toUpperCase());
43
- } catch (Exception e) {
44
- throw new RuntimeException(MessageFormat.format("illegal value_type={0}", type), e);
45
- }
46
- option.setValueTypeEnum(valueType);
29
+ PoiExcelColumnBean bean = beanList.get(column.getIndex());
30
+ PoiExcelColumnValueType valueType = bean.getValueType();
47
31
 
48
32
  if (valueType.useCell()) {
49
- index = resolveColumnIndex(column, option, index, valueType);
33
+ index = resolveColumnIndex(column, bean, index, valueType);
50
34
  if (index < 0) {
51
35
  index = 0;
52
36
  }
53
- log.info("column.name={} <- cell column={}, value_type={}", column.getName(),
54
- CellReference.convertNumToColString(index), valueType);
55
- option.setColumnIndex(index);
37
+ bean.setColumnIndex(index);
56
38
  indexMap.put(column.getName(), index);
39
+ if (log.isInfoEnabled()) {
40
+ String c = CellReference.convertNumToColString(index);
41
+ switch (valueType) {
42
+ default:
43
+ String suffix = bean.getValueTypeSuffix();
44
+ if (suffix != null) {
45
+ log.info("column.name={} <- cell_column={}, value_type={}, value=[{}]", column.getName(),
46
+ c, valueType, suffix);
47
+ } else {
48
+ log.info("column.name={} <- cell_column={}, value_type={}, value={}", column.getName(), c,
49
+ valueType, suffix);
50
+ }
51
+ break;
52
+ case CELL_VALUE:
53
+ case CELL_FORMULA:
54
+ case COLUMN_NUMBER:
55
+ log.info("column.name={} <- cell_column={}, value_type={}", column.getName(), c, valueType);
56
+ break;
57
+ }
58
+ }
57
59
  } else {
58
- log.info("column.name={} <- value_type={}", column.getName(), valueType);
60
+ if (log.isInfoEnabled()) {
61
+ switch (valueType) {
62
+ default:
63
+ String suffix = bean.getValueTypeSuffix();
64
+ if (suffix != null) {
65
+ log.info("column.name={} <- value_type={}, value=[{}]", column.getName(), valueType, suffix);
66
+ } else {
67
+ log.info("column.name={} <- value_type={}, value={}", column.getName(), valueType, suffix);
68
+ }
69
+ break;
70
+ case SHEET_NAME:
71
+ case ROW_NUMBER:
72
+ log.info("column.name={} <- value_type={}", column.getName(), valueType);
73
+ break;
74
+ }
75
+ }
59
76
  }
60
77
  }
61
78
  }
62
79
 
63
- protected int resolveColumnIndex(Column column, ColumnOptionTask option, int index,
80
+ protected int resolveColumnIndex(Column column, PoiExcelColumnBean bean, int index,
64
81
  PoiExcelColumnValueType valueType) {
65
- Optional<String> numberOption = option.getColumnNumber();
82
+ Optional<String> numberOption = bean.getColumnNumber();
66
83
  if (numberOption.isPresent()) {
67
84
  String columnNumber = numberOption.get();
68
85
  if (columnNumber.length() >= 1) {
@@ -0,0 +1,102 @@
1
+ package org.embulk.parser.poi_excel.bean;
2
+
3
+ import java.util.ArrayList;
4
+ import java.util.HashMap;
5
+ import java.util.List;
6
+ import java.util.Map;
7
+ import java.util.Map.Entry;
8
+
9
+ import org.apache.poi.ss.usermodel.Sheet;
10
+ import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
11
+ import org.embulk.parser.poi_excel.PoiExcelParserPlugin.PluginTask;
12
+ import org.embulk.parser.poi_excel.PoiExcelParserPlugin.SheetOptionTask;
13
+ import org.embulk.spi.Column;
14
+ import org.embulk.spi.ColumnConfig;
15
+ import org.embulk.spi.Schema;
16
+
17
+ import com.google.common.base.Optional;
18
+
19
+ public class PoiExcelSheetBean {
20
+
21
+ protected final Sheet sheet;
22
+
23
+ private final List<SheetOptionTask> sheetTaskList = new ArrayList<>(2);
24
+
25
+ private final List<PoiExcelColumnBean> columnBeanList = new ArrayList<>();
26
+
27
+ public PoiExcelSheetBean(PluginTask task, Schema schema, Sheet sheet) {
28
+ this.sheet = sheet;
29
+
30
+ initializeSheetTask(task);
31
+ initializeColumnBean(task, schema);
32
+ }
33
+
34
+ private void initializeSheetTask(PluginTask task) {
35
+ String name = sheet.getSheetName();
36
+ Map<String, SheetOptionTask> map = task.getSheetOptions();
37
+ SheetOptionTask s = map.get(name);
38
+ if (s != null) {
39
+ sheetTaskList.add(s);
40
+ } else {
41
+ loop: for (Entry<String, SheetOptionTask> entry : map.entrySet()) {
42
+ String[] ss = entry.getKey().split("/");
43
+ for (String key : ss) {
44
+ if (key.trim().equalsIgnoreCase(name)) {
45
+ sheetTaskList.add(entry.getValue());
46
+ break loop;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ sheetTaskList.add(task);
52
+ }
53
+
54
+ private void initializeColumnBean(PluginTask task, Schema schema) {
55
+ List<ColumnConfig> list = task.getColumns().getColumns();
56
+
57
+ Map<String, ColumnOptionTask> map = new HashMap<>();
58
+ List<SheetOptionTask> slist = getSheetOption();
59
+ if (slist.size() >= 2) {
60
+ SheetOptionTask s = slist.get(0);
61
+ for (ColumnConfig c : s.getColumns().getColumns()) {
62
+ String name = c.getName();
63
+ ColumnOptionTask t = c.getOption().loadConfig(ColumnOptionTask.class);
64
+ map.put(name, t);
65
+ }
66
+ }
67
+
68
+ for (Column column : schema.getColumns()) {
69
+ String name = column.getName();
70
+ ColumnConfig c = list.get(column.getIndex());
71
+ ColumnOptionTask t = c.getOption().loadConfig(ColumnOptionTask.class);
72
+ PoiExcelColumnBean bean = new PoiExcelColumnBean(this, column, t, map.get(name));
73
+ columnBeanList.add(bean);
74
+ }
75
+
76
+ new PoiExcelColumnIndex().initializeColumnIndex(task, columnBeanList);
77
+ }
78
+
79
+ public final List<SheetOptionTask> getSheetOption() {
80
+ return sheetTaskList;
81
+ }
82
+
83
+ public int getSkipHeaderLines() {
84
+ List<SheetOptionTask> list = getSheetOption();
85
+ for (SheetOptionTask sheetTask : list) {
86
+ Optional<Integer> value = sheetTask.getSkipHeaderLines();
87
+ if (value.isPresent()) {
88
+ return value.get();
89
+ }
90
+ }
91
+ return 0;
92
+ }
93
+
94
+ public final List<PoiExcelColumnBean> getColumnBeans() {
95
+ return columnBeanList;
96
+ }
97
+
98
+ public final PoiExcelColumnBean getColumnBean(Column column) {
99
+ List<PoiExcelColumnBean> list = getColumnBeans();
100
+ return list.get(column.getIndex());
101
+ }
102
+ }
@@ -10,7 +10,7 @@ import java.util.TreeSet;
10
10
 
11
11
  import org.apache.poi.ss.usermodel.Cell;
12
12
  import org.apache.poi.ss.usermodel.Color;
13
- import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
13
+ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
14
14
  import org.embulk.parser.poi_excel.visitor.embulk.CellVisitor;
15
15
  import org.embulk.spi.Column;
16
16
  import org.embulk.spi.PageBuilder;
@@ -18,7 +18,6 @@ import org.embulk.spi.type.StringType;
18
18
 
19
19
  import com.fasterxml.jackson.core.JsonProcessingException;
20
20
  import com.fasterxml.jackson.databind.ObjectMapper;
21
- import com.google.common.base.Optional;
22
21
 
23
22
  public abstract class AbstractPoiExcelCellAttributeVisitor<A> {
24
23
 
@@ -30,24 +29,26 @@ public abstract class AbstractPoiExcelCellAttributeVisitor<A> {
30
29
  this.pageBuilder = visitorValue.getPageBuilder();
31
30
  }
32
31
 
33
- public void visit(Column column, ColumnOptionTask option, Cell cell, CellVisitor visitor) {
34
- A source = getAttributeSource(column, option, cell);
32
+ public void visit(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
33
+ A source = getAttributeSource(bean, cell);
35
34
  if (source == null) {
35
+ Column column = bean.getColumn();
36
36
  pageBuilder.setNull(column);
37
37
  return;
38
38
  }
39
39
 
40
- String suffix = option.getValueTypeSuffix();
40
+ String suffix = bean.getValueTypeSuffix();
41
41
  if (suffix != null) {
42
- visitKey(column, option, suffix, cell, source, visitor);
42
+ visitKey(bean, suffix, cell, source, visitor);
43
43
  } else {
44
- visitJson(column, option, cell, source, visitor);
44
+ visitJson(bean, cell, source, visitor);
45
45
  }
46
46
  }
47
47
 
48
- protected abstract A getAttributeSource(Column column, ColumnOptionTask option, Cell cell);
48
+ protected abstract A getAttributeSource(PoiExcelColumnBean bean, Cell cell);
49
49
 
50
- private void visitKey(Column column, ColumnOptionTask option, String key, Cell cell, A source, CellVisitor visitor) {
50
+ private void visitKey(PoiExcelColumnBean bean, String key, Cell cell, A source, CellVisitor visitor) {
51
+ Column column = bean.getColumn();
51
52
  Object value = getAttributeValue(column, cell, source, key);
52
53
  if (value == null) {
53
54
  pageBuilder.setNull(column);
@@ -67,12 +68,13 @@ public abstract class AbstractPoiExcelCellAttributeVisitor<A> {
67
68
  }
68
69
  }
69
70
 
70
- private void visitJson(Column column, ColumnOptionTask option, Cell cell, A source, CellVisitor visitor) {
71
+ private void visitJson(PoiExcelColumnBean bean, Cell cell, A source, CellVisitor visitor) {
72
+ Column column = bean.getColumn();
73
+
71
74
  Map<String, Object> result;
72
75
 
73
- Optional<List<String>> nameOption = option.getAttributeName();
74
- if (nameOption.isPresent()) {
75
- List<String> list = nameOption.get();
76
+ List<String> list = bean.getAttributeName();
77
+ if (!list.isEmpty()) {
76
78
  result = getSpecifiedValues(column, cell, source, list);
77
79
  } else {
78
80
  result = getAllValues(column, cell, source);
@@ -8,7 +8,7 @@ import org.apache.poi.ss.usermodel.Cell;
8
8
  import org.apache.poi.ss.usermodel.ClientAnchor;
9
9
  import org.apache.poi.ss.usermodel.Comment;
10
10
  import org.apache.poi.ss.usermodel.RichTextString;
11
- import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
11
+ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
12
12
  import org.embulk.spi.Column;
13
13
 
14
14
  public class PoiExcelCellCommentVisitor extends AbstractPoiExcelCellAttributeVisitor<Comment> {
@@ -18,7 +18,7 @@ public class PoiExcelCellCommentVisitor extends AbstractPoiExcelCellAttributeVis
18
18
  }
19
19
 
20
20
  @Override
21
- protected Comment getAttributeSource(Column column, ColumnOptionTask option, Cell cell) {
21
+ protected Comment getAttributeSource(PoiExcelColumnBean bean, Cell cell) {
22
22
  return cell.getCellComment();
23
23
  }
24
24
 
@@ -9,7 +9,7 @@ import org.apache.poi.ss.usermodel.CellStyle;
9
9
  import org.apache.poi.ss.usermodel.Font;
10
10
  import org.apache.poi.ss.usermodel.Workbook;
11
11
  import org.apache.poi.xssf.usermodel.XSSFFont;
12
- import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
12
+ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
13
13
  import org.embulk.spi.Column;
14
14
 
15
15
  public class PoiExcelCellFontVisitor extends AbstractPoiExcelCellAttributeVisitor<Font> {
@@ -19,7 +19,7 @@ public class PoiExcelCellFontVisitor extends AbstractPoiExcelCellAttributeVisito
19
19
  }
20
20
 
21
21
  @Override
22
- protected Font getAttributeSource(Column column, ColumnOptionTask option, Cell cell) {
22
+ protected Font getAttributeSource(PoiExcelColumnBean bean, Cell cell) {
23
23
  CellStyle style = cell.getCellStyle();
24
24
  short index = style.getFontIndex();
25
25
  Workbook book = visitorValue.getSheet().getWorkbook();
@@ -8,7 +8,7 @@ import org.apache.poi.ss.usermodel.Cell;
8
8
  import org.apache.poi.ss.usermodel.CellStyle;
9
9
  import org.apache.poi.ss.usermodel.Workbook;
10
10
  import org.apache.poi.xssf.usermodel.XSSFCellStyle;
11
- import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
11
+ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
12
12
  import org.embulk.spi.Column;
13
13
  import org.embulk.spi.type.StringType;
14
14
 
@@ -19,7 +19,7 @@ public class PoiExcelCellStyleVisitor extends AbstractPoiExcelCellAttributeVisit
19
19
  }
20
20
 
21
21
  @Override
22
- protected CellStyle getAttributeSource(Column column, ColumnOptionTask option, Cell cell) {
22
+ protected CellStyle getAttributeSource(PoiExcelColumnBean bean, Cell cell) {
23
23
  return cell.getCellStyle();
24
24
  }
25
25
 
@@ -6,23 +6,22 @@ import java.util.List;
6
6
  import org.apache.poi.ss.usermodel.Cell;
7
7
  import org.apache.poi.ss.usermodel.CellValue;
8
8
  import org.apache.poi.ss.usermodel.CreationHelper;
9
+ import org.apache.poi.ss.usermodel.FormulaError;
9
10
  import org.apache.poi.ss.usermodel.FormulaEvaluator;
10
11
  import org.apache.poi.ss.usermodel.Row;
11
12
  import org.apache.poi.ss.usermodel.Sheet;
12
13
  import org.apache.poi.ss.usermodel.Workbook;
13
14
  import org.apache.poi.ss.util.CellRangeAddress;
14
15
  import org.embulk.parser.poi_excel.PoiExcelColumnValueType;
15
- import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
16
16
  import org.embulk.parser.poi_excel.PoiExcelParserPlugin.FormulaReplaceTask;
17
- import org.embulk.parser.poi_excel.PoiExcelParserPlugin.PluginTask;
17
+ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
18
+ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean.ErrorStrategy;
18
19
  import org.embulk.parser.poi_excel.visitor.embulk.CellVisitor;
19
20
  import org.embulk.spi.Column;
20
21
  import org.embulk.spi.Exec;
21
22
  import org.embulk.spi.PageBuilder;
22
23
  import org.slf4j.Logger;
23
24
 
24
- import com.google.common.base.Optional;
25
-
26
25
  public class PoiExcelCellValueVisitor {
27
26
  private final Logger log = Exec.getLogger(getClass());
28
27
 
@@ -34,9 +33,11 @@ public class PoiExcelCellValueVisitor {
34
33
  this.pageBuilder = visitorValue.getPageBuilder();
35
34
  }
36
35
 
37
- public void visitCellValue(Column column, ColumnOptionTask option, Cell cell, CellVisitor visitor) {
36
+ public void visitCellValue(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
38
37
  assert cell != null;
39
38
 
39
+ Column column = bean.getColumn();
40
+
40
41
  int cellType = cell.getCellType();
41
42
  switch (cellType) {
42
43
  case Cell.CELL_TYPE_NUMERIC:
@@ -46,32 +47,33 @@ public class PoiExcelCellValueVisitor {
46
47
  visitor.visitCellValueString(column, cell, cell.getStringCellValue());
47
48
  return;
48
49
  case Cell.CELL_TYPE_FORMULA:
49
- PoiExcelColumnValueType valueType = option.getValueTypeEnum();
50
+ PoiExcelColumnValueType valueType = bean.getValueType();
50
51
  if (valueType == PoiExcelColumnValueType.CELL_FORMULA) {
51
52
  visitor.visitCellFormula(column, cell);
52
53
  } else {
53
- visitCellValueFormula(column, option, cell, visitor);
54
+ visitCellValueFormula(bean, cell, visitor);
54
55
  }
55
56
  return;
56
57
  case Cell.CELL_TYPE_BLANK:
57
- visitCellValueBlank(column, option, cell, visitor);
58
+ visitCellValueBlank(bean, cell, visitor);
58
59
  return;
59
60
  case Cell.CELL_TYPE_BOOLEAN:
60
61
  visitor.visitCellValueBoolean(column, cell, cell.getBooleanCellValue());
61
62
  return;
62
63
  case Cell.CELL_TYPE_ERROR:
63
- visitCellValueError(column, option, cell, cell.getErrorCellValue(), visitor);
64
+ visitCellValueError(bean, cell, cell.getErrorCellValue(), visitor);
64
65
  return;
65
66
  default:
66
67
  throw new IllegalStateException(MessageFormat.format("unsupported POI cellType={0}", cellType));
67
68
  }
68
69
  }
69
70
 
70
- protected void visitCellValueBlank(Column column, ColumnOptionTask option, Cell cell, CellVisitor visitor) {
71
+ protected void visitCellValueBlank(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
71
72
  assert cell.getCellType() == Cell.CELL_TYPE_BLANK;
72
73
 
73
- PluginTask task = visitorValue.getPluginTask();
74
- boolean search = option.getSearchMergedCell().or(task.getSearchMergedCell());
74
+ Column column = bean.getColumn();
75
+
76
+ boolean search = bean.getSearchMergedCell();
75
77
  if (!search) {
76
78
  visitor.visitCellValueBlank(column, cell);
77
79
  return;
@@ -96,7 +98,7 @@ public class PoiExcelCellValueVisitor {
96
98
  return;
97
99
  }
98
100
 
99
- visitCellValue(column, option, firstCell, visitor);
101
+ visitCellValue(bean, firstCell, visitor);
100
102
  return;
101
103
  }
102
104
  }
@@ -104,19 +106,16 @@ public class PoiExcelCellValueVisitor {
104
106
  visitor.visitCellValueBlank(column, cell);
105
107
  }
106
108
 
107
- protected void visitCellValueFormula(Column column, ColumnOptionTask option, Cell cell, CellVisitor visitor) {
109
+ protected void visitCellValueFormula(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
108
110
  assert cell.getCellType() == Cell.CELL_TYPE_FORMULA;
109
111
 
110
- Optional<List<FormulaReplaceTask>> replaceOption = option.getFormulaReplace();
111
- if (!replaceOption.isPresent()) {
112
- PluginTask task = visitorValue.getPluginTask();
113
- replaceOption = task.getFormulaReplace();
114
- }
115
- if (replaceOption.isPresent()) {
112
+ Column column = bean.getColumn();
113
+
114
+ List<FormulaReplaceTask> list = bean.getFormulaReplace();
115
+ if (!list.isEmpty()) {
116
116
  String formula = cell.getCellFormula();
117
117
  String old = formula;
118
118
 
119
- List<FormulaReplaceTask> list = replaceOption.get();
120
119
  for (FormulaReplaceTask replace : list) {
121
120
  String regex = replace.getRegex();
122
121
  String replacement = replace.getTo();
@@ -143,10 +142,17 @@ public class PoiExcelCellValueVisitor {
143
142
  FormulaEvaluator evaluator = helper.createFormulaEvaluator();
144
143
  cellValue = evaluator.evaluate(cell);
145
144
  } catch (Exception e) {
146
- PluginTask task = visitorValue.getPluginTask();
147
- boolean setNull = option.getFormulaErrorNull().or(task.getFormulaErrorNull());
148
- if (setNull) {
149
- pageBuilder.setNull(column);
145
+ ErrorStrategy strategy = bean.getEvaluateErrorStrategy();
146
+ switch (strategy.getStrategy()) {
147
+ default:
148
+ break;
149
+ case CONSTANT:
150
+ String value = strategy.getValue();
151
+ if (value == null) {
152
+ pageBuilder.setNull(column);
153
+ } else {
154
+ visitor.visitCellValueString(column, cell, value);
155
+ }
150
156
  return;
151
157
  }
152
158
 
@@ -168,7 +174,7 @@ public class PoiExcelCellValueVisitor {
168
174
  visitor.visitCellValueBoolean(column, cellValue, cellValue.getBooleanValue());
169
175
  return;
170
176
  case Cell.CELL_TYPE_ERROR:
171
- visitCellValueError(column, option, cellValue, cellValue.getErrorValue(), visitor);
177
+ visitCellValueError(bean, cellValue, cellValue.getErrorValue(), visitor);
172
178
  return;
173
179
  case Cell.CELL_TYPE_FORMULA:
174
180
  default:
@@ -176,13 +182,28 @@ public class PoiExcelCellValueVisitor {
176
182
  }
177
183
  }
178
184
 
179
- protected void visitCellValueError(Column column, ColumnOptionTask option, Object cell, int errorCode,
180
- CellVisitor visitor) {
181
- PluginTask task = visitorValue.getPluginTask();
182
- boolean setNull = option.getCellErrorNull().or(task.getCellErrorNull());
183
- if (setNull) {
185
+ protected void visitCellValueError(PoiExcelColumnBean bean, Object cell, int errorCode, CellVisitor visitor) {
186
+ Column column = bean.getColumn();
187
+
188
+ ErrorStrategy strategy = bean.getCellErrorStrategy();
189
+ switch (strategy.getStrategy()) {
190
+ default:
184
191
  pageBuilder.setNull(column);
185
192
  return;
193
+ case CONSTANT:
194
+ String value = strategy.getValue();
195
+ if (value == null) {
196
+ pageBuilder.setNull(column);
197
+ } else {
198
+ visitor.visitCellValueString(column, cell, value);
199
+ }
200
+ return;
201
+ case ERROR_CODE:
202
+ break;
203
+ case EXCEPTION:
204
+ FormulaError error = FormulaError.forInt((byte) errorCode);
205
+ throw new RuntimeException(MessageFormat.format("encount cell error. error_code={0}({1})", errorCode,
206
+ error.getString()));
186
207
  }
187
208
 
188
209
  visitor.visitCellValueError(column, cell, errorCode);