Problem Statement: I want to import a JSON string as an excel file using Aspose.Cells for .NET.
JSON details:
JSON string serialized based on object - ResponseMessage,
public class ResponseMessage
{
public List LstMyCustomDatatype { get; set; }
public List<string> LstErrorMessages { get; set; }
}
public class MyCustomDatatype
{
public int Prop1{ get; set; }
public string Prop2{ get; set; }
public string Prop3{ get; set; }
public string Prop4{ get; set; }
}
Where, No. of items in first and second list will differ and need not match. For ex, MyCustomDatatype can include 4 MyCustomDatatype kind of list items and LstErrorMessages can include any number of strings like zero or two or ten etc.
MyCustomDatatype is balanced a JSON internally. For 4 MyCustomDatatype objects, it will have value for each property.
Now, I am able to import JSON string to excel only if LstErrorMessages has no items, otherwise it fails with the exception - Invalid end column index.
My current code details:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
JsonLayoutOptions options = new JsonLayoutOptions();
options.TitleStyle = SetStyles();
options.ArrayAsTable = true;
// Import JSON Data
JsonUtility.ImportData(jsonContent, worksheet.Cells, 0, 0, options);
// Auto-fit all the columns
worksheet.AutoFitColumns();
// Save Excel file
workbook.Save(reportFileName);
Notes:
- code based on: Import Data into Worksheet|Documentation
- jsonContent is a valid JSON. Able to view in JSON Visualizer in Visual Studio.
Could not locate more information for this issue on support.
Kindly, let me know if more details required. Kindly help me out.
Regards,
Apurva