JSONをExcelに変換する

JSONをExcelワークブックに変換する

Aspose.Cells for Python via .NETライブラリがベストな判断を提供しているため、JSONをExcelファイルに変換する方法を不明に思う必要はありません。Aspose.Cells for Python via .NET APIは、JSON形式をスプレッドシートに変換する機能を提供します。JsonLoadOptions クラスを使用して、ワークブックにJSONをインポートするための追加設定を指定できます。

以下のコード例は、JSONをExcelワークブックにインポートする方法を示しています。参照用に、ソースファイルをコードによって生成されたxlsxファイルに変換するためのコードが含まれています。

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

以下のコード例は、JsonLoadOptionsクラスを使用して追加の設定を指定することで、JSONをExcelワークブックにインポートする方法を示しています。コードで生成されたxlsxファイルへの変換のために、source fileを参照してください。

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

以下のコード例は、JSON文字列をExcelワークブックにインポートする方法を示しています。JSONのインポート時にレイアウトの場所を指定することもできます。コードで生成されたxlsxファイルへの変換のために、JSON文字列を参照してください。

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