I have a google doc template file named ‘TemplateDOC’ which will append a paragraph heading at last “11. Annex of Google Sheet Records.” at page 11 after appendPageBreak(). I need to set the page layout landscape so I can insert data range from a googlesheet named ‘logDATA’. The code goes like this but the result is null, please help to reach out the solution.
body.appendPageBreak();
body.appendParagraph("n11. Annex of Google Sheet Records.");
var paragraphs = body.getParagraphs();
var pageCounter = 1;
var switchToLandscape = false;
for (var pLen = 0; pLen < paragraphs.length; pLen++){
var paragraph = paragraphs[pLen];
if(paragraph.getText() == "11. Annex of Google Sheet Records." ){
switchToLandscape = true;
break;
}
}
if(switchToLandscape && paragraph.getType() == DocumentApp.ElementType.BODY_SECTION){
pageCounter++;
}
if(pageCounter==11){
var element = paragraph;
var parent = element.getParent();
if(parent.getType()==DocumentApp.ElementType.BODY_SECTION){
var attribute = {};
attribute[DocumentApp.Attribute.PAGE_WIDTH]=792;
attribute[DocumentApp.Attribute.PAGE_HEIGHT]=612;
parent.setAttributes(attribute);
}
1