【问题标题】:Why Application.get_Caller(Type.Missing) returns a negative integer?为什么 Application.get_Caller(Type.Missing) 返回一个负整数?
【发布时间】:2011-12-14 19:12:24
【问题描述】:

get_Caller(Type.Missing) 方法有些奇怪。它返回一个负整数 -2146826265,而不是应有的 Range 对象。

以前有人遇到过这个问题吗?为什么会这样,我应该如何解决它?

谢谢。

Excel.Range range = (Excel.Range) application.get_Caller(System.Type.Missing);

如果我尝试显式用户类型Excel.Range,上述代码将失败。错误消息说,“无法将类型 'int' 转换为 'Microsoft.Office.Interop.Excel.Range'。

编辑:

获取单元格的调用者的目的是将其传递给我的以下函数:

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 并在原始单元格中显示它。有没有更好的方法来实现该功能?

【问题讨论】:

  • 对我来说看起来像一个 HResult。不幸的是,搜索 800a07e7 并没有找到任何有用的东西。
  • 你能指定页面吗?我通过谷歌搜索找不到它。

标签: c# excel com interop vsto


【解决方案1】:

查看MSDN Library article 末尾关于 Application.Caller 属性的表格。您已经发现了#REF 的价值!错误。谷歌“excel 错误 2023”以获取更多信息。我有点怀疑你可以使用这个属性,因为调用者是你的 C# 程序。

【讨论】:

  • 我已经更新了问题帖子,请查看 EIDT,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-15
  • 2010-12-23
  • 1970-01-01
  • 1970-01-01
  • 2020-12-12
相关资源
最近更新 更多