This project is read-only.

XLS file created from template doesn't save correctly - any ideas?

Sep 5, 2013 at 12:56 PM

Using NPOI, I'm successfully creating a spreadsheet from an XLT template, but when I subsequently open the spreadsheet in MS Excel it still thinks it's an XLT template.

I've checked through the online documentation and my code appears to be correct - does anyone have any ideas on what I'm doing wrong please?

Steps to re-produce are as follows:

1) Create XLT template (using MS Excel)
2) Use the following code to create a spreadsheet from the template
const string templatePath = @"C:\Temp\Template.xlt";
const string spreadsheetPath = @"C:\Temp\Spreadsheet.xls";
HSSFWorkbook workbook;
using (var fs = new FileStream(templatePath, FileMode.Open))
                workbook = new HSSFWorkbook(fs);
using (var fs = new FileStream(spreadsheetPath, FileMode.Create))
3) Open the file in MS Excel and click File > Save As

At this point MS Excel thinks you are trying to save an XLT template file (it automatically selects to save as type xlt file).

If anyone has any ideas on what I might be doing wrong, or if this is a genuine bug, that would really helpful!

If it has any bearing, I'm using NPOI v2.0.1.0 and Excel 2003.

Oct 10, 2013 at 5:23 AM
It's suggested that you directly use xls as the template. xlt file is never tested by NPOI test cases. I'm not sure if the structure is same or not.
Oct 10, 2013 at 9:51 AM
Thanks Tonyqus.

We are re-writing an existing application, and the upstream systems provide templates in xlt format. Therefore we have to stick with XLT unfortunately.

Aspose.Cells can handle xlt files, so we may proceed down that route for this part of the system.