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)