Java code implementation for Excel encryption, decryption (set or remove open password)

Source: Internet
Author: User
Tags decrypt

Use the Jxcell component to perform the functions of encrypting and decrypting Excel.

  Jxcell.jar "Click to download" (This jar has no use limit, you know)

The specific code is as follows:

Importjava.io.IOException;Importcom.jxcell.CellException;ImportCom.jxcell.View;/*** Excel encryption, decryption code * *@authorLifq * @date 2015-3-13 pm 02:13:24*/ Public classEncryptdecryptutil {/*** Read Excel and Encrypt * *@paramURL * Excel file path Example: D:\\word.xls *@parampwd * Encryption password*/     Public Static voidEncrypt (string URL, string pwd) {View M_view=NewView (); Try {            //Read Excelm_view.read (URL); //Set the workbook open passwordm_view.write (URL, pwd); } Catch(cellexception e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); }    }    /*** Excel Decryption * *@returnvoid *@authorLifq * @date 2015-3-13 pm 02:15:49*/     Public Static voiddecrypt (string URL, string pwd) {View M_view=NewView (); Try {            //read the encrypted Excel filem_view.read (URL, pwd); //write without password protectedm_view.write (URL); } Catch(Exception e) {System.out.println (E.getmessage ()); }    }     Public Static voidMain (String args[]) {//The following 1 and 22 methods should be performed separately, you can see the effect//        //1. Add G:\\test.xls to open password 123Encryptdecryptutil.encrypt ("G:\\test.xls", "123"); //2. Remove the G:\\test.xls password 123Encryptdecryptutil.decrypt ("G:\\test.xls", "123"); }}

After encryption: (Prompt for password when open 123)

Java code implementation for Excel encryption, decryption (set or remove open password)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.