[英]Remove table if contains string
I am looking to automatically remove tables in slides if they contain a specific text string. 我正在寻找自动删除幻灯片中包含特定文本字符串的表格的方法。 This is what I currently have, but for some reason, the findText() doesn't seem to work and I can't figure out an alternative to this...
这是我目前拥有的,但是由于某种原因,findText()似乎无法正常工作,我无法找出替代方案……
function removeUnwantedTables() {
var gotSlides =
SlidesApp.openById('1gJjGBbaQXWhP8uhVIoccV2h_RL7_gsxvg_NW-qNCcLU').getSlides();
for (var i = 0; i < gotSlides.length; i++) {
var slide = gotSlides[i];
var tables = slide.getTables();
for (var k = 0; k < tables.length; k++) {
var allTables = tables[k];
if (allTables.findText('{{remove-this-table}}') > 0) {
allTables.remove();
}
}
}
}
Does anyone have a solution to this? 有人对此有解决方案吗?
How about this modification? 这个修改怎么样? I think that there may be several answers.
我认为可能会有几个答案。 So please think of this as one of them.
因此,请将此视为其中之一。
getCell()
, each cell are retrieved and compared to the string of {{remove-this-table}}
. getCell()
,可以检索每个单元格并将其与{{remove-this-table}}
的字符串进行比较。
{{remove-this-table}}
is found, the table is removed and the for loop is broken away. {{remove-this-table}}
,该表将被删除,并且for循环将被断开。 function removeUnwantedTables() {
var gotSlides = SlidesApp.openById('1gJjGBbaQXWhP8uhVIoccV2h_RL7_gsxvg_NW-qNCcLU').getSlides();
for (var i = 0; i < gotSlides.length; i++) {
var slide = gotSlides[i];
var tables = slide.getTables();
if (tables.length > 0) {
for (var k = 0; k < tables.length; k++) {
var allTables = tables[k];
row = allTables.getNumRows();
col = allTables.getNumColumns();
var values = [];
for (var r = 0; r < row; r++) {
for (var c = 0; c < col; c++) {
var v = allTables.getCell(r, c).getText().asString();
if (v.indexOf("{{remove-this-table}}") > -1) {
values.push(v);
break;
}
}
if (values.length > 0) {
allTables.remove();
break;
}
}
}
}
}
}
If this was not what you want, I'm sorry. 如果这不是您想要的,对不起。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.