ms-word - 尝试删除包含表中内容控件的行时,Word Addin 崩溃
问题描述
我正在开发一个 Word 插件(Word API + Office.js),我正在使用内容控件,我正在尝试读取内容控件中的表格内容,我需要在其中删除空行
示例:我在内容控件中有这个表我必须删除空白行
我可以使用此代码实现此功能,但是如果表包含一个空白的内容控件,那么当我尝试删除该行时,插件本身就会崩溃。
function checktable(element) {
Word.run(function (context) {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
var contentControl = context.document.contentControls.getByTag('control1').getFirst();
var table = contentControl.tables.getFirst();
context.load(contentControl, 'tables');
table.load('values');
return context.sync()
.then(function () {
// Get the longest word from the selection.
if (contentControl.tables.items.length === 0) {
document.getElementById('lblstatus').innerText += "No Tables found";
}
else {
document.getElementById('lblstatus').innerText += " Tables found";
var Tablevaules = table.values;
for (var i = 0, len = Tablevaules.length; i < len; i++)
{
var nullcheck = "";
var inner=Tablevaules[i];
// inner loop applies to sub-arrays
for (var j = 0, len2 = inner.length; j < len2; j++) {
// accesses each element of each sub-array in turn
if (inner[j] == "") {
if (nullcheck != "False") {
nullcheck = "True";
}
}
else {
nullcheck = "False";
}
}
if (nullcheck == "True") {
table.deleteRows(i);
}
}
}
})
.then(context.sync)
.then(function () {
// Queue a command to highlight the search results.
document.getElementById('lblstatus').innerText += element + ":" + "Successs";
});
})
.catch(errorHandler);
}
请让我知道我是否遗漏了什么或已知的错误!
解决方案
推荐阅读
- php - 如何让我的引导程序和 jquery 在 Wamp 虚拟主机中工作?
- android - 在升级到 gradle 插件 3.2.0 时,出现错误“无法在 main-dex 文件中容纳请求的类”
- swift - 根据选择的indexPath加载具体的json message_ids
- google-apps-script - 如何在字符串中包含变量?
- python - 在 PyTorch 中训练神经网络时,损失始终是“nan”
- spring-boot - 如何将用户的 GPS 位置与可用的 GPS 位置进行比较?
- java - Android 应用程序 - 乘除多个用户输入的值
- lua - 为什么下面这段 Lua 代码完全有效?
- javascript - 如何在带有列表的 for 循环中使用 .each()?
- python-3.x - 如何使用机械化将对象解析为 HTML?