Convert Excel format XLS to XLSX using C#

lockevn
1 min readJun 11, 2018

--

I use EPPlus library to process Excel file (and automate a lot of work). It is a great library, very fast and full feature.

One disadvantage of EPPlus is lacking ability to work with old format XLS (which is binary format, belongs to Microsoft only)

We can convert XLS to XLSX using Excel Interop (you must have Excel installed on your computer).

  • Create new C# Console application
  • Run this in Package Management Console

Install-Package Microsoft.Office.Interop.Excel

Use this function

/// <summary>
/// Using Microsoft.Office.Interop to convert XLS to XLSX format, to work with EPPlus library
/// </summary>
/// <param name="filesFolder"></param>
public static string ConvertXLS_XLSX(FileInfo file) {
var app = new Microsoft.Office.Interop.Excel.Application();
var xlsFile = file.FullName;
var wb = app.Workbooks.Open(xlsFile);
var xlsxFile = xlsFile + "x";
wb.SaveAs(Filename: xlsxFile, FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);
wb.Close();
app.Quit();
return xlsxFile;
}

If this post helps you or saves your time, please go buy me a beer ;)

--

--

lockevn
lockevn

Written by lockevn

Developer, Sportman. Write code with joy, bake app with heart. Opinions are my own. If you feel I save your time, go http://BuyMeACoff.ee/Lockevn

Responses (2)