We help IT Professionals succeed at work.

How to copy the XLSX file to XLS file using C#

kravindra
kravindra used Ask the Experts™
on
I want copy the data from XLSX file to XLS file in c#
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010

Commented:

You can pen the xlsx file programmatically using excel interop and save it as xls file.

Excel.Application oXls = new Microsoft.Office.Interop.Excel.ApplicationClass();
                    
object oMissing = System.Reflection.Missing.Value;

                   
                   Excel.Workbook oSpr = oXls.Workbooks.Open("ExcelData.xlsx", oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
                   object fileFormat = Excel.XlFileFormat.xlXMLSpreadsheet;
                
                   
                    oSpr.SaveAs("ExcelData.xls", ref fileFormat, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
                    oSpr.Close();
                    oXls.Quit();

Open in new window

Top Expert 2010
Commented:

A correction in the above code in SaveAs method:
Excel.Application oXls = new Microsoft.Office.Interop.Excel.ApplicationClass();
                    
object oMissing = System.Reflection.Missing.Value;

Excel.Workbook oSpr = oXls.Workbooks.Open("ExcelData.xlsx", oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);

object fileFormat = Excel.XlFileFormat.xlXMLSpreadsheet;              
                   
oSpr.SaveAs(paramExportFilePath, ref fileFormat, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);

oSpr.Close();
oXls.Quit();

Open in new window