Java 类net.sf.jasperreports.engine.data.JRXlsxDataSource 实例源码

项目:ireport-fork    文件:JRXlsxDataSourceConnection.java   
/**
 *  This method return an instanced JRDataDource to the database.
 *  If isJDBCConnection() return true => getJRDataSource() return false
 */
@Override
public net.sf.jasperreports.engine.JRDataSource getJRDataSource() { 

    try {
        JRXlsxDataSource ds = new JRXlsxDataSource(new File(getFilename()));
        if (this.getCustomDateFormat() != null && this.getCustomDateFormat().length() > 0)
        {
            ds.setDateFormat(new SimpleDateFormat(this.getCustomDateFormat()));
        }
        if (this.getCustomNumberFormat() != null && this.getCustomNumberFormat().length() > 0)
        {
            ds.setNumberFormat(new DecimalFormat(this.getCustomNumberFormat()));
        }

        ds.setUseFirstRowAsHeader( isUseFirstRowAsHeader());

        if (!isUseFirstRowAsHeader())
        {
            String[] names = new String[getColumnNames().size()];
            int[] indexes = new int[getColumnNames().size()];

            for (int i=0; i<names.length; ++i )
            {
                names[i] = ""+getColumnNames().get(i);
                indexes[i] = (getColumnIndexes().size() > i) ? getColumnIndexes().get(i) : i;
            }
            ds.setColumnNames( names, indexes);
        }

        return ds;

    } catch (Exception ex)
    {
        ex.printStackTrace();
        return super.getJRDataSource();
    }
}