Current location - Quotes Website - Signature design - Java adds digital signature in Excel VBA uses digital signature.
Java adds digital signature in Excel VBA uses digital signature.
Java adds digital signature in Excel VBA uses digital signature. You can add a digital signature to Excel so that the document owner can declare the ownership or validity of the document. The following describes how to add a signature to an Excel workbook with Java program code.

Tools/materials

Excel version: 20 13

Compilation environment: IntelliJ IDEA20 18

JDK version: 1.8.0

Excel library tool: spire.xls.jar 4.3.4

Digital certificates and passwords

operational approach

0 1

Under the folder path of the IDEA project, save an Excel file with the version of 2013xlxx file; And a digital certificate in pfx format with a known password. As shown in the figure:

02

Introduce the package of excel library tool spire.xls.jar into the idea project, as shown in the following figure:

03

Type the following code in the program:

Import com.spire.xls. *;

Import com.spire.xls.digital.certificate and private key;

Import java.util.date;

Public class AddSignature {

The public static void main(String[] args) throws an exception {

//Load Excel workbook

Workbook wb = new workbook ();

WB . loadfromfile(" test . xlsx ");

//Add a digital signature

Wb.addDigitalSignature (new certificate and private key ("cer.pfx", "123654yes!") ), "The author is Mia", new date ());

//Save the document

WB . savet ofile(" add signature . xlsx ",ExcelVersion。 Version 2013);

WB . dispose();

}

}

04

Execute the program and generate the document. View the effect of signature addition in the result document:

1. Add signature

Import com.spire.xls. *;

Import com.spire.xls.digital.certificate and private key;

Import java.util.date;

Public class AddSignature {

The public static void main(String[] args) throws an exception {

//Load Excel workbook

Workbook wb = new workbook ();

WB . loadfromfile(" test . xlsx ");

//Add a digital signature

Wb.addDigitalSignature (new certificate and private key ("cer.pfx", "123654yes!") ), "The author is Mia", new date ());

//Save the document

WB . savet ofile(" add signature . xlsx ",ExcelVersion。 Version 2013);

WB . dispose();

}

}

2. Check whether it is signed.

Import com.spire.xls. *;

Common class detection signature {

Public static void main(String[] args) {

//Load Excel workbook

Workbook wb = new workbook ();

WB . loadfromfile(" add signature . xlsx ");

//Judge whether the document is signed.

Boolean signature = wb.isdigitalysigned ();

If (signature = = true)

{

System.out.println ("The document is signed!" );

}

other

{

System.out.println ("unsigned document!" );

}

}

}

Delete signature

Import com.spire.xls. *;

Public class RemoveSignature {

Public static void main(String[] args) {

//Load Excel workbook

Workbook wb = new workbook ();

WB . loadfromfile(" add signature . xlsx ");

//Delete signature

WB . removealldigitalsignatures();

//Save the document

WB . savetofile(" remove signature . xlsx ",ExcelVersion。 Version 2013);

WB . dispose();

}

}

After executing the program code, there is no signature in the generated result document.

Special tips

The path in the code is the folder path of the IDEA project, and the path can also be customized.