Shrivallabh
Shrivallabh

Reputation: 2903

Excel file created in Excel 2007 is not opening in Excel 2003 using c#

Below is my Code to show Excel

    objExcel = new Microsoft.Excel.Interop.Application();
object objOpt = System.Reflection.Missing.Value;
            objExcel.Visible = true;
    objExcel.Workbooks.Open(fi.FullName,
                    objOpt, objOpt, objOpt, objOpt, objOpt, objOpt, objOpt,
                    objOpt, objOpt, objOpt, objOpt, objOpt, objOpt, objOpt);

Now the problem is if i have xls file made with excel 2003 it will work if the file is made with excel 2007,2010 then it won't open.Gives the error File is not in recognizable form Same code runs fine in win7.

Anychanges i need to do in reading excel file of both 2003 and 2007.

Note:Both files created in excel 2003 and 2007 has extension .xls

Upvotes: 0

Views: 344

Answers (1)

jle
jle

Reputation: 9489

If you make an Excel file programmatically and name it with the .xls extension from Excel 2007 or 2010, you may be making an Open XML (.xlsx) file unknowingly, as this is the default save format for those versions of Excel. Essentially, if you are hard coding the file name, you may be saving an .xlsx file with the .xls extension, which would explain why you can't open the files. Try renaming the files generated from Excel 2007 to the .xlsx extension and see if you can open them.

Upvotes: 1

Related Questions