I'm using the EPPLUS library to read data from Excel to create another file. Unfortunately it does not support the .XLSM extension file. Is there a nice way to convert .XLSM files to .XLSX file for the purpose of reading the file with EPPLUS?
(using EPPLUS for reading would be nice because all my code is already written using it :) )
In order to do this you will need to use the Open XML SDK 2.0. Below is a snippet of code that worked for me when I tried it:
What this code does is it takes your macro enabled workbook file and opens it into a
SpreadsheetDocument
object. The type of this object isMacroEnabledWorkbook
, but since you want it as aWorkbook
you call theChangeDocumentType
method to change it from aMacroEnabledWorkbook
to aWorkbook
. This will work since the underlying XML is the same between a .xlsm and a .xlsx file.Using the Open XML SDK, like in amurra's answer, but in addition to changing doc type, VbaDataPart and VbaProjectPart should be removed, otherwise Excel will show error a file is corrupted.