Search in sources :

Example 1 with ReportBand

use of com.haulmont.yarg.structure.ReportBand in project tutorials by eugenp.

the class DocumentController method generateDocument.

@RequestMapping(path = "/generate/doc", method = RequestMethod.GET)
public void generateDocument(HttpServletResponse response) throws IOException {
    ReportBuilder reportBuilder = new ReportBuilder();
    ReportTemplateBuilder reportTemplateBuilder = new ReportTemplateBuilder().documentPath("./src/main/resources/Letter.docx").documentName("Letter.docx").outputType(ReportOutputType.docx).readFileFromPath();
    reportBuilder.template(reportTemplateBuilder.build());
    BandBuilder bandBuilder = new BandBuilder();
    String json = FileUtils.readFileToString(new File("./src/main/resources/Data.json"));
    ReportBand main = bandBuilder.name("Main").query("Main", "parameter=param1 $.main", "json").build();
    reportBuilder.band(main);
    Report report = reportBuilder.build();
    Reporting reporting = new Reporting();
    reporting.setFormatterFactory(new DefaultFormatterFactory());
    reporting.setLoaderFactory(new DefaultLoaderFactory().setJsonDataLoader(new JsonDataLoader()));
    response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
    reporting.runReport(new RunParams(report).param("param1", json), response.getOutputStream());
}
Also used : RunParams(com.haulmont.yarg.reporting.RunParams) ReportBuilder(com.haulmont.yarg.structure.impl.ReportBuilder) BandBuilder(com.haulmont.yarg.structure.impl.BandBuilder) Report(com.haulmont.yarg.structure.Report) JsonDataLoader(com.haulmont.yarg.loaders.impl.JsonDataLoader) ReportTemplateBuilder(com.haulmont.yarg.structure.impl.ReportTemplateBuilder) DefaultFormatterFactory(com.haulmont.yarg.formatters.factory.DefaultFormatterFactory) Reporting(com.haulmont.yarg.reporting.Reporting) File(java.io.File) DefaultLoaderFactory(com.haulmont.yarg.loaders.factory.DefaultLoaderFactory) ReportBand(com.haulmont.yarg.structure.ReportBand) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DefaultFormatterFactory (com.haulmont.yarg.formatters.factory.DefaultFormatterFactory)1 DefaultLoaderFactory (com.haulmont.yarg.loaders.factory.DefaultLoaderFactory)1 JsonDataLoader (com.haulmont.yarg.loaders.impl.JsonDataLoader)1 Reporting (com.haulmont.yarg.reporting.Reporting)1 RunParams (com.haulmont.yarg.reporting.RunParams)1 Report (com.haulmont.yarg.structure.Report)1 ReportBand (com.haulmont.yarg.structure.ReportBand)1 BandBuilder (com.haulmont.yarg.structure.impl.BandBuilder)1 ReportBuilder (com.haulmont.yarg.structure.impl.ReportBuilder)1 ReportTemplateBuilder (com.haulmont.yarg.structure.impl.ReportTemplateBuilder)1 File (java.io.File)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1