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
http://www.microsoft.com/en-us/download/details.aspx?id=18346
You can learn more about Interop installation process on given link
http://msdn.microsoft.com/en-us/library/vstudio/kh3965hw(v=vs.100).aspx
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);
workbooks.Close();
excel.Workbooks.Close();
Comments
Post a Comment