Convert-Excel-to-JSON with C++

Convert Excel Workbook to JSON

No need to wonder how to convert an Excel workbook to JSON, because the Aspose.Cells for C++ library provides the best solution. 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 worksheets to JSON.

The following code example demonstrates exporting an Excel workbook to JSON. Please see the code that converts the source file (sample.xlsx) 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 a 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 an Excel workbook to JSON. Please see the code that converts the source file (sample.xlsx) 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 options for saving the file.
    JsonSaveOptions options;

    // Set the export range.
    options.SetExportArea(CellArea::CreateCellArea(u"B1", u"C4"));

    // Load your source workbook
    Workbook workbook(u"sample.xlsx");

    // Convert the workbook to a JSON file.
    workbook.Save(u"sample_out.json", options);

    std::cout << "Workbook successfully converted to JSON!" << std::endl;

    Aspose::Cells::Cleanup();
}