2013年10月7日星期一

With poi-3.6-20091214.jar achieve java to excel file encryption

I spent a lot of online methods, but without success !

HSSFWorkbook wb = new HSSFWorkbook (new FileInputStream (file));
/ / set password protection ·
wb . writeProtectWorkbook (" 111111", "owner");


red logo is the shelf package which is not constructed this way ? very strange to ask you , can be useful for java achieve excel file encryption ah ? Be specific usable ! You Are the One ah !
------ Solution ---------------------------------------- ----
you find the API is , ah , why it did not run successfully ? Did you get Excel2007 format files in the trial ?
I realize you posted an example , there are few things to note
1. now POI3.5 3.6 do not support the XSSF part of the Excel xlsx file is encrypted , so use 2003 format file
2. running instance has finished, open the file again , you can read on, you choose a password through a non- read-only mode
3. give stickers is just a demo, specific code need to adjust some of the elegance

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.FileInputStream;
import java.io.File;
import java.io.FileOutputStream;

public class EncodExcel2003 {
    public static void main(String[] args)throws Exception{
        FileInputStream fis=new FileInputStream(new File("resources/excel/" +
                "stuInfo.xls")); //这里换成你本地的excel相对路径或绝对路径
        HSSFWorkbook workbook=new HSSFWorkbook(fis);

        //   writeProtectWorkbook第一个参数是打开Excel文件的密码
        //   writeProtectWorkbook第二个参数是现实文件密码是由谁设置的
        //   第二个参数用中文可能会出现乱码的情况,我用utf8编码workspace
        //   可能用gbk不会有乱码
        workbook.writeProtectWorkbook("password","admin");
        FileOutputStream fos=new FileOutputStream(new File("resources/excel/" +
                "stuInfo.xls"));//这里换成你本地的excel相对路径或绝对路径
        workbook.write(fos);
        fis.close();
        fos.close();

    }
}


If you can not solve the problem, you can leave a message or message me CSDN above
------ For reference only ------------------- --------------------
can be achieved , but I have not studied , ha ha.
------ For reference only -------------------------------------- -
did not know before, the next concern
lz realized after Veg code Kazakh
------ For reference only --------------------------- ------------
not done , Bangding , I wish you good luck
------ For reference only ------------ ---------------------------
3 floor provides way too brothers can be encrypted , but still can not meet my needs , What I need is the password to open the encrypted excel file can not be read-only , etc. see the content , you must enter a password to open the job !
------ For reference only --- ------------------------------------
landlord solved? I also use this function to solve the trouble to say about
------ For reference only ------------------------- --------------

I want you do to achieve this functionality landlord

没有评论:

发表评论