0

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

    function onGetFirstRangeParaClick() {

    var textToFind = "Word",
        range,
        paragraph;
    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();
                context.load(range, "text, paragraphs");
                return context.sync();
            })
            .then(function () {
                paragraph = range.paragraphs.first;
                context.load(paragraph, "text");
                return context.sync();
            })
            .then(function() {
                $("#getFirstRangeParaResult").text(paragraph.text);
            });
    })
    .catch(onError);
}

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

{"name":"OfficeExtension.Error","code":"GeneralException","message":"GeneralException","traceMessages":[],"debugInfo":{"errorLocation":"ParagraphCollection.first"},"stack":"GeneralException: GeneralException\\n   at Anonymous function (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:8360:6)\\n   at lib$es6$promise$$internal$$tryCatch (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9595:8)\\n   at lib$es6$promise$$internal$$invokeCallback (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9605:8)\\n   at lib$es6$promise$$internal$$publish (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9581:9)\\n   at lib$es6$promise$asap$$flush (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9400:8)"}

デバッグ PreviewCDN (//appsforoffice.microsoft.com/lib/beta/hosted/office.debug.js) を使用しており、Office バージョン 1610 (ビルド 7466.2038) を実行しています。

paragraphs.firstに変更されている Api ドキュメントで気付きましたparagraphs.getFirst()が、使用するように変更したかのように、まだ実装されているようには見えませんgetFirst()。次のエラーが発生します。

Object doesn't support property or method 'getFirst'  

ParagraphCollection に first または getFirst() をどのように使用すればよいですか?

4

1 に答える 1