For the purpose of everyday analysis of financial results, there's a way to create reports from JSON data and lay them out in several formats like PDF, DOCX, XLSX, PPTX, ODS, XML, CSV, etc. You can then combine it with your 4GL application to:
For generating a report, you have to prepare the following:
To create a report, proceed as follows:
Step 1. Install LibreOffice on your machine: LibreOffice Installation.
Step 2. Install Node.JS of a version 14 or higher, and install npm:
sudo apt install npm
Step 3. Create a Node project:
npm init
Step 4. Add the Carbone dependency:
npm i carbone
Step 6. Create a script (for example, we will call the following script rg.mjs):
import carbone
from 'carbone';
import fs from 'fs';
const options = {
convertTo : 'pdf' //can be docx, txt, ...
}
const template = process.argv[2];
const data = JSON.parse(fs.readFileSync(process.argv[3], {encoding: 'utf8'}));
const output = process.argv[4];
const format = process.argv[5];
if (format) {
options.convertTo = format;
}
carbone.render(template, data, options, function(err, result){
if (err) {
return console.log(err);
}
fs.writeFileSync(output, result);
process.exit(); // to kill LibreOffice workers automatically
});
Step 7. Create a template and use it in the command for the report creation:
node rg.mjs <path_to_template> <path_to_data_file> <path_to_output_file> <optional_output_format>