- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 java 8 和 apache POI 和 POI-OOXML 3.14
这是我的方法:
private static void encryptXlsx(String inputPath, String outputPath, String password) throws IOException, InvalidFormatException, GeneralSecurityException {
//create a new workbook
Workbook wb = WorkbookFactory.create(new File(inputPath));
//Add password protection and encrypt the file
POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
Encryptor enc = info.getEncryptor();
enc.confirmPassword(password); // s3cr3t is your password to open sheet.
OPCPackage opc = OPCPackage.open(new File(inputPath), PackageAccess.READ_WRITE);
OutputStream os = enc.getDataStream(fs);
opc.save(os);
opc.close();
FileOutputStream fos = new FileOutputStream(outputPath);
fs.writeFilesystem(fos);
fos.close();
}
错误堆栈是:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.apache.xmlbeans.impl.store.Cur$CurLoadContext.attr(Cur.java:3044)
at org.apache.xmlbeans.impl.store.Cur$CurLoadContext.attr(Cur.java:3065)
at org.apache.xmlbeans.impl.store.Locale$SaxHandler.startElement(Locale.java:3263)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.reportStartTag(Piccolo.java:1082)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseAttributesNS(PiccoloLexer.java:1802)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseOpenTagNS(PiccoloLexer.java:1521)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseTagNS(PiccoloLexer.java:1362)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseXMLNS(PiccoloLexer.java:1293)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseXML(PiccoloLexer.java:1261)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.yylex(PiccoloLexer.java:4812)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yylex(Piccolo.java:1290)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yyparse(Piccolo.java:1400)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:714)
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3479)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1277)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1264)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
at org.apache.poi.POIXMLTypeLoader.parse(POIXMLTypeLoader.java:92)
at org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:173)
at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:165)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.parseSheet(XSSFWorkbook.java:417)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:382)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:178)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:249)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:293)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:252)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:231)
at XlsxEncryptExample.encryptXlsx(XlsxEncryptExample.java:36)
at XlsxEncryptExample.main(XlsxEncryptExample.java:28)
进程已完成,退出代码为 1
如果有人能给我指出一种在不使用这么多内存的情况下读取该文件的方法,一个比 POI 或任何其他可能的解决方案更好地保护密码的库,我将不胜感激。
最佳答案
据我了解documentation POI 通常将整个电子表格读取到内存中。它确实说
Note that the usermodel system has a higher memory footprint than the low level eventusermodel, but has the major advantage of being much simpler to work with. Also please be aware that as the new XSSF supported Excel 2007 OOXML (.xlsx) files are XML based, the memory footprint for processing them is higher than for the older HSSF supported (.xls) binary files.
它继续提供低内存占用的替代方案。
关于java - 尝试用密码保护中等大小的 XLSX 工作簿 (~=80MB) 时,Apache POI 抛出 OOM 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61463301/
我有一个本地存储库,有一个大文件被意外添加到其中。现在,即时通讯几乎落后了100次提交。当我尝试推送到GitHub时,它给了我一个错误。 我需要做任何我需要做的事情,以便能够推送此存储库的其余部分。
我正在尝试分配内存NSImage*originalLocationImage; NSURL *fileURL = [NSURL fileURLWithPath:originalLocation];//
我如何以及在何处可以编辑CDH4.7中的输入拆分大小,默认情况下为64 MB,但我想将其称为1MB,因为我的MR作业运行缓慢并且我想提高MR作业的速度。我想需要编辑cor-site属性IO.file.
我创建了一个 DLL,其中包含一个从 C# 代码调用的 JNI 函数。作为长时间运行的 GUI 应用程序的 C# 应用程序多次调用该函数。 我的 JNI 函数调用 JNI_GetCreatedJava
运行 TestDFSIO 后,我得到了以下指标: 2019-04-30 09:50:35,790 INFO fs.TestDFSIO: Date & time: Tue Apr
我正在测试连接到 Xcode 5.1.1 的运行 iOS 7.1 的 iPhone 4。我不明白为什么当仪器显示我的应用程序仅使用几兆字节并且有大量可用内存时我会收到内存警告甚至崩溃(见附件)。有什么
我有一个假设的值数据库,每个值的大小为 4 个字节(即 4,000,000,000)。所有值都存在于数据库中,因此它以 0 开头,以最大的 4 字节数字结尾。 只有一次,我想通过将 1 到 10000
我有一个字符串元组的 python 列表,格式如下:lst = [('xxx', 'yyy'), ...etc]。该列表包含大约 8154741 个元组。我使用了一个分析器,它说该列表占用大约 500
我需要每秒发送 1,00,000 批记录。我在实验后得到的是 azure event hub 的事件限制为 10,00,000 个字节。我的每条记录有 145 字节,我必须发送的总记录是 1,00,0
HDFS块大小默认为128 MB(来源:https://hadoop.apache.org/docs/r2.9.0/hadoop-project-dist/hadoop-hdfs/hdfs-defau
我需要每秒发送 1,00,000 批记录。我在实验后得到的是 azure event hub 的事件限制为 10,00,000 个字节。我的每条记录有 145 字节,我必须发送的总记录是 1,00,0
我正在 Linux 机器上运行 Jboss EAP 服务器 6.1。分配的堆内存如下。 JAVA_OPTS="-Xms2048m -Xmx2048m -XX:MaxPermSize=256m -Dja
我最近提出并解决了一个关于将大于 2 MB 的 .PDF 文件作为 BLOBS 上传到 MySQL 数据库的问题。我不得不更改我的 php.ini 文件中的一些设置和 MySQL 的最大数据包设置。然
我需要创建一个文本文件(字母数字),其大小(精确或接近)以 MB 为单位等于我输入的数字,例如 1 MB。我试图生成一个字符串,认为一个字符是 16 位或 2 字节,所以:1KB = 1024 字节
我已经阅读了很多有关通过设置 yarn.scheduler.maximum-allocation-mb 来解决此类问题的内容,我已将其设置为 2gb,因为我当前正在运行 select count(*)
这个问题在这里已经有了答案: this exceeds GitHub's file size limit [duplicate] (3 个回答) 1年前关闭。 核心程序崩溃数据。 我不知道核心文件是从
我已经建立了一个 Electron 应用程序,并使用 Electron 打包程序对其进行了打包。我制作了238MB的Windows bundle 包,而Linux版本是450 MB。我将其与也是 El
这个问题在这里已经有了答案: Generate an integer that is not among four billion given ones (38 个答案) 关闭 9 年前。 Give
我的 Meteor 应用程序获取一个 CSV 文件,使用 Baby Parse(Papa Parse for server)对其进行解析,并将数据插入到 MongoDB 集合中。 每个 CSV 行都作
Amazon SES 有 10 MB 的文件限制 我的问题是 有没有其他方法可以发送超过 10 MB 的文件? 最佳答案 这是一个硬限制。 您需要做的是包含您当前包含在电子邮件中的 Assets 的
我是一名优秀的程序员,十分优秀!