带有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屋!