Google apps script 设置行格式、行间距、后间距、前间距的setAttribute()

Google apps script 设置行格式、行间距、后间距、前间距的setAttribute(),google-apps-script,Google Apps Script,我正试图从一个模板文件在谷歌文档中生成一个报告。复制文档时,它会将所有格式重置为用户的默认格式,而不是原始文档中的格式。我尝试了以下方法,尝试在文档、tableRow和tableCell级别上设置格式,但创建报告时,行距为1.5,段落后有一个空格 var style = {}; style[DocumentApp.Attribute.SPACING_AFTER] =0; style[DocumentApp.Attribute.SPACING_BEFORE] =0; style[DocumentA

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

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

关于如何让报告遵循这些属性,有什么建议吗?

用户需要能够编辑报告,还是只需查看报告?为什么不生成pdf?每次我完成后,它都会保存格式

var file = DocsList.getFileById('1DIfn_wVpXSI4hU5zG43Fvp2ZdpUP_KqgtgFRT9NWJ7E');
var newFile = DocsList.copy(file, ename+'-'+reportDate+'Monthly Report');
var report=DocsList.createFile(newFile.getAs("application/pdf")).rename(newFile.getName() + ".pdf");
var a = report.getID();
var doc = DocumentApp.openById(a);

由于set属性没有设置属性,并且不能将任何元素强制转换为段落,因此我通过获取所有段落并通过在末尾添加这些段落来手动设置这些段落,从而解决了此问题

var p=doc.getParagraphs();
  for(i=0;i<p.length; i++){
    p[i].setLineSpacing(1).setSpacingAfter(0);
var p=doc.getparations();

对于(i=0;i,我认为前后间距和行间距不是与表格单元格对象关联的属性。必须引用子段落才能设置这些属性

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

你能分享一下你是如何复制文档的吗?可能有什么地方出了问题。var file=DocsList.getFileById('1DIfn_wvpxsi4hu5zg43fvp2zdppup_KqgtgFRT9NWJ7E');var newFile=DocsList.copy(file,ename+'-'+reportDate+'Monthly Report');var a=newFile.getId();var doc=documentpp.openById(a);我仍然无法看到此问题。我只是尝试使用上面的代码复制“模板”文件,它保留了所有原始格式,包括行距。您的问题是无法通过应用程序脚本或格式(行距)实现所需的格式吗复制文件时丢失?非常感谢!段落。setAttributes(样式)似乎不起作用。添加getChild(0)后,然后设置属性可以正常工作。谢谢!