取消保护工作表
Contents
[
Hide
]
如果开发人员需要在运行时从受保护的工作表中移除保护,以便对文件进行一些更改?这可以很容易地通过Aspose.Cells完成。
取消保护工作表
使用Microsoft Excel
要取消工作表的保护:
在工具菜单中,选择保护,然后选择取消保护工作表。 除非工作表受到密码保护,否则保护将被移除。 在这种情况下,会提示输入密码。 输入密码,工作表将取消保护。
使用Aspose.Cells取消简单保护的工作表
可以通过调用Worksheet类的Unprotect方法来取消工作表的保护。 简单受保护的工作表是没有设置密码保护的工作表。 可以通过调用Unprotect方法来取消这样的工作表的保护而不传递参数。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Unprotecting the worksheet without a password | |
worksheet.Unprotect(); | |
// Saving the Workbook | |
workbook.Save(dataDir + "output.xls", SaveFormat.Excel97To2003); |
使用Aspose.Cells取消受密码保护的工作表
受密码保护的工作表是使用密码保护的工作表。 可以通过调用带有密码参数的重载版本的Unprotect方法来取消这样的工作表的保护。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Unprotecting the worksheet with a password | |
worksheet.Unprotect(""); | |
// Save Workbook | |
workbook.Save(dataDir + "output.out.xls"); |