This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener). # HTTP URLs that Could Not Be Fixed These URLs were unable to be fixed. Please review them to see if they can be manually resolved. * [ ] http://jexcelapi.sourceforge.net (200) with 1 occurrences could not be migrated: ([https](https://jexcelapi.sourceforge.net) result AnnotatedConnectException). # Fixed URLs ## Fixed But Review Recommended These URLs were fixed, but the https status was not OK. However, the https status was the same as the http request or http redirected to an https URL, so they were migrated. Your review is recommended. * [ ] http://progit.org/book/ch3-6.html (301) with 4 occurrences migrated to: https://progit.org/book/ch3-6.html ([https](https://progit.org/book/ch3-6.html) result SSLHandshakeException). * [ ] http://progit.org/book/ch5-2.html (301) with 2 occurrences migrated to: https://progit.org/book/ch5-2.html ([https](https://progit.org/book/ch5-2.html) result SSLHandshakeException). * [ ] http://book.git-scm.com/4_interactive_rebasing.html (301) with 1 occurrences migrated to: https://book.git-scm.com/4_interactive_rebasing.html ([https](https://book.git-scm.com/4_interactive_rebasing.html) result 404). * [ ] http://help.github.com/send-pull-requests (404) with 2 occurrences migrated to: https://help.github.com/send-pull-requests ([https](https://help.github.com/send-pull-requests) result 404). ## Fixed Success These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended. * [ ] http://maven.apache.org with 1 occurrences migrated to: https://maven.apache.org ([https](https://maven.apache.org) result 200). * [ ] http://poi.apache.org with 1 occurrences migrated to: https://poi.apache.org ([https](https://poi.apache.org) result 200). * [ ] http://projects.spring.io/spring-batch/ with 1 occurrences migrated to: https://projects.spring.io/spring-batch/ ([https](https://projects.spring.io/spring-batch/) result 200). * [ ] http://spring.io/tools/sts with 1 occurrences migrated to: https://spring.io/tools/sts ([https](https://spring.io/tools/sts) result 200). * [ ] http://stackoverflow.com/faq with 1 occurrences migrated to: https://stackoverflow.com/faq ([https](https://stackoverflow.com/faq) result 200). * [ ] http://stackoverflow.com/questions/134882/undoing-a-git-rebase with 1 occurrences migrated to: https://stackoverflow.com/questions/134882/undoing-a-git-rebase ([https](https://stackoverflow.com/questions/134882/undoing-a-git-rebase) result 200). * [ ] http://stackoverflow.com/questions/tagged/spring-batch with 1 occurrences migrated to: https://stackoverflow.com/questions/tagged/spring-batch ([https](https://stackoverflow.com/questions/tagged/spring-batch) result 200). * [ ] http://docs.spring.io/spring-batch/reference/html/configureJob.html with 1 occurrences migrated to: https://docs.spring.io/spring-batch/reference/html/configureJob.html ([https](https://docs.spring.io/spring-batch/reference/html/configureJob.html) result 301). * [ ] http://help.github.com/fork-a-repo/ with 2 occurrences migrated to: https://help.github.com/fork-a-repo/ ([https](https://help.github.com/fork-a-repo/) result 301). * [ ] http://help.github.com/send-pull-requests/ with 2 occurrences migrated to: https://help.github.com/send-pull-requests/ ([https](https://help.github.com/send-pull-requests/) result 301). * [ ] http://help.github.com/set-up-git-redirect with 1 occurrences migrated to: https://help.github.com/set-up-git-redirect ([https](https://help.github.com/set-up-git-redirect) result 301).
77 lines
3.6 KiB
Markdown
77 lines
3.6 KiB
Markdown
# spring-batch-excel
|
|
|
|
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](https://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.
|
|
|
|
#### XML
|
|
|
|
<bean id="excelReader" class="org.springframework.batch.item.excel.poi.PoiItemReader">
|
|
<property name="resource" value="/path/to/your/excel/file" />
|
|
<property name="rowMapper">
|
|
<bean class="org.springframework.batch.item.excel.mapping.PassThroughRowMapper" />
|
|
</property>
|
|
</bean>
|
|
|
|
#### Java Config
|
|
|
|
@Bean
|
|
public PoiItemReader excelReader() {
|
|
PoiItemReader reader = new PoiItemReader();
|
|
reader.setResource(new ClassPathResource("/path/to/your/excel/file"));
|
|
reader.setRowMapper(rowMapper());
|
|
return reader;
|
|
}
|
|
|
|
@Bean
|
|
public RowMapper rowMapper() {
|
|
return new PassThroughRowMapper();
|
|
}
|
|
|
|
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` 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, 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 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[]`.
|
|
|
|
### BeanWrapperRowMapper
|
|
Uses a `BeanWrapper` to convert a given row into an object. Uses the column names of the given `RowSet` to map column to properties of the `targetType` or prototype bean.
|
|
|
|
<bean id="excelReader" class="org.springframework.batch.item.excel.poi.PoiItemReader">
|
|
<property name="resource" value="/path/to/your/excel/file" />
|
|
<property name="rowMapper">
|
|
<bean class="org.springframework.batch.item.excel.mapping.BeanWrapperowMapper">
|
|
<property name="targetType" value="com.your.package.Player" />
|
|
<bean>
|
|
</property>
|
|
</bean>
|
|
|
|
[1]: http://jexcelapi.sourceforge.net
|
|
[2]: https://poi.apache.org |