Hello,
Similar to my question here, I’d like to know how I’ll be able to instantiate a template builder when the template is deployed in a webapp.
I tried doing this:
ReportTemplateBuilder reportTemplateBuilder = new ReportTemplateBuilder()
.documentName("liquidationReport1stPage.xlsx")
.documentPath("reports/liquidationReport1stPage.xlsx")
.documentContent(documentContent)
.outputType(ReportOutputType.xlsx)
.readFileFromPath();
However, it seems from this code, it reads from the local file system:
public ReportTemplateBuilder readFileFromPath() throws IOException {
Preconditions.checkNotNull(reportTemplate.documentPath, "\"documentPath\" parameter is null. Can not load data from null path");
reportTemplate.documentContent = FileUtils.readFileToByteArray(new File(reportTemplate.documentPath));
return this;
}
My code after instantiating the template are the ff.:
BandBuilder bandBuilder = new BandBuilder();
ReportBand main= bandBuilder.name("Main").query("Main", "return [\n" +
" [\n" +
" 'district': 'District 1',\n" +
" 'locale' : 'Chiba',\n" +
" 'forTheMonthOf' : 'For the Month of May 2016'\n" +
" ]]", "groovy").build();
Report report = reportBuilder.build();
Reporting reporting = new Reporting();
reporting.setFormatterFactory(new DefaultFormatterFactory());
reporting.setLoaderFactory(
new DefaultLoaderFactory()
.setGroovyDataLoader(new GroovyDataLoader(new DefaultScriptingImpl())));
ReportOutputDocument reportOutputDocument = reporting.runReport(new RunParams(report));
byte[] contents = reportOutputDocument.getContent();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
String filename = "liquidation_report.xlsx";
headers.set("Content-Disposition", "attachment; filename=" + filename);
headers.setContentLength(contents.length);
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(contents, headers, HttpStatus.OK);
return response;
This results to the ff. excel error:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error040160_01.xml</logFileName>
<summary>
Excel found unreadable content in 'XXXXX.xlsx'
</summary>
<additionalInfo>
<info>Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.</info>
</additionalInfo>
<removedParts summary="Removed parts:">
<removedPart>Removed part: XML error in /xl/calcChain.xml .
Formula from /xl/calcChain.xml part (Calculation properties) fatal error. Location, line 1, column 421.</removedPart>
</removedParts>
<repairedParts summary="List of Repair">
<repairedPart>Repaired Part: XML error in /xl/worksheets/sheet1.xml part. Fatal error. Line 1, Column 1268.</repairedPart>
</repairedParts>
</recoveryLog>
I’m attaching the actual error as well (albeit it’s in Japanese). I just translated it here.
Regards,
Jonathan