Word Javascript API insert table 抛出 InvalidArgument 异常
Word Javascript API insert table throws InvalidArgument exception
我试图在我的 word 文档中插入 table,但每次我在控制台中收到 InvalidArgument
异常。
这是我的代码:
Word.run(function (context) {
var selectionRange = context.document.getSelection();
var paragraph = selectionRange.insertParagraph("", Word.InsertLocation.before);
return context.sync()
.then(function () {
var table = paragraph.insertTable(3, 4, Word.InsertLocation.before, [
["Column1", "Column2", "Column3", "Column4"],
["test1", "test2", "test3", "test4"],
["test5", "test6", "test7", "test8"]
]);
table.styleBuiltIn = Word.Style.gridTable1Light;
})
.then(context.sync)
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log('Error: ' + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
我做错了什么吗?
尝试改变
var paragraph = selectionRange.insertParagraph("", Word.InsertLocation.before);
var table = paragraph.insertTable(3, 4, Word.InsertLocation.before, [
["Column1", "Column2", "Column3", "Column4"],
["test1", "test2", "test3", "test4"],
["test5", "test6", "test7", "test8"]
]);
和
var paragraph = selectionRange.insertParagraph("", "Before");
var table = paragraph.insertTable(3, 4, "Before", [
["Column1", "Column2", "Column3", "Column4"],
["test1", "test2", "test3", "test4"],
["test5", "test6", "test7", "test8"]
]);
我发现了问题。 insertTable 仅在 Word API 版本 1.3 中受支持,Office 2019 支持该版本。我使用的是 Office 2016,它仅适用于 1.1。
参考 Link 微软文档:
https://docs.microsoft.com/de-de/office/dev/add-ins/reference/requirement-sets/word-api-requirement-sets
我试图在我的 word 文档中插入 table,但每次我在控制台中收到 InvalidArgument
异常。
这是我的代码:
Word.run(function (context) {
var selectionRange = context.document.getSelection();
var paragraph = selectionRange.insertParagraph("", Word.InsertLocation.before);
return context.sync()
.then(function () {
var table = paragraph.insertTable(3, 4, Word.InsertLocation.before, [
["Column1", "Column2", "Column3", "Column4"],
["test1", "test2", "test3", "test4"],
["test5", "test6", "test7", "test8"]
]);
table.styleBuiltIn = Word.Style.gridTable1Light;
})
.then(context.sync)
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log('Error: ' + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
我做错了什么吗?
尝试改变
var paragraph = selectionRange.insertParagraph("", Word.InsertLocation.before);
var table = paragraph.insertTable(3, 4, Word.InsertLocation.before, [
["Column1", "Column2", "Column3", "Column4"],
["test1", "test2", "test3", "test4"],
["test5", "test6", "test7", "test8"]
]);
和
var paragraph = selectionRange.insertParagraph("", "Before");
var table = paragraph.insertTable(3, 4, "Before", [
["Column1", "Column2", "Column3", "Column4"],
["test1", "test2", "test3", "test4"],
["test5", "test6", "test7", "test8"]
]);
我发现了问题。 insertTable 仅在 Word API 版本 1.3 中受支持,Office 2019 支持该版本。我使用的是 Office 2016,它仅适用于 1.1。
参考 Link 微软文档: https://docs.microsoft.com/de-de/office/dev/add-ins/reference/requirement-sets/word-api-requirement-sets