Reputation: 31
I have got this code from Tanaike. It works but I don't understand the if
statement.
Can someone explain this to me?
var body = somedoc.getBody();
var range = body.findText("#PLACEHOLDER#");
var ele = range.getElement();
if (ele.getParent().getParent().getType() === DocumentApp.ElementType.BODY_SECTION) {
var offset = body.getChildIndex(ele.getParent());
body.insertTable(offset + 1, data);
}
Upvotes: 0
Views: 367
Reputation: 26796
Without seeing the rest of your code and question - what the code snippet does is to find a the text "PLACEHOLDER" in your document and to insert a table into the same StructuralElement
as the one containing the Paragraph
with your text.
if
statement verifies either the parent of the parent of ele
is a BodySection
ele
is a ParagraphElement
ele
is a Paragraph
StructuralElements
have a childIndex
var offset = body.getChildIndex(ele.getParent());
finds the childIndex
of the Paragraph
that contains ele
table
will have an index one higher than the Paragraph
, this means that it will be inserted directly after the Paragraph
Upvotes: 1