Posted 5 June 2026, 6:11 pm EST
Hello,
I need help with how to bind data to a template from a json file. I have been successful with instances but the documentation is not helping me with my use case. I have a sample schema below where I have elements at the root level and then an array of objects (a datatable), and I need to know how to bind the array. I do not know how many elements/rows are in the array but I DO know that the schema (columns) is always the same.
schema
{
"id": 1111,
"nb": "2016-02-19",
"rb": "2016-04-01",
"pd": "P",
"chgRows": [
{
"sid": 1234,
"cv": "010",
"pr": 100.00,
"rt": 150.00
},
{
"sid": 1523,
"cv": "020",
"pr": 180.00,
"rt": 140.00
}]
}Source code
public static void Template()
{
WorkbookOptions options = new WorkbookOptions();
options.setPixelBasedColumnWidth(true);
String realData="";
IWorkbook workbook = new Workbook(options);
workbook.open("C:/files/Exceltemplate.xlsx");
realData = new String(Files.readAllBytes(Paths.get("c:/temp/real.json")));
JsonDataSource real = new JsonDataSource(realData);
workbook.addDataSource("real",real);
workbook.processTemplate();
workbook.save("c:/temp/results.xlsx" );
}

