通过 C++ 保护或取消保护共享工作簿

可能的使用场景

您可以像以下截图中的 Microsoft Excel 一样使用 Aspose.Cells 保护或取消保护共享工作簿。Aspose.Cells 还支持使用 Workbook::ProtectSharedWorkbook() 和 Workbook::UnprotectSharedWorkbook() 方法进行此操作。

todo:image_alt_text

密码保护或取消保护共享工作簿

以下示例代码创建一个工作簿并保护它,同时启用共享,然后将其另存为 输出 Excel 文件。截图显示当您尝试取消保护时,Microsoft Excel 会提示您输入密码以取消保护。

todo:image_alt_text

示例代码

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Create empty Excel file
    Workbook wb;

    // Protect the Shared Workbook with Password
    wb.ProtectSharedWorkbook(u"1234");

    // Uncomment this line to Unprotect the Shared Workbook
    // wb.UnprotectSharedWorkbook(u"1234");

    // Save the output Excel file
    wb.Save(u"outputProtectSharedWorkbook.xlsx");

    std::cout << "Shared workbook protection applied successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}