Convert-JSON-to-Excel
Convert JSON to Excel Workbook
No need to wonder how to convert JSON to Excel file, because Aspose.Cells for Python via .NET library has best decision. The Aspose.Cells for Python via .NET API provides support for converting JSON format to spreadsheets. You can use JsonLoadOptions class to specify additional settings for importing JSON to Workbook.
The following code example demonstrates importing JSON to Excel Workbook. Please see the code to convert source file to to the xlsx file generated by the code for reference.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# create a Workbook object | |
wb = Workbook("sample.json") | |
# save file to xlsx format | |
wb.save("sample_out.xlsx") |
The following code example which uses JsonLoadOptions class to specify additional settings demonstrates importing JSON to Excel Workbook. Please see the code to convert source file to the xlsx file generated by the code for reference.
from aspose.cells import JsonLoadOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create an options of loading the file. | |
options = JsonLoadOptions() | |
# Indicates whether importing each attribute of JsonObject object as one worksheet when all child nodes are array nodes. | |
options.multiple_worksheets = True | |
book = Workbook("sample.json", options) | |
# save file to xlsx format | |
book.save("sample_out.xlsx") |
The following code example demonstrates importing JSON string to Excel Workbook. You can also specify the location of the layout when importing JSON. Please see the code to convert JSON string to to the xlsx file generated by the code for reference.
from aspose.cells import Workbook | |
from aspose.cells.utility import JsonLayoutOptions, JsonUtility | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
inputJson = r"[ | |
{ BEFORE: 'before cell', TEST: 'asd1', AFTER: 'after cell' }, | |
{ BEFORE: 'before cell', TEST: 'asd2', AFTER: 'after cell' }, | |
{ BEFORE: 'before cell', TEST: 'asd3', AFTER: 'after cell' }, | |
{ BEFORE: 'before cell', TEST: 'asd4', AFTER: 'after cell' } | |
]" | |
sheetName = "Sheet1" | |
row = 3 | |
column = 2 | |
# create a Workbook object | |
book = Workbook() | |
worksheet = book.worksheets.get(sheetName) | |
# set JsonLayoutOptions to treat Arrays as Table | |
jsonLayoutOptions = JsonLayoutOptions() | |
jsonLayoutOptions.array_as_table = True | |
JsonUtility.import_data(inputJson, worksheet.cells, row, column, jsonLayoutOptions) | |
# save file to xlsx format | |
book.save("out.xlsx") |