Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically convert Excel 2003 files to 2007+

Tags:

c#

.net

excel

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?

like image 385
Nick Avatar asked Sep 19 '13 20:09

Nick


People also ask

How do I convert Excel 2003 to 2007?

If you are using Office 2007, and have a 2003 file open (in Compatibility Mode), you can Convert the file to 2007. Just click on the Office button in the top left corner and select Convert from the menu. It will be converted to a 2007 file format, and will stay in the 2007 format when you change it.

How do I convert Microsoft Excel 97-2003 worksheet to Microsoft Excel worksheet?

Follow these steps: Click File > Export > Change File Type. Under Workbook File Types, double-click Excel 97-2003 Workbook (*. xls).

How do I convert Excel 2003 to 2010?

From the 2003 computer where it is, stick the file onto a flash drive, bring it over to the 2010 computer, and put it into whatever folder you want. Then, open the file, click the green File tab, and save as for file type Excel macro enabled workbook.


1 Answers

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();
}

Here is the link

hope it helps :D

like image 55
Tony Avatar answered Oct 01 '22 05:10

Tony