0

I have to pull data from an excel file. I was using the below piece of code since last year:

OleDbConnection cnn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + destFile + "; Extended Properties=Excel 12.0;");
string qText = @"select * from [sheetXY$]";
OleDbCommand oconn = new OleDbCommand(qText, cnn);
cnn.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(oconn);
adp.Fill(dt);
cnn.Close();

Since yesterday I get this error message: enter image description here

I had Office 2010 pro on my machine. According to some google suggestions I installed microsoft database access engine, made no difference. I re-installed whole office, made no difference. Then I installed Office 2013, no go.

What could possibly go wrong from a day to another, and how shall I fix it? I'm out of idea.

16
  • 2
    I was never successful reading Excel files in a reliable way using OLEDB. Sometimes filled cells are empty, you have to fiddle with your registry stackoverflow.com/questions/4551203/… and funny other things can happen. Nowadays I use epplus.codeplex.com or Aspose Cells for such tasks. Commented Jul 15, 2014 at 16:35
  • I had absolutely no issues till yesterday. I will try to find other, but similarly simple solutions. Commented Jul 15, 2014 at 16:43
  • Are you running on a 64-bit operating system and if so are you running the 32-bit or 64-bit copy of Office? If the former, then you need to make sure that you have installed the 32-bit version of the OLE drivers and also make sure your program is compiled for x86 mode Commented Jul 15, 2014 at 16:45
  • I'm on a 64-bit Win7 running 32-bit office. Commented Jul 15, 2014 at 16:49
  • Program compiled for x86. Commented Jul 15, 2014 at 16:51

2 Answers 2

7
+50

Save yourself time and headache and use EPPLUS instead. EPPLUS can be installed via Nuget and you don't have to deal with installing the Office Data access on other machine where your code runs.

Sign up to request clarification or add additional context in comments.

3 Comments

This sounds great. Though I don't even know what Nuget is. Can you provide link to examples on how EEPLUS should be used to read xlsx files?
Never mind. I found a great example. Now I can parse properly. But to be able to use this function EPPLUS.dll has to be in the same directory as my executable. So we have arrived to the question of installtion of it. Can you help me?
What development tool are you using Visual Studio? If so, what version?
0

You can go for openXML SDK. Which requires no machine level dependency.

http://www.codeproject.com/Articles/371203/Creating-basic-Excel-workbook-with-Open-XML

http://msdn.microsoft.com/en-us/library/office/gg575571(v=office.15).aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.