本文介绍了为行格式设置setAttribute(),line_spacing,SPACING_AFTER,SPACING_BEFORE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从模板文件生成Google文档中的报告。当它复制文档时,它会将所有格式重置为用户的默认格式,而不是原始文档中的格式。我尝试了以下尝试在文档,tableRow和tableCell级别上设置格式,但创建报表时行间距为1.5,段落后有空格

  var style = {}; 
样式[DocumentApp.Attribute.SPACING_AFTER] = 0;
样式[DocumentApp.Attribute.SPACING_BEFORE] = 0;
样式[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);

有关如何让报告遵循这些属性的建议?


  var p = doc.getParagraphs(); 
for(i = 0; i p [i] .setLineSpacing(1).setSpacingAfter(0);


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?

解决方案

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);

这篇关于为行格式设置setAttribute(),line_spacing,SPACING_AFTER,SPACING_BEFORE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:25