Здравствуйте. Интересует вопрос генерации отчёта из json в консоли linux используя yarg. С лёгкостью удалось реализовать получение отчёта используя postgresql. Проштудировав документацию в т.ч. https://github.com/cuba-platform/yarg/wiki/Data-loaders и форум, к сожалению, не нашёл алгоритма как создавать .xlsx или .docx отчёты из json.
Подскажите пожалуйста как запустить через yarg ваш пример отсюда https://github.com/cuba-platform/yarg/tree/master/core/modules/core/test/sample/invoice
Возможно, надо создать по-аналогии с postgresql файл reporting.properties, но что указывать в поле …driver я не смог понять (к сожалению, java не владею).
Здравствуйте.
Давайте чуть подробнее рассмотрим пример https://github.com/cuba-platform/yarg/tree/master/core/modules/core/test/sample/invoice
- Шаблон отчета имеет docx - формат. Таблицу совместимости форматов шаблона и выходного документа можно найти в данной документации: https://doc.cuba-platform.com/reporting-6.3-ru/template_to_output.html
Из таблицы понятно, что при шаблоне в DOCX, возможна генерация DOCX и PDF - документов
- Чтобы JSON-отчет из примера печатался в DOCX-формате мы должны внести модификации в invoice-json.xml - указать соответсвующие outputType и outputNamePattern для шаблона
(В моем проекте файлы лежат в директории D:/templates/)
<template code="DEFAULT" documentName="invoice.docx" documentPath="D:/template/invoice.docx" outputType="docx" outputNamePattern="invoice.docx" ></template>
- Чтобы файл генерировался с правильным именем, придется немного подправить InvoiceTest.java
public void testInvoiceJsonReport() throws Exception {
String template = "D:/template/invoice-json.xml";
String data = "D:/template/invoice-data.json";
Report report = new DefaultXmlReader().parseXml(FileUtils.readFileToString(new File(template)));
Reporting reporting = new Reporting();
DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory();
reporting.setFormatterFactory(formatterFactory);
reporting.setLoaderFactory(new DefaultLoaderFactory()
.setGroovyDataLoader(new GroovyDataLoader(new DefaultScriptingImpl()))
.setJsonDataLoader(new JsonDataLoader()));
String json = FileUtils.readFileToString(new File(data));
String namepattern = report.getReportTemplates().get("DEFAULT").getOutputNamePattern();
ReportOutputDocument reportOutputDocument = reporting.runReport(new RunParams(report).param("param1", json),
new FileOutputStream("D:/result/json-"+namepattern));
}
После этих модификаций будет генерироваться DOCX-репорт с именем json-invoice.docx
- Далее, если Вам требуется генерация отчета в XLSX-формате, необходимо:
а) создать XSLX-шаблон (пример можно найти тут: https://github.com/cuba-platform/yarg/wiki/Quick-start)
б) в invoice-json.xml настроить темплейт: указать путь до шаблона, проставить outputType=“xlsx” и outputNamePattern=“invoice.xlsx”
Должно работать.