1

検索を実行し、2 つの検索結果の間のテキストを選択する単語用のタスクペイン アドインを作成しました。数日前まで、次のコードは正常に実行されていました。

function onExpandTestClick() {

        var textToFind = "Word",
            range;
        return Word.run(function(context) {

            var searchResults = context.document.body.search(textToFind, { matchWildCards: false });
            context.load(searchResults, "text");
            return context.sync()
                .then(function() {
                    range = searchResults.items[0].getRange("End");
                    var rangeEnd = searchResults.items[1].getRange("Start");
                    range.expandTo(rangeEnd);
                    context.load(range, 'text');
                    return context.sync();
                })
                .then(function() {
                    range.select();
                    return context.sync();
                });
        })
        .catch(function (error) {
            console.log('Error: ' + JSON.stringify(error));
            }
        });
    }

ただし、現在、次のエラーがスローされています。

Error: {"name":"OfficeExtension.Error","code":"InvalidArgument","message":"InvalidArgument","traceMessages":[],"debugInfo":{"errorLocation":""},"stack":"InvalidArgument: InvalidArgument\n   at Anonymous function (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:183512)\n   at pi (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:198624)\n   at ht (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:198711)\n   at g (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:198531)\n   at l (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:197117)"}

ここで推奨されているように PreviewCDN を使用していますhttps://github.com/OfficeDev/office-js-docs/tree/WordJs_1.3_Openspec で、Office バージョン 16.0.7167.2040 を実行しています。

これはメソッドを使用する正しいrange.expandTo方法ですか? または、APIで何かが変更されましたか?

4

1 に答える 1

1

設計にわずかな変更がありますが、メソッドを正しく使用しています。ExpandTo のセマンティック (最新のドキュメントでわかるように) は、呼び出し範囲を変更するのではなく、新しく拡張された範囲を返すことです。

この変更には Office.js ライブラリの更新が必要です。現在、ベータ CDN に問題があるようです。現在公開されているビルドと一致するように更新に取り組んでいます。

したがって、現時点では、この修正を待つことをお勧めします。

ありがとう!

于 2016-08-25T22:51:20.117 に答える