创建使用Apache POI保护的Excel文件的密码? [英] Create a password protected excel file using apache poi?

查看:333
本文介绍了创建使用Apache POI保护的Excel文件的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个简单的Java程序中使用(Apache的POI)API来创建Excel文件。
我使用Oracle 10g作为数据库,并使用ojdbc14罐子。

I am developing a simple Java program to create excel file using (Apache POI) API. I am using oracle 10g as a database and using ojdbc14 jar.

我有一个名为USERINFO有3列即表用户名,密码,名称
现在,使用 APACHE POI ,我已经能够把所有的行中的Excel文件。

I have a table called USERINFO having 3 columns namely USERNAME,PASSWORD , NAME. Now using APACHE POI , i have been able to put all the rows in excel file.

由于文件包含如用​​户名和密码的敏感数据,我想使它密码保护。
在论坛上,我已经找到了如何读取密码保护的文件,但不是如何创建它们。
因此,如何我能做到这一点?

Since file contain sensitive data such as username and password, i want to make it password protected. On forums , i have found how to read password protected files but not how to create them. So how i can achieve this?

先谢谢了。

推荐答案

更新:随着3.10版的POI支持加密和解密的XLSX档案。请参见上的POI网站加密支持页面。下面的仍然是相关的XLS二进制工作簿。

Updated: As of version 3.10 POI supports encryption as well as decryption for XLSX files. See the "Encryption Support" page on POI's website. The below is still relevant for XLS binary workbooks.

根据加密支持页面上的POI网站 POI支持读取加密XLS和XLSX文件。加密是不是该页面,这意味着它不支持提及。这是由备份搜索POI网站加密仅返回结果的少数所有这一切都是关于解密。我也采取了看片源的加密实现,这似乎只处理解密。这并不奇怪; POI是专为数据提取和搜索索引,而不是创建新S preadsheets。

According to the "Encryption Support" page on POI's website POI supports reading encrypted XLS and XLSX files. Encrypting is not mentioned on that page, which implies that it's not supported. This is backed up by searching the POI site for "encrypt" which returns only a handful of results all of which are about decryption. I've also taken a look at the sources for their crypto implementation, which appears to only handle decryption. This isn't surprising; POI is designed for data extraction and search indexing, not for creating new spreadsheets.

正如其他人所建议的,它常常通过创建在Excel模板,然后用POI数据填充它来解决缺少功能的POI。不幸的是,不会加密工作,因为加密的S preadsheets的文件格式是完全不同的。

As others have suggested, it's often possible to work around missing features in POI by creating a template in Excel and then using POI to populate it with data. Unfortunately that won't work for encryption because the file format of encrypted spreadsheets is radically different.

如果你愿意支付的商业软件,最新版本的 ExtenXLS 有完整的读取和写入用Excel支持的所有加密格式的支持。刚刚构建的 EncryptedWorkBookHandle 而不是普通的 WorkBookHandle 。这将使用由未修改的JRE支持的强烈的密码,RC4为XLS和128位AES为XLSX。如果要使用256位AES与OOXML和你已经安装了的 JCE无限制政策您可以用 MSOfficeEncrypter 类这样做。

If you're willing to pay for commercial software, the latest version of ExtenXLS has full read and write support for all the encryption formats supported by Excel. Just construct an EncryptedWorkBookHandle instead of the normal WorkBookHandle. That will use the strongest possible cipher supported by an unmodified JRE, RC4 for XLS and 128-bit AES for XLSX. If you want to use 256-bit AES with OOXML and you've installed the JCE unlimited policy you can do so with the MSOfficeEncrypter class.

JExcelApi的,一个流行的开源Java小号preadsheet API,似乎不支持加密在所有。 的Aspose.Cells ,一个商业产品,<一个href=\"http://www.aspose.com/documentation/java-components/aspose.cells-for-java/setting-strong-encryption-type.html\"相对=nofollow>支持杨卫国加密。对于Actuate的e.S preadsheet文档似乎已经从净消失了,所以我不能告诉它是否支持加密。

JExcelAPI, a popular open-source Java spreadsheet API, does not appear to support encryption at all. Aspose.Cells, a commercial offering, supports stong encryption. The documentation for Actuate's e.Spreadsheet seems to have disappeared from the 'net, so I can't tell whether it supports encryption or not.

由于没有自由可用的Java小号preadsheet的API似乎支持写入加密的S preadsheets,如果你不是愿意使用商业软件,你需要拿出一个解决办法。你可以,例如,写在S preadsheet到一个加密的ZIP文件。 java.util.zip 不支持加密,但它看起来像的 Zip4j 一样。

Since none of the freely available Java spreadsheet APIs seems to support writing encrypted spreadsheets, if you're not willing to use commercial software you'll need to come up with a workaround. You could, for example, write the spreadsheet into an encrypted ZIP file. java.util.zip doesn't support encryption, but it looks like Zip4j does.

全面披露:我对Extentech背后的公司ExtenXLS工作

Full disclosure: I work for Extentech, the company behind ExtenXLS.

这篇关于创建使用Apache POI保护的Excel文件的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆