第五章:关于工作簿的使用
▲第二节:将数字签名添加到已经签名的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 passwordstring certFileName = sourceDir + "AsposeDemo.pfx";string password = "aspose";//Load the workbook which is already digitally signed to add new digital signatureAspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(sourceDir + "sampleDigitallySignedByCells.xlsx");//Create the digital signature collectionAspose.Cells.DigitalSignatures.DigitalSignatureCollection dsCollection = new Aspose.Cells.DigitalSignatures.DigitalSignatureCollection();//Create new certificateSystem.Security.Cryptography.X509Certificates.X509Certificate2 certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(certFileName, password);//Create new digital signature and add it in digital signature collectionAspose.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 workbookworkbook.AddDigitalSignature(dsCollection);//Save the workbook and dispose it.workbook.Save(outputDir + "outputDigitallySignedByCells.xlsx");workbook.Dispose();
还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!