Convert-JSON-to-Excel
Contents
[
Hide
]
Aspose.Cells は、Json(JavaScript Object Notation) ファイルの Excel ワークブックへの変換をサポートしています。
JSON を Excel ブックに変換
Apose.Cells for .NET ライブラリが最適な決定を行うため、JSON を Excel ファイルに変換する方法を考える必要はありません。 Aspose.Cells API は、JSON 形式をスプレッドシートに変換するためのサポートを提供します。使用できますJsonLoadOptionsクラスを使用して、JSON を Workbook にインポートするための追加設定を指定します。
次のコード例は、JSON を Excel ブックにインポートする方法を示しています。変換するコードを参照してくださいソースファイル参照用のコードによって生成された xlsx ファイルに。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// create a Workbook object | |
Workbook wb = new Workbook("sample.json"); | |
//save file to xlsx format | |
wb.Save("sample_out.xlsx"); |
JsonLoadOptions クラスを使用して追加の設定を指定する次のコード例は、JSON を Excel ワークブックにインポートする方法を示しています。変換するコードを参照してくださいソースファイル参照用のコードによって生成された xlsx ファイルに。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. | |
JsonLoadOptions options = new JsonLoadOptions(); | |
//Indicates whether importing each attribute of JsonObject object as one worksheet when all child nodes are array nodes. | |
options.MultipleWorksheets = true; | |
Workbook book = new Workbook("sample.json", options); | |
//save file to xlsx format | |
book.Save("sample_out.xlsx"); |
次のコード例は、JSON 文字列を Excel ブックにインポートする方法を示しています。 JSON をインポートするときに、レイアウトの場所を指定することもできます。参照用に、コードによって生成された xlsx ファイルに JSON 文字列を変換するコードを参照してください。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
string inputJson = @"[ | |
{ 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' } | |
]"; | |
string sheetName = "Sheet1"; | |
int row = 3; | |
int column = 2; | |
// create a Workbook object | |
Workbook book = new Workbook(); | |
Worksheet worksheet = book.Worksheets[sheetName]; | |
// set JsonLayoutOptions to treat Arrays as Table | |
JsonLayoutOptions jsonLayoutOptions = new JsonLayoutOptions(); | |
jsonLayoutOptions.ArrayAsTable = true; | |
JsonUtility.ImportData(inputJson, worksheet.Cells, row, column, jsonLayoutOptions); | |
//save file to xlsx format | |
book.Save("out.xlsx"); |