Excel管理控件Aspose.Cells開發(fā)者指南(二十三):將數(shù)字簽名添加到已經(jīng)簽名的Excel文件中
Aspose.Cells for .NET是Excel電子表格編程API,可加快電子表格管理和處理任務(wù),支持構(gòu)建具有生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印電子表格功能的跨平臺(tái)應(yīng)用程序。
在接下來(lái)的系列教程中,將為開發(fā)者帶來(lái)Aspose.Cells for .NET的一系列使用教程,例如關(guān)于加載保存轉(zhuǎn)換、字體、渲染、繪圖、智能標(biāo)記等等。本文將講解如何將數(shù)字簽名添加到已經(jīng)簽名的Excel文件中。
第五章:關(guān)于工作簿的使用
▲第二節(jié):將數(shù)字簽名添加到已經(jīng)簽名的Excel文件中
Aspose.Cells提供了Workbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) 方法,可用于將數(shù)字簽名添加到已簽名的Excel文件中。
注意:在將數(shù)字簽名添加到已經(jīng)簽名的Excel文檔時(shí),請(qǐng)注意,如果原始文檔是Aspose.Cells生成的文檔,則可以正常工作。但是,如果原始文檔是由其他引擎(例如Microsoft Excel等)生成的,則Aspose.Cells無(wú)法在加載并重新保存文件后使文件保持不變,這將使原始簽名無(wú)效。
下面的示例代碼演示了如何利用 Workbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) 方法將數(shù)字簽名添加到已簽名的Excel文件中。請(qǐng)檢查此代碼中使用的示例Excel文件。該文件已經(jīng)過數(shù)字簽名。屏幕截圖顯示了執(zhí)行后示例代碼對(duì)示例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();
還想要更多嗎?您可以點(diǎn)擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請(qǐng)隨時(shí)加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。