Click here to Skip to main content
15,943,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I want to read data from an excel file and want to store it in a datatable. Previously I was using interop excel.But it give COM exception many time.So I want to switch to OPENXML. But I am unable to read xls file in it .It is showing Corrupted data exception.Any 1 has sample code to fix it.
Which is better to read excel file ?

Is dere any way to stop COM exception ?

Excel connection via OLEDB:
How to query and display excel data by using ASP.NET, ADO.NET, and Visual C# .NET

Excel connectivity using NPOI:

Hope it helps.
Share this answer
I don't know. I use, OleDB, and the Jet or ACE engine to read and write Excel like a database.[^][^]
Share this answer
Thanks all for your response.

Is dere any way to manage xls, xlsx file in OPENXML?
Share this answer
hypermellow 17-Sep-13 10:43am    
.xlsx is based on the openxml format, .xls was not.

I wouldn't think you could use openxml to view .xls files.

If you need to read from both types, then I would go with the OLEDB approach.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900