用C++将工作簿转换为JSON

将Excel工作簿转换为JSON

Aspose.Cells API支持将电子表格转换为JSON格式。将工作簿导出为JSON,只需将SaveFormat::Json作为Workbook::Save方法的第二个参数传递。也可以使用JsonSaveOptions类来设置导出工作表为JSON的其他参数。

以下的代码示例演示了如何使用 SaveFormat::Json 枚举成员将活动工作表导出为 JSON。请查看代码以将源文件转换为由代码生成的输出 JSON 文件作为参考。

#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

    // Source directory path
    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    // Path of input excel file
    U16String inputFilePath = srcDir + u"Book1.xlsx";

    // Create workbook
    Workbook workbook(inputFilePath);

    // Save the workbook as JSON
    U16String outputFilePath = srcDir + u"book1.json";
    workbook.Save(outputFilePath);

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

    Aspose::Cells::Cleanup();
}

** 高级主题**