excel 加密 與 去除密碼


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM