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;
}
Aggregations