إضافة توقيع رقمي إلى ملف إكسل تم توقيعه بالفعل
Contents
[
Hide
]
سيناريوهات الاستخدام المحتملة
توفر Aspose.Cells الطريقة Workbook.addDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) التي يمكنك استخدامها لإضافة توقيع رقمي إلى ملف Excel موقعًا مسبقًا.
يرجى ملاحظة أنه عند إضافة توقيع رقمي إلى مستند إكسل تم توقيعه بالفعل، إذا كان المستند الأصلي هو وثيقة تم إنشاؤها بواسطة Aspose.Cells، سيعمل بشكل جيد. ولكن إذا كان المستند الأصلي قد تم إنشاؤه بواسطة محركات أخرى (مثل Microsoft Excel وما إلى ذلك)، فإن Aspose.Cells لن تتمكن من الحفاظ على الوثيقة بعد التحميل وإعادة حفظها، وهذا سيجعل التوقيع الأصلي غير صالح.
إضافة توقيع رقمي إلى ملف إكسل تم توقيعه بالفعل
يوضح الرمز النموذجي التالي كيفية الاستفادة من الطريقة Workbook.addDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) لإضافة توقيع رقمي إلى ملف Excel موقعًا مسبقًا. يرجى التحقق من ملف Excel النموذجي المستخدم في هذا الرمز. تم توقيع هذا الملف رقميًا بالفعل. يرجى التحقق من ملف Excel الناتج الذي تم إنشاؤه من خلال الرمز. لقد استخدمنا شهادة العرض التوضيحي المسماة AsposeTest.pfx في هذا الرمز والتي تحتوي على كلمة مرور aspose. تظهر اللقطة الشاشية تأثير الرمز النموذجي على ملف Excel النموذجي بعد التنفيذ.
الكود المثالي
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-Java | |
// Certificate file and its password | |
String certFileName = "AsposeTest.pfx"; | |
String password = "aspose"; | |
// Load the workbook which is already digitally signed to add new digital signature | |
Workbook workbook = new Workbook(srcDir + "sampleDigitallySignedByCells.xlsx"); | |
// Create the digital signature collection | |
DigitalSignatureCollection dsCollection = new DigitalSignatureCollection(); | |
// Create new digital signature and add it in digital signature collection | |
// ------------------------------------------------------------ | |
// --------------Begin::creating signature--------------------- | |
// Load the certificate into an instance of InputStream | |
InputStream inStream = new FileInputStream(srcDir + certFileName); | |
// Create an instance of KeyStore with PKCS12 cryptography | |
java.security.KeyStore inputKeyStore = java.security.KeyStore.getInstance("PKCS12"); | |
// Use the KeyStore.load method to load the certificate stream and its password | |
inputKeyStore.load(inStream, password.toCharArray()); | |
// Create an instance of DigitalSignature and pass the instance of KeyStore, password, comments and time | |
DigitalSignature signature = new DigitalSignature(inputKeyStore, password, | |
"Aspose.Cells added new digital signature in existing digitally signed workbook.", | |
com.aspose.cells.DateTime.getNow()); | |
dsCollection.add(signature); | |
// ------------------------------------------------------------ | |
// --------------End::creating signature----------------------- | |
// Add digital signature collection inside the workbook | |
workbook.addDigitalSignature(dsCollection); | |
// Save the workbook and dispose it. | |
workbook.save(outDir + "outputDigitallySignedByCells.xlsx"); | |
workbook.dispose(); |