Skip to content

bsorrentino/Excel-Xml-Mapping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This project has moving to GITHUB from KENAI


What is Excel Xml Mapping

To import and export XML data in Excel, an XML Map that associates XML elements with data in cells to get the results, would be very useful. To create one, you need to have an XML schema file (.xsd) and an XML data file (.xml). After creating the XML Map, you can map XML elements the way you want. The link below explain the xml mapping feature and how to use it.

Map XML elements to cells in a XML Map

Project goal

Since, until version 3.5-beta6, seems that apache POI project doesn't support importXML feature yet, i've created this project to provide , in a easy way and without need of native code , this very useful feature from excel 2007.

Usage

XSSFWorkbook wb;
java.io.Reader xmlSource;
java.io.OutputStream result;

File file = new File("src/test/resources/TestImportXml.xlsx");
File fileXml = new File("src/test/resources/TestImportData.xml");

// load an XLSX file with mapping informations
wb = new XSSFWorkbook(file.getAbsolutePath());

xmlSource = new java.io.FileReader( fileXml );

result =  new java.io.FileOutputStream("target/testImportXmlout.xlsx");

WorkbookUtils.importXML( wb,  xmlSource, result );

Data Conversion

The data conversion is supported for types:

  • Boolean
  • Date
  • DateTime - xs:dateTime format supported [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm]
  • Time
  • Double
  • Long
  • Float

Customize data conversion

It is possible ovveride the default data conversion behaviour implementing the Converter interface

public static interface WorkbookUtils.Converter<T> {
  T convert( SimpleValue value) throws Exception;
}

Through the following methods published from WorkbookUtils class

public static Converter<Integer> registerIntConverter( Converter<Integer> converter );

public static Converter<Float> registerFloatConverter( Converter<Float> converter );

public static Converter<Double> registerDoubleConverter( Converter<Double> converter ) ;

public static Converter<Long> registerLongConverter( Converter<Long> converter ) ;

public static Converter<Boolean> registerBooleanConverter( Converter<Boolean> converter ) ;

public static Converter<java.util.Date> registerDateConverter( Converter<java.util.Date> converter ) ;

public static Converter<java.util.Date> registerDateTimeConverter( Converter<java.util.Date> converter ) ;

public static Converter<java.util.Date> registerTimeConverter( Converter<java.util.Date> converter ) ;

About

Apache POI extension to support xml mapping in excel 2007

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages