@Shyamu,
We have analyzed your expected output and observed that you want to expand data in two dimensions i.e. row wise and column wise that is not supported. You may try importing data with JSON utility that iterates nested list and imports data into workbook.
public static void main(String[] args) throws Exception {
String dataresult = "[\r\n" +
" {\r\n" +
" \"id\": \"1\",\r\n" +
" \"name\": \"Name 1\",\r\n" +
" \"code\": \"CODE2\",\r\n" +
" \"itemunit\": \"Days\",\r\n" +
" \"description\": \"Descriped\",\r\n" +
" \"itemcategory\": \"Custom Itemcategory\",\r\n" +
" \"type\": \"OL Type\",\r\n" +
" \"firstitemvalue\": \"100\",\r\n" +
"\"firstitemdate\": \"2021-06-09T17:36:37Z\",\r\n" +
"\"enditemvalue\": \"100\",\r\n" +
"\"enditemdate\": \"2021-06-09T17:36:37Z\",\r\n" +
" \"intermediateitem\": [{\r\n" +
" \r\n" +
" \"value\": \"20\",\r\n" +
"\"date\":\"2021-06-09T17:36:37Z\"\r\n" +
"}, {\r\n" +
" \r\n" +
" \"value\": \"30\",\r\n" +
"\"date\":\"2021-06-09T17:36:37Z\"\r\n" +
"}, {\r\n" +
" \r\n" +
" \"value\": \"40\",\r\n" +
"\"date\":\"2021-06-09T17:36:37Z\"\r\n" +
"}],\r\n"+
" \"comments\": \"Commented\"\r\n" +
" },\r\n" +
" {\r\n" +
" \"id\": \"2\",\r\n" +
" \"name\": \"Name 2\",\r\n" +
" \"code\": \"COD1\",\r\n" +
" \"itemunit\": \"Days\",\r\n" +
" \"description\": \"Descriped\",\r\n" +
" \"itemcategory\": \"Custom Itemcategory\",\r\n" +
" \"type\": \"Custom Type\",\r\n" +
" \"firstitemvalue\": \"100\",\r\n" +
"\"firstitemdate\": \"2021-06-09T17:36:37Z\",\r\n" +
"\"enditemvalue\": \"100\",\r\n" +
"\"enditemdate\": \"2021-06-09T17:36:37Z\",\r\n" +
" \"intermediateitem\": [{\r\n" +
" \r\n" +
" \"value\": \"20\",\r\n" +
"\"date\":\"2021-06-09T17:36:37Z\"\r\n" +
"}, {\r\n" +
" \r\n" +
" \"value\": \"30\",\r\n" +
"\"date\":\"2021-06-09T17:36:37Z\"\r\n" +
"}, {\r\n" +
" \r\n" +
" \"value\": \"40\",\r\n" +
"\"date\":\"2021-06-09T17:36:37Z\"\r\n" +
"}, {\r\n" +
" \r\n" +
" \"value\": \"50\",\r\n" +
"\"date\":\"2021-06-09T17:36:37Z\"\r\n" +
"}],\r\n" +
" \"comments\": \"Commented\"\r\n" +
" }\r\n" +
"]";
ImportJsonString(dataresult);
// Print the message
System.out.println("WorkSheet executed successfully.");
}
static void ImportJsonString(String dataresult) throws Exception
{
//Create workbook object
Workbook wb = new Workbook();
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Specify import table options
ImportTableOptions opts = new ImportTableOptions();
// Set Styles
CellsFactory factory = new CellsFactory();
Style style = factory.createStyle();
style.setHorizontalAlignment(TextAlignmentType.CENTER);
style.getFont().setColor(Color.getBlueViolet());
style.getFont().setBold(true);
// Set JsonLayoutOptions
JsonLayoutOptions options = new JsonLayoutOptions();
options.setTitleStyle(style);
options.setArrayAsTable(true);
// Import JSON Data
JsonUtility.importData(dataresult, ws.getCells(), 0, 0, options);
// Save Excel file
wb.save("ImportingFromJson.xlsx");
}