VB.net Excel.worksheet().cells().Value

后端 未结 2 1429
南笙
南笙 2021-01-20 07:38

Trying to write information in Excel worksheet But have some strange problems ;) i looked info on Google but no result.. So plz help )

I Add reference Microsoft.exce

2条回答
  •  耶瑟儿~
    2021-01-20 07:53

    With Excel interop, a lot of the time a return value will be in the form of an Object so you need to cast to the correct type to get it's actual properties.

    So do something like this (my VB is rusty so may not be completely correct)...

    Dim rng as Excel.Range
    
    rng = CType(shXL.Cells(1, 1), Excel.Range)
    Checker = rng.Value
    

    Note: I've separated it out into two lines because it's important not use double-dot references with Office interop (e.g., Worksheet.Cell.Value) because you end up with objects you can't release, which will cause issues with Excel not closing properly.

    Note2: the .Value property also returns as an object so you'll probably want to cast that too

提交回复
热议问题