JavaScript API不适用于Excel 2013吗? [英] JavaScript API does not work for Excel 2013?

查看:96
本文介绍了JavaScript API不适用于Excel 2013吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚收到我提交的一个加载项的变更建议报告.它说Your add-in is not working in the Excel 2013 client on Windows 7 with Internet Explorer 11.

I just got a change recommendation report for one add-in I submitted. It says Your add-in is not working in the Excel 2013 client on Windows 7 with Internet Explorer 11.

我一直在Excel 2016Excel Online中测试我的加载项.因此,我刚刚安装了Excel 2013(版本15.0.4841.1000,其中包括 SP1 ) ,的确该外接程序无法正常工作.但是似乎没有什么工作...

I have always been testing my add-in in Excel 2016 and Excel Online. So I just installed Excel 2013 (version 15.0.4841.1000, which includes SP1), indeed the add-in does not work. But it seems that few things work...

例如,下面的示例函数在Excel Online下的单元格A1中写入haha,而在Excel 2013中则没有任何内容.

For example, the following example function writes haha in Cell A1 under Excel Online, whereas, it does not anything in Excel 2013.

function test () {
    Excel.run(function (ctx) {
        var range = ctx.workbook.worksheets.getItem("Sheet1").getRange("A1");
        range.values = [["haha"]];
        return ctx.sync();
    });
}

那么有人知道JavaScript API是否支持Excel 2013吗?如果没有,很多专业人士将无法使用加载项,因为他们仍然使用Excel 2013 ...

So does anyone know if JavaScript API supports Excel 2013? If not, many professionals will not be able to use add-ins because they are still with Excel 2013...

PS:我看到办公室商店中有很多加载项需要Excel 2013 or laterExcel 2013 Service Pack 1 or later.如果JavaScript API不支持Excel 2013,这些加载项(例如

PS: I see there are lots of add-ins in office store require Excel 2013 or later or Excel 2013 Service Pack 1 or later. If JavaScript API does not support Excel 2013, how have these add-ins (eg, Stock Connector) been developed?

在清单XML中:

<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">

在我的Home.html中,我有:

<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>

我想以下设置等同于说不应在Excel 2013中使用该加载项?

Edit 2: I guess the following setting is equivalent to say the add-in is not supposed to be used in Excel 2013?

<Hosts>
  <Host Name="Workbook" />
</Hosts>
<Requirements>
  <Sets>
    <Set Name="ExcelApi" MinVersion="1.2"/>
  </Sets>
</Requirements>
<DefaultSettings>
  ...
</DefaultSettings>

推荐答案

使用Office.js API时,您会看到每个方法都带有一个API集指定.例如:

When you use the Office.js APIs, you will see that each method is annotated with an API set designation. For example:

这些API集对应于外接程序将使用的Office版本.需求集的列表及其支持的位置可以在

These API sets correspond to what versions of Office the add-in will work on. The list of requirement sets, and where they're supported, can be found at http://dev.office.com/reference/add-ins/office-add-in-requirement-sets.

Excel 2016+(以及Office Online和Mac/iOS等效版本)仅支持 所有新的Office 2016特定于主机的API集(ExcelApi,WordApi等). API版本号(1.1 vs. 1.2 vs. 1.3)对应于API的更新,这些更新是在Office 2016的RTM版本之后(随1.1出厂提供的)添加的).那些具有Office 365订阅(家庭或企业)的客户可以使用这些更新.购买Office 2016磁盘/MSI产品的客户将仅具有原始的1.1 API.

Any of the new Office 2016 host-specific API sets (ExcelApi, WordApi, etc.) are only supported on Excel 2016+ (and Office Online and Mac/iOS equivalents). The API version number (1.1 vs. 1.2 vs. 1.3) corresponds to updates to the APIs, that were added past the RTM build of Office 2016 (which shipped with 1.1 out-of-the-box). Those updates are available to customers who have an Office 365 subscription (home or business). Customers who bought a disk/MSI product of Office 2016 will only have the original 1.1 APIs.

您可以通过两种方式使用需求集.如果您的加载项100%取决于特定的API集,则应在清单文件中列出它.这样,对于不支持该特定API集的Office版本,该加载项甚至不会出现在插入/管理加载项"对话框中.

You can use the requirement sets in two ways. If your add-in 100% depends on a particular API set, you should list it in your manifest file. That way, the add-in won't even be proffered on the "Insert/Manage Add-ins" dialog for Office versions that don't support that particular API set.

另一方面,如果您只使用一组API,并且可以不这样做(即使这会降低体验),则可以执行点亮方案".也就是说,您将列出需要所需的最低版本,然后使用运行时检查来检测特定的API集是否可用.

On the other hand, if you're only using a few APIs in the set, and could do without (even if it's a bit of a degraded experience), you can do the "light-up scenario". That is, you will list the lowest possible version that you do need, and then use a runtime check to detect whether a particular API set is available.

具体示例:假设您有一个Excel加载项,它可以创建一个新工作表并将数据输出到表中.这需要ExcelApi 1.1版本或更高版本.理想情况下,您还希望 能够设置列宽,但是range.format.columnWidth仅在ExcelApi 1.2中可用.如果客户使用的是旧版本,则不想阻止使用他们的加载项-毕竟,即使不是最佳状态,您的大部分功能仍然可以使用,但是您可以想要使用新的API.在这种情况下,应该在清单中指定ExcelApi 1.1,然后在JavaScript中进行运行时检查,以确定是否可以运行range.format.columnWidth代码.即:

Concrete example: suppose you have an Excel Add-in that creates a new sheet and outputs data into a table. This requires ExcelApi 1.1 version or higher. Ideally you would also like to be able to set the column widths, but range.format.columnWidth is only available in ExcelApi 1.2. You don't want to block customers from using your Add-in if they have an old version -- after all, the bulk of your functionality will still work, even if not optimally -- but you do want to make use of the new APIs. In that case, you should specify ExcelApi 1.1 in your manifest, and then do a runtime check in you JavaScript to determine if you can run the range.format.columnWidth code. I.e.:

if (Office.context.requirements.isSetSupported("ExcelApi", 1.2 )
{
   range.format.columnWidth = 25;
}

有关的答案,请参见整洁的方法获取环境(即Office版本)

这篇关于JavaScript API不适用于Excel 2013吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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