① 用java實現對EXCEL加打開密碼的方法
需要用到poi,加密用到HSSFWorkbook的writeProtectWorkbook方法。
具體實現如下:
package excel;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class Writer {
public static final String FILE = "./workbook.xls";
public static void main(String[] args) {
FileOutputStream fileOut = null;
try {
// 創 建一個工作薄
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(FILE));
// 設置密 碼 保 護 ·
wb.writeProtectWorkbook("password", "owner");
// 寫入excel文件
fileOut = new FileOutputStream(FILE);
wb.write(fileOut);
fileOut.close();
} catch (IOException io) {
io.printStackTrace();
} finally {
if (fileOut != null) {
try {
fileOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
註:先創建一個workbook.xls把不然會報錯。
② 怎麼用JAVA給生成的EXCEL加密
Biff8EncryptionKey.setCurrentUserPassword("pass");
NPOIFSFileSystem fs = new NPOIFSFileSystem(new File("file.xls"), true);
HSSFWorkbook hwb = new HSSFWorkbook(fs.getRoot(), true);
Biff8EncryptionKey.setCurrentUserPassword(null);
// RC4 CryptoApi support ppt - decryption
Biff8EncryptionKey.setCurrentUserPassword("pass");
NPOIFSFileSystem fs = new NPOIFSFileSystem(new File("file.ppt"), true);
HSLFSlideShow hss = new HSLFSlideShow(fs);
...
// Option 1: remove password
Biff8EncryptionKey.setCurrentUserPassword(null);
OutputStream os = new FileOutputStream("decrypted.ppt");
hss.write(os);
os.close();
...
// Option 2: change encryption settings (experimental)
// need to cache data (i.e. read all data) before changing the key size
PictureData picsExpected[] = hss.getPictures();
hss.getDocumentSummaryInformation();
EncryptionInfo ei = hss.getDocumentEncryptionAtom().getEncryptionInfo();
((CryptoAPIEncryptionHeader)ei.getHeader()).setKeySize(0x78);
OutputStream os = new FileOutputStream("file_120bit.ppt");
hss.write(os);
os.close();
③ JAVA實現EXCEL加密
需要用到poi。
其最新lib下載地址如下:
http://www.apache.org/dyn/closer.cgi/poi/release/bin/poi-bin-3.6-20091214.zip
把其中的poi-3.6-20091214.jar加入classpath中。
加密用到
HSSFWorkbook的writeProtectWorkbook方法。
具體實現如下:
package excel;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class Writer {
public static final String FILE = "./workbook.xls";
public static void main(String[] args) {
FileOutputStream fileOut = null;
try {
// 創 建一個工作薄
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(FILE));
// 設置密 碼 保 護 ·
wb.writeProtectWorkbook("password", "owner");
// 寫入excel文件
fileOut = new FileOutputStream(FILE);
wb.write(fileOut);
fileOut.close();
} catch (IOException io) {
io.printStackTrace();
} finally {
if (fileOut != null) {
try {
fileOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
註:先創建一個workbook.xls把不然會報錯。
④ EXCEL加密 JAVA
用這個不行么
⑤ java 可以讀取加密的Excel文件嗎
首先你這個Excel文件是從哪裡來的,很可能是從一個頁面上下載來的,而這個頁面做的功能就是導出Excel,但做偷懶了,沒有用jxl和POI等庫,而是用直接用jsp生成html寫的。
因此你上傳時就要要判斷了,如果是真的excel就要用jxl或POI解析,如果只是html,就要用HTML的解析方法了。
⑥ Java Excel jxl 加密問題
View m_view = new View();
// read excel
m_view.read(url);
// set the workbook open password
m_view.write(url, pwd);
⑦ 求java實現excel2007加密的方法
抽象Java類實現。所有的具體工廠必須實現這個Java介面或繼承這個抽象的Java類。
- 具體工廠(Factory)角色:這個角色直接在客戶端的調用下創建產品的實例,這個角色含有選擇合適的產品對象的邏輯,而這個邏輯是