简体   繁体   English

vsto Excel 2010 add in-在内容引用另一个单元格和公式时获取单元格的值

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

I'm trying to get the value of a cell using this: Globals.Sheet3.Cells.Range["A2"].Value2 as string; 我正在尝试使用以下方法获取单元格的值:Globals.Sheet3.Cells.Range [“ A2”]。Value2作为字符串; Cell A2 refers to a cell on a different sheet that in turn refers to a formula on another sheet. 单元格A2是指另一张工作表上的单元格,而该单元格又​​是另一张工作表上的公式。 The code above always returns null. 上面的代码始终返回null。 How can I get the text of cell a2? 如何获取单元格a2的文本?

If you use... 如果您使用...

VB.Net VB.Net

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

C# 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. 从这个问题尚不清楚,问题是否出在VB.Net或C#代码的一部分上,但是我想说问题出在您使用Range方法的方式,还是您使用Globals对象的方式。

UPATE to QUESTION: Based on feedback from the questioner, the ANSWER to this question is to use code such as... C# 正确的问题:根据提问者的反馈,对此问题的答案是使用诸如... C#的代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM