Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report