Lägg till digital signatur i en redan signerad Excel-fil
Contents
[
Hide
]
Möjliga användningsscenarier
Aspose.Cells tillhandahållerWorkbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)metod som du kan använda för att lägga till digital signatur i en redan signerad Excel-fil.
Observera att när du lägger till en digital signatur till ett redan signerat Excel-dokument, om originaldokumentet är Aspose.Cells-genererat dokument, fungerar det bra. Men om originaldokumentet genereras av andra motorer (t.ex. Microsoft Excel etc.), kan Aspose.Cells inte behålla filen densamma efter att ha laddats in och sparats på nytt, vilket gör att den ursprungliga signaturen blir ogiltig.
Lägg till digital signatur i en redan signerad Excel-fil
Följande exempelkod visade hur man använder sig avWorkbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) metod för att lägga till digital signatur till redan signerad Excel-fil. Vänligen kontrolleraexempel på Excel-fil används i denna kod. Den här filen är redan digitalt signerad. Vänligen kontrollerautdata Excel-fil genereras av koden. Vi har använt democertifikatet som heterAsposeDemo.pfx i denna kod som har ett lösenordasposeSkärmdumpen visar effekten av exempelkoden på exemplet i Excel-filen efter körning.
Exempelkod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |