I am trying to export SharePoint online list to excel 2007 using C# console application. I have got the code from the following url (https://gallery.technet.microsoft.com/Alternate-to-Timer-Job-d840eb2b/view/Discussions). It is exporting to excel 2003. But I need it in excel 2007.

Please help.

  • do you have excel 2007 installed ? did you try to open the exported file in 2007 excel ? – Akarsh Gupta Jun 29 '16 at 7:36
  • Hi Akarsh, Yes I do have installed 2007 excel. while debugging the code it is exporting as "Microsoft Excel 97-2003 Worksheet (.xls)" but i need it in Microsoft Excel Worksheet (.xlsx) format. Having doubt if we need to provide any excel provider settings in app.config but not sure.. – Roshan Jun 29 '16 at 9:37


I was reviewing the code which you have shared, there is a line where you need to do the modification. The below code is in the solution you posted, you need to change the ".xls" to ".xlsx" from the excelFilename with Path. This should resolve the issue with Excel version you are having.

string excelFileName = string.Format(@"D:\SPListData\EmergencyContacts_{0}.xls", DateTime.Now.Ticks.ToString());
  • Akarsh, Thanks for your reply. I tried it by changing the extension ".xls" to ".xlsx". the file is exporting but unable to view the data. receiving the error message as "excel cannot open the file because the file format or file extension is not valid" . if i change it to .csv then i can able to view. but still exploring to view in xlsx. – Roshan Jun 29 '16 at 11:09
  • The Code use HtmlTextWriter and not Excel Interop, you should modify the code and use Microsoft.Office.Interop.Excel to create excel files, you can find this dll on your machine for Excel 2007, as you have installed Excel 2007. – Akarsh Gupta Jun 29 '16 at 11:51
  • I have installed the EPPLUS .net libraries. Since it is new to me searching for the similar code to modify in my program. please help me if you know any blogs related to my program. Thanks. – Roshan Jun 30 '16 at 4:42
  • Check out this blog - codeproject.com/Articles/680421/… – Akarsh Gupta Jun 30 '16 at 8:52
  • still i am unable to fix the issue to export in Workbook(XLSX). Now I am exporting it in csv by changing the extension. I am getting <tr><td></td> etc with the data. Do you have any idea how can we remove while export. I am using the same code. – Roshan Jul 13 '16 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.