excel office js库中范围格式的autofitColumns无法正常工作

时间:2016-10-17 08:09:34

标签: excel ms-office office-js

办公室js的excel api 1.1中的范围格式的autofitColumns似乎无法正常工作或我没有正确使用

代码示例:

Excel.run(function (ctx) {
    var sheet = ctx.workbook.worksheets.getActiveWorksheet();
    sheet.getRange("A1:B2").format.autofitColumns();
    return ctx.sync();
})
.catch(function errorHandler(error) {
    console.log("Error: " + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
         console.log("Debug info: " + JSON.stringify(error.debugInfo));
    });

错误对象如下。

Error: {"description":"Object doesn't support property or method 'autofitColumns'","number":-2146827850,"stack":"TypeError: Object doesn't support property or method 'autofitColumns'\n   at ....

我还尝试加载"格式"和/或"格式/ *"首先然后同步,但没有工作

我正在运行Excel 2016 Windows 64位版

1 个答案:

答案 0 :(得分:2)

自动调整仅在ExcelApi 1.2中添加(您可以在该方法的intellisense注释中看到)。所以,如果我不得不猜测,我想知道你是否在Office 2016的RTM / MSI版本上。如果你对需求集进行运行时检查,你是否会得到Office.context.requirements.isSetSupported('ExcelApi', 1.1)返回true,但同样的调用是1.2返回false?