Class 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)
    • 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.IOException
        Creates a data source instance from an XLSX or XLS data input stream.
        Parameters:
        is - an input stream containing XLSX or XLS data
        Throws:
        JRException
        java.io.IOException
      • AbstractPoiXlsDataSource

        public AbstractPoiXlsDataSource​(java.io.InputStream is,
                                        boolean closeInputStream)
                                 throws JRException,
                                        java.io.IOException
        Creates a data source instance from an XLSX or XLS data input stream.
        Parameters:
        is - an input stream containing XLSX or XLS data
        Throws:
        JRException
        java.io.IOException
      • AbstractPoiXlsDataSource

        public AbstractPoiXlsDataSource​(java.io.File file)
                                 throws JRException,
                                        java.io.IOException
        Creates a data source instance from an XLSX or XLS file.
        Parameters:
        file - a file containing XLSX or XLS data
        Throws:
        JRException
        java.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 JasperReportsContext
        location - a String representing XLSX or XLS data source
        Throws:
        java.io.IOException
        JRException
      • AbstractPoiXlsDataSource

        public AbstractPoiXlsDataSource​(RepositoryContext context,
                                        java.lang.String location)
                                 throws JRException,
                                        java.io.IOException
        Throws:
        JRException
        java.io.IOException
    • 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 JRException
        Description copied from interface: JRDataSource
        Tries 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: JRRewindableDataSource
        Moves back to the first element in the data source.
      • getFieldValue

        public java.lang.Object getFieldValue​(JRField jrField)
                                       throws JRException
        Description copied from interface: JRDataSource
        Gets 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:
        close in class AbstractXlsDataSource