Code Monkey home page Code Monkey logo

spring-batch-excel's Introduction

DEPRECATED

This repository no longer contains the most recent version of the Spring Batch Excel project. The code has been improved and moved the the Spring Batch Extensions project.

spring-batch-excel

Spring Batch extension which contains ItemReader implementations for Excel. Support for both JExcel and Apache POI is available.

Configuration

Next to the configuration of Spring Batch one needs to configure an ItemReader which knows how to read an Excel file. 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 or Apache Poi) and cababilities of both technologies (JExcel cannot read xlsx files, whereas Apache POI can read those).

<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>

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.

Optionally one can also set the skippedRowsCallback, linesToSkip and strict property.

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.

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.

PassThroughRowMapper

Transforms the read row from excel into a String[].

DefaultRowMapper

Tries to convert the given row into an object, for this a org.springframework.batch.item.excel.transform.RowTokenizer and a org.springframework.batch.item.file.mapping.FieldSetMapper (from the Spring Batch project) is needed.

By default the org.springframework.batch.item.excel.transform.DefaultRowTokenizer is used. This implementation assumes that the first row contains the column names. The column names are used to map to attributes on the object we are trying to create. How this mapping is done is configurable through a org.springframework.batch.item.excel.transform.ColumnToAttributeConverter implementation. Again 2 implementations are provided by the framework

  • org.springframework.batch.item.excel.transform.PassThroughColumnToAttributeConverter
  • org.springframework.batch.item.excel.transform.MappingColumnToAttributeConverter

The PassThroughColumnToAttributeConverter simply assumes that the column name corresponds to a property on the object that is being created. The MappingColumnToAttributeConverter contains a (optional) column-name to property-name mapping.

spring-batch-excel's People

Contributors

mdeinum avatar

Watchers

James Cloos avatar Krishna Kant Mishra avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.