开发者

vsto excel 2010 add in - get value of cell when contents refer to another cell and formula

开发者 https://www.devze.com 2023-03-29 01:24 出处:网络
I\'m trying to get the value of a cell using this: Globals.Sheet3.Cells.Range[\"A2\"].Val开发者_StackOverflowue2 as string;

I'm trying to get the value of a cell using this: Globals.Sheet3.Cells.Range["A2"].Val开发者_StackOverflowue2 as string; Cell A2 refers to a cell on a different sheet that in turn refers to a formula on another sheet. The code above always returns null. How can I get the text of cell a2?


If you use...

VB.Net

Dim res As String
res = ThisWorkbook.Worksheets("Sheet3").Range("A2").Value2.ToString()

C#

String res = "";
res = ThisWorkbook.Worksheets["Sheet3"].Range("A2").Value2.ToString()

Does that work?

It's not clear from the question if the problem is with a section of VB.Net or C# code, however I'd say the problem is either with the way your a using the Range method, or possibly with your use of the Globals object.

UPATE to QUESTION: Based on feedback from the questioner, the ANSWER to this question is to use code such as... C#

String res = "";
res = ThisWorkbook.Worksheets["Sheet3"].Range("A2").Text
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号