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

£可爱£侵袭症+ 提交于 2019-12-02 01:46:35

That's because .Cells() returns an object.

You can try converting it to a Excel Cell object in another step, or you can try this (for example):

shXL.Range("A2").Value

With conversion will be:

Dim xRng As Excel.Range = CType(shXL.Cells(3,3), Excel.Range)
Dim val As Object = xRng.Value()

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!