embulk-parser-poi_excel 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9eabdb80c2cf4ef399fd2d9b0ec1f255cdda7ee1
4
- data.tar.gz: 3b3ec43a2141a303fd234439aeef7ce2bd1da7ae
3
+ metadata.gz: 17272dd82557dd34357f3407c8d4eb7658e31ed2
4
+ data.tar.gz: e135d924eae7de15e5da96c381511a38f2d35426
5
5
  SHA512:
6
- metadata.gz: f93efdbd29139564ee732ebcae17a7ecbec39b03ab9f6a161ae7ffc172760386d21c1f26aa36b399ca286b8ec315b6cd849dda3960e353085c64cbf627738b41
7
- data.tar.gz: 95822b832a14fdba92b2181f178d93abff62e2dd25daeadbc4ddb4ee37cb958ca5d649c56f20f9f1c50f410e67f9fc398af28dd1adc1337204bfb91824befb15
6
+ metadata.gz: 7922a700f58a63aefb895334ab5483da14e4f1c36dce2beac9868de28e8c61f88ce34487c660f804d9540b176afcf73258d12c9035867271d6a020ccfe63d217
7
+ data.tar.gz: 4908655995c8abe3dc4bd552defb4a8142eecd093ebd5bb0b728f06030737d764e2851a31bfa479d87d3469b61a18d8beef57cc0cd40f919c34538aefd9e056a
data/README.md CHANGED
@@ -10,7 +10,7 @@ This plugin uses Apache POI.
10
10
 
11
11
  ## Configuration
12
12
 
13
- * **sheet**: sheet name. (string, default: `Sheet1`)
13
+ * **sheets**: sheet name. (list of string, required)
14
14
  * **skip_header_lines**: skip rows. (integer, default: `0`)
15
15
  * **columns**: column definition. see below. (hash, required)
16
16
 
@@ -24,14 +24,14 @@ This plugin uses Apache POI.
24
24
 
25
25
  ### value
26
26
 
27
- * **cell_value**: value in cell.
28
- * **cell_formula**: formula in cell. (if cell is not formula, same `cell_value`.)
29
- * **cell_style**: all cell style attributes. returned json string. see **attribute_name**. (**type** required `string`)
30
- * **cell_font**: all cell font attributes. returned json string. see **attribute_name**. (**type** required `string`)
31
- * **cell_comment**: all cell comment attributes. returned json string. see **attribute_name**. (**type** required `string`)
32
- * **sheet_name**: sheet name.
33
- * **row_number**: row number(1 origin).
34
- * **column_number**: column number(1 origin).
27
+ * `cell_value`: value in cell.
28
+ * `cell_formula`: formula in cell. (if cell is not formula, same `cell_value`.)
29
+ * `cell_style`: all cell style attributes. returned json string. see **attribute_name**. (**type** required `string`)
30
+ * `cell_font`: all cell font attributes. returned json string. see **attribute_name**. (**type** required `string`)
31
+ * `cell_comment`: all cell comment attributes. returned json string. see **attribute_name**. (**type** required `string`)
32
+ * `sheet_name`: sheet name.
33
+ * `row_number`: row number(1 origin).
34
+ * `column_number`: column number(1 origin).
35
35
 
36
36
  ### column_number
37
37
 
@@ -87,7 +87,7 @@ in:
87
87
  type: any file input plugin type
88
88
  parser:
89
89
  type: poi_excel
90
- sheet: "DQ10-orb"
90
+ sheets: ["DQ10-orb"]
91
91
  skip_header_lines: 1 # first row is header.
92
92
  columns:
93
93
  - {name: row, type: long, value: row_number}
@@ -102,17 +102,14 @@ if omit `value`, specified `cell_value`.
102
102
  if omit `column_number` when valus is `cell_value`, specified next column.
103
103
  if omit `column_number` when valus is `cell_style`, specified same column.
104
104
 
105
- ### execute
105
+
106
+ ## Install
106
107
 
107
108
  ```
108
- $ cd ~/your-workspace
109
- $ git clone https://github.com/hishidama/embulk-parser-poi_excel.git
110
- $ cd embulk-parser-poi_excel
111
- $ ./gradlew package
112
- $ cd /your-embulk-working-dir
113
- $ embulk run -L ~/your-workspace/embulk-parser-poi_excel config.yml
109
+ $ embulk gem install embulk-parser-poi_excel
114
110
  ```
115
111
 
112
+
116
113
  ## Build
117
114
 
118
115
  ```
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.1.0"
16
+ version = "0.1.1"
17
17
 
18
18
  dependencies {
19
19
  compile "org.embulk:embulk-core:0.7.5"
@@ -1,6 +1,7 @@
1
1
  package org.embulk.parser.poi_excel;
2
2
 
3
3
  import java.io.IOException;
4
+ import java.util.ArrayList;
4
5
  import java.util.List;
5
6
 
6
7
  import org.apache.poi.EncryptedDocumentException;
@@ -11,6 +12,7 @@ import org.apache.poi.ss.usermodel.Workbook;
11
12
  import org.apache.poi.ss.usermodel.WorkbookFactory;
12
13
  import org.embulk.config.Config;
13
14
  import org.embulk.config.ConfigDefault;
15
+ import org.embulk.config.ConfigException;
14
16
  import org.embulk.config.ConfigSource;
15
17
  import org.embulk.config.Task;
16
18
  import org.embulk.config.TaskSource;
@@ -26,18 +28,28 @@ import org.embulk.spi.Schema;
26
28
  import org.embulk.spi.SchemaConfig;
27
29
  import org.embulk.spi.time.TimestampParser;
28
30
  import org.embulk.spi.util.FileInputInputStream;
31
+ import org.slf4j.Logger;
29
32
 
30
33
  import com.google.common.base.Optional;
31
34
  import com.ibm.icu.text.MessageFormat;
32
35
 
33
36
  public class PoiExcelParserPlugin implements ParserPlugin {
37
+ private final Logger log = Exec.getLogger(getClass());
34
38
 
35
39
  public static final String TYPE = "poi_excel";
36
40
 
37
41
  public interface PluginTask extends Task, TimestampParser.Task {
38
42
  @Config("sheet")
39
- @ConfigDefault("\"Sheet1\"")
40
- public String getSheet();
43
+ @ConfigDefault("null")
44
+ public Optional<String> getSheet();
45
+
46
+ @Config("sheets")
47
+ @ConfigDefault("[]")
48
+ public List<String> getSheets();
49
+
50
+ @Config("ignore_sheet_not_found")
51
+ @ConfigDefault("false")
52
+ public boolean getIgnoreSheetNotFound();
41
53
 
42
54
  @Config("skip_header_lines")
43
55
  @ConfigDefault("0")
@@ -145,6 +157,16 @@ public class PoiExcelParserPlugin implements ParserPlugin {
145
157
  public void run(TaskSource taskSource, Schema schema, FileInput input, PageOutput output) {
146
158
  PluginTask task = taskSource.loadTask(PluginTask.class);
147
159
 
160
+ List<String> sheetNames = new ArrayList<>();
161
+ Optional<String> sheetOption = task.getSheet();
162
+ if (sheetOption.isPresent()) {
163
+ sheetNames.add(sheetOption.get());
164
+ }
165
+ sheetNames.addAll(task.getSheets());
166
+ if (sheetNames.isEmpty()) {
167
+ throw new ConfigException("Attribute sheets is required but not set");
168
+ }
169
+
148
170
  try (FileInputInputStream is = new FileInputInputStream(input)) {
149
171
  while (is.nextFile()) {
150
172
  Workbook workbook;
@@ -154,39 +176,47 @@ public class PoiExcelParserPlugin implements ParserPlugin {
154
176
  throw new RuntimeException(e);
155
177
  }
156
178
 
157
- String sheetName = task.getSheet();
158
- Sheet sheet = workbook.getSheet(sheetName);
159
- if (sheet == null) {
160
- throw new RuntimeException(MessageFormat.format("not found sheet={0}", sheetName));
161
- }
162
-
163
- run(task, schema, sheet, output);
179
+ run(task, schema, workbook, sheetNames, output);
164
180
  }
165
181
  }
166
182
  }
167
183
 
168
- protected void run(PluginTask task, Schema schema, Sheet sheet, PageOutput output) {
184
+ protected void run(PluginTask task, Schema schema, Workbook workbook, List<String> sheetNames, PageOutput output) {
169
185
  int skipHeaderLines = task.getSkipHeaderLines();
170
186
  final int flushCount = task.getFlushCount();
171
187
 
172
- try (final PageBuilder pageBuilder = new PageBuilder(Exec.getBufferAllocator(), schema, output)) {
173
- PoiExcelVisitorFactory factory = newPoiExcelVisitorFactory(task, sheet, pageBuilder);
174
- PoiExcelColumnVisitor visitor = factory.getPoiExcelColumnVisitor();
175
-
176
- int count = 0;
177
- for (final Row row : sheet) {
178
- if (row.getRowNum() < skipHeaderLines) {
179
- continue;
188
+ try (PageBuilder pageBuilder = new PageBuilder(Exec.getBufferAllocator(), schema, output)) {
189
+ for (String sheetName : sheetNames) {
190
+ Sheet sheet = workbook.getSheet(sheetName);
191
+ if (sheet == null) {
192
+ if (task.getIgnoreSheetNotFound()) {
193
+ log.info("ignore: not found sheet={}", sheetName);
194
+ continue;
195
+ } else {
196
+ throw new RuntimeException(MessageFormat.format("not found sheet={0}", sheetName));
197
+ }
180
198
  }
181
199
 
182
- visitor.setRow(row);
183
- schema.visitColumns(visitor);
184
- pageBuilder.addRecord();
200
+ log.info("sheet={}", sheetName);
201
+ PoiExcelVisitorFactory factory = newPoiExcelVisitorFactory(task, sheet, pageBuilder);
202
+ PoiExcelColumnVisitor visitor = factory.getPoiExcelColumnVisitor();
203
+
204
+ int count = 0;
205
+ for (Row row : sheet) {
206
+ if (row.getRowNum() < skipHeaderLines) {
207
+ continue;
208
+ }
209
+
210
+ visitor.setRow(row);
211
+ schema.visitColumns(visitor);
212
+ pageBuilder.addRecord();
185
213
 
186
- if (++count >= flushCount) {
187
- pageBuilder.flush();
188
- count = 0;
214
+ if (++count >= flushCount) {
215
+ pageBuilder.flush();
216
+ count = 0;
217
+ }
189
218
  }
219
+ pageBuilder.flush();
190
220
  }
191
221
  pageBuilder.finish();
192
222
  }
@@ -48,7 +48,7 @@ public abstract class AbstractPoiExcelCellAttributeVisitor<A> {
48
48
  protected abstract A getAttributeSource(Column column, ColumnOptionTask option, Cell cell);
49
49
 
50
50
  private void visitKey(Column column, ColumnOptionTask option, String key, Cell cell, A source, CellVisitor visitor) {
51
- Object value = getAttributeValue(column, option, cell, source, key);
51
+ Object value = getAttributeValue(column, cell, source, key);
52
52
  if (value == null) {
53
53
  pageBuilder.setNull(column);
54
54
  } else if (value instanceof String) {
@@ -59,6 +59,8 @@ public abstract class AbstractPoiExcelCellAttributeVisitor<A> {
59
59
  visitor.visitCellValueBoolean(column, source, (Boolean) value);
60
60
  } else if (value instanceof Double) {
61
61
  visitor.visitCellValueNumeric(column, source, (Double) value);
62
+ } else if (value instanceof Map) {
63
+ visitor.visitCellValueString(column, source, convertJsonString(value));
62
64
  } else {
63
65
  throw new IllegalStateException(MessageFormat.format("unsupported conversion. type={0}, value={1}", value
64
66
  .getClass().getName(), value));
@@ -70,41 +72,46 @@ public abstract class AbstractPoiExcelCellAttributeVisitor<A> {
70
72
 
71
73
  Optional<List<String>> nameOption = option.getAttributeName();
72
74
  if (nameOption.isPresent()) {
73
- result = new LinkedHashMap<>();
74
-
75
75
  List<String> list = nameOption.get();
76
- for (String key : list) {
77
- Object value = getAttributeValue(column, option, cell, source, key);
78
- result.put(key, value);
79
- }
76
+ result = getSpecifiedValues(column, cell, source, list);
80
77
  } else {
81
- result = new TreeMap<>();
82
-
83
- Collection<String> keys = getAttributeSupplierMap().keySet();
84
- for (String key : keys) {
85
- if (acceptKey(key)) {
86
- Object value = getAttributeValue(column, option, cell, source, key);
87
- result.put(key, value);
88
- }
89
- }
78
+ result = getAllValues(column, cell, source);
90
79
  }
91
80
 
92
- String json;
93
- try {
94
- ObjectMapper mapper = new ObjectMapper();
95
- json = mapper.writeValueAsString(result);
96
- } catch (JsonProcessingException e) {
97
- throw new RuntimeException(e);
81
+ String json = convertJsonString(result);
82
+ visitor.visitCellValueString(column, cell, json);
83
+ }
84
+
85
+ protected final Map<String, Object> getSpecifiedValues(Column column, Cell cell, A source, List<String> keyList) {
86
+ Map<String, Object> result = new LinkedHashMap<>();
87
+
88
+ for (String key : keyList) {
89
+ Object value = getAttributeValue(column, cell, source, key);
90
+ result.put(key, value);
98
91
  }
99
92
 
100
- visitor.visitCellValueString(column, cell, json);
93
+ return result;
94
+ }
95
+
96
+ protected final Map<String, Object> getAllValues(Column column, Cell cell, A source) {
97
+ Map<String, Object> result = new TreeMap<>();
98
+
99
+ Collection<String> keys = getAttributeSupplierMap().keySet();
100
+ for (String key : keys) {
101
+ if (acceptKey(key)) {
102
+ Object value = getAttributeValue(column, cell, source, key);
103
+ result.put(key, value);
104
+ }
105
+ }
106
+
107
+ return result;
101
108
  }
102
109
 
103
110
  protected boolean acceptKey(String key) {
104
111
  return true;
105
112
  }
106
113
 
107
- private Object getAttributeValue(Column column, ColumnOptionTask option, Cell cell, A source, String key) {
114
+ protected final Object getAttributeValue(Column column, Cell cell, A source, String key) {
108
115
  Map<String, AttributeSupplier<A>> map = getAttributeSupplierMap();
109
116
  AttributeSupplier<A> supplier = map.get(key.toLowerCase());
110
117
  if (supplier == null) {
@@ -130,4 +137,13 @@ public abstract class AbstractPoiExcelCellAttributeVisitor<A> {
130
137
  }
131
138
 
132
139
  protected abstract Map<String, AttributeSupplier<A>> getAttributeSupplierMap();
140
+
141
+ protected final String convertJsonString(Object result) {
142
+ try {
143
+ ObjectMapper mapper = new ObjectMapper();
144
+ return mapper.writeValueAsString(result);
145
+ } catch (JsonProcessingException e) {
146
+ throw new RuntimeException(e);
147
+ }
148
+ }
133
149
  }
@@ -5,6 +5,7 @@ import java.util.HashMap;
5
5
  import java.util.Map;
6
6
 
7
7
  import org.apache.poi.ss.usermodel.Cell;
8
+ import org.apache.poi.ss.usermodel.ClientAnchor;
8
9
  import org.apache.poi.ss.usermodel.Comment;
9
10
  import org.apache.poi.ss.usermodel.RichTextString;
10
11
  import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
@@ -21,13 +22,20 @@ public class PoiExcelCellCommentVisitor extends AbstractPoiExcelCellAttributeVis
21
22
  return cell.getCellComment();
22
23
  }
23
24
 
25
+ protected boolean acceptKey(String key) {
26
+ if (key.equals("client_anchor")) {
27
+ return false;
28
+ }
29
+ return true;
30
+ }
31
+
24
32
  @Override
25
33
  protected Map<String, AttributeSupplier<Comment>> getAttributeSupplierMap() {
26
34
  return SUPPLIER_MAP;
27
35
  }
28
36
 
29
- protected static final Map<String, AttributeSupplier<Comment>> SUPPLIER_MAP;
30
- static {
37
+ private final Map<String, AttributeSupplier<Comment>> SUPPLIER_MAP;
38
+ {
31
39
  Map<String, AttributeSupplier<Comment>> map = new HashMap<>(32);
32
40
  map.put("author", new AttributeSupplier<Comment>() {
33
41
  @Override
@@ -60,9 +68,27 @@ public class PoiExcelCellCommentVisitor extends AbstractPoiExcelCellAttributeVis
60
68
  return rich.getString();
61
69
  }
62
70
  });
63
-
64
- // TODO getClientAnchor
65
-
71
+ map.put("client_anchor", new AttributeSupplier<Comment>() {
72
+ @Override
73
+ public Object get(Column column, Cell cell, Comment comment) {
74
+ return getClientAnchorValue(column, cell, comment, null);
75
+ }
76
+ });
77
+ for (String key : PoiExcelClientAnchorVisitor.getKeys()) {
78
+ map.put("client_anchor." + key, new AttributeSupplier<Comment>() {
79
+ @Override
80
+ public Object get(Column column, Cell cell, Comment comment) {
81
+ return getClientAnchorValue(column, cell, comment, key);
82
+ }
83
+ });
84
+ }
66
85
  SUPPLIER_MAP = Collections.unmodifiableMap(map);
67
86
  }
87
+
88
+ final Object getClientAnchorValue(Column column, Cell cell, Comment comment, String key) {
89
+ ClientAnchor anchor = comment.getClientAnchor();
90
+ PoiExcelVisitorFactory factory = visitorValue.getVisitorFactory();
91
+ PoiExcelClientAnchorVisitor delegator = factory.getPoiExcelClientAnchorVisitor();
92
+ return delegator.getClientAnchorValue(column, cell, anchor, key);
93
+ }
68
94
  }
@@ -31,7 +31,7 @@ public class PoiExcelCellFontVisitor extends AbstractPoiExcelCellAttributeVisito
31
31
  return SUPPLIER_MAP;
32
32
  }
33
33
 
34
- protected static final Map<String, AttributeSupplier<Font>> SUPPLIER_MAP;
34
+ private static final Map<String, AttributeSupplier<Font>> SUPPLIER_MAP;
35
35
  static {
36
36
  Map<String, AttributeSupplier<Font>> map = new HashMap<>(32);
37
37
  map.put("font_name", new AttributeSupplier<Font>() {
@@ -35,8 +35,7 @@ public class PoiExcelCellStyleVisitor extends AbstractPoiExcelCellAttributeVisit
35
35
  return SUPPLIER_MAP;
36
36
  }
37
37
 
38
- protected static final Map<String, AttributeSupplier<CellStyle>> SUPPLIER_MAP;
39
-
38
+ private static final Map<String, AttributeSupplier<CellStyle>> SUPPLIER_MAP;
40
39
  static {
41
40
  Map<String, AttributeSupplier<CellStyle>> map = new HashMap<>(32);
42
41
  map.put("alignment", new AttributeSupplier<CellStyle>() {
@@ -23,13 +23,13 @@ import org.slf4j.Logger;
23
23
 
24
24
  import com.google.common.base.Optional;
25
25
 
26
- public class PoiExcelCellVisitor {
26
+ public class PoiExcelCellValueVisitor {
27
27
  private final Logger log = Exec.getLogger(getClass());
28
28
 
29
29
  protected final PoiExcelVisitorValue visitorValue;
30
30
  protected final PageBuilder pageBuilder;
31
31
 
32
- public PoiExcelCellVisitor(PoiExcelVisitorValue visitorValue) {
32
+ public PoiExcelCellValueVisitor(PoiExcelVisitorValue visitorValue) {
33
33
  this.visitorValue = visitorValue;
34
34
  this.pageBuilder = visitorValue.getPageBuilder();
35
35
  }
@@ -0,0 +1,100 @@
1
+ package org.embulk.parser.poi_excel.visitor;
2
+
3
+ import java.util.Collection;
4
+ import java.util.Collections;
5
+ import java.util.HashMap;
6
+ import java.util.Map;
7
+
8
+ import org.apache.poi.ss.usermodel.Cell;
9
+ import org.apache.poi.ss.usermodel.ClientAnchor;
10
+ import org.embulk.parser.poi_excel.PoiExcelParserPlugin.ColumnOptionTask;
11
+ import org.embulk.spi.Column;
12
+
13
+ public class PoiExcelClientAnchorVisitor extends AbstractPoiExcelCellAttributeVisitor<ClientAnchor> {
14
+
15
+ public PoiExcelClientAnchorVisitor(PoiExcelVisitorValue visitorValue) {
16
+ super(visitorValue);
17
+ }
18
+
19
+ public Object getClientAnchorValue(Column column, Cell cell, ClientAnchor anchor, String key) {
20
+ if (key == null || key.isEmpty()) {
21
+ return getAllValues(column, cell, anchor);
22
+ }
23
+
24
+ return getAttributeValue(column, cell, anchor, key);
25
+ }
26
+
27
+ @Override
28
+ protected ClientAnchor getAttributeSource(Column column, ColumnOptionTask option, Cell cell) {
29
+ throw new UnsupportedOperationException();
30
+ }
31
+
32
+ @Override
33
+ protected Map<String, AttributeSupplier<ClientAnchor>> getAttributeSupplierMap() {
34
+ return SUPPLIER_MAP;
35
+ }
36
+
37
+ private static final Map<String, AttributeSupplier<ClientAnchor>> SUPPLIER_MAP;
38
+ static {
39
+ Map<String, AttributeSupplier<ClientAnchor>> map = new HashMap<>(16);
40
+ map.put("anchor_type", new AttributeSupplier<ClientAnchor>() {
41
+ @Override
42
+ public Object get(Column column, Cell cell, ClientAnchor anchor) {
43
+ return (long) anchor.getAnchorType();
44
+ }
45
+ });
46
+ map.put("col1", new AttributeSupplier<ClientAnchor>() {
47
+ @Override
48
+ public Object get(Column column, Cell cell, ClientAnchor anchor) {
49
+ return (long) anchor.getCol1();
50
+ }
51
+ });
52
+ map.put("col2", new AttributeSupplier<ClientAnchor>() {
53
+ @Override
54
+ public Object get(Column column, Cell cell, ClientAnchor anchor) {
55
+ return (long) anchor.getCol2();
56
+ }
57
+ });
58
+ map.put("dx1", new AttributeSupplier<ClientAnchor>() {
59
+ @Override
60
+ public Object get(Column column, Cell cell, ClientAnchor anchor) {
61
+ return (long) anchor.getDx1();
62
+ }
63
+ });
64
+ map.put("dx2", new AttributeSupplier<ClientAnchor>() {
65
+ @Override
66
+ public Object get(Column column, Cell cell, ClientAnchor anchor) {
67
+ return (long) anchor.getDx2();
68
+ }
69
+ });
70
+ map.put("dy1", new AttributeSupplier<ClientAnchor>() {
71
+ @Override
72
+ public Object get(Column column, Cell cell, ClientAnchor anchor) {
73
+ return (long) anchor.getDy1();
74
+ }
75
+ });
76
+ map.put("dy2", new AttributeSupplier<ClientAnchor>() {
77
+ @Override
78
+ public Object get(Column column, Cell cell, ClientAnchor anchor) {
79
+ return (long) anchor.getDy2();
80
+ }
81
+ });
82
+ map.put("row1", new AttributeSupplier<ClientAnchor>() {
83
+ @Override
84
+ public Object get(Column column, Cell cell, ClientAnchor anchor) {
85
+ return (long) anchor.getRow1();
86
+ }
87
+ });
88
+ map.put("row2", new AttributeSupplier<ClientAnchor>() {
89
+ @Override
90
+ public Object get(Column column, Cell cell, ClientAnchor anchor) {
91
+ return (long) anchor.getRow2();
92
+ }
93
+ });
94
+ SUPPLIER_MAP = Collections.unmodifiableMap(map);
95
+ }
96
+
97
+ public static Collection<String> getKeys() {
98
+ return SUPPLIER_MAP.keySet();
99
+ }
100
+ }
@@ -54,6 +54,8 @@ public class PoiExcelColumnIndex {
54
54
  CellReference.convertNumToColString(index), valueType);
55
55
  option.setColumnIndex(index);
56
56
  indexMap.put(column.getName(), index);
57
+ } else {
58
+ log.info("column.name={} <- value_type={}", column.getName(), valueType);
57
59
  }
58
60
  }
59
61
  }
@@ -125,7 +125,7 @@ public class PoiExcelColumnVisitor implements ColumnVisitor {
125
125
  }
126
126
 
127
127
  private void visitCellValue(Column column, ColumnOptionTask option, Cell cell, CellVisitor visitor) {
128
- PoiExcelCellVisitor delegator = factory.getPoiExcelCellVisitor();
128
+ PoiExcelCellValueVisitor delegator = factory.getPoiExcelCellValueVisitor();
129
129
  delegator.visitCellValue(column, option, cell, visitor);
130
130
  }
131
131
 
@@ -100,17 +100,17 @@ public class PoiExcelVisitorFactory {
100
100
  }
101
101
 
102
102
  // cell value/formula
103
- private PoiExcelCellVisitor poiExcelCellVisitor;
103
+ private PoiExcelCellValueVisitor poiExcelCellValueVisitor;
104
104
 
105
- public final PoiExcelCellVisitor getPoiExcelCellVisitor() {
106
- if (poiExcelCellVisitor == null) {
107
- poiExcelCellVisitor = newPoiExcelCellVisitor();
105
+ public final PoiExcelCellValueVisitor getPoiExcelCellValueVisitor() {
106
+ if (poiExcelCellValueVisitor == null) {
107
+ poiExcelCellValueVisitor = newPoiExcelCellValueVisitor();
108
108
  }
109
- return poiExcelCellVisitor;
109
+ return poiExcelCellValueVisitor;
110
110
  }
111
111
 
112
- protected PoiExcelCellVisitor newPoiExcelCellVisitor() {
113
- return new PoiExcelCellVisitor(visitorValue);
112
+ protected PoiExcelCellValueVisitor newPoiExcelCellValueVisitor() {
113
+ return new PoiExcelCellValueVisitor(visitorValue);
114
114
  }
115
115
 
116
116
  // cell style
@@ -142,19 +142,33 @@ public class PoiExcelVisitorFactory {
142
142
  }
143
143
 
144
144
  // cell comment
145
- private PoiExcelCellCommentVisitor PoiExcelCellCommentVisitor;
145
+ private PoiExcelCellCommentVisitor poiExcelCellCommentVisitor;
146
146
 
147
147
  public final PoiExcelCellCommentVisitor getPoiExcelCellCommentVisitor() {
148
- if (PoiExcelCellCommentVisitor == null) {
149
- PoiExcelCellCommentVisitor = newPoiExcelCellCommentVisitor();
148
+ if (poiExcelCellCommentVisitor == null) {
149
+ poiExcelCellCommentVisitor = newPoiExcelCellCommentVisitor();
150
150
  }
151
- return PoiExcelCellCommentVisitor;
151
+ return poiExcelCellCommentVisitor;
152
152
  }
153
153
 
154
154
  protected PoiExcelCellCommentVisitor newPoiExcelCellCommentVisitor() {
155
155
  return new PoiExcelCellCommentVisitor(visitorValue);
156
156
  }
157
157
 
158
+ // ClientAnchor
159
+ private PoiExcelClientAnchorVisitor poiExcelClientAnchorVisitor;
160
+
161
+ public final PoiExcelClientAnchorVisitor getPoiExcelClientAnchorVisitor() {
162
+ if (poiExcelClientAnchorVisitor == null) {
163
+ poiExcelClientAnchorVisitor = newPoiExcelClientAnchorVisitor();
164
+ }
165
+ return poiExcelClientAnchorVisitor;
166
+ }
167
+
168
+ protected PoiExcelClientAnchorVisitor newPoiExcelClientAnchorVisitor() {
169
+ return new PoiExcelClientAnchorVisitor(visitorValue);
170
+ }
171
+
158
172
  // color
159
173
  private PoiExcelColorVisitor poiExcelColorVisitor;
160
174
 
@@ -25,7 +25,7 @@ public class TestPoiExcelParserPlugin {
25
25
  tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
26
26
 
27
27
  EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
28
- parser.set("sheet", "test1");
28
+ parser.set("sheets", Arrays.asList("test1"));
29
29
  parser.set("skip_header_lines", 1);
30
30
  parser.set("default_timezone", "Asia/Tokyo");
31
31
  parser.addColumn("boolean", "boolean");
@@ -73,7 +73,7 @@ public class TestPoiExcelParserPlugin {
73
73
  tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
74
74
 
75
75
  EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
76
- parser.set("sheet", "test1");
76
+ parser.set("sheets", Arrays.asList("test1"));
77
77
  parser.set("skip_header_lines", 1);
78
78
  parser.set("cell_error_null", false);
79
79
  parser.addColumn("sheet", "string").set("value", "sheet_name");
@@ -184,4 +184,24 @@ public class TestPoiExcelParserPlugin {
184
184
  assertThat(r.getAsString("a"), is(a));
185
185
  assertThat(r.getAsString("b"), is(b));
186
186
  }
187
+
188
+ @Test
189
+ public void test_sheets() throws ParseException {
190
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
191
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
192
+
193
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
194
+ parser.set("sheets", Arrays.asList("formula_replace", "merged_cell"));
195
+ parser.addColumn("a", "string");
196
+
197
+ URL inFile = getClass().getResource("test1.xls");
198
+ List<OutputRecord> result = tester.runParser(inFile, parser);
199
+
200
+ assertThat(result.size(), is(2 + 4));
201
+ assertThat(result.get(0).getAsString("a"), is("boolean"));
202
+ assertThat(result.get(1).getAsString("a"), is("test2-b1"));
203
+ assertThat(result.get(2).getAsString("a"), is("test3-a1"));
204
+ assertThat(result.get(3).getAsString("a"), is("data"));
205
+ }
206
+ }
187
207
  }
@@ -1,10 +1,13 @@
1
1
  package org.embulk.parser.poi_excel;
2
2
 
3
3
  import static org.hamcrest.CoreMatchers.is;
4
+ import static org.hamcrest.CoreMatchers.nullValue;
4
5
  import static org.junit.Assert.assertThat;
6
+ import static org.junit.Assert.fail;
5
7
 
6
8
  import java.net.URL;
7
9
  import java.text.ParseException;
10
+ import java.util.Arrays;
8
11
  import java.util.List;
9
12
 
10
13
  import org.embulk.parser.EmbulkPluginTester;
@@ -39,4 +42,58 @@ public class TestPoiExcelParserPlugin_cellComment {
39
42
  assertThat(record.getAsString("comment"), is(comment));
40
43
  assertThat(record.getAsString("author"), is(author));
41
44
  }
45
+
46
+ @Test
47
+ public void testComment_all() throws ParseException {
48
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
49
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
50
+
51
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
52
+ parser.set("sheet", "comment");
53
+ parser.addColumn("comment", "string").set("value", "cell_comment");
54
+
55
+ URL inFile = getClass().getResource("test1.xls");
56
+ List<OutputRecord> result = tester.runParser(inFile, parser);
57
+
58
+ assertThat(result.size(), is(2));
59
+ check2(result, 0, "hishidama", "hishidama:\\nmy comment");
60
+ check2(result, 1, null, null);
61
+ }
62
+ }
63
+
64
+ private void check2(List<OutputRecord> result, int index, String author, String comment) {
65
+ OutputRecord record = result.get(index);
66
+ // System.out.println(record);
67
+ String s = record.getAsString("comment");
68
+ if (author == null && comment == null) {
69
+ assertThat(s, is(nullValue()));
70
+ return;
71
+ }
72
+
73
+ if (!s.contains(String.format("\"author\":\"%s\"", author))) {
74
+ fail(s);
75
+ }
76
+ if (!s.contains(String.format("\"string\":\"%s\"", comment))) {
77
+ fail(s);
78
+ }
79
+ }
80
+
81
+ @Test
82
+ public void testComment_keys() throws ParseException {
83
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
84
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
85
+
86
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
87
+ parser.set("sheet", "comment");
88
+ parser.addColumn("comment", "string").set("value", "cell_comment")
89
+ .set("attribute_name", Arrays.asList("author", "string"));
90
+
91
+ URL inFile = getClass().getResource("test1.xls");
92
+ List<OutputRecord> result = tester.runParser(inFile, parser);
93
+
94
+ assertThat(result.size(), is(2));
95
+ check2(result, 0, "hishidama", "hishidama:\\nmy comment");
96
+ check2(result, 1, null, null);
97
+ }
98
+ }
42
99
  }
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hishidama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-12 00:00:00.000000000 Z
11
+ date: 2015-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -61,7 +61,8 @@ files:
61
61
  - src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellCommentVisitor.java
62
62
  - src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellFontVisitor.java
63
63
  - src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellStyleVisitor.java
64
- - src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellVisitor.java
64
+ - src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java
65
+ - src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelClientAnchorVisitor.java
65
66
  - src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColorVisitor.java
66
67
  - src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnIndex.java
67
68
  - src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java
@@ -84,7 +85,7 @@ files:
84
85
  - src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_columnNumber.java
85
86
  - src/test/resources/org/embulk/parser/poi_excel/test1.xls
86
87
  - classpath/commons-codec-1.9.jar
87
- - classpath/embulk-parser-poi_excel-0.1.0.jar
88
+ - classpath/embulk-parser-poi_excel-0.1.1.jar
88
89
  - classpath/embulk-standards-0.7.5.jar
89
90
  - classpath/poi-3.13.jar
90
91
  - classpath/poi-ooxml-3.13.jar