为什么Application.get_Caller(Type.Missing)返回一个负整数? [英] Why Application.get_Caller(Type.Missing) returns a negative integer?
问题描述
get_Caller(Type.Missing)
方法很奇怪。它返回一个负整数, -2146826265 ,而不是范围对象,因为它应该。
There's something weird about get_Caller(Type.Missing)
method. It returns a negative integer, -2146826265, instead of the Range object as it should.
之前有人遇到此问题吗?为什么这样,我该如何解决呢?
Has anyone come across this issue before? Why is that and how should I solve it?
感谢。
Excel.Range range = (Excel.Range) application.get_Caller(System.Type.Missing);
如果我尝试明确用户类型 Excel.Range
。错误消息无法将类型'int'转换为'Microsoft.Office.Interop.Excel.Range'。
The above code would fail if I try to explicitly user type Excel.Range
. The error message says, 'Cannot convert type 'int' to 'Microsoft.Office.Interop.Excel.Range'.
编辑:
获取单元格的调用者的意图是将它传递给我的以下函数:
The intention of getting caller of the cell is to pass it to my following function:
private string getResultFromResultSheet(Excel.Range originalSheetRange, Excel.Worksheet resultSheet)
{
string DataResult = "";
try
{
string os_currentAddress = originalSheetRange.get_Address(Type.Missing, Type.Missing, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing);
Excel.Range currentRRange = null;
currentRRange = resultSheet.get_Range(os_currentAddress, Type.Missing);
if (currentRRange != null)
{
if (string.IsNullOrEmpty(Convert.ToString(currentRRange.Value)))
DataResult = "";
else
DataResult = Convert.ToString(currentRRange.Value);
}
}
catch (Exception ex)
{
}
return DataResult;
}
使用该函数的返回值,我可以将其传递回UDF,在原始单元格中显示它。有没有更好的方法来实现该函数?
With the return value from that function, I can pass it back to UDF and display it in the original cell. Is there any better way to implement the function?
推荐答案
查看 MSDN库文章关于Application.Caller属性。你发现了#REF的价值!错误。 Google'excel error 2023'的其他信息。我有点怀疑你可以使用这个属性,因为调用者是你的C#程序。
Review the table at the end of this MSDN Library article about the Application.Caller property. You've discovered the value of the #REF! error. Google 'excel error 2023' for additional info. I kinda doubt you can use this property, given that the caller is your C# program.
这篇关于为什么Application.get_Caller(Type.Missing)返回一个负整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!