Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add a digital signature to an Excel document using Java

Shulou Source: shulou.com Published: 2022-06-01 12:50:01 10月01日 Update

This article mainly explains the "how to use Java to add digital signatures to Excel documents", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "how to use Java to add digital signatures to Excel documents" it!

This code test environment

Excel version: 2013

Compilation environment: IntelliJ IDEA2018

JDK version: 1.8.0

Excel Library tool: spire.xls.jar 4.3.4

Pfx digital certificate (and password)

The following shows how to implement each of the three code blocks.

1. Add signature import com.spire.xls.*;import com.spire.xls.digital.CertificateAndPrivateKey;import java.util.Date;public class AddSignature {public static void main (String [] args) throws Exception {/ / load Excel workbook Workbook wb = new Workbook (); wb.loadFromFile ("test.xlsx"); / / add digital signature wb.addDigitalSignature (new CertificateAndPrivateKey ("cer.pfx", "123654yes!"), "The Author is Mia", new Date ()) / / Save the document wb.saveToFile ("AddSignature.xlsx", ExcelVersion.Version2013); wb.dispose ();}} 2. Detect whether to sign import com.spire.xls.*;public class DetectSignature {public static void main (String [] args) {/ / load Excel workbook Workbook wb = new Workbook (); wb.loadFromFile ("AddSignature.xlsx"); / / determine whether the document is signed boolean signature= wb.isDigitallySigned (); if (signature==true) {System.out.println ("document signed!") Else {System.out.println ("unsigned document!") ; 3. Delete signature import com.spire.xls.*;public class RemoveSignature {public static void main (String [] args) {/ / load Excel workbook Workbook wb = new Workbook (); wb.loadFromFile ("AddSignature.xlsx"); / / Delete signature wb.removeAllDigitalSignatures (); / / Save document wb.saveToFile ("RemoveSignature.xlsx", ExcelVersion.Version2013); wb.dispose ();}}

After the program code is executed, there is no signature in the resulting document.

Thank you for your reading, the above is the "how to use Java to add digital signatures to Excel documents" of the content, after the study of this article, I believe you on how to use Java to add digital signatures to Excel documents have a deeper understanding of the problem, the specific use of the situation also need to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Documents numbers digital signatures code study work content version environment three passwords that is tools ideas situations digital certificates articles more knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology NVidia Microsoft Xiaomi