Excel管理控件Aspose.Cells開發者指南(二十三):將數字簽名添加到已經簽名的Excel文件中
Aspose.Cells for .NET是Excel電子表格編程API,可加快電子表格管理和處理任務,支持構建具有生成,修改,轉換,呈現和打印電子表格功能的跨平臺應用程序。
在接下來的系列教程中,將為開發者帶來Aspose.Cells for .NET的一系列使用教程,例如關于加載保存轉換、字體、渲染、繪圖、智能標記等等。本文將講解如何將數字簽名添加到已經簽名的Excel文件中。
第五章:關于工作簿的使用
▲第二節:將數字簽名添加到已經簽名的Excel文件中
Aspose.Cells提供了Workbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) 方法,可用于將數字簽名添加到已簽名的Excel文件中。
注意:在將數字簽名添加到已經簽名的Excel文檔時,請注意,如果原始文檔是Aspose.Cells生成的文檔,則可以正常工作。但是,如果原始文檔是由其他引擎(例如Microsoft Excel等)生成的,則Aspose.Cells無法在加載并重新保存文件后使文件保持不變,這將使原始簽名無效。
下面的示例代碼演示了如何利用 Workbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) 方法將數字簽名添加到已簽名的Excel文件中。請檢查此代碼中使用的示例Excel文件。該文件已經過數字簽名。屏幕截圖顯示了執行后示例代碼對示例Excel文件的影響。

//Certificate file and its password string certFileName = sourceDir + "AsposeDemo.pfx"; string password = "aspose"; //Load the workbook which is already digitally signed to add new digital signature Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(sourceDir + "sampleDigitallySignedByCells.xlsx"); //Create the digital signature collection Aspose.Cells.DigitalSignatures.DigitalSignatureCollection dsCollection = new Aspose.Cells.DigitalSignatures.DigitalSignatureCollection(); //Create new certificate System.Security.Cryptography.X509Certificates.X509Certificate2 certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(certFileName, password); //Create new digital signature and add it in digital signature collection Aspose.Cells.DigitalSignatures.DigitalSignature signature = new Aspose.Cells.DigitalSignatures.DigitalSignature(certificate, "Aspose.Cells added new digital signature in existing digitally signed workbook.", DateTime.Now); dsCollection.Add(signature); //Add digital signature collection inside the workbook workbook.AddDigitalSignature(dsCollection); //Save the workbook and dispose it. workbook.Save(outputDir + "outputDigitallySignedByCells.xlsx"); workbook.Dispose();
還想要更多嗎?您可以點擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入Aspose技術交流群(642018183),我們很高興為您提供查詢和咨詢。