Specify exceller in build.gradle
dependencies {
compile("org.bbreak.excella:excella-core:1.12")
compile("org.bbreak.excella:excella-reports:1.11")
compile("org.bbreak.excella:excella-trans:1.8")
}
Create an Excel template by referring to the following http://excella-core.github.io/excella-core/reference/index.html http://excella-core.osdn.jp/excella-reports/reference/index.html
ExcellMakeService.java
ReportBook outputBook = new ReportBook("C:\\templace\\template.xlsx", "./out", ExcelExporter.FORMAT_TYPE);
ReportSheet outputSheet = new ReportSheet("report");
outputBook.addReportSheet(outputSheet);
//Describe the process to set the value to the variable defined in the template here.(abridgement)
ReportProcessor reportProcessor = new ReportProcessor();
try {
reportProcessor.process(outputBook);
} catch (Exception e) {
e.printStackTrace();
}
Since version 1.12 does not include exceller-pdf exporter, get the source from the following site. https://github.com/excella-core/excella-pdfexporter
Build by incorporating the source obtained from the above into the project.
Since Libre Office is used for conversion to PDF, download and install from the following https://ja.libreoffice.org/
Add code to ExcellMakeService.java above
ExcellMakeService.java
System.setProperty("java.io.tmpdir", "/tmp/");
//Set the path of the obtained Libre Office.
System.setProperty("office.home", "C:\\Program Files\\LibreOffice");
//ExcelExporter.FORMAT_TYPE to OoPdfExporter.FORMAT_Change to TYPE
ReportBook outputBook = new ReportBook("C:\\templace\\template.xlsx", "./out", OoPdfExporter.FORMAT_TYPE);
ReportSheet outputSheet = new ReportSheet("report");
outputBook.addReportSheet(outputSheet);
//Describe the process to set the value to the variable defined in the template here.(abridgement)
ReportProcessor reportProcessor = new ReportProcessor();
//Added OoPdfExporter to Exporter
reportProcessor.addReportBookExporter(new OoPdfExporter());
try {
reportProcessor.process(outputBook);
} catch (Exception e) {
e.printStackTrace();
}
Recommended Posts