package com.scoket.service.excel; import com.jxcell.CellException; import com.jxcell.View; import java.io.IOException; /** * Created by kongweichun on 2019/1/29. * chongqing liangyao */ public class EncryptDecryptUtil { public static void main(String args[]) { //加密excel文件 EncryptDecryptUtil.encrypt("F:\\acb.xls", "123"); //去除excel文件密碼 EncryptDecryptUtil.decrypt("F:\\acb.xls", "123"); } /** * 對excel進行加密 * @param url excel文件路徑 * @param pwd 設置excel打開密碼 */ public static void encrypt(String url, String pwd) { View m_view = new View(); try { // 讀取excel m_view.read(url); // 設置excel打開密碼 m_view.write(url, pwd); } catch (CellException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } /** * excel 去除密碼 執行此方法excel將沒有密碼 * @param url 需要解密的excel文件路徑 * @param pwd excel密碼 */ public static void decrypt(String url, String pwd) { View m_view = new View(); try { //讀取需要解密的excel文件 m_view.read(url, pwd); //去除excel密碼 m_view.write(url); } catch (Exception e) { System.out.println(e.getMessage()); } } }
jxcell架包下載:https://files.cnblogs.com/files/codigup/jxcell.zip