Class ExcelDataSource

  • All Implemented Interfaces:
    JRDataSource, JRRewindableDataSource

    public class ExcelDataSource
    extends AbstractPoiXlsDataSource
    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

      • 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

        public ExcelDataSource​(java.io.InputStream is)
                        throws JRException,
                               java.io.IOException
        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
        java.io.IOException
      • ExcelDataSource

        public ExcelDataSource​(java.io.InputStream is,
                               ExcelFormatEnum format)
                        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
        format - the Excel format
        Throws:
        JRException
        java.io.IOException
      • ExcelDataSource

        public ExcelDataSource​(java.io.InputStream is,
                               boolean closeInputStream,
                               ExcelFormatEnum format)
                        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
        format - the Excel format
        Throws:
        JRException
        java.io.IOException
      • ExcelDataSource

        public ExcelDataSource​(java.io.File file)
                        throws JRException,
                               java.io.IOException
        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:
        java.io.FileNotFoundException
        JRException
        java.io.IOException
      • ExcelDataSource

        public ExcelDataSource​(java.io.File file,
                               ExcelFormatEnum format)
                        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
        format - the Excel format
        Throws:
        java.io.FileNotFoundException
        JRException
        java.io.IOException
      • ExcelDataSource

        public ExcelDataSource​(JasperReportsContext jasperReportsContext,
                               java.lang.String location)
                        throws JRException,
                               java.io.IOException
        Creates a datasource 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
      • ExcelDataSource

        public ExcelDataSource​(JasperReportsContext jasperReportsContext,
                               java.lang.String location,
                               ExcelFormatEnum format)
                        throws JRException,
                               java.io.IOException
        Creates a datasource instance that reads XLSX or XLS data from a given location.
        Parameters:
        jasperReportsContext - the JasperReportsContext
        location - a String representing XLSX or XLS data source
        format - the Excel format
        Throws:
        java.io.IOException
        JRException
    • Method Detail

      • loadWorkbook

        protected org.apache.poi.ss.usermodel.Workbook loadWorkbook​(java.io.InputStream inputStream)
                                                             throws java.io.IOException
        Specified by:
        loadWorkbook in class AbstractPoiXlsDataSource
        Throws:
        java.io.IOException