C#中CellReference的单元格中的值

我正在使用Office Excel VSTO。 我在工作簿中有一个单元格的单元格引用信息。 说, Sheet1!$ A $ 5 。 我想获得这个单元格中的信息及其types。 无论如何,VSTO都有可能吗?
我现在打破这个单元格引用到表单和单元格获取值。 我想更简单的方法是可能的。

我不确定这是否是你以后的样子,但是下面给你直接访问单元格:

var range = (Range)Globals.ThisAddIn.Application.Range["Sheet1!$a$5"]; var cellContent = range.Value2; 

好吧,我想我有你的问题想通了。
您想要使用VSTOreplace您正在使用的工作簿链接来更新当前工作簿中的值。
对我来说,线索是…
1.想要获得这个单元格及其types的信息
2.使用VSTO来做到这一点
我现在打破这个单元格的参考
顺便说一句,如果我上面的假设是正确的,那么请编辑您的问题,使未来的读者更有意义。

代码示例

 //get workbook link cell ref var range = (Range)Globals.ThisAddIn.Application.Range["Sheet1!$a$5"]; //determine type // if straight linking a value this step is unnecessary unless using the type info to format the cell // or because you are doing a transformation or aggregation on the data prior to putting it somewhere. // if needed... do some try/catchs on casting it to oledate, bool, double, string in that order. // get value var value = range.Value2; // update "active" sheet var sht = (Excel.WorkSheet)Globals.ThisAddIn.Application.ActiveSheet; sht.Range["A1"].Value2 = value; // don't forget to call FinalReleaseCOMObject and GC.WaitForPendingFinalizers/GC.Collect block!! 

还要注意的是,如果你使用代码INSTEAD,你将会“打破单元格引用”。 请注意,您可以保留工作簿链接,但是使用代码方法没有意义。 我的build议是在一般的使用代码,因为它更灵活,但是当你想要速度(configuration)和数据不需要超过基本操作(SUM,IF,基本的math运算符)时利用链接。