无法从已定义的名称获取范围 [英] Can't get range from a defined name

查看:76
本文介绍了无法从已定义的名称获取范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Excel 2016(Office 365)32位,16.0.6965.2115,Visual Studio 14.0.25425.01更新3 我很确定下面的语句曾经起作用,但是现在不再起作用:

Excel 2016 (Office 365) 32 bits, 16.0.6965.2115, Visual Studio 14.0.25425.01 Update 3 I'm quite sure the statement below used to work, but now it doesn't work anymore:

var range = ctx.workbook.names.getItem("Countries").getRange();

我收到一条错误消息,指出不支持getRange方法,但是应该按照文档

I get an error stating that there is no support for getRange method, but it should be supported as documented here.
What am I'm doing wrong?

---这是我正在使用的代码---

--- this is the code I'm using ---

function paintRange() {
    Excel.run(function (ctx) {
        var range = ctx.workbook.names.getItem("Countries").getRange();
        range.format.fill = "green";

        return ctx.sync();
    }).catch(function (error) {
        app.showNotification("Error", error);
    })
}

paintRange附加到按钮.有一个全球范围定义的名称,称为国家". 除了我提到的错误之外,我没有其他错误的详细信息,我还尝试打开快速监视窗口以获取更多线索.

paintRange is attached to a button. There is a global scope defined name called Countries. I don't have any more details of the error besides the one I mentioned, I also tried opening the quick watch window to get more clues.

推荐答案

更新:该问题已通过CDN更新得到解决.您现在应该可以使用namedItem.getRange().感谢您报告此问题,并允许我们快速解决此问题.

UPDATE: The issue is fixed with an update to the CDN. You should be able to use namedItem.getRange() now. Thanks for reporting the issue, and allowing us to do a quick turn-around on it.

================

================

Felipe,看来您绝对正确.这绝对是一个错误.让我与合适的人聊天,以尽快解决此回归问题.我将看看我们是否也可以采取一些措施来避免将来再次发生这种情况.

Felipe, looks like you're absolutely right. This is definitely a bug. Let me talk to the right folks to get this regression fixed as soon as we can. I'll see if we can put in some processes to avoid this in the future, as well.

从立即解决方案的角度来看,有两个选择:

From an immediate-workaround perspective, two options:

  1. 使用BETA CDN(尤其是用于开发中的外接程序而不是生产版外接程序).该URL为: https://appsforoffice.microsoft.com/lib/beta/hosted/office.js

暂时填充意外删除的getRange功能.在Office.initialize内,包含以下代码:

Do a temporarily filling in of the inadvertently-removed getRange functionality. Inside of Office.initialize, include the following code:

if (!Excel.NamedItem.prototype.getRange) {
    Excel.NamedItem.prototype.getRange=function () {
        return new Excel.Range(this.context,
            OfficeExtension.ObjectPathFactory.createMethodObjectPath(
                this.context, this, "GetRange",
                OfficeExtension.OperationType.Read, [], false, true, null
            )
        );
    };
}

即使恢复了功能,#2中的变通办法也不会造成损害,但是我仍然建议您在解决问题后进行心理记录以删除此问题.修复潜在的错误后,我将更新此线程,希望在几周内(作为一个非常粗略的估计,等待可能会延迟它的任何复杂问题).

The workaround in #2 should not cause harm even after the functionality is restored, but I would none-the-less recommend making a mental note to remove this after we've fixed the issue. I'll update this thread once we have fixed the underlying bug, hopefully within a weeks' time (as a very rough estimate, pending any complications that might delay it).

感谢引起我们的注意-单个错误以及使对该API的回归都未被注意到的底层过程.

Thanks for bringing it to our attention -- both the individual bug, and the underlying process that let the regression to this one API go unnoticed.

这篇关于无法从已定义的名称获取范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆