Fügen Sie eine digitale Signatur zu einer bereits signierten Excel Datei hinzu

Mögliche Verwendungsszenarien

Aspose.Cells stellt die Methode Workbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) bereit, die Sie nutzen können, um einer bereits signierten Excel-Datei eine digitale Signatur hinzuzufügen.

Wie fügt man eine digitale Signatur zu einer bereits signierten Excel-Datei hinzu

Der folgende Beispielcode zeigt, wie die Methode Workbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) verwendet wird, um einer bereits signierten Excel-Datei eine digitale Signatur hinzuzufügen. Bitte überprüfen Sie die Beispiel-Excel-Datei, die in diesem Code verwendet wird. Diese Datei ist bereits digital signiert. Bitte überprüfen Sie die Ausgabedatei Excel, die vom Code generiert wurde. Für dieses Beispiel haben wir das Demo-Zertifikat mit dem Namen AsposeDemo.pfx verwendet, das ein Passwort aspose hat. Der Screenshot zeigt die Auswirkung des Beispielcodes auf die Beispiel-Excel-Datei nach der Ausführung.

todo:image_alt_text

Beispielcode

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