加密和解密ODS文件

在OpenOffice Calc中加密

  1. 选择另存为并点击加上密码保存框。
  2. 点击保存按钮。
  3. 在打开密码窗口中的输入打开文件的密码确认密码字段中键入所需的密码。
  4. 点击确定按钮以保存文件。

使用Aspose.Cells for .Net加密ODS文件

要对ODS文件进行加密,加载文件并在保存之前将WorkbookSettings.Password值设置为实际密码。加密的输出ODS文件只能在OpenOffice中打开。

// 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。

// 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");