我正在开发一个简单的 Java 程序来使用 (Apache POI) API 创建 Excel 文件。 我使用 Oracle 10g 作为数据库并使用 ojdbc14 JAR 文件。
我有一个名为 USERINFO 的表,它包含三列,即 USERNAME
、PASSWORD
和 NAME。
现在使用 Apache POI,我已经能够将所有行放入 Excel 文件中。
由于该文件包含用户名和密码等敏感数据,我想对其进行密码保护。 在论坛上,我找到了如何读取受密码保护的文件,但没有找到如何创建它们。 那么我该如何实现呢?
最佳答案
更新:从版本 3.10 开始,POI 支持对 XLSX 文件进行加密和解密。参见 the "Encryption Support" page on POI's website .以下内容仍然与 XLS 二进制工作簿相关。
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.
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、XLS 的 RC4 和 XLSX 的 128 位 AES 支持的最强密码。如果您想将 256 位 AES 与 OOXML 一起使用,并且您已经安装了 JCE unlimited policy您可以使用 MSOfficeEncrypter
类来做到这一点。
JExcelAPI ,一种流行的开源 Java 电子表格 API,似乎根本不支持加密。 Aspose.Cells ,商业产品,supports stong encryption . Actuate 的 e.Spreadsheet 的文档似乎已经从网上消失了,所以我无法判断它是否支持加密。
由于免费提供的 Java 电子表格 API 似乎都不支持编写加密电子表格,如果您不愿意使用商业软件,则需要想出一个解决方法。例如,您可以将电子表格写入加密的 ZIP 文件。 java.util.zip
不支持加密,但看起来像Zip4j
完全披露:我为 ExtenXLS 背后的公司 Extentech 工作。
关于java - 使用 Apache POI 创建受密码保护的 Excel 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8817290/