embulk-parser-poi_excel 0.1.5 → 0.1.12
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 +80 -21
- data/build.gradle +21 -11
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +5 -6
- data/gradlew +43 -35
- data/gradlew.bat +4 -10
- data/src/main/java/org/embulk/parser/poi_excel/PoiExcelColumnValueType.java +25 -3
- data/src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java +102 -11
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java +132 -6
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnIndex.java +167 -47
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelSheetBean.java +13 -1
- data/src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecord.java +52 -0
- data/src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecordColumn.java +80 -0
- data/src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecordRow.java +76 -0
- data/src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecordSheet.java +49 -0
- data/src/main/java/org/embulk/parser/poi_excel/bean/record/RecordType.java +114 -0
- data/src/main/java/org/embulk/parser/poi_excel/bean/util/PoiExcelCellAddress.java +59 -0
- data/src/main/java/org/embulk/parser/poi_excel/bean/util/SearchMergedCell.java +71 -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 +87 -41
- 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 +60 -12
- 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/MergedRegionFinder.java +9 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/util/MergedRegionList.java +20 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/util/MergedRegionMap.java +55 -0
- data/src/main/java/org/embulk/parser/poi_excel/visitor/util/MergedRegionNothing.java +12 -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 +94 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_recordType.java +192 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_sheets.java +35 -1
- metadata +36 -17
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
|
|
2
2
|
|
3
3
|
import static org.hamcrest.CoreMatchers.is;
|
4
4
|
import static org.hamcrest.CoreMatchers.nullValue;
|
5
|
-
import static org.
|
5
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
6
6
|
import static org.junit.Assert.fail;
|
7
7
|
|
8
8
|
import java.net.URL;
|
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
|
|
2
2
|
|
3
3
|
import static org.hamcrest.CoreMatchers.is;
|
4
4
|
import static org.hamcrest.CoreMatchers.nullValue;
|
5
|
-
import static org.
|
5
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
6
6
|
import static org.junit.Assert.fail;
|
7
7
|
|
8
8
|
import java.net.URL;
|
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
|
|
2
2
|
|
3
3
|
import static org.hamcrest.CoreMatchers.is;
|
4
4
|
import static org.hamcrest.CoreMatchers.nullValue;
|
5
|
-
import static org.
|
5
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
6
6
|
import static org.junit.Assert.fail;
|
7
7
|
|
8
8
|
import java.net.URL;
|
@@ -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
|
import static org.junit.Assert.fail;
|
6
6
|
|
7
7
|
import java.net.URL;
|
@@ -9,7 +9,7 @@ import java.text.ParseException;
|
|
9
9
|
import java.util.Arrays;
|
10
10
|
import java.util.List;
|
11
11
|
|
12
|
-
import org.apache.poi.ss.usermodel.
|
12
|
+
import org.apache.poi.ss.usermodel.BorderStyle;
|
13
13
|
import org.embulk.parser.EmbulkPluginTester;
|
14
14
|
import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
|
15
15
|
import org.embulk.parser.EmbulkTestParserConfig;
|
@@ -44,11 +44,11 @@ public class TestPoiExcelParserPlugin_cellStyle {
|
|
44
44
|
List<OutputRecord> result = tester.runParser(inFile, parser);
|
45
45
|
|
46
46
|
assertThat(result.size(), is(5));
|
47
|
-
check1(result, 0, "red", 255, 0, 0, "top",
|
47
|
+
check1(result, 0, "red", 255, 0, 0, "top", BorderStyle.THIN.getCode(), 0, 0, 0);
|
48
48
|
check1(result, 1, "green", 0, 128, 0, null, 0, 0, 0, 0);
|
49
|
-
check1(result, 2, "blue", 0, 0, 255, "left", 0, 0,
|
50
|
-
check1(result, 3, "white", 255, 255, 255, "right", 0, 0, 0,
|
51
|
-
check1(result, 4, "black", 0, 0, 0, "bottom", 0,
|
49
|
+
check1(result, 2, "blue", 0, 0, 255, "left", 0, 0, BorderStyle.THIN.getCode(), 0);
|
50
|
+
check1(result, 3, "white", 255, 255, 255, "right", 0, 0, 0, BorderStyle.THIN.getCode());
|
51
|
+
check1(result, 4, "black", 0, 0, 0, "bottom", 0, BorderStyle.MEDIUM.getCode(), 0, 0);
|
52
52
|
}
|
53
53
|
}
|
54
54
|
|
@@ -81,11 +81,11 @@ public class TestPoiExcelParserPlugin_cellStyle {
|
|
81
81
|
List<OutputRecord> result = tester.runParser(inFile, parser);
|
82
82
|
|
83
83
|
assertThat(result.size(), is(5));
|
84
|
-
check2(result, 0, "red", 255, 0, 0, "top",
|
84
|
+
check2(result, 0, "red", 255, 0, 0, "top", BorderStyle.THIN.getCode(), 0, 0, 0);
|
85
85
|
check2(result, 1, "green", 0, 128, 0, null, 0, 0, 0, 0);
|
86
|
-
check2(result, 2, "blue", 0, 0, 255, "left", 0, 0,
|
87
|
-
check2(result, 3, "white", 255, 255, 255, "right", 0, 0, 0,
|
88
|
-
check2(result, 4, "black", 0, 0, 0, "bottom", 0,
|
86
|
+
check2(result, 2, "blue", 0, 0, 255, "left", 0, 0, BorderStyle.THIN.getCode(), 0);
|
87
|
+
check2(result, 3, "white", 255, 255, 255, "right", 0, 0, 0, BorderStyle.THIN.getCode());
|
88
|
+
check2(result, 4, "black", 0, 0, 0, "bottom", 0, BorderStyle.MEDIUM.getCode(), 0, 0);
|
89
89
|
}
|
90
90
|
}
|
91
91
|
|
@@ -130,11 +130,11 @@ public class TestPoiExcelParserPlugin_cellStyle {
|
|
130
130
|
List<OutputRecord> result = tester.runParser(inFile, parser);
|
131
131
|
|
132
132
|
assertThat(result.size(), is(5));
|
133
|
-
check2(result, 0, "red", 255, 0, 0, "top",
|
133
|
+
check2(result, 0, "red", 255, 0, 0, "top", BorderStyle.THIN.getCode(), 0, 0, 0);
|
134
134
|
check2(result, 1, "green", 0, 128, 0, null, 0, 0, 0, 0);
|
135
|
-
check2(result, 2, "blue", 0, 0, 255, "left", 0, 0,
|
136
|
-
check2(result, 3, "white", 255, 255, 255, "right", 0, 0, 0,
|
137
|
-
check2(result, 4, "black", 0, 0, 0, "bottom", 0,
|
135
|
+
check2(result, 2, "blue", 0, 0, 255, "left", 0, 0, BorderStyle.THIN.getCode(), 0);
|
136
|
+
check2(result, 3, "white", 255, 255, 255, "right", 0, 0, 0, BorderStyle.THIN.getCode());
|
137
|
+
check2(result, 4, "black", 0, 0, 0, "bottom", 0, BorderStyle.MEDIUM.getCode(), 0, 0);
|
138
138
|
}
|
139
139
|
}
|
140
140
|
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
package org.embulk.parser.poi_excel;
|
2
|
+
|
3
|
+
import static org.hamcrest.CoreMatchers.is;
|
4
|
+
import static org.hamcrest.MatcherAssert.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.apache.poi.ss.usermodel.CellType;
|
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_cellType {
|
22
|
+
|
23
|
+
@DataPoints
|
24
|
+
public static String[] FILES = { "test1.xls", "test2.xlsx" };
|
25
|
+
|
26
|
+
@Theory
|
27
|
+
public void testCellType(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("sheets", Arrays.asList("test1"));
|
33
|
+
parser.set("skip_header_lines", 3);
|
34
|
+
parser.addColumn("long", "long").set("column_number", "A").set("value", "cell_type");
|
35
|
+
parser.addColumn("string", "string").set("column_number", "A").set("value", "cell_type");
|
36
|
+
|
37
|
+
URL inFile = getClass().getResource(excelFile);
|
38
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
39
|
+
|
40
|
+
assertThat(result.size(), is(5));
|
41
|
+
check1(result, 0, CellType.NUMERIC, "NUMERIC");
|
42
|
+
check1(result, 1, CellType.STRING, "STRING");
|
43
|
+
check1(result, 2, CellType.FORMULA, "FORMULA");
|
44
|
+
check1(result, 3, CellType.BOOLEAN, "BOOLEAN");
|
45
|
+
check1(result, 4, CellType.FORMULA, "FORMULA");
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
@Theory
|
50
|
+
public void testCellCachedType(String excelFile) throws ParseException {
|
51
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
52
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
53
|
+
|
54
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
55
|
+
parser.set("sheets", Arrays.asList("test1"));
|
56
|
+
parser.set("skip_header_lines", 3);
|
57
|
+
parser.addColumn("long", "long").set("column_number", "A").set("value", "cell_cached_type");
|
58
|
+
parser.addColumn("string", "string").set("column_number", "A").set("value", "cell_cached_type");
|
59
|
+
|
60
|
+
URL inFile = getClass().getResource(excelFile);
|
61
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
62
|
+
|
63
|
+
assertThat(result.size(), is(5));
|
64
|
+
check1(result, 0, CellType.NUMERIC, "NUMERIC");
|
65
|
+
check1(result, 1, CellType.STRING, "STRING");
|
66
|
+
check1(result, 2, CellType.BOOLEAN, "BOOLEAN");
|
67
|
+
check1(result, 3, CellType.BOOLEAN, "BOOLEAN");
|
68
|
+
check1(result, 4, CellType.ERROR, "ERROR");
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
@SuppressWarnings("deprecation")
|
73
|
+
private void check1(List<OutputRecord> result, int index, CellType cellType, String s) throws ParseException {
|
74
|
+
OutputRecord r = result.get(index);
|
75
|
+
// System.out.println(r);
|
76
|
+
assertThat(r.getAsLong("long"), is((long) cellType.getCode()));
|
77
|
+
assertThat(r.getAsString("string"), is(s));
|
78
|
+
}
|
79
|
+
}
|
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
|
|
2
2
|
|
3
3
|
import static org.hamcrest.CoreMatchers.is;
|
4
4
|
import static org.hamcrest.CoreMatchers.nullValue;
|
5
|
-
import static org.
|
5
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
6
6
|
|
7
7
|
import java.net.URL;
|
8
8
|
import java.text.ParseException;
|
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
|
|
2
2
|
|
3
3
|
import static org.hamcrest.CoreMatchers.is;
|
4
4
|
import static org.hamcrest.CoreMatchers.nullValue;
|
5
|
-
import static org.
|
5
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
6
6
|
|
7
7
|
import java.net.URL;
|
8
8
|
import java.text.ParseException;
|
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
|
|
2
2
|
|
3
3
|
import static org.hamcrest.CoreMatchers.is;
|
4
4
|
import static org.hamcrest.CoreMatchers.nullValue;
|
5
|
-
import static org.
|
5
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
6
6
|
import static org.junit.Assert.fail;
|
7
7
|
|
8
8
|
import java.net.URL;
|
@@ -0,0 +1,90 @@
|
|
1
|
+
package org.embulk.parser.poi_excel;
|
2
|
+
|
3
|
+
import static org.hamcrest.CoreMatchers.is;
|
4
|
+
import static org.hamcrest.MatcherAssert.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
|
+
}
|
@@ -0,0 +1,94 @@
|
|
1
|
+
package org.embulk.parser.poi_excel;
|
2
|
+
|
3
|
+
import static org.hamcrest.CoreMatchers.is;
|
4
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
5
|
+
|
6
|
+
import java.net.URL;
|
7
|
+
import java.text.ParseException;
|
8
|
+
import java.util.List;
|
9
|
+
|
10
|
+
import org.embulk.parser.EmbulkPluginTester;
|
11
|
+
import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
|
12
|
+
import org.embulk.parser.EmbulkTestParserConfig;
|
13
|
+
import org.junit.experimental.theories.DataPoints;
|
14
|
+
import org.junit.experimental.theories.Theories;
|
15
|
+
import org.junit.experimental.theories.Theory;
|
16
|
+
import org.junit.runner.RunWith;
|
17
|
+
|
18
|
+
@RunWith(Theories.class)
|
19
|
+
public class TestPoiExcelParserPlugin_mergedCell {
|
20
|
+
|
21
|
+
@DataPoints
|
22
|
+
public static String[] FILES = { "test1.xls", "test2.xlsx" };
|
23
|
+
|
24
|
+
@Theory
|
25
|
+
public void testSearchMergedCell_default(String excelFile) throws ParseException {
|
26
|
+
test(excelFile, null, true);
|
27
|
+
}
|
28
|
+
|
29
|
+
@Theory
|
30
|
+
public void testSearchMergedCell_true(String excelFile) throws ParseException {
|
31
|
+
// compatibility ver 0.1.7
|
32
|
+
test(excelFile, true, true);
|
33
|
+
}
|
34
|
+
|
35
|
+
@Theory
|
36
|
+
public void testSearchMergedCell_false(String excelFile) throws ParseException {
|
37
|
+
// compatibility ver 0.1.7
|
38
|
+
test(excelFile, false, false);
|
39
|
+
}
|
40
|
+
|
41
|
+
@Theory
|
42
|
+
public void testSearchMergedCell_none(String excelFile) throws ParseException {
|
43
|
+
test(excelFile, "none", false);
|
44
|
+
}
|
45
|
+
|
46
|
+
@Theory
|
47
|
+
public void testSearchMergedCell_linear(String excelFile) throws ParseException {
|
48
|
+
test(excelFile, "linear_search", true);
|
49
|
+
}
|
50
|
+
|
51
|
+
@Theory
|
52
|
+
public void testSearchMergedCell_tree(String excelFile) throws ParseException {
|
53
|
+
test(excelFile, "tree_search", true);
|
54
|
+
}
|
55
|
+
|
56
|
+
@Theory
|
57
|
+
public void testSearchMergedCell_hash(String excelFile) throws ParseException {
|
58
|
+
test(excelFile, "hash_search", true);
|
59
|
+
}
|
60
|
+
|
61
|
+
private void test(String excelFile, Object arg, boolean search) {
|
62
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
63
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
64
|
+
|
65
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
66
|
+
parser.set("sheet", "merged_cell");
|
67
|
+
if (arg != null) {
|
68
|
+
parser.set("search_merged_cell", arg);
|
69
|
+
}
|
70
|
+
parser.addColumn("a", "string");
|
71
|
+
parser.addColumn("b", "string");
|
72
|
+
|
73
|
+
URL inFile = getClass().getResource(excelFile);
|
74
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
75
|
+
|
76
|
+
assertThat(result.size(), is(4));
|
77
|
+
if (search) {
|
78
|
+
check6(result, 0, "test3-a1", "test3-a1");
|
79
|
+
} else {
|
80
|
+
check6(result, 0, "test3-a1", null);
|
81
|
+
}
|
82
|
+
check6(result, 1, "data", "0");
|
83
|
+
check6(result, 2, null, null);
|
84
|
+
check6(result, 3, null, null);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
private void check6(List<OutputRecord> result, int index, String a, String b) {
|
89
|
+
OutputRecord r = result.get(index);
|
90
|
+
// System.out.println(r);
|
91
|
+
assertThat(r.getAsString("a"), is(a));
|
92
|
+
assertThat(r.getAsString("b"), is(b));
|
93
|
+
}
|
94
|
+
}
|
@@ -0,0 +1,192 @@
|
|
1
|
+
package org.embulk.parser.poi_excel;
|
2
|
+
|
3
|
+
import static org.hamcrest.CoreMatchers.is;
|
4
|
+
import static org.hamcrest.MatcherAssert.assertThat;
|
5
|
+
|
6
|
+
import java.net.URL;
|
7
|
+
import java.text.ParseException;
|
8
|
+
import java.util.List;
|
9
|
+
|
10
|
+
import org.embulk.parser.EmbulkPluginTester;
|
11
|
+
import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
|
12
|
+
import org.embulk.parser.EmbulkTestParserConfig;
|
13
|
+
import org.junit.experimental.theories.DataPoints;
|
14
|
+
import org.junit.experimental.theories.Theories;
|
15
|
+
import org.junit.experimental.theories.Theory;
|
16
|
+
import org.junit.runner.RunWith;
|
17
|
+
|
18
|
+
@RunWith(Theories.class)
|
19
|
+
public class TestPoiExcelParserPlugin_recordType {
|
20
|
+
|
21
|
+
@DataPoints
|
22
|
+
public static String[] FILES = { "test1.xls", "test2.xlsx" };
|
23
|
+
|
24
|
+
@Theory
|
25
|
+
public void testRecordType_row(String excelFile) throws ParseException {
|
26
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
27
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
28
|
+
|
29
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
30
|
+
parser.set("sheet", "test1");
|
31
|
+
parser.set("record_type", "row");
|
32
|
+
parser.set("skip_header_lines", 1);
|
33
|
+
parser.addColumn("text", "string").set("cell_column", "D");
|
34
|
+
parser.addColumn("text_row", "long").set("cell_column", "D").set("value", "row_number");
|
35
|
+
parser.addColumn("text_col", "long").set("cell_column", "D").set("value", "column_number");
|
36
|
+
parser.addColumn("text2", "string").set("cell_row", "4");
|
37
|
+
parser.addColumn("text2_row", "long").set("cell_row", "4").set("value", "row_number");
|
38
|
+
parser.addColumn("text2_col", "long").set("cell_row", "4").set("value", "column_number");
|
39
|
+
parser.addColumn("address1", "string").set("cell_address", "B1").set("value", "cell_value");
|
40
|
+
parser.addColumn("address2", "string").set("cell_column", "D").set("cell_row", "2");
|
41
|
+
parser.addColumn("fix_row", "long").set("cell_address", "B1").set("value", "row_number");
|
42
|
+
parser.addColumn("fix_col", "long").set("cell_address", "B1").set("value", "column_number");
|
43
|
+
|
44
|
+
URL inFile = getClass().getResource(excelFile);
|
45
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
46
|
+
|
47
|
+
assertThat(result.size(), is(7));
|
48
|
+
check1(result, 0, "abc");
|
49
|
+
check1(result, 1, "def");
|
50
|
+
check1(result, 2, "456");
|
51
|
+
check1(result, 3, "abc");
|
52
|
+
check1(result, 4, "abc");
|
53
|
+
check1(result, 5, "true");
|
54
|
+
check1(result, 6, null);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
private void check1(List<OutputRecord> result, int index, String text) {
|
59
|
+
OutputRecord record = result.get(index);
|
60
|
+
// System.out.println(record);
|
61
|
+
assertThat(record.getAsString("text"), is(text));
|
62
|
+
assertThat(record.getAsLong("text_row"), is((long) index + 2));
|
63
|
+
assertThat(record.getAsLong("text_col"), is(4L));
|
64
|
+
assertThat(record.getAsString("text2"), is("42283"));
|
65
|
+
assertThat(record.getAsLong("text2_row"), is(4L));
|
66
|
+
assertThat(record.getAsLong("text2_col"), is(5L));
|
67
|
+
assertThat(record.getAsString("address1"), is("long"));
|
68
|
+
assertThat(record.getAsString("address2"), is("abc"));
|
69
|
+
assertThat(record.getAsLong("fix_row"), is(1L));
|
70
|
+
assertThat(record.getAsLong("fix_col"), is(2L));
|
71
|
+
}
|
72
|
+
|
73
|
+
@Theory
|
74
|
+
public void testRecordType_column0(String excelFile) throws ParseException {
|
75
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
76
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
77
|
+
|
78
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
79
|
+
parser.set("sheet", "test1");
|
80
|
+
parser.set("record_type", "column");
|
81
|
+
// parser.set("skip_header_lines", 0);
|
82
|
+
parser.addColumn("text", "string").set("cell_row", "5");
|
83
|
+
parser.addColumn("text_row", "long").set("cell_row", "5").set("value", "row_number");
|
84
|
+
parser.addColumn("text_col", "long").set("cell_row", "5").set("value", "column_number");
|
85
|
+
parser.addColumn("text2", "string").set("cell_column", "D");
|
86
|
+
parser.addColumn("text2_row", "long").set("cell_column", "D").set("value", "row_number");
|
87
|
+
parser.addColumn("text2_col", "long").set("cell_column", "D").set("value", "column_number");
|
88
|
+
parser.addColumn("address1", "string").set("cell_address", "B1").set("value", "cell_value");
|
89
|
+
parser.addColumn("address2", "string").set("cell_column", "D").set("cell_row", "2");
|
90
|
+
parser.addColumn("fix_row", "long").set("cell_address", "B1").set("value", "row_number");
|
91
|
+
parser.addColumn("fix_col", "long").set("cell_address", "B1").set("value", "column_number");
|
92
|
+
|
93
|
+
URL inFile = getClass().getResource(excelFile);
|
94
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
95
|
+
|
96
|
+
assertThat(result.size(), is(7));
|
97
|
+
int z = 1;
|
98
|
+
check2(result, 0, z, "true");
|
99
|
+
check2(result, 1, z, "123");
|
100
|
+
check2(result, 2, z, "123.4");
|
101
|
+
check2(result, 3, z, "abc");
|
102
|
+
check2(result, 4, z, "2015/10/07");
|
103
|
+
check2(result, 5, z, null);
|
104
|
+
check2(result, 6, z, "CELL_TYPE_STRING");
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
@Theory
|
109
|
+
public void testRecordType_column1(String excelFile) throws ParseException {
|
110
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
111
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
112
|
+
|
113
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
114
|
+
parser.set("sheet", "test1");
|
115
|
+
parser.set("record_type", "column");
|
116
|
+
parser.set("skip_header_lines", 1);
|
117
|
+
parser.addColumn("text", "string").set("cell_row", "5");
|
118
|
+
parser.addColumn("text_row", "long").set("cell_row", "5").set("value", "row_number");
|
119
|
+
parser.addColumn("text_col", "long").set("cell_row", "5").set("value", "column_number");
|
120
|
+
parser.addColumn("text2", "string").set("cell_column", "D");
|
121
|
+
parser.addColumn("text2_row", "long").set("cell_column", "D").set("value", "row_number");
|
122
|
+
parser.addColumn("text2_col", "long").set("cell_column", "D").set("value", "column_number");
|
123
|
+
parser.addColumn("address1", "string").set("cell_address", "B1").set("value", "cell_value");
|
124
|
+
parser.addColumn("address2", "string").set("cell_column", "D").set("cell_row", "2");
|
125
|
+
parser.addColumn("fix_row", "long").set("cell_address", "B1").set("value", "row_number");
|
126
|
+
parser.addColumn("fix_col", "long").set("cell_address", "B1").set("value", "column_number");
|
127
|
+
|
128
|
+
URL inFile = getClass().getResource(excelFile);
|
129
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
130
|
+
|
131
|
+
assertThat(result.size(), is(6));
|
132
|
+
int z = 2;
|
133
|
+
check2(result, 0, z, "123");
|
134
|
+
check2(result, 1, z, "123.4");
|
135
|
+
check2(result, 2, z, "abc");
|
136
|
+
check2(result, 3, z, "2015/10/07");
|
137
|
+
check2(result, 4, z, null);
|
138
|
+
check2(result, 5, z, "CELL_TYPE_STRING");
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
private void check2(List<OutputRecord> result, int index, int z, String text) {
|
143
|
+
OutputRecord record = result.get(index);
|
144
|
+
// System.out.println(record);
|
145
|
+
assertThat(record.getAsString("text"), is(text));
|
146
|
+
assertThat(record.getAsLong("text_row"), is(5L));
|
147
|
+
assertThat(record.getAsLong("text_col"), is((long) index + z));
|
148
|
+
assertThat(record.getAsString("text2"), is("abc"));
|
149
|
+
assertThat(record.getAsLong("text2_row"), is(6L));
|
150
|
+
assertThat(record.getAsLong("text2_col"), is(4L));
|
151
|
+
assertThat(record.getAsString("address1"), is("long"));
|
152
|
+
assertThat(record.getAsString("address2"), is("abc"));
|
153
|
+
assertThat(record.getAsLong("fix_row"), is(1L));
|
154
|
+
assertThat(record.getAsLong("fix_col"), is(2L));
|
155
|
+
}
|
156
|
+
|
157
|
+
@Theory
|
158
|
+
public void testRecordType_sheet(String excelFile) throws ParseException {
|
159
|
+
try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
|
160
|
+
tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
|
161
|
+
|
162
|
+
EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
|
163
|
+
parser.set("sheet", "style");
|
164
|
+
parser.set("record_type", "sheet");
|
165
|
+
parser.addColumn("text", "string");
|
166
|
+
parser.addColumn("text_row", "long").set("cell_row", "5").set("value", "row_number");
|
167
|
+
parser.addColumn("text_col", "long").set("cell_column", "6").set("value", "column_number");
|
168
|
+
parser.addColumn("address1", "string").set("cell_address", "B1").set("value", "cell_value");
|
169
|
+
parser.addColumn("address2", "string").set("cell_column", "A").set("cell_row", "4");
|
170
|
+
parser.addColumn("fix_row", "long").set("cell_address", "B1").set("value", "row_number");
|
171
|
+
parser.addColumn("fix_col", "long").set("cell_address", "B1").set("value", "column_number");
|
172
|
+
|
173
|
+
URL inFile = getClass().getResource(excelFile);
|
174
|
+
List<OutputRecord> result = tester.runParser(inFile, parser);
|
175
|
+
|
176
|
+
assertThat(result.size(), is(1));
|
177
|
+
check3(result, 0, "red");
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
private void check3(List<OutputRecord> result, int index, String text) {
|
182
|
+
OutputRecord record = result.get(index);
|
183
|
+
// System.out.println(record);
|
184
|
+
assertThat(record.getAsString("text"), is(text));
|
185
|
+
assertThat(record.getAsLong("text_row"), is(5L));
|
186
|
+
assertThat(record.getAsLong("text_col"), is(6L));
|
187
|
+
assertThat(record.getAsString("address1"), is("top"));
|
188
|
+
assertThat(record.getAsString("address2"), is("white"));
|
189
|
+
assertThat(record.getAsLong("fix_row"), is(1L));
|
190
|
+
assertThat(record.getAsLong("fix_col"), is(2L));
|
191
|
+
}
|
192
|
+
}
|