加密和解密ODS文件
Contents
[
Hide
]
OpenOffice.org是一个功能齐全的办公套件,支持对文件进行密码保护和加密。然而,加密的ODS文件只能在提供密码后才能在OpenOffice中打开。Excel无法打开加密的ODS文件,可能会弹出警告消息。与其他文件类型不同,加密选项不适用于ODS文件。
Aspose.Cells允许对ODS文件进行加密和解密。解密的ODS文件可以同时在Excel和OpenOffice中打开。
在OpenOffice Calc中加密
- 选择另存为并点击加上密码保存框。
- 点击保存按钮。
- 在打开密码窗口中的输入打开文件的密码和确认密码字段中键入所需的密码。
- 点击确定按钮以保存文件。
使用Aspose.Cells for .Net加密ODS文件
要对ODS文件进行加密,加载文件并在保存之前将WorkbookSettings.Password值设置为实际密码。加密的输出ODS文件只能在OpenOffice中打开。
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 sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Open an ODS file | |
Workbook workbook = new Workbook(sourceDir + "sampleODSFile.ods"); | |
// Password protect the file | |
workbook.Settings.Password = "1234"; | |
// Save the ODS file | |
workbook.Save(outputDir + "outputEncryptedODSFile.ods"); |
使用Aspose.Cells for .Net解密ODS文件
要解密ODS文件,通过在LoadOptions.Password中提供密码来加载文件。一旦文件加载完成,将WorkbookSettings.Password字符串设置为null。
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 sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Open an encrypted ODS file | |
Aspose.Cells.LoadOptions loadOptions = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Ods); | |
// Set original password | |
loadOptions.Password = "1234"; | |
// Load the encrypted ODS file with the appropriate load options | |
Workbook workbook = new Workbook(sourceDir + "sampleEncryptedODSFile.ods", loadOptions); | |
// Set the password to null | |
workbook.Settings.Password = null; | |
// Save the decrypted ODS file | |
workbook.Save(outputDir + "outputDecryptedODSFile.ods"); |