net.sf.jasperreports.engine.data
Class JRXlsDataSource

java.lang.Object
  extended by net.sf.jasperreports.engine.data.JRAbstractTextDataSource
      extended by net.sf.jasperreports.engine.data.JRXlsDataSource
All Implemented Interfaces:
JRDataSource, JRRewindableDataSource

public class JRXlsDataSource
extends JRAbstractTextDataSource
implements JRRewindableDataSource

This data source implementation reads an XLS stream.

The default naming convention is to name report fields COLUMN_x and map each column with the field found at index x in each row (these indices start with 0). To avoid this situation, users can either specify a collection of column names or set a flag to read the column names from the first row of the CSV file.

Version:
$Id: JRXlsDataSource.java 5346 2012-05-08 12:08:01Z teodord $
Author:
Teodor Danciu (teodord@users.sourceforge.net)

Constructor Summary
JRXlsDataSource(java.io.File file)
          Creates a data source instance from an XLS file.
JRXlsDataSource(java.io.InputStream is)
          Creates a data source instance from an XLS data input stream.
JRXlsDataSource(JasperReportsContext jasperReportsContext, java.lang.String location)
          Creates a datasource instance that reads XLS data from a given location.
JRXlsDataSource(java.lang.String location)
           
JRXlsDataSource(jxl.Workbook workbook)
          Creates a data source instance from a workbook.
 
Method Summary
 void close()
          Closes the reader.
 java.util.Map<java.lang.String,java.lang.Integer> getColumnNames()
           
 java.text.DateFormat getDateFormat()
          Gets the date format that will be used to parse date fields.
 java.lang.Object getFieldValue(JRField jrField)
          Gets the field value for the current position.
 java.text.NumberFormat getNumberFormat()
          Gets the number format that will be used to parse numeric fields.
 void moveFirst()
          Moves back to the first element in the data source.
 boolean next()
          Tries to position the cursor on the next element in the data source.
 void setColumnIndexes(java.lang.Integer[] columnIndexes)
          Specifies an array of integers representing the column indexes in the sheet.
 void setColumnNames(java.lang.String[] columnNames)
          Specifies an array of strings representing column names matching field names in the report template.
 void setColumnNames(java.lang.String[] columnNames, int[] columnIndexes)
          Specifies an array of strings representing column names matching field names in the report template and an array of integers representing the column indexes in the sheet.
 void setDateFormat(java.text.DateFormat dateFormat)
          Sets the desired date format to be used for parsing date fields.
 void setNumberFormat(java.text.NumberFormat numberFormat)
          Sets the desired number format to be used for parsing numeric fields.
 void setUseFirstRowAsHeader(boolean useFirstRowAsHeader)
          Specifies whether the first row of the XLS file should be considered a table header, containing column names matching field names in the report template.
 
Methods inherited from class net.sf.jasperreports.engine.data.JRAbstractTextDataSource
convertNumber, convertStringValue, getConvertBean, getDatePattern, getFormattedDate, getFormattedNumber, getLocale, getNumberPattern, getTimeZone, setDatePattern, setLocale, setLocale, setNumberPattern, setTextAttributes, setTimeZone, setTimeZone
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JRXlsDataSource

public JRXlsDataSource(jxl.Workbook workbook)
Creates a data source instance from a workbook.

Parameters:
workbook - the workbook

JRXlsDataSource

public JRXlsDataSource(java.io.InputStream is)
                throws JRException,
                       java.io.IOException
Creates a data source instance from an XLS data input stream.

Parameters:
is - an input stream containing XLS data
Throws:
JRException
java.io.IOException

JRXlsDataSource

public JRXlsDataSource(java.io.File file)
                throws JRException,
                       java.io.FileNotFoundException,
                       java.io.IOException
Creates a data source instance from an XLS file.

Parameters:
file - a file containing XLS data
Throws:
JRException
java.io.FileNotFoundException
java.io.IOException

JRXlsDataSource

public JRXlsDataSource(JasperReportsContext jasperReportsContext,
                       java.lang.String location)
                throws JRException,
                       java.io.IOException
Creates a datasource instance that reads XLS data from a given location.

Parameters:
jasperReportsContext - the JasperReportsContext
location - a String representing XLS data source
Throws:
java.io.IOException
JRException

JRXlsDataSource

public JRXlsDataSource(java.lang.String location)
                throws JRException,
                       java.io.IOException
Throws:
JRException
java.io.IOException
See Also:
JRXlsDataSource(JasperReportsContext, String)
Method Detail

next

public boolean next()
             throws JRException
Description copied from interface: JRDataSource
Tries to position the cursor on the next element in the data source.

Specified by:
next in interface JRDataSource
Returns:
true if there is a next record, false otherwise
Throws:
JRException - if any error occurs while trying to move to the next element

moveFirst

public void moveFirst()
Description copied from interface: JRRewindableDataSource
Moves back to the first element in the data source.

Specified by:
moveFirst in interface JRRewindableDataSource

getFieldValue

public java.lang.Object getFieldValue(JRField jrField)
                               throws JRException
Description copied from interface: JRDataSource
Gets the field value for the current position.

Specified by:
getFieldValue in interface JRDataSource
Returns:
an object containing the field value. The object type must be the field object type.
Throws:
JRException

getDateFormat

public java.text.DateFormat getDateFormat()
Gets the date format that will be used to parse date fields.


setDateFormat

public void setDateFormat(java.text.DateFormat dateFormat)
Sets the desired date format to be used for parsing date fields.


getNumberFormat

public java.text.NumberFormat getNumberFormat()
Gets the number format that will be used to parse numeric fields.


setNumberFormat

public void setNumberFormat(java.text.NumberFormat numberFormat)
Sets the desired number format to be used for parsing numeric fields.


setColumnNames

public void setColumnNames(java.lang.String[] columnNames)
Specifies an array of strings representing column names matching field names in the report template.


setColumnNames

public void setColumnNames(java.lang.String[] columnNames,
                           int[] columnIndexes)
Specifies an array of strings representing column names matching field names in the report template and an array of integers representing the column indexes in the sheet. Both array parameters must be not-null and have the same number of values.


setColumnIndexes

public void setColumnIndexes(java.lang.Integer[] columnIndexes)
Specifies an array of integers representing the column indexes in the sheet.


setUseFirstRowAsHeader

public void setUseFirstRowAsHeader(boolean useFirstRowAsHeader)
Specifies whether the first row of the XLS file should be considered a table header, containing column names matching field names in the report template.


close

public void close()
Closes the reader. Users of this data source should close it after usage.


getColumnNames

public java.util.Map<java.lang.String,java.lang.Integer> getColumnNames()


© 2001-2010 Jaspersoft Corporation www.jaspersoft.com