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

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

问题描述

我正在开发一个简单的Java程序来使用(Apache POI)API来创建excel文件。
我使用oracle 10g作为数据库并使用ojdbc14 jar。

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列,即 USERNAME, PASSWORD,NAME。
现在使用 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网站加密 / a>只返回一小部分结果,所有这些都是关于解密的。我也看过他们的加密实现的源码,这似乎只能处理解密。这并不奇怪POI是为数据提取和搜索索引设计的,而不是用于创建新的电子表格。

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.

正如其他人所建议的那样,通常可以通过创建一个模板来解决POI中的缺失功能在Excel中,然后使用POI填充数据。不幸的是,由于加密电子表格的文件格式截然不同,所以加密不起作用。

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无限制政策,您可以使用 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电子表格API,似乎并不支持加密。 Aspose.Cells ,一个商业广告提供,支持stong加密。 Actuate的e.Spreadsheet的文档似乎已经从'net'消失了,所以我不知道是否支持加密。

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电子表格API似乎支持编写加密的电子表格,如果您不愿意使用商业软件,您需要提出解决方法。例如,您可以将电子表格写入加密的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天全站免登陆