تحويل JSON إلى Excel

تحويل JSON إلى مصنف Excel

لا داعي للتساؤل عن كيفية تحويل JSON إلى ملف Excel ، لأن مكتبة Apose.Cells for .NET لديها أفضل قرار. يوفر Aspose.Cells API دعمًا لتحويل تنسيق JSON إلى جداول بيانات. يمكنك استخدامJsonLoadOptions فئة لتحديد إعدادات إضافية لاستيراد JSON إلى المصنف.

يوضح مثال التعليمات البرمجية التالي استيراد JSON إلى Excel Workbook. يرجى الاطلاع على الكود للتحويلمصدر الملف إلى ملف 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 Workbook. يرجى الاطلاع على الكود للتحويلمصدر الملف إلى ملف xlsx الذي تم إنشاؤه بواسطة الكود كمرجع.

// 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 Workbook. يمكنك أيضًا تحديد موقع التخطيط عند استيراد JSON. الرجاء مراجعة الكود لتحويل سلسلة JSON إلى ملف xlsx الذي تم إنشاؤه بواسطة الرمز كمرجع.

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