Package net.sf.jasperreports.engine.data
Class AbstractPoiXlsDataSource
- java.lang.Object
-
- net.sf.jasperreports.engine.data.JRAbstractTextDataSource
-
- net.sf.jasperreports.engine.data.AbstractXlsDataSource
-
- net.sf.jasperreports.engine.data.AbstractPoiXlsDataSource
-
- All Implemented Interfaces:
JRDataSource,JRRewindableDataSource
- Direct Known Subclasses:
ExcelDataSource,JRXlsxDataSource,XlsDataSource
public abstract class AbstractPoiXlsDataSource extends AbstractXlsDataSource
This data source implementation reads an XLSX or 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 XLSX or XLS file.
- Author:
- Sanda Zaharia (shertage@users.sourceforge.net)
-
-
Field Summary
-
Fields inherited from class net.sf.jasperreports.engine.data.AbstractXlsDataSource
columnIndexMap, columnNames, dateFormat, EXCEPTION_MESSAGE_KEY_XLS_COLUMN_NAMES_MISMATCH_COLUMN_INDEXES, EXCEPTION_MESSAGE_KEY_XLS_FIELD_VALUE_NOT_RETRIEVED, EXCEPTION_MESSAGE_KEY_XLS_SHEET_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_XLS_SHEET_NOT_FOUND, INDEXED_COLUMN_PREFIX, numberFormat, PROPERTY_FIELD_COLUMN_INDEX, PROPERTY_FIELD_COLUMN_NAME, sheetSelection, useFirstRowAsHeader
-
Fields inherited from class net.sf.jasperreports.engine.data.JRAbstractTextDataSource
EXCEPTION_MESSAGE_KEY_CANNOT_CONVERT_FIELD_TYPE, EXCEPTION_MESSAGE_KEY_CANNOT_MODIFY_PROPERTIES_AFTER_START, EXCEPTION_MESSAGE_KEY_NODE_NOT_AVAILABLE, EXCEPTION_MESSAGE_KEY_NULL_DOCUMENT, EXCEPTION_MESSAGE_KEY_NULL_SELECT_EXPRESSION, EXCEPTION_MESSAGE_KEY_UNKNOWN_COLUMN_NAME, EXCEPTION_MESSAGE_KEY_UNKNOWN_NUMBER_TYPE
-
-
Constructor Summary
Constructors Constructor Description AbstractPoiXlsDataSource(java.io.File file)Creates a data source instance from an XLSX or XLS file.AbstractPoiXlsDataSource(java.io.InputStream is)Creates a data source instance from an XLSX or XLS data input stream.AbstractPoiXlsDataSource(java.io.InputStream is, boolean closeInputStream)Creates a data source instance from an XLSX or XLS data input stream.AbstractPoiXlsDataSource(java.lang.String location)AbstractPoiXlsDataSource(JasperReportsContext jasperReportsContext, java.lang.String location)Creates a data source instance that reads XLSX or XLS data from a given location.AbstractPoiXlsDataSource(RepositoryContext context, java.lang.String location)AbstractPoiXlsDataSource(org.apache.poi.ss.usermodel.Workbook workbook)Creates a data source instance from a workbook.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckReadStarted()voidclose()Closes the reader.java.lang.StringgetFieldFormatPattern(JRField jrField)java.lang.ObjectgetFieldValue(JRField jrField)Gets the field value for the current position.java.lang.StringgetStringFieldValue(JRField jrField)protected abstract org.apache.poi.ss.usermodel.WorkbookloadWorkbook(java.io.InputStream is)voidmoveFirst()Moves back to the first element in the data source.booleannext()Tries to position the cursor on the next element in the data source.-
Methods inherited from class net.sf.jasperreports.engine.data.AbstractXlsDataSource
getColumnIndex, getColumnNames, getDateFormat, getNumberFormat, getSheetSelection, setColumnIndexes, setColumnNames, setColumnNames, setDateFormat, setNumberFormat, setSheetSelection, setUseFirstRowAsHeader
-
Methods inherited from class net.sf.jasperreports.engine.data.JRAbstractTextDataSource
convertNumber, convertStringValue, getConvertBean, getDatePattern, getLocale, getNumberPattern, getTextAttributes, getTimeZone, setDatePattern, setLocale, setLocale, setNumberPattern, setTextAttributes, setTextAttributes, setTimeZone, setTimeZone
-
-
-
-
Constructor Detail
-
AbstractPoiXlsDataSource
public AbstractPoiXlsDataSource(org.apache.poi.ss.usermodel.Workbook workbook)
Creates a data source instance from a workbook.- Parameters:
workbook- the workbook
-
AbstractPoiXlsDataSource
public AbstractPoiXlsDataSource(java.io.InputStream is) throws JRException, java.io.IOExceptionCreates a data source instance from an XLSX or XLS data input stream.- Parameters:
is- an input stream containing XLSX or XLS data- Throws:
JRExceptionjava.io.IOException
-
AbstractPoiXlsDataSource
public AbstractPoiXlsDataSource(java.io.InputStream is, boolean closeInputStream) throws JRException, java.io.IOExceptionCreates a data source instance from an XLSX or XLS data input stream.- Parameters:
is- an input stream containing XLSX or XLS data- Throws:
JRExceptionjava.io.IOException
-
AbstractPoiXlsDataSource
public AbstractPoiXlsDataSource(java.io.File file) throws JRException, java.io.IOExceptionCreates a data source instance from an XLSX or XLS file.- Parameters:
file- a file containing XLSX or XLS data- Throws:
JRExceptionjava.io.IOException
-
AbstractPoiXlsDataSource
public AbstractPoiXlsDataSource(JasperReportsContext jasperReportsContext, java.lang.String location) throws JRException, java.io.IOException
Creates a data source instance that reads XLSX or XLS data from a given location.- Parameters:
jasperReportsContext- the JasperReportsContextlocation- a String representing XLSX or XLS data source- Throws:
java.io.IOExceptionJRException
-
AbstractPoiXlsDataSource
public AbstractPoiXlsDataSource(RepositoryContext context, java.lang.String location) throws JRException, java.io.IOException
- Throws:
JRExceptionjava.io.IOException
-
AbstractPoiXlsDataSource
public AbstractPoiXlsDataSource(java.lang.String location) throws JRException, java.io.IOException- Throws:
JRExceptionjava.io.IOException- See Also:
AbstractPoiXlsDataSource(JasperReportsContext, String)
-
-
Method Detail
-
loadWorkbook
protected abstract org.apache.poi.ss.usermodel.Workbook loadWorkbook(java.io.InputStream is) throws java.io.IOException- Throws:
java.io.IOException
-
next
public boolean next() throws JRExceptionDescription copied from interface:JRDataSourceTries to position the cursor on the next element in the data source.- 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:JRRewindableDataSourceMoves back to the first element in the data source.
-
getFieldValue
public java.lang.Object getFieldValue(JRField jrField) throws JRException
Description copied from interface:JRDataSourceGets the field value for the current position.- Returns:
- an object containing the field value. The object type must be the field object type.
- Throws:
JRException
-
close
public void close()
Closes the reader. Users of this data source should close it after usage.- Specified by:
closein classAbstractXlsDataSource
-
checkReadStarted
protected void checkReadStarted()
- Specified by:
checkReadStartedin classAbstractXlsDataSource
-
getStringFieldValue
public java.lang.String getStringFieldValue(JRField jrField) throws JRException
- Throws:
JRException
-
getFieldFormatPattern
public java.lang.String getFieldFormatPattern(JRField jrField) throws JRException
- Throws:
JRException
-
-