I am trying to generate a report in a Google doc from a template file. When it copies the document it resets all of the formatting to the defaulted for the user and not what the format in the original doc is. I've tried the following to try and set the formatting on a both the document, tableRow and tableCell level though when the report is created the line spacing is 1.5 and there is a space after paragraph
var style = {};
style[DocumentApp.Attribute.SPACING_AFTER] =0;
style[DocumentApp.Attribute.SPACING_BEFORE] =0;
style[DocumentApp.Attribute.LINE_SPACING]=1;
var newrow= tables[2].insertTableRow(n).setBold(false).setAttributes(style);
if(j==0){
newrow.insertTableCell(0,reportDate).setPaddingBottom(0).setPaddingTop(0).setAttributes(style);
}
else{
newrow.insertTableCell(0,'').setPaddingBottom(0).setPaddingTop(0).setAttributes(style);
}
newrow.insertTableCell(0,values1[rowId1][1]+' '+values1[rowId1][2]).setPaddingBottom(0).setPaddingTop(0).setAttributes(style);
newrow.insertTableCell(0,'').setPaddingBottom(0).setPaddingTop(0).setAttributes(style);
doc.editAsText().setAttributes(style);
any suggestions on how to have the report follow these attributes?
I believe the SPACING_AFTER, SPACING_BEFORE & LINE_SPACING are not attributes associated with the TABLE_CELL object. You must reference the child PARAGRAPH in order to set these.
var style = {};
style[DocumentApp.Attribute.SPACING_AFTER] =0;
style[DocumentApp.Attribute.SPACING_BEFORE] =0;
style[DocumentApp.Attribute.LINE_SPACING]=1;
var newrow = tables[2]
.insertTableRow(n)
.setBold(false);
if (j == 0) {
newrow.insertTableCell(0,reportDate)
.setPaddingBottom(0)
.setPaddingTop(0);
}
else {
newrow.insertTableCell(0,'').setPaddingBottom(0).setPaddingTop(0);
}
newrow.insertTableCell(0,values1[rowId1][1]+' '+values1[rowId1][2])
.setPaddingBottom(0)
.setPaddingTop(0);
newrow.insertTableCell(0,'')
.setPaddingBottom(0)
.setPaddingTop(0);
var newrowTableCell = newrow.getChild(0);
var newrowParagraph = newrowTableCell.getChild(0).setAttributes(style);
As the set attributes was not setting the attributes and you can not cast any of the elements as paragraphs I resolved this problem by getting all of the paragraphs and setting them manually by adding this at the end
var p=doc.getParagraphs();
for(i=0;i<p.length; i++){
p[i].setLineSpacing(1).setSpacingAfter(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With