I have a C# application that exports data to Excel. I have Excel 2010 and VS 2012 on my machine and am using .Net 4.5.
I quietly export in the background with Excel hidden from the user and then save it and launch it using Process.Start, but when I do this, Excel tells me that it can't open the file because the file format or file extension is not valid.
Here is my code:
xlApp = new Excel.Application();
Excel.Workbook myWBk;
myWBk = xlApp.Workbooks.Add(1);
// Some code to dump data to Excel
string sFilename = Environment.CurrentDirectory + @"\LHGR.xlsx";
myWBk.SaveAs(sFilename, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
myWBk.Close();
Process.Start(sFilename);
I have tried using the ".xls" extension, but then it saves it as an Excel 97-2003 format (which I can open) but it warns me that it is limiting the columns to 256 - I have more than that.
Any thoughts?