Dönüştür-JSON-to-Excel

JSON’i Excel Çalışma Kitabına Dönüştür

JSON Excel dosyasına nasıl dönüştürülür diye düşünmenize gerek yok çünkü Aspose.Cells Java kitaplığı en iyi kararı verir. Aspose.Cells Java API, JSON formatını elektronik tablolara dönüştürmek için destek sağlar. KullanabilirsinizJsonLoadOptions JSON’i Çalışma Kitabına içe aktarmak için ek ayarları belirtmek için sınıf.

Aşağıdaki kod örneği, JSON’in Excel Çalışma Kitabına alınmasını gösterir. Lütfen dönüştürülecek koda bakınKaynak dosyası referans için kod tarafından oluşturulan xlsx dosyasına.

//Load Source JSON file
Workbook workbook = new Workbook("sample.json");
//Save file to xlsx format
workbook.save("sample_out.xlsx");

Ek ayarlar belirtmek için JsonLoadOptions sınıfını kullanan aşağıdaki kod örneği, JSON’in Excel Çalışma Kitabına alınmasını gösterir. Lütfen dönüştürülecek koda bakınKaynak dosyası referans için kod tarafından oluşturulan xlsx dosyasına.

//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.setMultipleWorksheets(true);
Workbook book = new Workbook("sample.json", options);
//save file to xlsx format
book.save("sample_out2.xlsx");

Aşağıdaki kod örneği, JSON dizesinin Excel Çalışma Kitabına alınmasını gösterir. JSON’i içe aktarırken yerleşimin konumunu da belirtebilirsiniz. Lütfen JSON dizesini referans için kod tarafından oluşturulan xlsx dosyasına dönüştürmek için koda bakın.

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.getWorksheets().get(sheetName);
//set JsonLayoutOptions to treat Arrays as Table
JsonLayoutOptions jsonLayoutOptions = new JsonLayoutOptions();
jsonLayoutOptions.setArrayAsTable(true);
JsonUtility.importData(inputJson, worksheet.getCells(), row, column, jsonLayoutOptions);
//save file to xlsx format
book.save("out.xlsx");