// Create a new workbook Workbook workbook = new Workbook(); //Load template file from resource InputStream templateFile = this.getResourceStream("xlsx/Template_JsonDataImageTemplate.xlsx"); workbook.open(templateFile); //Get data from json file String jsonText = ""; try (InputStream stream = this.getResourceStream("json/imageTemplate.json")) { ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = stream.read(buffer)) != -1) { result.write(buffer, 0, length); } jsonText = result.toString("UTF-8"); } catch (IOException e) { e.printStackTrace(); } // Create a JsonDataSource JsonDataSource datasource = new JsonDataSource(jsonText); //Init template global settings workbook.getNames().add("TemplateOptions.KeepLineSize", "true"); //Add data source workbook.addDataSource("ds", datasource); //Invoke to process the template workbook.processTemplate(); // Save to an excel file workbook.save("JsonDataImageTemplate.xlsx");