すでに署名されたExcelファイルにデジタル署名を追加する

可能な使用シナリオ

Aspose.Cellsは、すでに署名されたExcelファイルにデジタル署名を追加するために使用できるWorkbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)メソッドを提供します。

すでに署名されたExcelファイルにデジタル署名を追加する方法

次のサンプルコードは、Workbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)メソッドを使用してすでに署名されたExcelファイルにデジタル署名を追加する方法を示しています。このコードで使用されているサンプルExcelファイルについては、サンプルExcelファイルをご確認ください。このファイルはすでにデジタルで署名されています。コードでデモ証明書であるAsposeDemo.pfxを使用し、そのパスワードは aspose です。スクリーンショットは、コードの実行後にサンプルExcelファイルに与える効果を示しています。

todo:image_alt_text

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//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();