使用谷歌应用程序脚本操纵谷歌文档中的单元格高度

时间:2013-01-22 09:42:39

标签: google-apps-script

我正在尝试使用Google Apps Script在Google文档上绘制一个表格,然后将结果转换为PDF。这工作正常,但我无法操纵细胞的高度。 这是我的代码:

var TemplateCopyBody = DocumentApp.openById("id").getActiveSection();
var tableStyle = {};
tableStyle[DocumentApp.Attribute.FONT_SIZE] = 8;
tableStyle[DocumentApp.Attribute.FONT_FAMILY] =  DocumentApp.FontFamily.UBUNTU;
tableStyle[DocumentApp.Attribute.BOLD] = 0;
tableStyle[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = 0;
tableStyle[DocumentApp.Attribute.PADDING_RIGHT] = 0;
tableStyle[DocumentApp.Attribute.HEIGHT] = 0;


/* Function to populate my table */
var myTable = new Array();
for(var i=0;i<RESULT.marksDetails.length -1;i++){
  myTable[i] = RESULT.notesDetails[i];
  Logger.log("insertion table : "+i);
}


TemplateCopyBody.appendTable(myTable).setAttributes(tableStyle).setColumnWidth(0, 300);

我真的需要你的帮助!

1 个答案:

答案 0 :(得分:0)

要将每隔一行的高度更改为45像素,将其他行的高度更改为22像素,我会做类似的事情:

var newTable = TemplateCopyBody.appendTable(myTable);
  for(var i=1; i < myTable.length ;i++){
    if(i % 2 == 0)
      newTable.getRow(i).setMinimumHeight(22);
    else
      newTable.getRow(i).setMinimumHeight(45);
  }
  newTable.setAttributes(tableStyle).setColumnWidth(0, 300);
相关问题