Да. Если вы использовали офис 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));
}
});
}
На самом деле я создаю это приложение для слова онлайн в Office 365. Кроме того, мне нужно содержание в формате HTML. – Vipul
Чтобы получить содержимое HTML, вместо использования свойства ** text ** мы можем использовать ** getHtml() ** methoed. См. Обновление. –