embulk-parser-poi_excel 0.1.11 → 0.1.13
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/LICENSE.txt +21 -21
- data/README.md +247 -233
- data/build.gradle +92 -86
- data/classpath/{embulk-parser-poi_excel-0.1.11.jar → embulk-parser-poi_excel-0.1.13.jar} +0 -0
- data/gradlew +172 -172
- data/src/main/java/org/embulk/parser/poi_excel/PoiExcelColumnValueType.java +23 -3
- data/src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java +38 -23
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java +23 -1
- data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnIndex.java +114 -28
- 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 +55 -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 +18 -9
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java +8 -1
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java +26 -26
- data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorValue.java +28 -1
- data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/CellVisitor.java +9 -0
- data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_recordType.java +192 -0
- metadata +9 -3
@@ -0,0 +1,55 @@
|
|
1
|
+
package org.embulk.parser.poi_excel.bean.record;
|
2
|
+
|
3
|
+
import org.apache.poi.ss.usermodel.Cell;
|
4
|
+
import org.apache.poi.ss.util.CellReference;
|
5
|
+
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
6
|
+
import org.embulk.spi.Exec;
|
7
|
+
import org.slf4j.Logger;
|
8
|
+
|
9
|
+
public class PoiExcelRecordSheet extends PoiExcelRecord {
|
10
|
+
private final Logger log = Exec.getLogger(getClass());
|
11
|
+
|
12
|
+
private boolean exists;
|
13
|
+
|
14
|
+
@Override
|
15
|
+
protected void initializeLoop(int skipHeaderLines) {
|
16
|
+
this.exists = true;
|
17
|
+
}
|
18
|
+
|
19
|
+
@Override
|
20
|
+
public boolean exists() {
|
21
|
+
return exists;
|
22
|
+
}
|
23
|
+
|
24
|
+
@Override
|
25
|
+
public void moveNext() {
|
26
|
+
this.exists = false;
|
27
|
+
}
|
28
|
+
|
29
|
+
@Override
|
30
|
+
protected void logStartEnd(String part) {
|
31
|
+
if (log.isDebugEnabled()) {
|
32
|
+
log.debug("sheet({}) {}", getSheet().getSheetName(), part);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
@Override
|
37
|
+
public int getRowIndex(PoiExcelColumnBean bean) {
|
38
|
+
throw new UnsupportedOperationException("unsupported at record_type=sheet");
|
39
|
+
}
|
40
|
+
|
41
|
+
@Override
|
42
|
+
public int getColumnIndex(PoiExcelColumnBean bean) {
|
43
|
+
throw new UnsupportedOperationException("unsupported at record_type=sheet");
|
44
|
+
}
|
45
|
+
|
46
|
+
@Override
|
47
|
+
public Cell getCell(PoiExcelColumnBean bean) {
|
48
|
+
throw new UnsupportedOperationException("unsupported at record_type=sheet");
|
49
|
+
}
|
50
|
+
|
51
|
+
@Override
|
52
|
+
public CellReference getCellReference(PoiExcelColumnBean bean) {
|
53
|
+
return null;
|
54
|
+
}
|
55
|
+
}
|
@@ -0,0 +1,114 @@
|
|
1
|
+
package org.embulk.parser.poi_excel.bean.record;
|
2
|
+
|
3
|
+
import java.text.MessageFormat;
|
4
|
+
import java.util.ArrayList;
|
5
|
+
import java.util.List;
|
6
|
+
|
7
|
+
import org.embulk.config.ConfigException;
|
8
|
+
import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
|
9
|
+
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
10
|
+
|
11
|
+
import com.google.common.base.Optional;
|
12
|
+
|
13
|
+
public enum RecordType {
|
14
|
+
ROW {
|
15
|
+
@Override
|
16
|
+
public Optional<String> getRecordOption(PoiExcelColumnBean bean) {
|
17
|
+
return bean.getRowNumber();
|
18
|
+
}
|
19
|
+
|
20
|
+
@Override
|
21
|
+
public String getRecordOptionName() {
|
22
|
+
return ColumnOptionTask.CELL_ROW;
|
23
|
+
}
|
24
|
+
|
25
|
+
@Override
|
26
|
+
public Optional<String> getNumberOption(PoiExcelColumnBean bean) {
|
27
|
+
return bean.getColumnNumber();
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public String getNumberOptionName() {
|
32
|
+
return ColumnOptionTask.CELL_COLUMN;
|
33
|
+
}
|
34
|
+
|
35
|
+
@Override
|
36
|
+
public PoiExcelRecord newPoiExcelRecord() {
|
37
|
+
return new PoiExcelRecordRow();
|
38
|
+
}
|
39
|
+
},
|
40
|
+
COLUMN {
|
41
|
+
@Override
|
42
|
+
public Optional<String> getRecordOption(PoiExcelColumnBean bean) {
|
43
|
+
return bean.getColumnNumber();
|
44
|
+
}
|
45
|
+
|
46
|
+
@Override
|
47
|
+
public String getRecordOptionName() {
|
48
|
+
return ColumnOptionTask.CELL_COLUMN;
|
49
|
+
}
|
50
|
+
|
51
|
+
@Override
|
52
|
+
public Optional<String> getNumberOption(PoiExcelColumnBean bean) {
|
53
|
+
return bean.getRowNumber();
|
54
|
+
}
|
55
|
+
|
56
|
+
@Override
|
57
|
+
public String getNumberOptionName() {
|
58
|
+
return ColumnOptionTask.CELL_ROW;
|
59
|
+
}
|
60
|
+
|
61
|
+
@Override
|
62
|
+
public PoiExcelRecord newPoiExcelRecord() {
|
63
|
+
return new PoiExcelRecordColumn();
|
64
|
+
}
|
65
|
+
},
|
66
|
+
SHEET {
|
67
|
+
@Override
|
68
|
+
public Optional<String> getRecordOption(PoiExcelColumnBean bean) {
|
69
|
+
return Optional.absent();
|
70
|
+
}
|
71
|
+
|
72
|
+
@Override
|
73
|
+
public String getRecordOptionName() {
|
74
|
+
return "-";
|
75
|
+
}
|
76
|
+
|
77
|
+
@Override
|
78
|
+
public Optional<String> getNumberOption(PoiExcelColumnBean bean) {
|
79
|
+
return Optional.absent();
|
80
|
+
}
|
81
|
+
|
82
|
+
@Override
|
83
|
+
public String getNumberOptionName() {
|
84
|
+
return "-";
|
85
|
+
}
|
86
|
+
|
87
|
+
@Override
|
88
|
+
public PoiExcelRecord newPoiExcelRecord() {
|
89
|
+
return new PoiExcelRecordSheet();
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
public abstract Optional<String> getRecordOption(PoiExcelColumnBean bean);
|
94
|
+
|
95
|
+
public abstract String getRecordOptionName();
|
96
|
+
|
97
|
+
public abstract Optional<String> getNumberOption(PoiExcelColumnBean bean);
|
98
|
+
|
99
|
+
public abstract String getNumberOptionName();
|
100
|
+
|
101
|
+
public abstract PoiExcelRecord newPoiExcelRecord();
|
102
|
+
|
103
|
+
public static RecordType of(String value) {
|
104
|
+
try {
|
105
|
+
return RecordType.valueOf(value.toUpperCase());
|
106
|
+
} catch (Exception e) {
|
107
|
+
List<String> list = new ArrayList<>();
|
108
|
+
for (RecordType s : RecordType.values()) {
|
109
|
+
list.add(s.name().toLowerCase());
|
110
|
+
}
|
111
|
+
throw new ConfigException(MessageFormat.format("illegal record_type={0}. expected={1}", value, list), e);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
@@ -7,41 +7,50 @@ import org.apache.poi.ss.usermodel.Row;
|
|
7
7
|
import org.apache.poi.ss.usermodel.Sheet;
|
8
8
|
import org.apache.poi.ss.usermodel.Workbook;
|
9
9
|
import org.apache.poi.ss.util.CellReference;
|
10
|
+
import org.embulk.parser.poi_excel.bean.record.PoiExcelRecord;
|
10
11
|
|
11
12
|
public class PoiExcelCellAddress {
|
12
13
|
private final CellReference cellReference;
|
13
14
|
|
14
|
-
public PoiExcelCellAddress(
|
15
|
-
this.cellReference =
|
15
|
+
public PoiExcelCellAddress(CellReference cellReference) {
|
16
|
+
this.cellReference = cellReference;
|
16
17
|
}
|
17
18
|
|
18
19
|
public String getSheetName() {
|
19
20
|
return cellReference.getSheetName();
|
20
21
|
}
|
21
22
|
|
22
|
-
public Sheet getSheet(
|
23
|
+
public Sheet getSheet(PoiExcelRecord record) {
|
23
24
|
String sheetName = getSheetName();
|
24
25
|
if (sheetName != null) {
|
25
|
-
Workbook book =
|
26
|
+
Workbook book = record.getSheet().getWorkbook();
|
26
27
|
Sheet sheet = book.getSheet(sheetName);
|
27
28
|
if (sheet == null) {
|
28
29
|
throw new RuntimeException(MessageFormat.format("not found sheet. sheetName={0}", sheetName));
|
29
30
|
}
|
30
31
|
return sheet;
|
31
32
|
} else {
|
32
|
-
return
|
33
|
+
return record.getSheet();
|
33
34
|
}
|
34
35
|
}
|
35
36
|
|
36
|
-
public
|
37
|
-
|
37
|
+
public int getRowIndex() {
|
38
|
+
return cellReference.getRow();
|
39
|
+
}
|
40
|
+
|
41
|
+
public int getColumnIndex() {
|
42
|
+
return cellReference.getCol();
|
43
|
+
}
|
44
|
+
|
45
|
+
public Cell getCell(PoiExcelRecord record) {
|
46
|
+
Sheet sheet = getSheet(record);
|
38
47
|
|
39
|
-
Row row = sheet.getRow(
|
48
|
+
Row row = sheet.getRow(getRowIndex());
|
40
49
|
if (row == null) {
|
41
50
|
return null;
|
42
51
|
}
|
43
52
|
|
44
|
-
return row.getCell(
|
53
|
+
return row.getCell(getColumnIndex());
|
45
54
|
}
|
46
55
|
|
47
56
|
public String getString() {
|
@@ -13,6 +13,7 @@ import org.apache.poi.ss.usermodel.Row;
|
|
13
13
|
import org.apache.poi.ss.usermodel.Sheet;
|
14
14
|
import org.apache.poi.ss.usermodel.Workbook;
|
15
15
|
import org.apache.poi.ss.util.CellRangeAddress;
|
16
|
+
import org.apache.poi.ss.util.CellReference;
|
16
17
|
import org.embulk.parser.poi_excel.PoiExcelColumnValueType;
|
17
18
|
import org.embulk.parser.poi_excel.PoiExcelParserPlugin.FormulaReplaceTask;
|
18
19
|
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
@@ -159,7 +160,13 @@ public class PoiExcelCellValueVisitor {
|
|
159
160
|
String regex = replace.getRegex();
|
160
161
|
String replacement = replace.getTo();
|
161
162
|
|
162
|
-
|
163
|
+
if (replacement.contains("${row}")) {
|
164
|
+
replacement = replacement.replace("${row}", Integer.toString(cell.getRowIndex() + 1));
|
165
|
+
}
|
166
|
+
if (replacement.contains("${column}")) {
|
167
|
+
replacement = replacement.replace("${column}",
|
168
|
+
CellReference.convertNumToColString(cell.getColumnIndex() + 1));
|
169
|
+
}
|
163
170
|
|
164
171
|
formula = formula.replaceAll(regex, replacement);
|
165
172
|
}
|
@@ -4,11 +4,11 @@ import java.text.MessageFormat;
|
|
4
4
|
|
5
5
|
import org.apache.poi.ss.usermodel.Cell;
|
6
6
|
import org.apache.poi.ss.usermodel.CellType;
|
7
|
-
import org.apache.poi.ss.usermodel.Row;
|
8
7
|
import org.apache.poi.ss.usermodel.Sheet;
|
9
8
|
import org.apache.poi.ss.util.CellReference;
|
10
9
|
import org.embulk.parser.poi_excel.PoiExcelColumnValueType;
|
11
10
|
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
11
|
+
import org.embulk.parser.poi_excel.bean.record.PoiExcelRecord;
|
12
12
|
import org.embulk.parser.poi_excel.bean.util.PoiExcelCellAddress;
|
13
13
|
import org.embulk.parser.poi_excel.visitor.embulk.CellVisitor;
|
14
14
|
import org.embulk.spi.Column;
|
@@ -24,7 +24,7 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
24
24
|
protected final PageBuilder pageBuilder;
|
25
25
|
protected final PoiExcelVisitorFactory factory;
|
26
26
|
|
27
|
-
protected
|
27
|
+
protected PoiExcelRecord record;
|
28
28
|
|
29
29
|
public PoiExcelColumnVisitor(PoiExcelVisitorValue visitorValue) {
|
30
30
|
this.visitorValue = visitorValue;
|
@@ -32,8 +32,8 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
32
32
|
this.factory = visitorValue.getVisitorFactory();
|
33
33
|
}
|
34
34
|
|
35
|
-
public void
|
36
|
-
this.
|
35
|
+
public void setRecord(PoiExcelRecord record) {
|
36
|
+
this.record = record;
|
37
37
|
}
|
38
38
|
|
39
39
|
@Override
|
@@ -69,10 +69,17 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
69
69
|
visitCell(column, visitor);
|
70
70
|
} catch (Exception e) {
|
71
71
|
String sheetName = visitorValue.getSheet().getSheetName();
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
CellReference ref = record.getCellReference(visitorValue.getColumnBean(column));
|
73
|
+
|
74
|
+
String message;
|
75
|
+
if (ref != null) {
|
76
|
+
message = MessageFormat.format("error at {0} cell={1}!{2}. {3}", column, sheetName,
|
77
|
+
ref.formatAsString(), e.getMessage());
|
78
|
+
} else {
|
79
|
+
message = MessageFormat.format("error at {0} sheet={1}. {2}", column, sheetName, e.getMessage());
|
80
|
+
}
|
81
|
+
|
82
|
+
throw new RuntimeException(message, e);
|
76
83
|
}
|
77
84
|
if (log.isTraceEnabled()) {
|
78
85
|
log.trace("{} end", column);
|
@@ -85,9 +92,12 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
85
92
|
PoiExcelCellAddress cellAddress = bean.getCellAddress();
|
86
93
|
|
87
94
|
switch (valueType) {
|
95
|
+
case FILE_NAME:
|
96
|
+
visitor.visitFileName(column);
|
97
|
+
return;
|
88
98
|
case SHEET_NAME:
|
89
99
|
if (cellAddress != null) {
|
90
|
-
Sheet sheet = cellAddress.getSheet(
|
100
|
+
Sheet sheet = cellAddress.getSheet(record);
|
91
101
|
visitor.visitSheetName(column, sheet);
|
92
102
|
} else {
|
93
103
|
visitor.visitSheetName(column);
|
@@ -96,28 +106,18 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
96
106
|
case ROW_NUMBER:
|
97
107
|
int rowIndex;
|
98
108
|
if (cellAddress != null) {
|
99
|
-
|
100
|
-
if (cell == null) {
|
101
|
-
visitCellNull(column);
|
102
|
-
return;
|
103
|
-
}
|
104
|
-
rowIndex = cell.getRowIndex();
|
109
|
+
rowIndex = cellAddress.getRowIndex();
|
105
110
|
} else {
|
106
|
-
rowIndex =
|
111
|
+
rowIndex = record.getRowIndex(bean);
|
107
112
|
}
|
108
113
|
visitor.visitRowNumber(column, rowIndex + 1);
|
109
114
|
return;
|
110
115
|
case COLUMN_NUMBER:
|
111
116
|
int columnIndex;
|
112
117
|
if (cellAddress != null) {
|
113
|
-
|
114
|
-
if (cell == null) {
|
115
|
-
visitCellNull(column);
|
116
|
-
return;
|
117
|
-
}
|
118
|
-
columnIndex = cell.getColumnIndex();
|
118
|
+
columnIndex = cellAddress.getColumnIndex();
|
119
119
|
} else {
|
120
|
-
columnIndex =
|
120
|
+
columnIndex = record.getColumnIndex(bean);
|
121
121
|
}
|
122
122
|
visitor.visitColumnNumber(column, columnIndex + 1);
|
123
123
|
return;
|
@@ -128,12 +128,12 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
|
|
128
128
|
break;
|
129
129
|
}
|
130
130
|
|
131
|
-
assert valueType.useCell();
|
131
|
+
// assert valueType.useCell();
|
132
132
|
Cell cell;
|
133
133
|
if (cellAddress != null) {
|
134
|
-
cell = cellAddress.getCell(
|
134
|
+
cell = cellAddress.getCell(record);
|
135
135
|
} else {
|
136
|
-
cell =
|
136
|
+
cell = record.getCell(bean);
|
137
137
|
}
|
138
138
|
if (cell == null) {
|
139
139
|
visitCellNull(column);
|
@@ -1,22 +1,27 @@
|
|
1
1
|
package org.embulk.parser.poi_excel.visitor;
|
2
2
|
|
3
|
+
import java.lang.reflect.Method;
|
4
|
+
|
3
5
|
import org.apache.poi.ss.usermodel.Sheet;
|
4
6
|
import org.embulk.parser.poi_excel.PoiExcelParserPlugin.PluginTask;
|
5
7
|
import org.embulk.parser.poi_excel.bean.PoiExcelColumnBean;
|
6
8
|
import org.embulk.parser.poi_excel.bean.PoiExcelSheetBean;
|
7
9
|
import org.embulk.spi.Column;
|
10
|
+
import org.embulk.spi.FileInput;
|
8
11
|
import org.embulk.spi.PageBuilder;
|
9
12
|
import org.embulk.spi.Schema;
|
10
13
|
|
11
14
|
public class PoiExcelVisitorValue {
|
12
15
|
private final PluginTask task;
|
16
|
+
private final FileInput input;
|
13
17
|
private final Sheet sheet;
|
14
18
|
private final PageBuilder pageBuilder;
|
15
19
|
private final PoiExcelSheetBean sheetBean;
|
16
20
|
private PoiExcelVisitorFactory factory;
|
17
21
|
|
18
|
-
public PoiExcelVisitorValue(PluginTask task, Schema schema, Sheet sheet, PageBuilder pageBuilder) {
|
22
|
+
public PoiExcelVisitorValue(PluginTask task, Schema schema, FileInput input, Sheet sheet, PageBuilder pageBuilder) {
|
19
23
|
this.task = task;
|
24
|
+
this.input = input;
|
20
25
|
this.sheet = sheet;
|
21
26
|
this.pageBuilder = pageBuilder;
|
22
27
|
this.sheetBean = new PoiExcelSheetBean(task, schema, sheet);
|
@@ -26,6 +31,28 @@ public class PoiExcelVisitorValue {
|
|
26
31
|
return task;
|
27
32
|
}
|
28
33
|
|
34
|
+
private Method hintOfCurrentInputFileNameForLogging;
|
35
|
+
private Method optional_orElse;
|
36
|
+
|
37
|
+
public String getFileName() {
|
38
|
+
if (hintOfCurrentInputFileNameForLogging == null) {
|
39
|
+
try {
|
40
|
+
this.hintOfCurrentInputFileNameForLogging = FileInput.class
|
41
|
+
.getMethod("hintOfCurrentInputFileNameForLogging");
|
42
|
+
this.optional_orElse = Class.forName("java.util.Optional").getMethod("orElse", Object.class);
|
43
|
+
} catch (Exception e) {
|
44
|
+
throw new RuntimeException("use Embulk 0.9.12 or later for value=file_name", e);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
try {
|
49
|
+
Object fileNameOption = hintOfCurrentInputFileNameForLogging.invoke(input);
|
50
|
+
return (String) optional_orElse.invoke(fileNameOption, (String) null);
|
51
|
+
} catch (Exception e) {
|
52
|
+
throw new RuntimeException(e);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
29
56
|
public Sheet getSheet() {
|
30
57
|
return sheet;
|
31
58
|
}
|
@@ -39,6 +39,15 @@ public abstract class CellVisitor {
|
|
39
39
|
|
40
40
|
public abstract void visitValueLong(Column column, Object source, long value);
|
41
41
|
|
42
|
+
public void visitFileName(Column column) {
|
43
|
+
String fileName = visitorValue.getFileName();
|
44
|
+
if (fileName == null) {
|
45
|
+
pageBuilder.setNull(column);
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
visitCellValueString(column, null, fileName);
|
49
|
+
}
|
50
|
+
|
42
51
|
public abstract void visitSheetName(Column column);
|
43
52
|
|
44
53
|
public abstract void visitSheetName(Column column, Sheet sheet);
|
@@ -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
|
+
}
|
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.13
|
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: 2023-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +52,7 @@ files:
|
|
52
52
|
- classpath/commons-codec-1.10.jar
|
53
53
|
- classpath/commons-collections4-4.1.jar
|
54
54
|
- classpath/curvesapi-1.04.jar
|
55
|
-
- classpath/embulk-parser-poi_excel-0.1.
|
55
|
+
- classpath/embulk-parser-poi_excel-0.1.13.jar
|
56
56
|
- classpath/embulk-standards-0.7.5.jar
|
57
57
|
- classpath/poi-3.17.jar
|
58
58
|
- classpath/poi-ooxml-3.17.jar
|
@@ -69,6 +69,11 @@ files:
|
|
69
69
|
- src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java
|
70
70
|
- src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnIndex.java
|
71
71
|
- src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelSheetBean.java
|
72
|
+
- src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecord.java
|
73
|
+
- src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecordColumn.java
|
74
|
+
- src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecordRow.java
|
75
|
+
- src/main/java/org/embulk/parser/poi_excel/bean/record/PoiExcelRecordSheet.java
|
76
|
+
- src/main/java/org/embulk/parser/poi_excel/bean/record/RecordType.java
|
72
77
|
- src/main/java/org/embulk/parser/poi_excel/bean/util/PoiExcelCellAddress.java
|
73
78
|
- src/main/java/org/embulk/parser/poi_excel/bean/util/SearchMergedCell.java
|
74
79
|
- src/main/java/org/embulk/parser/poi_excel/visitor/AbstractPoiExcelCellAttributeVisitor.java
|
@@ -108,6 +113,7 @@ files:
|
|
108
113
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_convertError.java
|
109
114
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_formula.java
|
110
115
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_mergedCell.java
|
116
|
+
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_recordType.java
|
111
117
|
- src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_sheets.java
|
112
118
|
- src/test/resources/org/embulk/parser/poi_excel/test1.xls
|
113
119
|
- src/test/resources/org/embulk/parser/poi_excel/test2.xlsx
|