Hello, I’d like to know what value to set to documentPath if using this in a web application.
This was the guide I used:
currently, I set it to a local path. And it works perfectly.
However, if I deploy it to the cloud, what location should I set it to?
incomes.xml
<report name="report">
<templates>
<template code="DEFAULT" documentName="incomes.xlsx" documentPath="D:\\localpath\\incomes.xlsx" outputType="xlsx" outputNamePattern="incomes.xlsx"/>
</templates>
<rootBand name="Root" orientation="H">
<bands>
<band name="Header" orientation="H"/>
<band name="Incomes" orientation="H">
<queries>
<query name="Data_set_1" type="groovy">
<script>
return [['month':'Jan', 'profit':10000], ['month': 'Feb', 'profit': 12000], ['month': 'March', 'profit': 15000], ['month': 'Apr', 'profit': 12000]]
</script>
</query>
</queries>
</band>
<band name="Footer" orientation="H"/>
<band name="Chart" orientation="H"/>
</bands>
<queries/>
</rootBand>
</report>
This is my controller.
ReportController.java
@RequestMapping(value="/reports/getpdf", method=RequestMethod.GET)
public @ResponseBody ResponseEntity<byte[]> getPDF() throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("incomes.xml").getFile());
Report report = new DefaultXmlReader().parseXml(readFileToString(file));
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 = "output.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;
}