C#: Getting a cell's value with Excel.interop

前端 未结 3 2018
不知归路
不知归路 2021-01-13 21:29

I want to get the value of a cell from an excel file with a software in C#; NOT THE TEXT, because the text depend of the size of the column, and I must not change it myself,

相关标签:
3条回答
  • 2021-01-13 21:54

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

    var cellRangeValue = rng_ResolutionCell.get_Value(System.Type.Missing);
    
    0 讨论(0)
  • 2021-01-13 21:55

    I have often found codes a little more complex than needed all over. Basically reading a cell is as simple as:

    Xl.Range rng = sheet.Cells[row, column] as Xl.Range;
    return rng.Value2;
    
    0 讨论(0)
  • 2021-01-13 22:19

    Also:

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

    Usage:

    if((string)(ws_Varsheet.Cells[x, y].Value2 != "")
    {
       // process
    }
    
    0 讨论(0)
提交回复
热议问题