embulk-parser-poi_excel 0.1.4 → 0.1.10

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -5
  3. data/build.gradle +18 -8
  4. data/src/main/java/org/embulk/parser/poi_excel/PoiExcelColumnValueType.java +4 -0
  5. data/src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java +80 -3
  6. data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java +103 -6
  7. data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnIndex.java +74 -37
  8. data/src/main/java/org/embulk/parser/poi_excel/bean/util/PoiExcelCellAddress.java +50 -0
  9. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellFontVisitor.java +0 -6
  10. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellStyleVisitor.java +11 -11
  11. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellTypeVisitor.java +52 -0
  12. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java +106 -37
  13. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelClientAnchorVisitor.java +1 -1
  14. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java +64 -4
  15. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorFactory.java +14 -0
  16. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/BooleanCellVisitor.java +5 -0
  17. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/CellVisitor.java +3 -0
  18. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/DoubleCellVisitor.java +5 -0
  19. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/LongCellVisitor.java +5 -0
  20. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/StringCellVisitor.java +30 -2
  21. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/TimestampCellVisitor.java +5 -0
  22. data/src/main/java/org/embulk/parser/poi_excel/visitor/util/MergedRegionMap.java +51 -0
  23. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin.java +27 -79
  24. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellAddress.java +69 -0
  25. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellComment.java +1 -1
  26. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellError.java +1 -1
  27. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellFont.java +1 -1
  28. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellStyle.java +14 -14
  29. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellType.java +79 -0
  30. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_columnNumber.java +1 -1
  31. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_constant.java +1 -1
  32. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_convertError.java +1 -1
  33. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_formula.java +90 -0
  34. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_mergedCell.java +89 -0
  35. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_sheets.java +35 -1
  36. metadata +26 -18
@@ -8,6 +8,7 @@ import java.util.Map;
8
8
  import org.apache.poi.ss.util.CellReference;
9
9
  import org.embulk.parser.poi_excel.PoiExcelColumnValueType;
10
10
  import org.embulk.parser.poi_excel.PoiExcelParserPlugin.PluginTask;
11
+ import org.embulk.parser.poi_excel.bean.util.PoiExcelCellAddress;
11
12
  import org.embulk.spi.Column;
12
13
  import org.embulk.spi.Exec;
13
14
  import org.embulk.spi.Schema;
@@ -36,43 +37,10 @@ public class PoiExcelColumnIndex {
36
37
  }
37
38
  bean.setColumnIndex(index);
38
39
  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
- }
59
- } else {
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
- }
40
+ }
41
+
42
+ if (log.isInfoEnabled()) {
43
+ logColumn(column, bean, valueType, index);
76
44
  }
77
45
  }
78
46
  }
@@ -80,6 +48,15 @@ public class PoiExcelColumnIndex {
80
48
  protected int resolveColumnIndex(Column column, PoiExcelColumnBean bean, int index,
81
49
  PoiExcelColumnValueType valueType) {
82
50
  Optional<String> numberOption = bean.getColumnNumber();
51
+ PoiExcelCellAddress cellAddress = bean.getCellAddress();
52
+
53
+ if (cellAddress != null) {
54
+ if (numberOption.isPresent()) {
55
+ throw new RuntimeException("only one of column_number, cell_address can be specified");
56
+ }
57
+ return index;
58
+ }
59
+
83
60
  if (numberOption.isPresent()) {
84
61
  String columnNumber = numberOption.get();
85
62
  if (columnNumber.length() >= 1) {
@@ -190,4 +167,64 @@ public class PoiExcelColumnIndex {
190
167
  }
191
168
  return index;
192
169
  }
170
+
171
+ protected void logColumn(Column column, PoiExcelColumnBean bean, PoiExcelColumnValueType valueType, int index) {
172
+ PoiExcelCellAddress cellAddress = bean.getCellAddress();
173
+
174
+ String cname, cvalue;
175
+ if (cellAddress != null) {
176
+ cname = "cell_address";
177
+ cvalue = cellAddress.getString();
178
+ } else {
179
+ cname = "cell_column";
180
+ cvalue = CellReference.convertNumToColString(index);
181
+ }
182
+
183
+ switch (valueType) {
184
+ default:
185
+ case CELL_VALUE:
186
+ case CELL_FORMULA:
187
+ case CELL_TYPE:
188
+ case CELL_CACHED_TYPE:
189
+ case COLUMN_NUMBER:
190
+ log.info("column.name={} <- {}={}, value_type={}", column.getName(), cname, cvalue, valueType);
191
+ break;
192
+ case CELL_STYLE:
193
+ case CELL_FONT:
194
+ case CELL_COMMENT:
195
+ String suffix = bean.getValueTypeSuffix();
196
+ if (suffix != null) {
197
+ log.info("column.name={} <- {}={}, value_type={}, value=[{}]", column.getName(), cname, cvalue,
198
+ valueType, suffix);
199
+ } else {
200
+ log.info("column.name={} <- {}={}, value_type={}, value={}", column.getName(), cname, cvalue,
201
+ valueType, suffix);
202
+ }
203
+ break;
204
+
205
+ case SHEET_NAME:
206
+ if (cellAddress != null && cellAddress.getSheetName() != null) {
207
+ log.info("column.name={} <- {}={}, value_type={}", column.getName(), cname, cvalue, valueType);
208
+ } else {
209
+ log.info("column.name={} <- value_type={}", column.getName(), valueType);
210
+ }
211
+ break;
212
+ case ROW_NUMBER:
213
+ if (cellAddress != null) {
214
+ log.info("column.name={} <- {}={}, value_type={}", column.getName(), cname, cvalue, valueType);
215
+ } else {
216
+ log.info("column.name={} <- value_type={}", column.getName(), valueType);
217
+ }
218
+ break;
219
+
220
+ case CONSTANT:
221
+ String value = bean.getValueTypeSuffix();
222
+ if (value != null) {
223
+ log.info("column.name={} <- value_type={}, value=[{}]", column.getName(), valueType, value);
224
+ } else {
225
+ log.info("column.name={} <- value_type={}, value={}", column.getName(), valueType, value);
226
+ }
227
+ break;
228
+ }
229
+ }
193
230
  }
@@ -0,0 +1,50 @@
1
+ package org.embulk.parser.poi_excel.bean.util;
2
+
3
+ import java.text.MessageFormat;
4
+
5
+ import org.apache.poi.ss.usermodel.Cell;
6
+ import org.apache.poi.ss.usermodel.Row;
7
+ import org.apache.poi.ss.usermodel.Sheet;
8
+ import org.apache.poi.ss.usermodel.Workbook;
9
+ import org.apache.poi.ss.util.CellReference;
10
+
11
+ public class PoiExcelCellAddress {
12
+ private final CellReference cellReference;
13
+
14
+ public PoiExcelCellAddress(String cellAddress) {
15
+ this.cellReference = new CellReference(cellAddress);
16
+ }
17
+
18
+ public String getSheetName() {
19
+ return cellReference.getSheetName();
20
+ }
21
+
22
+ public Sheet getSheet(Row currentRow) {
23
+ String sheetName = getSheetName();
24
+ if (sheetName != null) {
25
+ Workbook book = currentRow.getSheet().getWorkbook();
26
+ Sheet sheet = book.getSheet(sheetName);
27
+ if (sheet == null) {
28
+ throw new RuntimeException(MessageFormat.format("not found sheet. sheetName={0}", sheetName));
29
+ }
30
+ return sheet;
31
+ } else {
32
+ return currentRow.getSheet();
33
+ }
34
+ }
35
+
36
+ public Cell getCell(Row currentRow) {
37
+ Sheet sheet = getSheet(currentRow);
38
+
39
+ Row row = sheet.getRow(cellReference.getRow());
40
+ if (row == null) {
41
+ return null;
42
+ }
43
+
44
+ return row.getCell(cellReference.getCol());
45
+ }
46
+
47
+ public String getString() {
48
+ return cellReference.formatAsString();
49
+ }
50
+ }
@@ -100,12 +100,6 @@ public class PoiExcelCellFontVisitor extends AbstractPoiExcelCellAttributeVisito
100
100
  return (long) font.getIndex();
101
101
  }
102
102
  });
103
- map.put("boldweight", new AttributeSupplier<Font>() {
104
- @Override
105
- public Object get(Column column, Cell cell, Font font) {
106
- return (long) font.getBoldweight();
107
- }
108
- });
109
103
  map.put("bold", new AttributeSupplier<Font>() {
110
104
  @Override
111
105
  public Object get(Column column, Cell cell, Font font) {
@@ -41,16 +41,16 @@ public class PoiExcelCellStyleVisitor extends AbstractPoiExcelCellAttributeVisit
41
41
  map.put("alignment", new AttributeSupplier<CellStyle>() {
42
42
  @Override
43
43
  public Object get(Column column, Cell cell, CellStyle style) {
44
- return (long) style.getAlignment();
44
+ return (long) style.getAlignmentEnum().getCode();
45
45
  }
46
46
  });
47
47
  map.put("border", new AttributeSupplier<CellStyle>() {
48
48
  @Override
49
49
  public Object get(Column column, Cell cell, CellStyle style) {
50
- int n0 = style.getBorderTop();
51
- int n1 = style.getBorderBottom();
52
- int n2 = style.getBorderLeft();
53
- int n3 = style.getBorderRight();
50
+ int n0 = style.getBorderTopEnum().getCode();
51
+ int n1 = style.getBorderBottomEnum().getCode();
52
+ int n2 = style.getBorderLeftEnum().getCode();
53
+ int n3 = style.getBorderRightEnum().getCode();
54
54
  if (column.getType() instanceof StringType) {
55
55
  return String.format("%02x%02x%02x%02x", n0, n1, n2, n3);
56
56
  }
@@ -60,25 +60,25 @@ public class PoiExcelCellStyleVisitor extends AbstractPoiExcelCellAttributeVisit
60
60
  map.put("border_bottom", new AttributeSupplier<CellStyle>() {
61
61
  @Override
62
62
  public Object get(Column column, Cell cell, CellStyle style) {
63
- return (long) style.getBorderBottom();
63
+ return (long) style.getBorderBottomEnum().getCode();
64
64
  }
65
65
  });
66
66
  map.put("border_left", new AttributeSupplier<CellStyle>() {
67
67
  @Override
68
68
  public Object get(Column column, Cell cell, CellStyle style) {
69
- return (long) style.getBorderLeft();
69
+ return (long) style.getBorderLeftEnum().getCode();
70
70
  }
71
71
  });
72
72
  map.put("border_right", new AttributeSupplier<CellStyle>() {
73
73
  @Override
74
74
  public Object get(Column column, Cell cell, CellStyle style) {
75
- return (long) style.getBorderRight();
75
+ return (long) style.getBorderRightEnum().getCode();
76
76
  }
77
77
  });
78
78
  map.put("border_top", new AttributeSupplier<CellStyle>() {
79
79
  @Override
80
80
  public Object get(Column column, Cell cell, CellStyle style) {
81
- return (long) style.getBorderTop();
81
+ return (long) style.getBorderTopEnum().getCode();
82
82
  }
83
83
  });
84
84
  map.put("border_bottom_color", new AttributeSupplier<CellStyle>() {
@@ -154,7 +154,7 @@ public class PoiExcelCellStyleVisitor extends AbstractPoiExcelCellAttributeVisit
154
154
  map.put("fill_pattern", new AttributeSupplier<CellStyle>() {
155
155
  @Override
156
156
  public Object get(Column column, Cell cell, CellStyle style) {
157
- return (long) style.getFillPattern();
157
+ return (long) style.getFillPatternEnum().getCode();
158
158
  }
159
159
  });
160
160
  map.put("font_index", new AttributeSupplier<CellStyle>() {
@@ -190,7 +190,7 @@ public class PoiExcelCellStyleVisitor extends AbstractPoiExcelCellAttributeVisit
190
190
  map.put("vertical_alignment", new AttributeSupplier<CellStyle>() {
191
191
  @Override
192
192
  public Object get(Column column, Cell cell, CellStyle style) {
193
- return (long) style.getVerticalAlignment();
193
+ return (long) style.getVerticalAlignmentEnum().getCode();
194
194
  }
195
195
  });
196
196
  map.put("wrap_text", new AttributeSupplier<CellStyle>() {
@@ -0,0 +1,52 @@
1
+ package org.embulk.parser.poi_excel.visitor;
2
+
3
+ import org.apache.poi.ss.usermodel.Cell;
4
+ import org.apache.poi.ss.usermodel.CellType;
5
+ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
6
+ import org.embulk.parser.poi_excel.visitor.embulk.CellVisitor;
7
+ import org.embulk.spi.Column;
8
+ import org.embulk.spi.PageBuilder;
9
+ import org.embulk.spi.type.StringType;
10
+
11
+ public class PoiExcelCellTypeVisitor {
12
+ protected final PoiExcelVisitorValue visitorValue;
13
+ protected final PageBuilder pageBuilder;
14
+
15
+ public PoiExcelCellTypeVisitor(PoiExcelVisitorValue visitorValue) {
16
+ this.visitorValue = visitorValue;
17
+ this.pageBuilder = visitorValue.getPageBuilder();
18
+ }
19
+
20
+ public void visit(PoiExcelColumnBean bean, Cell cell, CellType cellType, CellVisitor visitor) {
21
+ assert cell != null;
22
+
23
+ Column column = bean.getColumn();
24
+ if (column.getType() instanceof StringType) {
25
+ String type = cellType.name();
26
+ visitor.visitCellValueString(column, cell, type);
27
+ return;
28
+ }
29
+
30
+ int code = getCode(cellType);
31
+ visitor.visitCellValueNumeric(column, cell, code);
32
+ }
33
+
34
+ private static int getCode(CellType cellType) {
35
+ switch (cellType) {
36
+ case NUMERIC:
37
+ return 0;
38
+ case STRING:
39
+ return 1;
40
+ case FORMULA:
41
+ return 2;
42
+ case BLANK:
43
+ return 3;
44
+ case BOOLEAN:
45
+ return 4;
46
+ case ERROR:
47
+ return 5;
48
+ default:
49
+ return -1;
50
+ }
51
+ }
52
+ }
@@ -4,6 +4,7 @@ import java.text.MessageFormat;
4
4
  import java.util.List;
5
5
 
6
6
  import org.apache.poi.ss.usermodel.Cell;
7
+ import org.apache.poi.ss.usermodel.CellType;
7
8
  import org.apache.poi.ss.usermodel.CellValue;
8
9
  import org.apache.poi.ss.usermodel.CreationHelper;
9
10
  import org.apache.poi.ss.usermodel.FormulaError;
@@ -16,7 +17,10 @@ import org.embulk.parser.poi_excel.PoiExcelColumnValueType;
16
17
  import org.embulk.parser.poi_excel.PoiExcelParserPlugin.FormulaReplaceTask;
17
18
  import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
18
19
  import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean.ErrorStrategy;
20
+ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean.FormulaHandling;
21
+ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean.SearchMergedCell;
19
22
  import org.embulk.parser.poi_excel.visitor.embulk.CellVisitor;
23
+ import org.embulk.parser.poi_excel.visitor.util.MergedRegionMap;
20
24
  import org.embulk.spi.Column;
21
25
  import org.embulk.spi.Exec;
22
26
  import org.embulk.spi.PageBuilder;
@@ -38,15 +42,15 @@ public class PoiExcelCellValueVisitor {
38
42
 
39
43
  Column column = bean.getColumn();
40
44
 
41
- int cellType = cell.getCellType();
45
+ CellType cellType = cell.getCellTypeEnum();
42
46
  switch (cellType) {
43
- case Cell.CELL_TYPE_NUMERIC:
47
+ case NUMERIC:
44
48
  visitor.visitCellValueNumeric(column, cell, cell.getNumericCellValue());
45
49
  return;
46
- case Cell.CELL_TYPE_STRING:
50
+ case STRING:
47
51
  visitor.visitCellValueString(column, cell, cell.getStringCellValue());
48
52
  return;
49
- case Cell.CELL_TYPE_FORMULA:
53
+ case FORMULA:
50
54
  PoiExcelColumnValueType valueType = bean.getValueType();
51
55
  if (valueType == PoiExcelColumnValueType.CELL_FORMULA) {
52
56
  visitor.visitCellFormula(column, cell);
@@ -54,13 +58,13 @@ public class PoiExcelCellValueVisitor {
54
58
  visitCellValueFormula(bean, cell, visitor);
55
59
  }
56
60
  return;
57
- case Cell.CELL_TYPE_BLANK:
61
+ case BLANK:
58
62
  visitCellValueBlank(bean, cell, visitor);
59
63
  return;
60
- case Cell.CELL_TYPE_BOOLEAN:
64
+ case BOOLEAN:
61
65
  visitor.visitCellValueBoolean(column, cell, cell.getBooleanCellValue());
62
66
  return;
63
- case Cell.CELL_TYPE_ERROR:
67
+ case ERROR:
64
68
  visitCellValueError(bean, cell, cell.getErrorCellValue(), visitor);
65
69
  return;
66
70
  default:
@@ -69,46 +73,111 @@ public class PoiExcelCellValueVisitor {
69
73
  }
70
74
 
71
75
  protected void visitCellValueBlank(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
72
- assert cell.getCellType() == Cell.CELL_TYPE_BLANK;
76
+ assert cell.getCellTypeEnum() == CellType.BLANK;
73
77
 
74
78
  Column column = bean.getColumn();
75
79
 
76
- boolean search = bean.getSearchMergedCell();
77
- if (!search) {
78
- visitor.visitCellValueBlank(column, cell);
79
- return;
80
+ CellRangeAddress region = findRegion(bean, cell);
81
+ if (region != null) {
82
+ Row firstRow = cell.getSheet().getRow(region.getFirstRow());
83
+ if (firstRow == null) {
84
+ visitCellNull(column);
85
+ return;
86
+ }
87
+ Cell firstCell = firstRow.getCell(region.getFirstColumn());
88
+ if (firstCell == null) {
89
+ visitCellNull(column);
90
+ return;
91
+ }
92
+
93
+ if (firstCell.getRowIndex() != cell.getRowIndex() || firstCell.getColumnIndex() != cell.getColumnIndex()) {
94
+ visitCellValue(bean, firstCell, visitor);
95
+ return;
96
+ }
97
+ }
98
+
99
+ visitor.visitCellValueBlank(column, cell);
100
+ }
101
+
102
+ protected CellRangeAddress findRegion(PoiExcelColumnBean bean, Cell cell) {
103
+ SearchMergedCell search = bean.getSearchMergedCell();
104
+ switch (search) {
105
+ case NONE:
106
+ return null;
107
+ case LINEAR_SEARCH:
108
+ return findRegionLinearSearch(bean, cell);
109
+ default:
110
+ return findRegionTreeSearch(bean, cell);
80
111
  }
112
+ }
81
113
 
114
+ protected CellRangeAddress findRegionLinearSearch(PoiExcelColumnBean bean, Cell cell) {
115
+ Sheet sheet = cell.getSheet();
82
116
  int r = cell.getRowIndex();
83
117
  int c = cell.getColumnIndex();
84
118
 
85
- Sheet sheet = cell.getSheet();
86
119
  int size = sheet.getNumMergedRegions();
87
120
  for (int i = 0; i < size; i++) {
88
- CellRangeAddress range = visitorValue.getSheet().getMergedRegion(i);
89
- if (range.isInRange(r, c)) {
90
- Row firstRow = sheet.getRow(range.getFirstRow());
91
- if (firstRow == null) {
92
- visitCellNull(column);
93
- return;
94
- }
95
- Cell firstCell = firstRow.getCell(range.getFirstColumn());
96
- if (firstCell == null) {
97
- visitCellNull(column);
98
- return;
99
- }
100
-
101
- visitCellValue(bean, firstCell, visitor);
102
- return;
121
+ CellRangeAddress region = sheet.getMergedRegion(i);
122
+ if (region.isInRange(r, c)) {
123
+ return region;
103
124
  }
104
125
  }
105
126
 
106
- visitor.visitCellValueBlank(column, cell);
127
+ return null;
128
+ }
129
+
130
+ private final MergedRegionMap mergedRegionMap = new MergedRegionMap();
131
+
132
+ protected CellRangeAddress findRegionTreeSearch(PoiExcelColumnBean bean, Cell cell) {
133
+ Sheet sheet = cell.getSheet();
134
+ int r = cell.getRowIndex();
135
+ int c = cell.getColumnIndex();
136
+
137
+ return mergedRegionMap.get(sheet, r, c);
107
138
  }
108
139
 
109
140
  protected void visitCellValueFormula(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
110
- assert cell.getCellType() == Cell.CELL_TYPE_FORMULA;
141
+ assert cell.getCellTypeEnum() == CellType.FORMULA;
142
+
143
+ FormulaHandling handling = bean.getFormulaHandling();
144
+ switch (handling) {
145
+ case CASHED_VALUE:
146
+ visitCellValueFormulaCashedValue(bean, cell, visitor);
147
+ break;
148
+ default:
149
+ visitCellValueFormulaEvaluate(bean, cell, visitor);
150
+ break;
151
+ }
152
+ }
153
+
154
+ protected void visitCellValueFormulaCashedValue(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
155
+ Column column = bean.getColumn();
156
+
157
+ CellType cellType = cell.getCachedFormulaResultTypeEnum();
158
+ switch (cellType) {
159
+ case NUMERIC:
160
+ visitor.visitCellValueNumeric(column, cell, cell.getNumericCellValue());
161
+ return;
162
+ case STRING:
163
+ visitor.visitCellValueString(column, cell, cell.getStringCellValue());
164
+ return;
165
+ case BLANK:
166
+ visitCellValueBlank(bean, cell, visitor);
167
+ return;
168
+ case BOOLEAN:
169
+ visitor.visitCellValueBoolean(column, cell, cell.getBooleanCellValue());
170
+ return;
171
+ case ERROR:
172
+ visitCellValueError(bean, cell, cell.getErrorCellValue(), visitor);
173
+ return;
174
+ case FORMULA:
175
+ default:
176
+ throw new IllegalStateException(MessageFormat.format("unsupported POI cellType={0}", cellType));
177
+ }
178
+ }
111
179
 
180
+ protected void visitCellValueFormulaEvaluate(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
112
181
  Column column = bean.getColumn();
113
182
 
114
183
  List<FormulaReplaceTask> list = bean.getFormulaReplace();
@@ -159,24 +228,24 @@ public class PoiExcelCellValueVisitor {
159
228
  throw new RuntimeException(MessageFormat.format("evaluate error. formula={0}", cell.getCellFormula()), e);
160
229
  }
161
230
 
162
- int cellType = cellValue.getCellType();
231
+ CellType cellType = cellValue.getCellTypeEnum();
163
232
  switch (cellType) {
164
- case Cell.CELL_TYPE_NUMERIC:
233
+ case NUMERIC:
165
234
  visitor.visitCellValueNumeric(column, cellValue, cellValue.getNumberValue());
166
235
  return;
167
- case Cell.CELL_TYPE_STRING:
236
+ case STRING:
168
237
  visitor.visitCellValueString(column, cellValue, cellValue.getStringValue());
169
238
  return;
170
- case Cell.CELL_TYPE_BLANK:
239
+ case BLANK:
171
240
  visitor.visitCellValueBlank(column, cellValue);
172
241
  return;
173
- case Cell.CELL_TYPE_BOOLEAN:
242
+ case BOOLEAN:
174
243
  visitor.visitCellValueBoolean(column, cellValue, cellValue.getBooleanValue());
175
244
  return;
176
- case Cell.CELL_TYPE_ERROR:
245
+ case ERROR:
177
246
  visitCellValueError(bean, cellValue, cellValue.getErrorValue(), visitor);
178
247
  return;
179
- case Cell.CELL_TYPE_FORMULA:
248
+ case FORMULA:
180
249
  default:
181
250
  throw new IllegalStateException(MessageFormat.format("unsupported POI cellType={0}", cellType));
182
251
  }