Short answer:
EPPlus does not support creating a file from an existing Excel xltx template.
Instead, use a pre-formatted xlsx file.
Long answer:
Dim excelFile As New FileInfo(filename) Dim reportTemplate As New FileInfo(templatePath) Dim xlFile As ExcelPackage = New ExcelPackage(excelFile, reportTemplate) ' Do Stuff xlFile.Save()
When creating an instance of a new ExcelPackage object using EPPlus, you must provide the template as the second parameter (see the code snippet above), however, by providing it with the xltx file, I continued to receive the corrupt output file in the same way as the user above. In the end, I found that providing the regular xlsx file as a template, rather than the actual template file, seemed to work.
This is an open source package, so I decided to take a quick look at the source.
It looks like the ExcelPackage constructors that accept the template parameter call the CreateFromTemplate () method. The comments of the CreateFromTemplate () method indicate that it expects the existing xlsx file to be used as a template, and not the actual template file.
So, although it can be assumed that the template parameter refers to the actual xltx template file, it seems that EPPlus does not support this.
source share