Java Encrypted Excel file (enter password when open)

Source: Internet
Author: User
Tags decrypt

Collection: AUTHOR:LIFQ

Package com.xxx. Xxx.utils;
Import java.io.IOException;

Import com.jxcell.CellException;
Import Com.jxcell.View;

/**
*
* @ClassName: Dataexcels
* @Description: Excel encryption and decryption
* @date: 2016-6-12 11:00:31
* @version
*/
public class Encryptexcelutil {

/**
* Read Excel and encrypt it
*
* @param URL
* Excel File Path Example: D:\\word.xls
* @param pwd
* Encrypt password
*/
public static void Encrypt (string URL, string pwd) {
View M_view = new View ();
try {
Reading an Excel document
M_view.read (URL);
Set document open password
M_view.write (URL, pwd);
} catch (Cellexception e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
}

/**
* Excel Decryption
*
* @return void
* @author LIFQ
* @date 2015-3-13 02:15:49
*/
public static void decrypt (string URL, string pwd) {
View M_view = new View ();
try {
Read the encrypted Excel file
M_view.read (URL, pwd);

Write without password protected
M_view.write (URL);
} catch (Exception e) {
System.out.println (E.getmessage ());
}
}

public static void Main (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 123
Encryptexcelutil.encrypt ("F:\\test.xls", "123");
2. Remove the G:\\test.xls password 123
Encryptexcelutil.decrypt ("F:\\test.xls", "123");

}
}

Portal: Encrypt the required jar package

Java Encrypted Excel file (enter password when open)

Related Article

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.