Class AbstractXlsDataSource

  • All Implemented Interfaces:
    JRDataSource, JRRewindableDataSource
    Direct Known Subclasses:
    AbstractPoiXlsDataSource, FastExcelDataSource

    public abstract class AbstractXlsDataSource
    extends JRAbstractTextDataSource
    implements 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 Detail

      • EXCEPTION_MESSAGE_KEY_XLS_COLUMN_NAMES_MISMATCH_COLUMN_INDEXES

        public static final String EXCEPTION_MESSAGE_KEY_XLS_COLUMN_NAMES_MISMATCH_COLUMN_INDEXES
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_XLS_FIELD_VALUE_NOT_RETRIEVED

        public static final String EXCEPTION_MESSAGE_KEY_XLS_FIELD_VALUE_NOT_RETRIEVED
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_XLS_SHEET_INDEX_OUT_OF_RANGE

        public static final String EXCEPTION_MESSAGE_KEY_XLS_SHEET_INDEX_OUT_OF_RANGE
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_XLS_SHEET_NOT_FOUND

        public static final String EXCEPTION_MESSAGE_KEY_XLS_SHEET_NOT_FOUND
        See Also:
        Constant Field Values
      • PROPERTY_FIELD_COLUMN_NAME

        public static final String PROPERTY_FIELD_COLUMN_NAME
        Property specifying the XLS column name for the dataset field.
        See Also:
        Constant Field Values
      • PROPERTY_FIELD_COLUMN_INDEX

        public static final String PROPERTY_FIELD_COLUMN_INDEX
        Property specifying the XLS column index for the dataset field.
        See Also:
        Constant Field Values
      • sheetSelection

        protected String sheetSelection
      • useFirstRowAsHeader

        protected boolean useFirstRowAsHeader
    • Constructor Detail

      • AbstractXlsDataSource

        public AbstractXlsDataSource()
    • Method Detail

      • getDateFormat

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

        public void setDateFormat​(DateFormat dateFormat)
        Sets the desired date format to be used for parsing date fields.
      • getNumberFormat

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

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

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

        public void setColumnNames​(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​(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 abstract void close()
        Closes the reader. Users of this data source should close it after usage.
      • checkReadStarted

        protected abstract void checkReadStarted()
      • getSheetSelection

        public String getSheetSelection()
      • setSheetSelection

        public void setSheetSelection​(String sheetSelection)