① 用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)角色:这个角色直接在客户端的调用下创建产品的实例,这个角色含有选择合适的产品对象的逻辑,而这个逻辑是