Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Reading Excel File content with Microsoft.ACE.OLEDB.12.0 gets a different cell decimal value depending on if file is open or closed

$
0
0

I've already posted my issue here:https://social.msdn.microsoft.com/Forums/vstudio/en-US/d0ac48b6-2f81-4600-82ac-f414f0addead/reading-excel-file-content-with-microsoftaceoledb120-gets-a-different-cell-decimal-value?forum=netfxbcl&prof=required

Maybe any of you could explain why this is happening, here you are a summary:

I’m reading a worksheet content into a DataTable with this connection string:

newOleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ filename +"; Extended Properties=\"Excel 12.0;HDR="+ paramHDR +";IMEX=1;\""))

Then, I’m looping through the DataRows and converting the object at each position to string.

Everything works fine, but I’m having an issue reading a particular cell:

I expect an integer value at that specific column, and sometimes my app reads “210.5” and sometimes it reads “211”.

In the Excel file, when you select this particular cell, in the formula bar you can see it has a decimal part, “210.5”, but since the cell format has zero decimal places, the cell itself shows 211 in the worksheet.

I also realised my app reads “210.5” when it runs while the Excel file is open at the same time the app is running, and it reads “211” if it is closed.

I found it curious, maybe anyone can give me some hint on the issue.

Just in case it’s useful, paramHDR=YES and my first 17 lines for that specific column are empty, but subsequent 1000 have an integer value (but this specific cell) which actually displays an integer, but its value has a decimal value.

I'm working on framework 2.0,Visual Studio 2008, Microsoft Office 2010 and my Excel file looks like this: (cell O20)

Thank you in advance.


Mary


Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>