0

I have created a taskpane addin for word that runs a search and will display the text for the first paragraph for the search result. Until a couple of days ago the following code was running successfully:

    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);
}

However now the following error is being thrown:

{"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)"}

I am using the debug PreviewCDN (//appsforoffice.microsoft.com/lib/beta/hosted/office.debug.js) and am running office version 1610 (Build 7466.2038)

I noticed in the Api documents that paragraphs.first is changing to paragraphs.getFirst() but it doesn't look like this is implemented yet as if I change to use getFirst() I get the following error:

Object doesn't support property or method 'getFirst'  

How should I be using first or getFirst() for a ParagraphCollection?

4

1 回答 1

0

感谢您使用预览版。正如你提到的,我们对一些属性进行了一些更改(即 obj.first、obj.last、obj.previous、obj.next 分别重命名为 getFirst()、getLast()、getLast() 和 getPrevious()支持这些功能的所有对象。

如果您安装了最新的 Insider Slow build (16.0.7571.2006) 或者如果您在 Insider fast build 中,那么您应该会看到更改有效。预览版 Office.js 将与 16.7571+ 版本同步

谢谢,希望这能澄清发生了什么..

于 2016-11-22T18:55:48.350 回答