Using Excel templates with Apache POI

Jake picture Jake · Apr 3, 2009 · Viewed 63.4k times · Source

Basic question: How do I load an Excel template for use with POI and then save it to an XLS file?

Edit:

The answer is:

FileInputStream inputStream = new FileInputStream(new File(templateFile));
Workbook workbook = new HSSFWorkbook(inputStream);

(Just load the template as a workbook and then write the workbook as an XLS file elsewhere.)

Answer

Brian Agnew picture Brian Agnew · Apr 3, 2009

Have you tried loading it up as a standard .xls using POI, amending it and then saving it ?

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.