Package net.sf.jasperreports.poi.data
Class ExcelDataSource
java.lang.Object
net.sf.jasperreports.engine.data.JRAbstractTextDataSource
net.sf.jasperreports.engine.data.AbstractXlsDataSource
net.sf.jasperreports.poi.data.AbstractPoiXlsDataSource
net.sf.jasperreports.poi.data.ExcelDataSource
- All Implemented Interfaces:
JRDataSource
,JRRewindableDataSource
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
ConstructorsConstructorDescriptionExcelDataSource
(File file) Creates a data source instance from an XLSX or XLS file with the default autodetect Excel format.ExcelDataSource
(File file, ExcelFormatEnum format) Creates a data source instance from an XLSX or XLS file.Creates a data source instance from an XLSX or XLS data input stream with the default autodetect Excel format.ExcelDataSource
(InputStream is, boolean closeInputStream, ExcelFormatEnum format) Creates a data source instance from an XLSX or XLS data input stream.ExcelDataSource
(InputStream is, ExcelFormatEnum format) Creates a data source instance from an XLSX or XLS data input stream.ExcelDataSource
(String location) ExcelDataSource
(String location, ExcelFormatEnum format) ExcelDataSource
(JasperReportsContext jasperReportsContext, String location) Creates a datasource instance that reads XLSX or XLS data from a given location.ExcelDataSource
(JasperReportsContext jasperReportsContext, String location, ExcelFormatEnum format) Creates a datasource instance that reads XLSX or XLS data from a given location.ExcelDataSource
(RepositoryContext repositoryContext, String location) ExcelDataSource
(RepositoryContext context, String location, ExcelFormatEnum format) ExcelDataSource
(org.apache.poi.hssf.usermodel.HSSFWorkbook workbook) Creates a data source instance from an Excel workbook with the XLS format.ExcelDataSource
(org.apache.poi.ss.usermodel.Workbook workbook) Creates a data source instance from a workbook with the default autodetect Excel format.ExcelDataSource
(org.apache.poi.xssf.usermodel.XSSFWorkbook workbook) Creates a data source instance from an Excel workbook with the XLSX format. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.poi.ss.usermodel.Workbook
loadWorkbook
(InputStream inputStream) Methods inherited from class net.sf.jasperreports.poi.data.AbstractPoiXlsDataSource
checkReadStarted, close, getFieldFormatPattern, getFieldValue, getStringFieldValue, moveFirst, next
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 Details
-
ExcelDataSource
public ExcelDataSource(org.apache.poi.ss.usermodel.Workbook workbook) Creates a data source instance from a workbook with the default autodetect Excel format.- Parameters:
workbook
- the workbook
-
ExcelDataSource
public ExcelDataSource(org.apache.poi.hssf.usermodel.HSSFWorkbook workbook) Creates a data source instance from an Excel workbook with the XLS format.- Parameters:
workbook
- the workbook
-
ExcelDataSource
public ExcelDataSource(org.apache.poi.xssf.usermodel.XSSFWorkbook workbook) Creates a data source instance from an Excel workbook with the XLSX format.- Parameters:
workbook
- the workbook
-
ExcelDataSource
Creates a data source instance from an XLSX or XLS data input stream with the default autodetect Excel format.- Parameters:
is
- an input stream containing XLSX or XLS data- Throws:
JRException
IOException
-
ExcelDataSource
Creates a data source instance from an XLSX or XLS data input stream.- Parameters:
is
- an input stream containing XLSX or XLS dataformat
- the Excel format- Throws:
JRException
IOException
-
ExcelDataSource
public ExcelDataSource(InputStream is, boolean closeInputStream, ExcelFormatEnum format) throws JRException, IOException Creates a data source instance from an XLSX or XLS data input stream.- Parameters:
is
- an input stream containing XLSX or XLS dataformat
- the Excel format- Throws:
JRException
IOException
-
ExcelDataSource
Creates a data source instance from an XLSX or XLS file with the default autodetect Excel format.- Parameters:
file
- a file containing XLSX or XLS data- Throws:
FileNotFoundException
JRException
IOException
-
ExcelDataSource
Creates a data source instance from an XLSX or XLS file.- Parameters:
file
- a file containing XLSX or XLS dataformat
- the Excel format- Throws:
FileNotFoundException
JRException
IOException
-
ExcelDataSource
public ExcelDataSource(JasperReportsContext jasperReportsContext, String location) throws JRException, IOException Creates a datasource instance that reads XLSX or XLS data from a given location.- Parameters:
jasperReportsContext
- the JasperReportsContextlocation
- a String representing XLSX or XLS data source- Throws:
IOException
JRException
-
ExcelDataSource
public ExcelDataSource(RepositoryContext repositoryContext, String location) throws JRException, IOException - Throws:
JRException
IOException
-
ExcelDataSource
public ExcelDataSource(JasperReportsContext jasperReportsContext, String location, ExcelFormatEnum format) throws JRException, IOException Creates a datasource instance that reads XLSX or XLS data from a given location.- Parameters:
jasperReportsContext
- the JasperReportsContextlocation
- a String representing XLSX or XLS data sourceformat
- the Excel format- Throws:
IOException
JRException
-
ExcelDataSource
public ExcelDataSource(RepositoryContext context, String location, ExcelFormatEnum format) throws JRException, IOException - Throws:
JRException
IOException
-
ExcelDataSource
- Throws:
JRException
IOException
- See Also:
-
ExcelDataSource
- Throws:
JRException
IOException
- See Also:
-
-
Method Details
-
loadWorkbook
protected org.apache.poi.ss.usermodel.Workbook loadWorkbook(InputStream inputStream) throws IOException - Specified by:
loadWorkbook
in classAbstractPoiXlsDataSource
- Throws:
IOException
-