use of org.pivot4j.PivotModel in project bamboobsc by billchen198318.
the class Pivot4JUtils method getPivotModel.
private static PivotModel getPivotModel(OlapDataSource dataSource, String mdx) throws Exception {
PivotModel model = new PivotModelImpl(dataSource);
model.setMdx(mdx);
model.initialize();
return model;
}
use of org.pivot4j.PivotModel 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;
}
use of org.pivot4j.PivotModel in project bamboobsc by billchen198318.
the class Pivot4JUtils method rendererHtml.
public static String rendererHtml(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.");
}
String body = "";
OlapConnection connection = OlapUtils.getConnection(mondrianUrl);
OlapDataSource dataSource = new SingleConnectionOlapDataSource(connection);
try {
PivotModel model = getPivotModel(dataSource, mdx);
TableRenderer renderer = getTableRenderer(showDimensionTitle, showParentMembers);
StringWriter writer = new StringWriter();
renderer.render(model, new HtmlRenderCallback(writer));
//writer.write(body);
body = writer.toString();
writer.flush();
writer.close();
} catch (Exception e) {
throw e;
} finally {
OlapUtils.nullConnection(connection);
connection = null;
dataSource = null;
}
return body;
}
Aggregations