C #: Getting cell value using Excel.interop

I want to get the cell value from an excel file with software in C #; NOT TEXT, because the text depends on the size of the column, and I should not change it myself, therefore this software should not be violated. Therefore, my choice was to get value.

I get my cell as a 1: 1 range, so I have a Range object, but the Value field and Value2 are not recognized by the language. I tried with get_Value (), but it needs a parameter, and I don’t know what to insert it, I did not find the documentation about it. Here is my code (extracted from the loop):

if((string)(ws_Varsheet.get_Range("L" + iIndex, "L" + iIndex).Text) != "") { rng_ResolutionCell = ws_Varsheet.get_Range("L" + iIndex, "L" + iIndex); float iResolution; rng_ResolutionCell.Cells.get_Value(&iResolution); //what to do here? str_Resolution = ((string)iResolution.toString()).Replace(",","."); str_Resolution = str_Resolution.Replace(" ",""); mObj.Str_Resolution="1"; } 

Can you help me? Thanks in advance.

+4
source share
3 answers

I often found the codes a little more complex than needed in everything. Basically reading a cell is as simple as:

 Xl.Range rng = sheet.Cells[row, column] as Xl.Range; return rng.Value2; 
+7
source

From this post on MSDN, it looks like you want something like:

 var cellRangeValue = rng_ResolutionCell.get_Value(System.Type.Missing); 
+2
source

also:

 newWS = (Microsoft.Office.Interop.Excel.Worksheet)newWB.Worksheets[2]; newWS.Select(); string ExcelCellContent = (string)newWS.Cells[2, 1].Value2; 

Using:

 if((string)(ws_Varsheet.Cells[x, y].Value2 != "") { // process } 
-1
source

All Articles