polish documentation

This commit is contained in:
Marten Deinum
2014-11-14 14:26:00 +01:00
committed by Michael Minella
parent 71a1babf98
commit 94f272a102

View File

@@ -1,16 +1,16 @@
# spring-batch-excel
Spring Batch extension which contains ItemReader implementations for Excel. Support for both JExcel and Apache POI is available.
Spring Batch extension which contains `ItemReader` implementations for Excel. Support for both [JExcel][1] and [Apache POI][2] is available. Simple xls documents can be read with both implementations, however for reading the newer xlsx format [Apache POI][2] is required.
## Configuration
Next to the [configuration of Spring Batch](http://docs.spring.io/spring-batch/2.2.x/reference/html/configureJob.html) one needs to configure an `ItemReader` which knows how to read an Excel file.
Next to the [configuration of Spring Batch](http://docs.spring.io/spring-batch/reference/html/configureJob.html) one needs to configure the `ItemReader` for the desired framework.
There are 2 `ItemReaders` one can configure:
- `org.springframework.batch.item.excel.jxl.JxlItemReader`
- `org.springframework.batch.item.excel.poi.PoiItemReader`
Configuration of both readers is the same, the difference is the used technology ([JExcel](http://jexcelapi.sourceforge.net) or [Apache Poi](http://poi.apache.org)) and cababilities of both technologies (JExcel cannot read xlsx files, whereas Apache POI can read those).
Configuration of both readers is the same.
<bean id="excelReader" class="org.springframework.batch.item.excel.poi.PoiItemReader">
<property name="resource" value="/path/to/your/excel/file" />
@@ -19,26 +19,28 @@ Configuration of both readers is the same, the difference is the used technology
</property>
</bean>
Each reader takes a `resource` which is the excel file to read and a `rowMapper` which transforms the row in excel to an object which you can use in the rest of the process.
The project has 2 default `org.springframework.batch.item.excel.RowMapper` implementations.
Each reader takes a `resource` and a `rowMapper`. The `resource` is the location of the excel file to read and the `rowMapper` transforms the rows in excel to an object which you can use in the rest of the process.
Optionally one can also set the `skippedRowsCallback`, `linesToSkip`, `strict` and `rowSetFactory` property.
Optionally one can also set the `skippedRowsCallback`, `linesToSkip`, `strict` and `rowSetFactory` properties.
##### skippedRowsCallback
When rows are skipped an optional `org.springframework.batch.item.excel.RowCallbackHandler` is called with the skipped row. This comes in handy when one needs to write the skipped rows to another file or create some logging.
##### linesToSkip
The number of lines to skip, this applies to each sheet in the Excel file.
The number of lines to skip, this applies to each sheet in the Excel file, can be useful if the first couple of lines provide header information.
##### strict
By default `true`. This controls wether or not an exception is thrown if the file doesn't exists, by default an exception will be thrown.
##### rowSetFactory
For reading rows a `RowSet` abstraction is used. To construct a `RowSet` for the current `Sheet` a `RowSetFactory` is used. The `DefaultRowSetFactory` constructs a `DefaultRowSet` and `DefaultRowSetMetaData`. For construction of the latter a `ColumnNameExtractor` is needed. At the moment there are 2 implementations
For reading rows a `RowSet` abstraction is used. To construct a `RowSet` for the current `Sheet` a `RowSetFactory` is needed. The `DefaultRowSetFactory` constructs a `DefaultRowSet` and `DefaultRowSetMetaData`. For construction of the latter a `ColumnNameExtractor` is needed. At the moment there are 2 implementations
- `StaticColumnNameExtractor` uses a preset list of column names.
- `RowNumberColumnNameExtractor` (**the default**) reads a given row (default 0) to determine the column names of the current sheet
## RowMappers
Next to the default `ItemReader` implementations there are also 2 `RowMapper` implementations.
### PassThroughRowMapper
Transforms the read row from excel into a `String[]`.
@@ -53,3 +55,6 @@ Uses a `BeanWrapper` to convert a given row into an object. Uses the column name
<bean>
</property>
</bean>
[1]: http://jexcelapi.sourceforge.net
[2]: http://poi.apache.org