带有 Excel 宏的 Java Apache Poi SXSSF [英] Java Apache Poi SXSSF with Excel Macros
问题描述
我有一个包含宏 (.xlsm) 的 excel 模板,我想读入它,向其中添加一百万行并写出.
I have a excel template that has macros (.xlsm), I want to read it in, add a million rows to it and write it out.
我知道使用包含宏的 POI 读取和重写文件将保留宏.我需要使用 SXSSF(内存限制)写出 excel,但 SXSSF 不读取文件.
I know that reading and re-writing files with POI that contain macros will preserve the macros. I need to write out the excel using SXSSF (ram limitations), but SXSSF doesn't read files.
问题:如何使用 XSSF 读取带有宏的 excel,然后使用 SXSSF 写出带有宏的 excel?
Question: How can I read in an excel with macros using XSSF, and then write out the excel with macros using SXSSF?
推荐答案
Apache POI 支持通过基于模板工作簿"的 SXSSFWorkbook 编写包含大量行的电子表格.请参阅 相关构造函数 了解详情.
Apache POI supports writing a spreadsheet with a large number of rows via SXSSFWorkbook based on a "template workbook". See the relevant constructor for details.
因此,您可以通过 XSSFWorkbook
打开 .xlsm,然后使用它作为模板创建 SXSSFWorkbook
.
So you would open the .xlsm via XSSFWorkbook
and then create the SXSSFWorkbook
with that as template.
据我所知,这也应该保持宏就位.
This should also keep the macros in place as far as I see.
这篇关于带有 Excel 宏的 Java Apache Poi SXSSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!