embulk-parser-poi_excel 0.1.7 → 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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -6
  3. data/build.gradle +16 -8
  4. data/classpath/{commons-codec-1.9.jar → commons-codec-1.10.jar} +0 -0
  5. data/classpath/commons-collections4-4.1.jar +0 -0
  6. data/classpath/curvesapi-1.04.jar +0 -0
  7. data/classpath/embulk-parser-poi_excel-0.1.10.jar +0 -0
  8. data/classpath/poi-3.17.jar +0 -0
  9. data/classpath/poi-ooxml-3.17.jar +0 -0
  10. data/classpath/{poi-ooxml-schemas-3.13.jar → poi-ooxml-schemas-3.17.jar} +0 -0
  11. data/src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java +6 -1
  12. data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java +51 -6
  13. data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnIndex.java +74 -39
  14. data/src/main/java/org/embulk/parser/poi_excel/bean/util/PoiExcelCellAddress.java +50 -0
  15. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellFontVisitor.java +0 -6
  16. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellStyleVisitor.java +11 -11
  17. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellTypeVisitor.java +24 -10
  18. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java +74 -44
  19. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelClientAnchorVisitor.java +1 -1
  20. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java +45 -9
  21. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/BooleanCellVisitor.java +5 -0
  22. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/CellVisitor.java +3 -0
  23. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/DoubleCellVisitor.java +5 -0
  24. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/LongCellVisitor.java +5 -0
  25. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/StringCellVisitor.java +5 -0
  26. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/TimestampCellVisitor.java +5 -0
  27. data/src/main/java/org/embulk/parser/poi_excel/visitor/util/MergedRegionMap.java +51 -0
  28. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin.java +1 -51
  29. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellAddress.java +69 -0
  30. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellComment.java +1 -1
  31. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellError.java +1 -1
  32. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellFont.java +1 -1
  33. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellStyle.java +14 -14
  34. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellType.java +15 -14
  35. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_columnNumber.java +1 -1
  36. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_constant.java +1 -1
  37. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_convertError.java +1 -1
  38. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_formula.java +1 -1
  39. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_mergedCell.java +89 -0
  40. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_sheets.java +1 -1
  41. metadata +23 -17
  42. data/classpath/embulk-parser-poi_excel-0.1.7.jar +0 -0
  43. data/classpath/poi-3.13.jar +0 -0
  44. data/classpath/poi-ooxml-3.13.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ab71cb044d2238a08719c80b1092f50cce9b84e
4
- data.tar.gz: c02f1e64148806369e8aca0e11a86daba48f134f
3
+ metadata.gz: '058cae76dc2aff62982491ddd1d29f0bc707d030'
4
+ data.tar.gz: 4b7652888f66faa0b3b3653cda9c3ba4b9d49887
5
5
  SHA512:
6
- metadata.gz: 0966c93aba6475e4c77a1a987be10a0413025bb96f7925b9f41413802ad9217c1366b06b1378369e7ee9dcad8b70ca843532cac70d606c08aa0553a9195f108e
7
- data.tar.gz: 06a1f63b2ba99e9f88410e72d1a29b5b3eb3b221394674a1568b9d4ed32a3292a95e93ed6639c2f26b6be513ee0f15d0199e96ee7b35ff4ba9082947f48908c5
6
+ metadata.gz: b700c88e34a05edd16d1d7444053540fae8f8ef7d596c709505f070ca4d3d0582e9c69da6cc253b97a595cbe5d3aad60f1a1bbb75b90110e573575ba32c4d752
7
+ data.tar.gz: a36bc92ebd495a908f98c53cb92ebd3c84c294df3cde9d2ea926f0c452c9a6d2fcce7646f9f906a6ed25b21fb14de1a2ecc6ea5ee6e8aeec10c8b46346efd070
data/README.md CHANGED
@@ -44,13 +44,15 @@ if omit **column_number** when **value** is `cell_value`, specified next column.
44
44
  * **type**: Embulk column type. (string, required)
45
45
  * **value**: value type. see below. (string, defualt: `cell_value`)
46
46
  * **column_number**: Excel column number. see below. (string, default: next column)
47
+ * **cell_address**: Excel cell address such as `A1`, `Sheet1!B3`. only one of `column_number`, `cell_address` can be specified. (string, not required)
47
48
  * **numeric_format**: format of numeric(double) to string such as `%4.2f`. (default: Java's Double.toString())
48
49
  * **attribute_name**: use with value `cell_style`, `cell_font`, etc. see below. (list of string)
49
50
  * **on_cell_error**: processing method of Cell error. see below. (string, default: `constant`)
50
- * **formula_handling** : processing method of formula. see below. (`evaluate` or `cashed_value`. default: `evaluate`)
51
+ * **formula_handling**: processing method of formula. see below. (`evaluate` or `cashed_value`. default: `evaluate`)
51
52
  * **on_evaluate_error**: processing method of evaluate formula error. see below. (string, default: `exception`)
52
- * **formula_replace** : replace formula before evaluate. see below.
53
+ * **formula_replace**: replace formula before evaluate. see below.
53
54
  * **on_convert_error**: processing method of convert error. see below. (string, default: `exception`)
55
+ * **search_merged_cell**: search merged cell when cell is BLANK. one of `none`, `linear_search`, `tree_search`. (string, default: `tree_search`)
54
56
 
55
57
  ### value
56
58
 
@@ -60,7 +62,7 @@ if omit **column_number** when **value** is `cell_value`, specified next column.
60
62
  * `cell_font`: all cell font attributes. returned json string. see **attribute_name**. (**type** required `string`)
61
63
  * `cell_comment`: all cell comment attributes. returned json string. see **attribute_name**. (**type** required `string`)
62
64
  * `cell_type`: cell type. returned Cell.getCellType() of POI.
63
- * `cell_cached_type`: cell cached formula result type. returned Cell.getCachedFormulaResultType() of POI when CellType==FORMULA, otherwise same as cell_type(returned Cell.getCellType()).
65
+ * `cell_cached_type`: cell cached formula result type. returned Cell.getCachedFormulaResultType() of POI when CellType==FORMULA, otherwise same as `cell_type` (returned Cell.getCellType()).
64
66
  * `sheet_name`: sheet name.
65
67
  * `row_number`: row number(1 origin).
66
68
  * `column_number`: column number(1 origin).
@@ -126,7 +128,7 @@ Processing method of Cell error (`#DIV/0!`, `#REF!`, etc).
126
128
  ```
127
129
 
128
130
  * `constant`: set null. (default)
129
- * `constant.`*value*: set value.
131
+ * `constant.`*value*: set specified value.
130
132
  * `error_code`: set error code.
131
133
  * `exception`: throw exception.
132
134
 
@@ -186,7 +188,7 @@ Processing method of convert error. ex) Excel boolean to Embulk timestamp
186
188
 
187
189
  ### sheet_options
188
190
 
189
- Options of indivisual sheet.
191
+ Options of individual sheet.
190
192
 
191
193
  ```yaml
192
194
  parser:
@@ -210,7 +212,7 @@ Options of indivisual sheet.
210
212
  ```
211
213
 
212
214
  **sheet_options** is map of sheet name.
213
- Map values are **skip_header_lines**, **colums**.
215
+ Map values are **skip_header_lines**, **columns**.
214
216
 
215
217
  **columns** is map of column name.
216
218
  Map values are same **columns** in **parser** (excluding `name`, `type`).
data/build.gradle CHANGED
@@ -1,6 +1,6 @@
1
1
  plugins {
2
2
  id "com.jfrog.bintray" version "1.1"
3
- id "com.github.jruby-gradle.base" version "0.1.5"
3
+ id "com.github.jruby-gradle.base" version "1.5.0"
4
4
  id "java"
5
5
  id "eclipse"
6
6
  }
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.1.7"
16
+ version = "0.1.10"
17
17
 
18
18
  sourceCompatibility = 1.7
19
19
  targetCompatibility = 1.7
@@ -23,8 +23,8 @@ dependencies {
23
23
  provided "org.embulk:embulk-core:0.7.5"
24
24
  compile "org.embulk:embulk-standards:0.7.5"
25
25
  // compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
26
- compile group: 'org.apache.poi', name : 'poi', version: '3.13'
27
- compile(group: 'org.apache.poi', name : 'poi-ooxml', version: '3.13') {
26
+ compile group: 'org.apache.poi', name : 'poi', version: '3.17'
27
+ compile(group: 'org.apache.poi', name : 'poi-ooxml', version: '3.17') {
28
28
  exclude group: 'stax', module: 'stax-api'
29
29
  }
30
30
  testCompile "junit:junit:4.+"
@@ -38,14 +38,22 @@ task classpath(type: Copy, dependsOn: ["jar"]) {
38
38
  clean { delete "classpath" }
39
39
 
40
40
  task gem(type: JRubyExec, dependsOn: ["gemspec", "classpath"]) {
41
- jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "build"
42
- script "${project.name}.gemspec"
41
+ jrubyArgs "-S"
42
+ script "gem"
43
+ scriptArgs "build", "${project.name}.gemspec"
43
44
  doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
44
45
  }
45
46
 
46
47
  task gemPush(type: JRubyExec, dependsOn: ["gem"]) {
47
- jrubyArgs "-rrubygems/gem_runner", "-eGem::GemRunner.new.run(ARGV)", "push"
48
- script "pkg/${project.name}-${project.version}.gem"
48
+ jrubyArgs "-S"
49
+ script "gem"
50
+ scriptArgs "push", "pkg/${project.name}-${project.version}.gem"
51
+ }
52
+
53
+ task gemUnpack(type: JRubyExec) {
54
+ jrubyArgs "-S"
55
+ script "gem"
56
+ scriptArgs "unpack", "pkg/${project.name}-${project.version}.gem"
49
57
  }
50
58
 
51
59
  task "package"(dependsOn: ["gemspec", "classpath"]) << {
Binary file
Binary file
Binary file
@@ -96,6 +96,11 @@ public class PoiExcelParserPlugin implements ParserPlugin {
96
96
  @ConfigDefault("null")
97
97
  public Optional<String> getColumnNumber();
98
98
 
99
+ // A1,B2,... or Sheet1!A1
100
+ @Config("cell_address")
101
+ @ConfigDefault("null")
102
+ public Optional<String> getCellAddress();
103
+
99
104
  // use when value_type=cell_style, cell_font, ...
100
105
  @Config("attribute_name")
101
106
  @ConfigDefault("null")
@@ -111,7 +116,7 @@ public class PoiExcelParserPlugin implements ParserPlugin {
111
116
  // search merged cell if cellType=BLANK
112
117
  @Config("search_merged_cell")
113
118
  @ConfigDefault("null")
114
- public Optional<Boolean> getSearchMergedCell();
119
+ public Optional<String> getSearchMergedCell();
115
120
 
116
121
  @Config("formula_handling")
117
122
  @ConfigDefault("null")
@@ -11,6 +11,7 @@ import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnCommonOptionTask;
11
11
  import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
12
12
  import org.embulk.parser.poi_excel.PoiExcelParserPlugin.FormulaReplaceTask;
13
13
  import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean.ErrorStrategy.Strategy;
14
+ import org.embulk.parser.poi_excel.bean.util.PoiExcelCellAddress;
14
15
  import org.embulk.spi.Column;
15
16
 
16
17
  import com.google.common.base.Optional;
@@ -107,6 +108,25 @@ public class PoiExcelColumnBean {
107
108
  return Optional.absent();
108
109
  }
109
110
 
111
+ private Optional<PoiExcelCellAddress> cellAddress;
112
+
113
+ public PoiExcelCellAddress getCellAddress() {
114
+ if (cellAddress == null) {
115
+ this.cellAddress = initializeCellAddress();
116
+ }
117
+ return cellAddress.orNull();
118
+ }
119
+
120
+ protected Optional<PoiExcelCellAddress> initializeCellAddress() {
121
+ for (ColumnOptionTask task : columnTaskList) {
122
+ Optional<String> option = task.getCellAddress();
123
+ if (option.isPresent()) {
124
+ return Optional.of(new PoiExcelCellAddress(option.get()));
125
+ }
126
+ }
127
+ return Optional.absent();
128
+ }
129
+
110
130
  protected abstract class CacheValue<T> {
111
131
  private T value;
112
132
 
@@ -248,20 +268,45 @@ public class PoiExcelColumnBean {
248
268
  return numericFormat.get();
249
269
  }
250
270
 
251
- private CacheValue<Boolean> searchMergedCell = new CacheValue<Boolean>() {
271
+ public enum SearchMergedCell {
272
+ NONE, LINEAR_SEARCH, TREE_SEARCH
273
+ }
274
+
275
+ private CacheValue<SearchMergedCell> searchMergedCell = new CacheValue<SearchMergedCell>() {
252
276
 
253
277
  @Override
254
- protected Optional<Boolean> getTaskValue(ColumnCommonOptionTask task) {
255
- return task.getSearchMergedCell();
278
+ protected Optional<SearchMergedCell> getTaskValue(ColumnCommonOptionTask task) {
279
+ Optional<String> option = task.getSearchMergedCell();
280
+ String value = option.or("null").trim();
281
+ switch (value.toLowerCase()) {
282
+ case "null":
283
+ return Optional.absent();
284
+ case "true": // compatibility ver 0.1.7
285
+ return Optional.of(getDefaultValue());
286
+ case "false": // compatibility ver 0.1.7
287
+ return Optional.of(SearchMergedCell.NONE);
288
+ default:
289
+ break;
290
+ }
291
+ try {
292
+ return Optional.of(SearchMergedCell.valueOf(value.toUpperCase()));
293
+ } catch (Exception e) {
294
+ List<String> list = new ArrayList<>();
295
+ for (SearchMergedCell s : SearchMergedCell.values()) {
296
+ list.add(s.name().toLowerCase());
297
+ }
298
+ throw new ConfigException(MessageFormat.format("illegal search_merged_cell={0}. expected={1}", value,
299
+ list), e);
300
+ }
256
301
  }
257
302
 
258
303
  @Override
259
- protected Boolean getDefaultValue() {
260
- return true;
304
+ protected SearchMergedCell getDefaultValue() {
305
+ return SearchMergedCell.TREE_SEARCH;
261
306
  }
262
307
  };
263
308
 
264
- public boolean getSearchMergedCell() {
309
+ public SearchMergedCell getSearchMergedCell() {
265
310
  return searchMergedCell.get();
266
311
  }
267
312
 
@@ -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,45 +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 CELL_TYPE:
55
- case CELL_CACHED_TYPE:
56
- case COLUMN_NUMBER:
57
- log.info("column.name={} <- cell_column={}, value_type={}", column.getName(), c, valueType);
58
- break;
59
- }
60
- }
61
- } else {
62
- if (log.isInfoEnabled()) {
63
- switch (valueType) {
64
- default:
65
- String suffix = bean.getValueTypeSuffix();
66
- if (suffix != null) {
67
- log.info("column.name={} <- value_type={}, value=[{}]", column.getName(), valueType, suffix);
68
- } else {
69
- log.info("column.name={} <- value_type={}, value={}", column.getName(), valueType, suffix);
70
- }
71
- break;
72
- case SHEET_NAME:
73
- case ROW_NUMBER:
74
- log.info("column.name={} <- value_type={}", column.getName(), valueType);
75
- break;
76
- }
77
- }
40
+ }
41
+
42
+ if (log.isInfoEnabled()) {
43
+ logColumn(column, bean, valueType, index);
78
44
  }
79
45
  }
80
46
  }
@@ -82,6 +48,15 @@ public class PoiExcelColumnIndex {
82
48
  protected int resolveColumnIndex(Column column, PoiExcelColumnBean bean, int index,
83
49
  PoiExcelColumnValueType valueType) {
84
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
+
85
60
  if (numberOption.isPresent()) {
86
61
  String columnNumber = numberOption.get();
87
62
  if (columnNumber.length() >= 1) {
@@ -192,4 +167,64 @@ public class PoiExcelColumnIndex {
192
167
  }
193
168
  return index;
194
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
+ }
195
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>() {
@@ -1,6 +1,7 @@
1
1
  package org.embulk.parser.poi_excel.visitor;
2
2
 
3
3
  import org.apache.poi.ss.usermodel.Cell;
4
+ import org.apache.poi.ss.usermodel.CellType;
4
5
  import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
5
6
  import org.embulk.parser.poi_excel.visitor.embulk.CellVisitor;
6
7
  import org.embulk.spi.Column;
@@ -16,23 +17,36 @@ public class PoiExcelCellTypeVisitor {
16
17
  this.pageBuilder = visitorValue.getPageBuilder();
17
18
  }
18
19
 
19
- private static final String[] CELL_TYPE_STRING = { "NUMERIC", "STRING", "FORMULA", "BLANK", "BOOLEAN", "ERROR" };
20
-
21
- public void visit(PoiExcelColumnBean bean, Cell cell, int cellType, CellVisitor visitor) {
20
+ public void visit(PoiExcelColumnBean bean, Cell cell, CellType cellType, CellVisitor visitor) {
22
21
  assert cell != null;
23
22
 
24
23
  Column column = bean.getColumn();
25
24
  if (column.getType() instanceof StringType) {
26
- String type;
27
- if (0 <= cellType && cellType < CELL_TYPE_STRING.length) {
28
- type = CELL_TYPE_STRING[cellType];
29
- } else {
30
- type = Integer.toString(cellType);
31
- }
25
+ String type = cellType.name();
32
26
  visitor.visitCellValueString(column, cell, type);
33
27
  return;
34
28
  }
35
29
 
36
- visitor.visitCellValueNumeric(column, cell, cellType);
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
+ }
37
51
  }
38
52
  }