How to Convert xls to xlsx

by Virender
April 12, 2012

Some time we need to convert .xls file to .xlsx. I giving one example how to convert xls to xlsx.

We are using Interop Library in this example. For run this software you need to Install Office Primary Interop Assemblies first. You can download it from

 You can learn more about Interop installation process on given link

Then need to add reference of “Microsoft.Office.Interop.Excel” into your project.

Note: If you not able to find Microsoft.Office.Interop.Excel.Application class , You need to install Interop Library first , Process given above.

string path=”D:\XlsFolder\1.xls”;

Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();

//avoid any security alert
excel.DisplayAlerts = false;

//Read source .xls excel file
var workbooks = excel.Workbooks.Open(path);

//Set path for destination
string tempFile = “D:\XlsxFolder\1.xlsx”;

workbooks.SaveAs(tempFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);





Related posts