JSONをExcelに変換する
JSONをExcelワークブックに変換する
ExcelファイルをJSONに変換する方法を疑問に思う必要はありません。なぜなら、Apose.Cells for .NETライブラリには最良の決定があるからです。Aspose.Cells APIは、JSON形式をスプレッドシートに変換するサポートを提供します。JsonLoadOptionsクラスを使用してJSONをワークブックにインポートするための追加設定を指定することができます。
以下のコード例は、JSONをExcelワークブックにインポートする方法を示しています。参照用に、ソースファイルをコードによって生成されたxlsxファイルに変換するためのコードが含まれています。
// 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ファイルへの変換のために、source fileを参照してください。
// 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文字列を参照してください。
// 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"); |