Convert-Excel-to-JSON with C++
Convert Excel Workbook to JSON
No need to wonder how to convert Excel Workbook to JSON, because Aspose.Cells for C++ library has the best decision. The Aspose.Cells API provides support for converting spreadsheets to JSON format. To export the workbook to JSON, pass SaveFormat.Json as the second parameter of the Workbook.Save method. You may also use the JsonSaveOptions class to specify additional settings for exporting worksheet to JSON.
The following code example demonstrates exporting Excel Workbook to JSON. Please see the code to convert source file to the JSON 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
// Load your source workbook
U16String inputFilePath(u"sample.xlsx");
Workbook workbook(inputFilePath);
// Convert the workbook to JSON file.
U16String outputFilePath(u"sample_out.json");
workbook.Save(outputFilePath, SaveFormat::Json);
std::cout << "Workbook converted to JSON successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
The following code example which uses the JsonSaveOptions class to specify additional settings demonstrates exporting Excel Workbook to JSON. Please see the code to convert source file to the JSON 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 of saving the file.
JsonSaveOptions options;
// Set the exporting range.
options.SetExportArea(CellArea::CreateCellArea(u"B1", u"C4"));
// Load your source workbook
Workbook workbook(u"sample.xlsx");
// Convert the workbook to json file.
workbook.Save(u"sample_out.json", options);
std::cout << "Workbook successfully converted to JSON!" << std::endl;
Aspose::Cells::Cleanup();
}