2016-06-22 6 views
0

Я создаю приложение слова O365, в котором хочу получить все содержимое страницы. В настоящее время я использую функцию getSelectedDataAsync(), но в этом случае мне нужно выбрать все содержимое.Как я могу получить содержимое текстовой страницы в приложении Office 365

Есть ли другой способ получить все содержимое без его выбора?

ответ

0

Да. Если вы использовали офис 2016, Word для IPAD, Word для Mac, мы можем использовать этот код, чтобы получить текст документа Word:

function getDataFromBody() { 
    // Run a batch operation against the Word object model. 
    Word.run(function (context) { 

     // Create a proxy object for the document body. 
     var body = context.document.body; 

     body.load("text"); 

     // Synchronize the document state by executing the queued commands, 
     // and return a promise to indicate task completion. 
     return context.sync().then(function() {    
      console.log("Body txt contents: " + body.text); 
     }); 
    }) 
    .catch(function (error) { 
     console.log("Error: " + JSON.stringify(error)); 
     if (error instanceof OfficeExtension.Error) { 
      console.log("Debug info: " + JSON.stringify(error.debugInfo)); 
     } 
    }); 
} 

Вы можете обратиться к новой версии API от here.

Update

Получить Html содержимого тела для Word:

function getDataFromBody() { 
    // Run a batch operation against the Word object model. 
    Word.run(function (context) { 

     // Create a proxy object for the document body. 
     var body = context.document.body; 

     // Queue a commmand to get the HTML contents of the body. 
     var bodyHTML = body.getHtml(); 

     // Synchronize the document state by executing the queued commands, 
     // and return a promise to indicate task completion. 
     return context.sync().then(function() { 
      console.log("Body HTML contents: " + bodyHTML.value); 
     }); 
    }) 
    .catch(function (error) { 
     console.log("Error: " + JSON.stringify(error)); 
     if (error instanceof OfficeExtension.Error) { 
      console.log("Debug info: " + JSON.stringify(error.debugInfo)); 
     } 
    }); 
} 
+0

На самом деле я создаю это приложение для слова онлайн в Office 365. Кроме того, мне нужно содержание в формате HTML. – Vipul

+0

Чтобы получить содержимое HTML, вместо использования свойства ** text ** мы можем использовать ** getHtml() ** methoed. См. Обновление. –