• poi


    出处: https://www.cnblogs.com/haha12/p/4335076.html

    使用jxcell组件来完成对excel加密、解密的功能。

      jxcell.jar【点击下载】(此jar没有使用限制,你懂得)

    具体代码如下:

    import java.io.IOException;
    
    import com.jxcell.CellException;
    import com.jxcell.View;
    
    /**
     * excel加密、解密 代码
     * 
     * @author lifq
     * @date 2015-3-13 下午02:13:24
     */
    public class EncryptDecryptUtil {
    
        /**
         * 读取excel,并进行加密
         * 
         * @param url
         *            excel文件路径 例:D:\word.xls
         * @param pwd
         *            加密密码
         */
        public static void encrypt(String url, String pwd) {
            View m_view = new View();
            try {
                // read excel
                m_view.read(url);
                // set the workbook open password
                m_view.write(url, pwd);
            } catch (CellException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
        /**
         * excel 解密
         * 
         * @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[]) {
            // 下面1与2 两个方法请分开执行,可以看到效果
            //
            //1. 把g:\test.xls 添加打开密码123
            EncryptDecryptUtil.encrypt("g:\test.xls", "123");
            //2. 把g:\test.xls 密码123 去除
            EncryptDecryptUtil.decrypt("g:\test.xls", "123");
    
        }
    }

    加密后效果图:(打开时提示输入密码123)

  • 相关阅读:
    HttpClient 教程 (四)
    HttpClient 教程 (三)
    HttpClient 教程 (二)
    HttpClient 教程 (一)
    git还原本地提交的某个历史记录
    ExtJS下拉列表使用方法(异步传输数据)
    Struts整合ExtJS
    既有post提交又有get提交时的后台处理办法
    Ajax调用查看页面的后台返回json格式数据
    如何在VS中快速导入新的源码以及文件夹
  • 原文地址:https://www.cnblogs.com/But-you/p/10781657.html
Copyright © 2020-2023  润新知