Convert JSON to Excel

Converti JSON in Excel Workbook

Non c’è bisogno di chiedersi come convertire un file JSON in formato Excel, perché la libreria Aspose.Cells per l’API Python via .NET ha la soluzione migliore. L’API Aspose.Cells per Python via .NET fornisce supporto per la conversione del formato JSON in fogli di calcolo. Puoi utilizzare la classe JsonLoadOptions per specificare impostazioni aggiuntive per l’importazione di JSON in un libro di lavoro.

L’esempio di codice seguente dimostra l’importazione di JSON in Excel Workbook. Si prega di consultare il codice per convertire file di origine nel file xlsx generato dal codice per riferimento.

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")

L’esempio di codice seguente che utilizza la classe JsonLoadOptions per specificare impostazioni aggiuntive dimostra l’importazione di JSON in Excel Workbook. Si prega di consultare il codice per convertire file di origine nel file xlsx generato dal codice per riferimento.

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")

L’esempio di codice seguente dimostra l’importazione di una stringa JSON in Excel Workbook. È anche possibile specificare la posizione del layout durante l’importazione di JSON. Si prega di consultare il codice per convertire la stringa JSON nel file xlsx generato dal codice per riferimento.

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")