Search in sources :

Example 1 with ExcelExporter

use of org.pivot4j.ui.poi.ExcelExporter in project bamboobsc by billchen198318.

the class Pivot4JUtils method exportExcelFile.

public static File exportExcelFile(String mondrianUrl, String mdx, boolean showDimensionTitle, boolean showParentMembers) throws Exception {
    if (StringUtils.isBlank(mondrianUrl) || StringUtils.isBlank(mdx)) {
        throw new java.lang.IllegalArgumentException("mondrian url and MDX cannot blank.");
    }
    File file = new File(Constants.getWorkTmpDir() + "/" + SimpleUtils.getUUIDStr() + ".xlsx");
    OutputStream os = new FileOutputStream(file);
    OlapConnection connection = OlapUtils.getConnection(mondrianUrl);
    OlapDataSource dataSource = new SingleConnectionOlapDataSource(connection);
    try {
        PivotModel model = getPivotModel(dataSource, mdx);
        TableRenderer renderer = getTableRenderer(showDimensionTitle, showParentMembers);
        ExcelExporter exporter = new ExcelExporter(os);
        exporter.setFormat(Format.XSSF);
        renderer.render(model, exporter);
    } catch (Exception e) {
        file = null;
        throw e;
    } finally {
        if (os != null) {
            IOUtils.closeQuietly(os);
            os = null;
        }
        OlapUtils.nullConnection(connection);
        connection = null;
        dataSource = null;
    }
    return file;
}
Also used : TableRenderer(org.pivot4j.ui.table.TableRenderer) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) OlapDataSource(org.olap4j.OlapDataSource) PivotModel(org.pivot4j.PivotModel) ExcelExporter(org.pivot4j.ui.poi.ExcelExporter) OlapConnection(org.olap4j.OlapConnection) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IOException(java.io.IOException)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OlapConnection (org.olap4j.OlapConnection)1 OlapDataSource (org.olap4j.OlapDataSource)1 PivotModel (org.pivot4j.PivotModel)1 SingleConnectionOlapDataSource (org.pivot4j.datasource.SingleConnectionOlapDataSource)1 ExcelExporter (org.pivot4j.ui.poi.ExcelExporter)1 TableRenderer (org.pivot4j.ui.table.TableRenderer)1