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.
- checksums.yaml +4 -4
- data/README.md +52 -5
- data/build.gradle +18 -8
- data/src/main/java/org/embulk/parser/poi_excel/PoiExcelColumnValueType.java +4 -0
- data/src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java +80 -3
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java +103 -6
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnIndex.java +74 -37
- data/src/main/java/org/embulk/parser/poi_excel/bean/util/PoiExcelCellAddress.java +50 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellFontVisitor.java +0 -6
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellStyleVisitor.java +11 -11
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellTypeVisitor.java +52 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java +106 -37
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelClientAnchorVisitor.java +1 -1
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java +64 -4
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorFactory.java +14 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/BooleanCellVisitor.java +5 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/CellVisitor.java +3 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/DoubleCellVisitor.java +5 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/LongCellVisitor.java +5 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/StringCellVisitor.java +30 -2
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/TimestampCellVisitor.java +5 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/util/MergedRegionMap.java +51 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin.java +27 -79
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellAddress.java +69 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellComment.java +1 -1
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellError.java +1 -1
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellFont.java +1 -1
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellStyle.java +14 -14
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellType.java +79 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_columnNumber.java +1 -1
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_constant.java +1 -1
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_convertError.java +1 -1
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_formula.java +90 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_mergedCell.java +89 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_sheets.java +35 -1
- metadata +26 -18
@@ -40,7 +40,7 @@ public class PoiExcelClientAnchorVisitor extends AbstractPoiExcelCellAttributeVi
|
|
40
40
|
map.put("anchor_type", new AttributeSupplier<ClientAnchor>() {
|
41
41
|
@Override
|
42
42
|
public Object get(Column column, Cell cell, ClientAnchor anchor) {
|
43
|
-
return (long) anchor.getAnchorType();
|
43
|
+
return (long) anchor.getAnchorType().value;
|
44
44
|
}
|
45
45
|
});
|
46
46
|
map.put("col1", new AttributeSupplier<ClientAnchor>() {
|
@@ -3,16 +3,22 @@ package org.embulk.parser.poi_excel.visitor;
|
|
3
3
|
import java.text.MessageFormat;
|
4
4
|
|
5
5
|
import org.apache.poi.ss.usermodel.Cell;
|
6
|
+
import org.apache.poi.ss.usermodel.CellType;
|
6
7
|
import org.apache.poi.ss.usermodel.Row;
|
8
|
+
import org.apache.poi.ss.usermodel.Sheet;
|
7
9
|
import org.apache.poi.ss.util.CellReference;
|
8
10
|
import org.embulk.parser.poi_excel.PoiExcelColumnValueType;
|
9
11
|
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
12
|
+
import org.embulk.parser.poi_excel.bean.util.PoiExcelCellAddress;
|
10
13
|
import org.embulk.parser.poi_excel.visitor.embulk.CellVisitor;
|
11
14
|
import org.embulk.spi.Column;
|
12
15
|
import org.embulk.spi.ColumnVisitor;
|
16
|
+
import org.embulk.spi.Exec;
|
13
17
|
import org.embulk.spi.PageBuilder;
|
18
|
+
import org.slf4j.Logger;
|
14
19
|
|
15
20
|
public class PoiExcelColumnVisitor implements ColumnVisitor {
|
21
|
+
private final Logger log = Exec.getLogger(getClass());
|
16
22
|
|
17
23
|
protected final PoiExcelVisitorValue visitorValue;
|
18
24
|
protected final PageBuilder pageBuilder;
|
@@ -56,6 +62,9 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
56
62
|
}
|
57
63
|
|
58
64
|
protected final void visitCell0(Column column, CellVisitor visitor) {
|
65
|
+
if (log.isTraceEnabled()) {
|
66
|
+
log.trace("{} start", column);
|
67
|
+
}
|
59
68
|
try {
|
60
69
|
visitCell(column, visitor);
|
61
70
|
} catch (Exception e) {
|
@@ -65,21 +74,52 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
65
74
|
throw new RuntimeException(MessageFormat.format("error at {0} cell={1}!{2}. {3}", column, sheetName, ref,
|
66
75
|
e.getMessage()), e);
|
67
76
|
}
|
77
|
+
if (log.isTraceEnabled()) {
|
78
|
+
log.trace("{} end", column);
|
79
|
+
}
|
68
80
|
}
|
69
81
|
|
70
82
|
protected void visitCell(Column column, CellVisitor visitor) {
|
71
83
|
PoiExcelColumnBean bean = visitorValue.getColumnBean(column);
|
72
84
|
PoiExcelColumnValueType valueType = bean.getValueType();
|
85
|
+
PoiExcelCellAddress cellAddress = bean.getCellAddress();
|
73
86
|
|
74
87
|
switch (valueType) {
|
75
88
|
case SHEET_NAME:
|
76
|
-
|
89
|
+
if (cellAddress != null) {
|
90
|
+
Sheet sheet = cellAddress.getSheet(currentRow);
|
91
|
+
visitor.visitSheetName(column, sheet);
|
92
|
+
} else {
|
93
|
+
visitor.visitSheetName(column);
|
94
|
+
}
|
77
95
|
return;
|
78
96
|
case ROW_NUMBER:
|
79
|
-
|
97
|
+
int rowIndex;
|
98
|
+
if (cellAddress != null) {
|
99
|
+
Cell cell = cellAddress.getCell(currentRow);
|
100
|
+
if (cell == null) {
|
101
|
+
visitCellNull(column);
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
rowIndex = cell.getRowIndex();
|
105
|
+
} else {
|
106
|
+
rowIndex = currentRow.getRowNum();
|
107
|
+
}
|
108
|
+
visitor.visitRowNumber(column, rowIndex + 1);
|
80
109
|
return;
|
81
110
|
case COLUMN_NUMBER:
|
82
|
-
|
111
|
+
int columnIndex;
|
112
|
+
if (cellAddress != null) {
|
113
|
+
Cell cell = cellAddress.getCell(currentRow);
|
114
|
+
if (cell == null) {
|
115
|
+
visitCellNull(column);
|
116
|
+
return;
|
117
|
+
}
|
118
|
+
columnIndex = cell.getColumnIndex();
|
119
|
+
} else {
|
120
|
+
columnIndex = bean.getColumnIndex();
|
121
|
+
}
|
122
|
+
visitor.visitColumnNumber(column, columnIndex + 1);
|
83
123
|
return;
|
84
124
|
case CONSTANT:
|
85
125
|
visitCellConstant(column, bean.getValueTypeSuffix(), visitor);
|
@@ -89,7 +129,12 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
89
129
|
}
|
90
130
|
|
91
131
|
assert valueType.useCell();
|
92
|
-
Cell cell
|
132
|
+
Cell cell;
|
133
|
+
if (cellAddress != null) {
|
134
|
+
cell = cellAddress.getCell(currentRow);
|
135
|
+
} else {
|
136
|
+
cell = currentRow.getCell(bean.getColumnIndex());
|
137
|
+
}
|
93
138
|
if (cell == null) {
|
94
139
|
visitCellNull(column);
|
95
140
|
return;
|
@@ -108,6 +153,16 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
108
153
|
case CELL_COMMENT:
|
109
154
|
visitCellComment(bean, cell, visitor);
|
110
155
|
return;
|
156
|
+
case CELL_TYPE:
|
157
|
+
visitCellType(bean, cell, cell.getCellTypeEnum(), visitor);
|
158
|
+
return;
|
159
|
+
case CELL_CACHED_TYPE:
|
160
|
+
if (cell.getCellTypeEnum() == CellType.FORMULA) {
|
161
|
+
visitCellType(bean, cell, cell.getCachedFormulaResultTypeEnum(), visitor);
|
162
|
+
} else {
|
163
|
+
visitCellType(bean, cell, cell.getCellTypeEnum(), visitor);
|
164
|
+
}
|
165
|
+
return;
|
111
166
|
default:
|
112
167
|
throw new UnsupportedOperationException(MessageFormat.format("unsupported value_type={0}", valueType));
|
113
168
|
}
|
@@ -144,4 +199,9 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
144
199
|
PoiExcelCellCommentVisitor delegator = factory.getPoiExcelCellCommentVisitor();
|
145
200
|
delegator.visit(bean, cell, visitor);
|
146
201
|
}
|
202
|
+
|
203
|
+
private void visitCellType(PoiExcelColumnBean bean, Cell cell, CellType cellType, CellVisitor visitor) {
|
204
|
+
PoiExcelCellTypeVisitor delegator = factory.getPoiExcelCellTypeVisitor();
|
205
|
+
delegator.visit(bean, cell, cellType, visitor);
|
206
|
+
}
|
147
207
|
}
|
@@ -159,6 +159,20 @@ public class PoiExcelVisitorFactory {
|
|
159
159
|
return new PoiExcelCellCommentVisitor(visitorValue);
|
160
160
|
}
|
161
161
|
|
162
|
+
// cell type
|
163
|
+
private PoiExcelCellTypeVisitor poiExcelCellTypeVisitor;
|
164
|
+
|
165
|
+
public final PoiExcelCellTypeVisitor getPoiExcelCellTypeVisitor() {
|
166
|
+
if (poiExcelCellTypeVisitor == null) {
|
167
|
+
poiExcelCellTypeVisitor = newPoiExcelCellTypeVisitor();
|
168
|
+
}
|
169
|
+
return poiExcelCellTypeVisitor;
|
170
|
+
}
|
171
|
+
|
172
|
+
protected PoiExcelCellTypeVisitor newPoiExcelCellTypeVisitor() {
|
173
|
+
return new PoiExcelCellTypeVisitor(visitorValue);
|
174
|
+
}
|
175
|
+
|
162
176
|
// ClientAnchor
|
163
177
|
private PoiExcelClientAnchorVisitor poiExcelClientAnchorVisitor;
|
164
178
|
|
@@ -38,6 +38,11 @@ public class BooleanCellVisitor extends CellVisitor {
|
|
38
38
|
@Override
|
39
39
|
public void visitSheetName(Column column) {
|
40
40
|
Sheet sheet = visitorValue.getSheet();
|
41
|
+
visitSheetName(column, sheet);
|
42
|
+
}
|
43
|
+
|
44
|
+
@Override
|
45
|
+
public void visitSheetName(Column column, Sheet sheet) {
|
41
46
|
int index = sheet.getWorkbook().getSheetIndex(sheet);
|
42
47
|
pageBuilder.setBoolean(column, index != 0);
|
43
48
|
}
|
@@ -3,6 +3,7 @@ package org.embulk.parser.poi_excel.visitor.embulk;
|
|
3
3
|
import java.text.MessageFormat;
|
4
4
|
|
5
5
|
import org.apache.poi.ss.usermodel.Cell;
|
6
|
+
import org.apache.poi.ss.usermodel.Sheet;
|
6
7
|
import org.embulk.config.ConfigException;
|
7
8
|
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
8
9
|
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean.ErrorStrategy;
|
@@ -40,6 +41,8 @@ public abstract class CellVisitor {
|
|
40
41
|
|
41
42
|
public abstract void visitSheetName(Column column);
|
42
43
|
|
44
|
+
public abstract void visitSheetName(Column column, Sheet sheet);
|
45
|
+
|
43
46
|
public abstract void visitRowNumber(Column column, int index1);
|
44
47
|
|
45
48
|
public abstract void visitColumnNumber(Column column, int index1);
|
@@ -45,6 +45,11 @@ public class DoubleCellVisitor extends CellVisitor {
|
|
45
45
|
@Override
|
46
46
|
public void visitSheetName(Column column) {
|
47
47
|
Sheet sheet = visitorValue.getSheet();
|
48
|
+
visitSheetName(column, sheet);
|
49
|
+
}
|
50
|
+
|
51
|
+
@Override
|
52
|
+
public void visitSheetName(Column column, Sheet sheet) {
|
48
53
|
int index = sheet.getWorkbook().getSheetIndex(sheet);
|
49
54
|
pageBuilder.setDouble(column, index);
|
50
55
|
}
|
@@ -45,6 +45,11 @@ public class LongCellVisitor extends CellVisitor {
|
|
45
45
|
@Override
|
46
46
|
public void visitSheetName(Column column) {
|
47
47
|
Sheet sheet = visitorValue.getSheet();
|
48
|
+
visitSheetName(column, sheet);
|
49
|
+
}
|
50
|
+
|
51
|
+
@Override
|
52
|
+
public void visitSheetName(Column column, Sheet sheet) {
|
48
53
|
int index = sheet.getWorkbook().getSheetIndex(sheet);
|
49
54
|
pageBuilder.setLong(column, index);
|
50
55
|
}
|
@@ -1,8 +1,11 @@
|
|
1
1
|
package org.embulk.parser.poi_excel.visitor.embulk;
|
2
2
|
|
3
|
+
import java.text.MessageFormat;
|
4
|
+
|
3
5
|
import org.apache.poi.ss.usermodel.FormulaError;
|
4
6
|
import org.apache.poi.ss.usermodel.Sheet;
|
5
7
|
import org.apache.poi.ss.util.CellReference;
|
8
|
+
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
6
9
|
import org.embulk.parser.poi_excel.visitor.PoiExcelVisitorValue;
|
7
10
|
import org.embulk.spi.Column;
|
8
11
|
|
@@ -14,11 +17,31 @@ public class StringCellVisitor extends CellVisitor {
|
|
14
17
|
|
15
18
|
@Override
|
16
19
|
public void visitCellValueNumeric(Column column, Object source, double value) {
|
20
|
+
String s = toString(column, source, value);
|
21
|
+
pageBuilder.setString(column, s);
|
22
|
+
}
|
23
|
+
|
24
|
+
protected String toString(Column column, Object source, double value) {
|
25
|
+
String format = getNumericFormat(column);
|
26
|
+
if (!format.isEmpty()) {
|
27
|
+
try {
|
28
|
+
return String.format(format, value);
|
29
|
+
} catch (Exception e) {
|
30
|
+
throw new IllegalArgumentException(MessageFormat.format(
|
31
|
+
"illegal String.format for double. numeric_format=\"{0}\"", format), e);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
17
35
|
String s = Double.toString(value);
|
18
36
|
if (s.endsWith(".0")) {
|
19
|
-
|
37
|
+
return s.substring(0, s.length() - 2);
|
20
38
|
}
|
21
|
-
|
39
|
+
return s;
|
40
|
+
}
|
41
|
+
|
42
|
+
protected String getNumericFormat(Column column) {
|
43
|
+
PoiExcelColumnBean bean = visitorValue.getColumnBean(column);
|
44
|
+
return bean.getNumericFormat();
|
22
45
|
}
|
23
46
|
|
24
47
|
@Override
|
@@ -47,6 +70,11 @@ public class StringCellVisitor extends CellVisitor {
|
|
47
70
|
@Override
|
48
71
|
public void visitSheetName(Column column) {
|
49
72
|
Sheet sheet = visitorValue.getSheet();
|
73
|
+
visitSheetName(column, sheet);
|
74
|
+
}
|
75
|
+
|
76
|
+
@Override
|
77
|
+
public void visitSheetName(Column column, Sheet sheet) {
|
50
78
|
pageBuilder.setString(column, sheet.getSheetName());
|
51
79
|
}
|
52
80
|
|
@@ -61,6 +61,11 @@ public class TimestampCellVisitor extends CellVisitor {
|
|
61
61
|
@Override
|
62
62
|
public void visitSheetName(Column column) {
|
63
63
|
Sheet sheet = visitorValue.getSheet();
|
64
|
+
visitSheetName(column, sheet);
|
65
|
+
}
|
66
|
+
|
67
|
+
@Override
|
68
|
+
public void visitSheetName(Column column, Sheet sheet) {
|
64
69
|
doConvertError(column, sheet.getSheetName(), new UnsupportedOperationException(
|
65
70
|
"unsupported conversion sheet_name to Embulk timestamp"));
|
66
71
|
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
package org.embulk.parser.poi_excel.visitor.util;
|
2
|
+
|
3
|
+
import java.util.Map;
|
4
|
+
import java.util.TreeMap;
|
5
|
+
import java.util.concurrent.ConcurrentHashMap;
|
6
|
+
|
7
|
+
import org.apache.poi.ss.usermodel.Sheet;
|
8
|
+
import org.apache.poi.ss.util.CellRangeAddress;
|
9
|
+
|
10
|
+
public class MergedRegionMap {
|
11
|
+
|
12
|
+
private final Map<Sheet, Map<Integer, Map<Integer, CellRangeAddress>>> sheetMap = new ConcurrentHashMap<>();
|
13
|
+
|
14
|
+
public CellRangeAddress get(Sheet sheet, int rowIndex, int columnIndex) {
|
15
|
+
Map<Integer, Map<Integer, CellRangeAddress>> rowMap = sheetMap.get(sheet);
|
16
|
+
if (rowMap == null) {
|
17
|
+
synchronized (sheet) {
|
18
|
+
rowMap = createRowMap(sheet);
|
19
|
+
sheetMap.put(sheet, rowMap);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
Map<Integer, CellRangeAddress> columnMap = rowMap.get(rowIndex);
|
24
|
+
if (columnMap == null) {
|
25
|
+
return null;
|
26
|
+
}
|
27
|
+
return columnMap.get(columnIndex);
|
28
|
+
}
|
29
|
+
|
30
|
+
protected Map<Integer, Map<Integer, CellRangeAddress>> createRowMap(Sheet sheet) {
|
31
|
+
Map<Integer, Map<Integer, CellRangeAddress>> rowMap = new TreeMap<>();
|
32
|
+
|
33
|
+
for (int i = sheet.getNumMergedRegions() - 1; i >= 0; i--) {
|
34
|
+
CellRangeAddress region = sheet.getMergedRegion(i);
|
35
|
+
|
36
|
+
for (int r = region.getFirstRow(); r <= region.getLastRow(); r++) {
|
37
|
+
Map<Integer, CellRangeAddress> columnMap = rowMap.get(r);
|
38
|
+
if (columnMap == null) {
|
39
|
+
columnMap = new TreeMap<>();
|
40
|
+
rowMap.put(r, columnMap);
|
41
|
+
}
|
42
|
+
|
43
|
+
for (int c = region.getFirstColumn(); c <= region.getLastColumn(); c++) {
|
44
|
+
columnMap.put(c, region);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
return rowMap;
|
50
|
+
}
|
51
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
package org.embulk.parser.poi_excel;
|
2
2
|
|
3
3
|
import static org.hamcrest.CoreMatchers.is;
|
4
|
-
import static org.
|
4
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
5
5
|
|
6
6
|
import java.net.URL;
|
7
7
|
import java.text.ParseException;
|
@@ -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;
|
@@ -74,6 +73,32 @@ public class TestPoiExcelParserPlugin {
|
|
74
73
|
assertThat(r.getAsTimestamp("timestamp"), is(timestamp));
|
75
74
|
}
|
76
75
|
|
76
|
+
@Theory
|
77
|
+
public void testNumricFormat(String excelFile) throws ParseException {
|
78
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
79
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
80
|
+
|
81
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
82
|
+
parser.set("sheets", Arrays.asList("test1"));
|
83
|
+
parser.set("skip_header_lines", 1);
|
84
|
+
parser.addColumn("value", "string").set("column_number", "C").set("numeric_format", "%.2f");
|
85
|
+
|
86
|
+
URL inFile = getClass().getResource(excelFile);
|
87
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
88
|
+
|
89
|
+
assertThat(result.size(), is(7));
|
90
|
+
checkNumricFormat(result, 0, "123.40");
|
91
|
+
checkNumricFormat(result, 1, "456.70");
|
92
|
+
checkNumricFormat(result, 2, "123.00");
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
private void checkNumricFormat(List<OutputRecord> result, int index, String s) {
|
97
|
+
OutputRecord r = result.get(index);
|
98
|
+
// System.out.println(r);
|
99
|
+
assertThat(r.getAsString("value"), is(s));
|
100
|
+
}
|
101
|
+
|
77
102
|
@Theory
|
78
103
|
public void testRowNumber(String excelFile) throws ParseException {
|
79
104
|
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
@@ -114,83 +139,6 @@ public class TestPoiExcelParserPlugin {
|
|
114
139
|
assertThat(r.getAsString("col-s"), is("A"));
|
115
140
|
}
|
116
141
|
|
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
|
-
@Theory
|
145
|
-
public void testSearchMergedCell_true(String excelFile) throws ParseException {
|
146
|
-
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
147
|
-
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
148
|
-
|
149
|
-
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
150
|
-
parser.set("sheet", "merged_cell");
|
151
|
-
parser.addColumn("a", "string");
|
152
|
-
parser.addColumn("b", "string");
|
153
|
-
|
154
|
-
URL inFile = getClass().getResource(excelFile);
|
155
|
-
List<OutputRecord> result = tester.runParser(inFile, parser);
|
156
|
-
|
157
|
-
assertThat(result.size(), is(4));
|
158
|
-
check6(result, 0, "test3-a1", "test3-a1");
|
159
|
-
check6(result, 1, "data", "0");
|
160
|
-
check6(result, 2, null, null);
|
161
|
-
check6(result, 3, null, null);
|
162
|
-
}
|
163
|
-
}
|
164
|
-
|
165
|
-
@Theory
|
166
|
-
public void testSearchMergedCell_false(String excelFile) throws ParseException {
|
167
|
-
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
168
|
-
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
169
|
-
|
170
|
-
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
171
|
-
parser.set("sheet", "merged_cell");
|
172
|
-
parser.set("search_merged_cell", false);
|
173
|
-
parser.addColumn("a", "string");
|
174
|
-
parser.addColumn("b", "string");
|
175
|
-
|
176
|
-
URL inFile = getClass().getResource(excelFile);
|
177
|
-
List<OutputRecord> result = tester.runParser(inFile, parser);
|
178
|
-
|
179
|
-
assertThat(result.size(), is(4));
|
180
|
-
check6(result, 0, "test3-a1", null);
|
181
|
-
check6(result, 1, "data", "0");
|
182
|
-
check6(result, 2, null, null);
|
183
|
-
check6(result, 3, null, null);
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
private void check6(List<OutputRecord> result, int index, String a, String b) {
|
188
|
-
OutputRecord r = result.get(index);
|
189
|
-
// System.out.println(r);
|
190
|
-
assertThat(r.getAsString("a"), is(a));
|
191
|
-
assertThat(r.getAsString("b"), is(b));
|
192
|
-
}
|
193
|
-
|
194
142
|
@Theory
|
195
143
|
public void test_sheets(String excelFile) throws ParseException {
|
196
144
|
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|