I'm looking for a way to essentially take a folder of excel files that are the old 2003 file extension .xls and convert them into .xlsm. I realize you can go into the excel sheet yourself and manually do it, but is there anyway to do it with code? Specifically using any sort of library?
Asked
Active
Viewed 2.5k times
11
-
@paqogomez ; this requires to have installation of MS office 2007 to use these interop libraries – Manish Jain May 19 '19 at 03:56
-
@ManishJain, if you follow the link i provided, you'll see that you're able to download them without having installed ms office – crthompson May 20 '19 at 21:28
-
@paqogomez I got "We're sorry, this download is no longer available. " when following link posted by you. Please check and provide another. – Manish Jain May 24 '19 at 06:21
-
@ManishJain sure enough. It must have disappeared only days ago because it was up when I checked it earlier this month. Probably support for 2007 has been dropped. [The 2010 files are available however.](https://www.microsoft.com/en-us/download/details.aspx?id=3508) If you really need the 2007, you'll probably have to find it from a non official source. – crthompson May 24 '19 at 15:48
1 Answers
21
This is not my code, but I have used ClosedXML before and it is awesome. I found this on the FAQ asking if it supports Excel 2003 which looks like it should work for you...
To clarify, this uses the Office Interop library not closedXML, but I mentioned it incase you had any additional modifications you needed.
public void Convert(String filesFolder)
{
files = Directory.GetFiles(filesFolder);
var app = new Microsoft.Office.Interop.Excel.Application();
var wb = app.Workbooks.Open(file);
wb.SaveAs(Filename: file + "x", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);
wb.Close();
app.Quit();
}
hope it helps :D

crthompson
- 15,653
- 6
- 58
- 80

Tony
- 3,269
- 1
- 27
- 48
-
2Keep in mind that Interop requires Excel installed on the server, and this won't work on Azure. See: https://stackoverflow.com/questions/12375943/how-to-create-an-instance-of-excel-if-excel-is-not-installed – Savage Oct 18 '19 at 14:45