embulk-parser-poi_excel 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/README.md +44 -2
- data/build.gradle +1 -1
- data/src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java +70 -2
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java +35 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java +39 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java +9 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin.java +0 -28
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_formula.java +90 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_sheets.java +34 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a6920bea2e679cbcc53f02a2c70485ba3d4b350
|
4
|
+
data.tar.gz: a83e9e1a2cb8ef78da34d7ef5602b66b3f2e48c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33920df4d360e86b5609f3939c63762b2f1d9b87a16f1923cf59ab5f16060ce1a2070c860e66d46fd50631a6a08f7677c7f32cb3dfc33e2084f1aca6fab75fe7
|
7
|
+
data.tar.gz: 043b272a531e072b07033c43a014021c8cf9e1e65a7e12f7079341cff35adf6dc429e30c3da3415f994698fa02aa401fd527771469094db93583408c081c2c31
|
data/README.md
CHANGED
@@ -28,12 +28,12 @@ in:
|
|
28
28
|
```
|
29
29
|
|
30
30
|
if omit **value**, specified `cell_value`.
|
31
|
-
if omit **column_number** when **
|
31
|
+
if omit **column_number** when **value** is `cell_value`, specified next column.
|
32
32
|
|
33
33
|
|
34
34
|
## Configuration
|
35
35
|
|
36
|
-
* **sheets**: sheet name. (list of string, required)
|
36
|
+
* **sheets**: sheet name. can use wildcards `*`, `?`. (list of string, required)
|
37
37
|
* **skip_header_lines**: skip rows. (integer, default: `0`)
|
38
38
|
* **columns**: column definition. see below. (hash, required)
|
39
39
|
* **sheet_options**: sheet option. see below. (hash, default: null)
|
@@ -46,6 +46,9 @@ if omit **column_number** when **valus** is `cell_value`, specified next column.
|
|
46
46
|
* **column_number**: Excel column number. see below. (string, default: next column)
|
47
47
|
* **attribute_name**: use with value `cell_style`, `cell_font`, etc. see below. (list of string)
|
48
48
|
* **on_cell_error**: processing method of Cell error. see below. (string, default: `constant`)
|
49
|
+
* **formula_handling** : processing method of formula. see below. (`evaluate` or `cashed_value`. default: `evaluate`)
|
50
|
+
* **on_evaluate_error**: processing method of evaluate formula error. see below. (string, default: `exception`)
|
51
|
+
* **formula_replace** : replace formula before evaluate. see below.
|
49
52
|
* **on_convert_error**: processing method of convert error. see below. (string, default: `exception`)
|
50
53
|
|
51
54
|
### value
|
@@ -125,6 +128,45 @@ Processing method of Cell error (`#DIV/0!`, `#REF!`, etc).
|
|
125
128
|
* `exception`: throw exception.
|
126
129
|
|
127
130
|
|
131
|
+
### formula_handling
|
132
|
+
|
133
|
+
Processing method of formula.
|
134
|
+
|
135
|
+
```yaml
|
136
|
+
columns:
|
137
|
+
- {name: foo, type: string, column_number: A, value: cell_value, formula_handling: cashed_value}
|
138
|
+
```
|
139
|
+
|
140
|
+
* `evaluate`: evaluate formula. (default)
|
141
|
+
* `cashed_value`: cashed value in cell.
|
142
|
+
|
143
|
+
|
144
|
+
### on_evaluate_error
|
145
|
+
|
146
|
+
Processing method of evaluate formula error.
|
147
|
+
|
148
|
+
```yaml
|
149
|
+
columns:
|
150
|
+
- {name: foo, type: string, column_number: A, value: cell_value, on_evaluate_error: constant}
|
151
|
+
```
|
152
|
+
|
153
|
+
* `constant`: set null.
|
154
|
+
* `constant.`*value*: set value.
|
155
|
+
* `exception`: throw exception. (default)
|
156
|
+
|
157
|
+
|
158
|
+
### formula_replace
|
159
|
+
|
160
|
+
Replace formula before evaluate.
|
161
|
+
|
162
|
+
```yaml
|
163
|
+
columns:
|
164
|
+
- {name: foo, type: string, column_number: A, value: cell_value, formula_replace: [{regex: aaa, to: "A${row}"}, {regex: bbb, to: "B${row}"}]}
|
165
|
+
```
|
166
|
+
|
167
|
+
`${row}` is replaced with the current row number.
|
168
|
+
|
169
|
+
|
128
170
|
### on_convert_error
|
129
171
|
|
130
172
|
Processing method of convert error. ex) Excel boolean to Embulk timestamp
|
data/build.gradle
CHANGED
@@ -2,8 +2,11 @@ package org.embulk.parser.poi_excel;
|
|
2
2
|
|
3
3
|
import java.io.IOException;
|
4
4
|
import java.util.ArrayList;
|
5
|
+
import java.util.LinkedHashSet;
|
5
6
|
import java.util.List;
|
6
7
|
import java.util.Map;
|
8
|
+
import java.util.Set;
|
9
|
+
import java.util.regex.Pattern;
|
7
10
|
|
8
11
|
import org.apache.poi.EncryptedDocumentException;
|
9
12
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
@@ -106,6 +109,10 @@ public class PoiExcelParserPlugin implements ParserPlugin {
|
|
106
109
|
@ConfigDefault("null")
|
107
110
|
public Optional<Boolean> getSearchMergedCell();
|
108
111
|
|
112
|
+
@Config("formula_handling")
|
113
|
+
@ConfigDefault("null")
|
114
|
+
public Optional<String> getFormulaHandling();
|
115
|
+
|
109
116
|
@Config("formula_replace")
|
110
117
|
@ConfigDefault("null")
|
111
118
|
public Optional<List<FormulaReplaceTask>> getFormulaReplace();
|
@@ -166,11 +173,62 @@ public class PoiExcelParserPlugin implements ParserPlugin {
|
|
166
173
|
throw new RuntimeException(e);
|
167
174
|
}
|
168
175
|
|
169
|
-
|
176
|
+
List<String> list = resolveSheetName(workbook, sheetNames);
|
177
|
+
if (log.isDebugEnabled()) {
|
178
|
+
log.debug("resolved sheet names={}", list);
|
179
|
+
}
|
180
|
+
run(task, schema, workbook, list, output);
|
170
181
|
}
|
171
182
|
}
|
172
183
|
}
|
173
184
|
|
185
|
+
private List<String> resolveSheetName(Workbook workbook, List<String> sheetNames) {
|
186
|
+
Set<String> set = new LinkedHashSet<>();
|
187
|
+
for (String s : sheetNames) {
|
188
|
+
if (s.contains("*") || s.contains("?")) {
|
189
|
+
int length = s.length();
|
190
|
+
StringBuilder sb = new StringBuilder(length * 2);
|
191
|
+
StringBuilder buf = new StringBuilder(32);
|
192
|
+
for (int i = 0; i < length;) {
|
193
|
+
int c = s.codePointAt(i);
|
194
|
+
switch (c) {
|
195
|
+
case '*':
|
196
|
+
if (buf.length() > 0) {
|
197
|
+
sb.append(Pattern.quote(buf.toString()));
|
198
|
+
buf.setLength(0);
|
199
|
+
}
|
200
|
+
sb.append(".*");
|
201
|
+
break;
|
202
|
+
case '?':
|
203
|
+
if (buf.length() > 0) {
|
204
|
+
sb.append(Pattern.quote(buf.toString()));
|
205
|
+
buf.setLength(0);
|
206
|
+
}
|
207
|
+
sb.append(".");
|
208
|
+
break;
|
209
|
+
default:
|
210
|
+
buf.appendCodePoint(c);
|
211
|
+
break;
|
212
|
+
}
|
213
|
+
i += Character.charCount(c);
|
214
|
+
}
|
215
|
+
if (buf.length() > 0) {
|
216
|
+
sb.append(Pattern.quote(buf.toString()));
|
217
|
+
}
|
218
|
+
String regex = sb.toString();
|
219
|
+
for (Sheet sheet : workbook) {
|
220
|
+
String name = sheet.getSheetName();
|
221
|
+
if (name.matches(regex)) {
|
222
|
+
set.add(name);
|
223
|
+
}
|
224
|
+
}
|
225
|
+
} else {
|
226
|
+
set.add(s);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
return new ArrayList<>(set);
|
230
|
+
}
|
231
|
+
|
174
232
|
protected void run(PluginTask task, Schema schema, Workbook workbook, List<String> sheetNames, PageOutput output) {
|
175
233
|
final int flushCount = task.getFlushCount();
|
176
234
|
|
@@ -193,18 +251,28 @@ public class PoiExcelParserPlugin implements ParserPlugin {
|
|
193
251
|
|
194
252
|
int count = 0;
|
195
253
|
for (Row row : sheet) {
|
196
|
-
|
254
|
+
int rowIndex = row.getRowNum();
|
255
|
+
if (rowIndex < skipHeaderLines) {
|
256
|
+
log.debug("row({}) skipped", rowIndex);
|
197
257
|
continue;
|
198
258
|
}
|
259
|
+
if (log.isDebugEnabled()) {
|
260
|
+
log.debug("row({}) start", rowIndex);
|
261
|
+
}
|
199
262
|
|
200
263
|
visitor.setRow(row);
|
201
264
|
schema.visitColumns(visitor);
|
202
265
|
pageBuilder.addRecord();
|
203
266
|
|
204
267
|
if (++count >= flushCount) {
|
268
|
+
log.trace("flush");
|
205
269
|
pageBuilder.flush();
|
206
270
|
count = 0;
|
207
271
|
}
|
272
|
+
|
273
|
+
if (log.isDebugEnabled()) {
|
274
|
+
log.debug("row({}) end", rowIndex);
|
275
|
+
}
|
208
276
|
}
|
209
277
|
pageBuilder.flush();
|
210
278
|
}
|
@@ -248,6 +248,41 @@ public class PoiExcelColumnBean {
|
|
248
248
|
return searchMergedCell.get();
|
249
249
|
}
|
250
250
|
|
251
|
+
public enum FormulaHandling {
|
252
|
+
EVALUATE, CASHED_VALUE
|
253
|
+
}
|
254
|
+
|
255
|
+
private CacheValue<FormulaHandling> formulaHandling = new CacheValue<FormulaHandling>() {
|
256
|
+
|
257
|
+
@Override
|
258
|
+
protected Optional<FormulaHandling> getTaskValue(ColumnCommonOptionTask task) {
|
259
|
+
Optional<String> option = task.getFormulaHandling();
|
260
|
+
String value = option.or("null");
|
261
|
+
if ("null".equalsIgnoreCase(value)) {
|
262
|
+
return Optional.absent();
|
263
|
+
}
|
264
|
+
try {
|
265
|
+
return Optional.of(FormulaHandling.valueOf(value.trim().toUpperCase()));
|
266
|
+
} catch (Exception e) {
|
267
|
+
List<String> list = new ArrayList<>();
|
268
|
+
for (FormulaHandling s : FormulaHandling.values()) {
|
269
|
+
list.add(s.name().toLowerCase());
|
270
|
+
}
|
271
|
+
throw new ConfigException(MessageFormat.format("illegal formula_handling={0}. expected={1}", value,
|
272
|
+
list), e);
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
@Override
|
277
|
+
protected FormulaHandling getDefaultValue() {
|
278
|
+
return FormulaHandling.EVALUATE;
|
279
|
+
}
|
280
|
+
};
|
281
|
+
|
282
|
+
public FormulaHandling getFormulaHandling() {
|
283
|
+
return formulaHandling.get();
|
284
|
+
}
|
285
|
+
|
251
286
|
private CacheValue<List<FormulaReplaceTask>> formulaReplace = new CacheValue<List<FormulaReplaceTask>>() {
|
252
287
|
|
253
288
|
@Override
|
@@ -16,6 +16,7 @@ import org.embulk.parser.poi_excel.PoiExcelColumnValueType;
|
|
16
16
|
import org.embulk.parser.poi_excel.PoiExcelParserPlugin.FormulaReplaceTask;
|
17
17
|
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
18
18
|
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean.ErrorStrategy;
|
19
|
+
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean.FormulaHandling;
|
19
20
|
import org.embulk.parser.poi_excel.visitor.embulk.CellVisitor;
|
20
21
|
import org.embulk.spi.Column;
|
21
22
|
import org.embulk.spi.Exec;
|
@@ -109,6 +110,44 @@ public class PoiExcelCellValueVisitor {
|
|
109
110
|
protected void visitCellValueFormula(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
|
110
111
|
assert cell.getCellType() == Cell.CELL_TYPE_FORMULA;
|
111
112
|
|
113
|
+
FormulaHandling handling = bean.getFormulaHandling();
|
114
|
+
switch (handling) {
|
115
|
+
case CASHED_VALUE:
|
116
|
+
visitCellValueFormulaCashedValue(bean, cell, visitor);
|
117
|
+
break;
|
118
|
+
default:
|
119
|
+
visitCellValueFormulaEvaluate(bean, cell, visitor);
|
120
|
+
break;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
protected void visitCellValueFormulaCashedValue(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
|
125
|
+
Column column = bean.getColumn();
|
126
|
+
|
127
|
+
int cellType = cell.getCachedFormulaResultType();
|
128
|
+
switch (cellType) {
|
129
|
+
case Cell.CELL_TYPE_NUMERIC:
|
130
|
+
visitor.visitCellValueNumeric(column, cell, cell.getNumericCellValue());
|
131
|
+
return;
|
132
|
+
case Cell.CELL_TYPE_STRING:
|
133
|
+
visitor.visitCellValueString(column, cell, cell.getStringCellValue());
|
134
|
+
return;
|
135
|
+
case Cell.CELL_TYPE_BLANK:
|
136
|
+
visitCellValueBlank(bean, cell, visitor);
|
137
|
+
return;
|
138
|
+
case Cell.CELL_TYPE_BOOLEAN:
|
139
|
+
visitor.visitCellValueBoolean(column, cell, cell.getBooleanCellValue());
|
140
|
+
return;
|
141
|
+
case Cell.CELL_TYPE_ERROR:
|
142
|
+
visitCellValueError(bean, cell, cell.getErrorCellValue(), visitor);
|
143
|
+
return;
|
144
|
+
case Cell.CELL_TYPE_FORMULA:
|
145
|
+
default:
|
146
|
+
throw new IllegalStateException(MessageFormat.format("unsupported POI cellType={0}", cellType));
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
protected void visitCellValueFormulaEvaluate(PoiExcelColumnBean bean, Cell cell, CellVisitor visitor) {
|
112
151
|
Column column = bean.getColumn();
|
113
152
|
|
114
153
|
List<FormulaReplaceTask> list = bean.getFormulaReplace();
|
@@ -10,9 +10,12 @@ import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
|
10
10
|
import org.embulk.parser.poi_excel.visitor.embulk.CellVisitor;
|
11
11
|
import org.embulk.spi.Column;
|
12
12
|
import org.embulk.spi.ColumnVisitor;
|
13
|
+
import org.embulk.spi.Exec;
|
13
14
|
import org.embulk.spi.PageBuilder;
|
15
|
+
import org.slf4j.Logger;
|
14
16
|
|
15
17
|
public class PoiExcelColumnVisitor implements ColumnVisitor {
|
18
|
+
private final Logger log = Exec.getLogger(getClass());
|
16
19
|
|
17
20
|
protected final PoiExcelVisitorValue visitorValue;
|
18
21
|
protected final PageBuilder pageBuilder;
|
@@ -56,6 +59,9 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
56
59
|
}
|
57
60
|
|
58
61
|
protected final void visitCell0(Column column, CellVisitor visitor) {
|
62
|
+
if (log.isTraceEnabled()) {
|
63
|
+
log.trace("{} start", column);
|
64
|
+
}
|
59
65
|
try {
|
60
66
|
visitCell(column, visitor);
|
61
67
|
} catch (Exception e) {
|
@@ -65,6 +71,9 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
65
71
|
throw new RuntimeException(MessageFormat.format("error at {0} cell={1}!{2}. {3}", column, sheetName, ref,
|
66
72
|
e.getMessage()), e);
|
67
73
|
}
|
74
|
+
if (log.isTraceEnabled()) {
|
75
|
+
log.trace("{} end", column);
|
76
|
+
}
|
68
77
|
}
|
69
78
|
|
70
79
|
protected void visitCell(Column column, CellVisitor visitor) {
|
@@ -10,7 +10,6 @@ import java.util.Arrays;
|
|
10
10
|
import java.util.List;
|
11
11
|
import java.util.TimeZone;
|
12
12
|
|
13
|
-
import org.embulk.config.ConfigSource;
|
14
13
|
import org.embulk.parser.EmbulkPluginTester;
|
15
14
|
import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
|
16
15
|
import org.embulk.parser.EmbulkTestParserConfig;
|
@@ -114,33 +113,6 @@ public class TestPoiExcelParserPlugin {
|
|
114
113
|
assertThat(r.getAsString("col-s"), is("A"));
|
115
114
|
}
|
116
115
|
|
117
|
-
@Theory
|
118
|
-
public void testForumlaReplace(String excelFile) throws ParseException {
|
119
|
-
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
120
|
-
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
121
|
-
|
122
|
-
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
123
|
-
parser.set("sheet", "formula_replace");
|
124
|
-
|
125
|
-
ConfigSource replace0 = tester.newConfigSource();
|
126
|
-
replace0.set("regex", "test1");
|
127
|
-
replace0.set("to", "merged_cell");
|
128
|
-
ConfigSource replace1 = tester.newConfigSource();
|
129
|
-
replace1.set("regex", "B1");
|
130
|
-
replace1.set("to", "B${row}");
|
131
|
-
parser.set("formula_replace", Arrays.asList(replace0, replace1));
|
132
|
-
|
133
|
-
parser.addColumn("text", "string");
|
134
|
-
|
135
|
-
URL inFile = getClass().getResource(excelFile);
|
136
|
-
List<OutputRecord> result = tester.runParser(inFile, parser);
|
137
|
-
|
138
|
-
assertThat(result.size(), is(2));
|
139
|
-
assertThat(result.get(0).getAsString("text"), is("test3-a1"));
|
140
|
-
assertThat(result.get(1).getAsString("text"), is("test2-b2"));
|
141
|
-
}
|
142
|
-
}
|
143
|
-
|
144
116
|
@Theory
|
145
117
|
public void testSearchMergedCell_true(String excelFile) throws ParseException {
|
146
118
|
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
@@ -0,0 +1,90 @@
|
|
1
|
+
package org.embulk.parser.poi_excel;
|
2
|
+
|
3
|
+
import static org.hamcrest.CoreMatchers.is;
|
4
|
+
import static org.junit.Assert.assertThat;
|
5
|
+
|
6
|
+
import java.net.URL;
|
7
|
+
import java.text.ParseException;
|
8
|
+
import java.util.Arrays;
|
9
|
+
import java.util.List;
|
10
|
+
|
11
|
+
import org.embulk.config.ConfigSource;
|
12
|
+
import org.embulk.parser.EmbulkPluginTester;
|
13
|
+
import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
|
14
|
+
import org.embulk.parser.EmbulkTestParserConfig;
|
15
|
+
import org.junit.experimental.theories.DataPoints;
|
16
|
+
import org.junit.experimental.theories.Theories;
|
17
|
+
import org.junit.experimental.theories.Theory;
|
18
|
+
import org.junit.runner.RunWith;
|
19
|
+
|
20
|
+
@RunWith(Theories.class)
|
21
|
+
public class TestPoiExcelParserPlugin_formula {
|
22
|
+
|
23
|
+
@DataPoints
|
24
|
+
public static String[] FILES = { "test1.xls", "test2.xlsx" };
|
25
|
+
|
26
|
+
@Theory
|
27
|
+
public void testForumlaHandlingCashedValue(String excelFile) throws ParseException {
|
28
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
29
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
30
|
+
|
31
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
32
|
+
parser.set("sheet", "formula_replace");
|
33
|
+
|
34
|
+
parser.addColumn("text", "string").set("formula_handling", "cashed_value");
|
35
|
+
|
36
|
+
URL inFile = getClass().getResource(excelFile);
|
37
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
38
|
+
|
39
|
+
assertThat(result.size(), is(2));
|
40
|
+
assertThat(result.get(0).getAsString("text"), is("boolean"));
|
41
|
+
assertThat(result.get(1).getAsString("text"), is("test2-b1"));
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
@Theory
|
46
|
+
public void testForumlaHandlingEvaluate(String excelFile) throws ParseException {
|
47
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
48
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
49
|
+
|
50
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
51
|
+
parser.set("sheet", "formula_replace");
|
52
|
+
|
53
|
+
parser.addColumn("text", "string").set("formula_handling", "evaluate");
|
54
|
+
|
55
|
+
URL inFile = getClass().getResource(excelFile);
|
56
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
57
|
+
|
58
|
+
assertThat(result.size(), is(2));
|
59
|
+
assertThat(result.get(0).getAsString("text"), is("boolean"));
|
60
|
+
assertThat(result.get(1).getAsString("text"), is("test2-b1"));
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
@Theory
|
65
|
+
public void testForumlaReplace(String excelFile) throws ParseException {
|
66
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
67
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
68
|
+
|
69
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
70
|
+
parser.set("sheet", "formula_replace");
|
71
|
+
|
72
|
+
ConfigSource replace0 = tester.newConfigSource();
|
73
|
+
replace0.set("regex", "test1");
|
74
|
+
replace0.set("to", "merged_cell");
|
75
|
+
ConfigSource replace1 = tester.newConfigSource();
|
76
|
+
replace1.set("regex", "B1");
|
77
|
+
replace1.set("to", "B${row}");
|
78
|
+
parser.set("formula_replace", Arrays.asList(replace0, replace1));
|
79
|
+
|
80
|
+
parser.addColumn("text", "string");
|
81
|
+
|
82
|
+
URL inFile = getClass().getResource(excelFile);
|
83
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
84
|
+
|
85
|
+
assertThat(result.size(), is(2));
|
86
|
+
assertThat(result.get(0).getAsString("text"), is("test3-a1"));
|
87
|
+
assertThat(result.get(1).getAsString("text"), is("test2-b2"));
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
@@ -89,4 +89,38 @@ public class TestPoiExcelParserPlugin_sheets {
|
|
89
89
|
assertThat(record.getAsString("text"), is(text));
|
90
90
|
assertThat(record.getAsLong("number"), is(number));
|
91
91
|
}
|
92
|
+
|
93
|
+
@Theory
|
94
|
+
public void testResolveSheetName1(String excelFile) throws ParseException {
|
95
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
96
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
97
|
+
|
98
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
99
|
+
parser.set("sheets", Arrays.asList("*es*"));
|
100
|
+
parser.addColumn("name", "string").set("value", "sheet_name");
|
101
|
+
|
102
|
+
URL inFile = getClass().getResource(excelFile);
|
103
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
104
|
+
|
105
|
+
OutputRecord record = result.get(0);
|
106
|
+
assertThat(record.getAsString("name"), is("test1"));
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
@Theory
|
111
|
+
public void testResolveSheetName2(String excelFile) throws ParseException {
|
112
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
113
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
114
|
+
|
115
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
116
|
+
parser.set("sheets", Arrays.asList("test?"));
|
117
|
+
parser.addColumn("name", "string").set("value", "sheet_name");
|
118
|
+
|
119
|
+
URL inFile = getClass().getResource(excelFile);
|
120
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
121
|
+
|
122
|
+
OutputRecord record = result.get(0);
|
123
|
+
assertThat(record.getAsString("name"), is("test1"));
|
124
|
+
}
|
125
|
+
}
|
92
126
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-parser-poi_excel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hishidama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,11 +88,12 @@ files:
|
|
88
88
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_columnNumber.java
|
89
89
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_constant.java
|
90
90
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_convertError.java
|
91
|
+
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_formula.java
|
91
92
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_sheets.java
|
92
93
|
- src/test/resources/org/embulk/parser/poi_excel/test1.xls
|
93
94
|
- src/test/resources/org/embulk/parser/poi_excel/test2.xlsx
|
94
95
|
- classpath/commons-codec-1.9.jar
|
95
|
-
- classpath/embulk-parser-poi_excel-0.1.
|
96
|
+
- classpath/embulk-parser-poi_excel-0.1.6.jar
|
96
97
|
- classpath/embulk-standards-0.7.5.jar
|
97
98
|
- classpath/poi-3.13.jar
|
98
99
|
- classpath/poi-ooxml-3.13.jar
|