Home > Back-end >  Getting the excel displayed value
Getting the excel displayed value

Time:01-23

I've been scouring for days and I can't seem find what should be an easy answer. The displayed value is not necessarily the value that from cell.InnerText. I see post after post that requires you to look at the cell.StyleIndex property & cell.DataType.value to determine how to get the displayed value. And while I have plugged in some of this code and it works I hit another case I didnt handle where the cell StyleIndex is null which I can only assume the cell is formatted as "General". The on screen value "-39718.96" while the cell.InnerText returns "-39718.959999999999". I realize there is a easy fix to this by Double.Parse(value).ToString() but there seems to be an endless supply of formats https://stackoverflow.com/a/4655716/1713000 and that's a shortlist and dates are another problem. It seems we are left to handle each different style ourselves. Did Microsoft really not create a public api that returns the formatted displayed value and has no one really written a complete solution to handle this cluster of a mess?

CodePudding user response:

Will use the ClosedXML lib instead

CodePudding user response:

Using Openxml for sheets is very difficult (much more so than using it for Word). If I were you I'd use the ClosedXMl nuget package as it simplifies Openxml for sheets.

  •  Tags:  
  • Related