Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
No need to wonder how to convert JSON to an Excel file, because the Aspose.Cells for C++ library provides the best solution. The Aspose.Cells API provides support for converting JSON format to spreadsheets. You can use the JsonLoadOptions class to specify additional settings for importing JSON into a workbook.
The following code example demonstrates importing JSON into an Excel workbook. Please see the code that converts the source file to the XLSX file generated by the code for reference.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Create a Workbook object from a JSON file
Workbook workbook(u"sample.json");
// Save the file to xlsx format
workbook.Save(u"sample_out.xlsx");
std::cout << "File saved successfully in xlsx format!" << std::endl;
Aspose::Cells::Cleanup();
}
The following code example, which uses the JsonLoadOptions class to specify additional settings, demonstrates importing JSON into an Excel workbook. Please see the code that converts the source file to the XLSX file generated by the code for reference.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Create an options object for loading the file.
JsonLoadOptions options;
// Indicates whether to import each attribute of a JsonObject as a separate worksheet when all child nodes are array nodes.
options.SetMultipleWorksheets(true);
// Create a workbook from the JSON file with the specified options.
U16String inputFilePath(u"sample.json");
Workbook book(inputFilePath, options);
// Save file to xlsx format.
U16String outputFilePath(u"sample_out.xlsx");
book.Save(outputFilePath);
std::cout << "File converted successfully to xlsx format!" << std::endl;
Aspose::Cells::Cleanup();
}
The following code example demonstrates importing a JSON string into an Excel workbook. You can also specify the location of the layout when importing JSON. Please see the code that converts the JSON string to the XLSX file generated by the code for reference.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// JSON input string
U16String inputJson = uR"([
{ 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' }
])";
U16String sheetName = u"Sheet1";
int32_t row = 3;
int32_t column = 2;
// Create a Workbook object
Workbook book;
Worksheet worksheet = book.GetWorksheets().Get(sheetName);
// Set JsonLayoutOptions to treat arrays as a table
JsonLayoutOptions jsonLayoutOptions;
jsonLayoutOptions.SetArrayAsTable(true);
// Import JSON data into the worksheet
JsonUtility::ImportData(inputJson, worksheet.GetCells(), row, column, jsonLayoutOptions);
// Save the file to xlsx format
book.Save(u"out.xlsx");
std::cout << "Data imported successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.