保护 Excel 文件 IronXL的 Encrypt 方法使开发人员能够对整个 Excel 工作簿和单个工作表应用密码保护。 此功能对于保护敏感数据至关重要,并确保只有授权用户才能访问或修改 Excel 文件的内容。 IronXL 还允许进行工作表级别的保护,从而防止用户编辑工作簿的某些部分或特定工作表。 这在协作环境中尤其有用,因为你可能希望限制编辑权限,但仍然允许用户查看数据或与数据进行交互。 此外,无论是否使用密码,都可以选择移除保护,这提供了灵活性,使其既适用于安全环境,也适用于需要临时恢复访问权限的情况。 总而言之,此功能是确保自动化数据处理工作流程中 Excel 文件安全的重要工具。 ## 使用密码加密工作簿的 5 个步骤 `var workBook = WorkBook.Load("sample.xlsx");` `workBook.Encrypt("myP@ssw0rd");` `var workSheet = workBook.DefaultWorkSheet;` `workSheet.ProtectSheet("myP@ssw0rd_sheet");` `workBook.Save();` 在这段代码中,首先使用 IronXL 的 WorkBook.Load() 方法从文件 sample.xlsx 加载工作簿。 工作簿加载完毕后,使用 Encrypt() 方法对整个工作簿应用密码保护,密码设置为 myP@ssw0rd。 这样可以确保没有正确的密码就无法打开或修改工作簿。 Next, the default worksheet of the workbook is accessed using the DefaultWorkSheet property. The ProtectSheet() method is then called on this worksheet, applying a password ("myP@ssw0rd_sheet") that restricts editing on the sheet level. 这样可以防止用户在未提供正确密码的情况下对受保护的工作表进行更改。 Finally, the Save() method is invoked to save the changes made to both the workbook and the worksheet, ensuring that the protection settings are preserved in the saved file. This ensures that the workbook and its worksheet are both securely protected and can only be accessed or modified with the respective passwords. 学习如何在 C# 中为 Excel 工作簿设置密码 相关文档链接 在Github上查看 相关教程 相关操作指南 类文档 下载IronXL DLL 报告此页面的问题 A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php Line: 12 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/libraries/Render.php Line: 489 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Examples.php Line: 44 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php Line: 19 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/libraries/Render.php Line: 489 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Examples.php Line: 44 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once 准备开始了吗? Nuget 下载 1,890,100 | 版本: 2026.3 刚刚发布 免费试用 免费 NuGet 下载 总下载量:1,890,100 查看许可证 A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php Line: 17 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/views/products/examples/index.php Line: 270 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 88 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 552 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Examples.php Line: 44 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php Line: 24 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/views/products/examples/index.php Line: 270 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 88 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 552 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Examples.php Line: 44 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once 还在滚动吗? 想快速获得证据? PM > Install-Package IronXl.Excel 运行示例 观看您的数据变成电子表格。 免费 NuGet 下载 总下载量:1,890,100 查看许可证