问题描述
基本问题:如何加载用于 POI 的 Excel 模板,然后将其保存到 XLS 文件中?
Basic question: How do I load an Excel template for use with POI and then save it to an XLS file?
答案是:
FileInputStream inputStream = new FileInputStream(new File(templateFile));
Workbook workbook = new HSSFWorkbook(inputStream);
(只需将模板作为工作簿加载,然后将工作簿作为 XLS 文件写入其他地方.)
(Just load the template as a workbook and then write the workbook as an XLS file elsewhere.)
推荐答案
您是否尝试过使用 POI 将其加载为标准 .xls 文件,对其进行修改然后保存?
Have you tried loading it up as a standard .xls using POI, amending it and then saving it ?
这是我用来在 POI 生成的 .xls 中插入宏的方法.我使用宏创建文件(当然是 .xls),然后将其加载到我的应用程序中,填充数据并另存为新创建的 .xls.一切正常.
This is the approach I've used for inserting macros in a POI-generated .xls. I create the file with the macro (admittedly as an .xls) and then load it into my app, populate with data and save as a newly-created .xls. That all worked fine.
这篇关于在 Apache POI 中使用 Excel 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!