0

I have create a very simply Google-Script to add a table into a Google Docs:

var body = DocumentApp.getActiveDocument().getFooter();
body.clear();

var cells = [
['Cell1', 'Cell2', 'Cell3', 'Cell4'],
['Cell5', 'Cell6', 'Cell7', 'Cell8'],
];

var myT = body.appendTable(cells);

var style ={};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Verdana';

myT.setAttributes(style);
myT.setColumnWidth(0, 178.661);
myT.setColumnWidth(1, 106.9681);
myT.setColumnWidth(2, 74.6011);

The script works fine. Now I get this question:

How can I change the "Cell Padding" from the Table? How can I the font or the color from a defined field (e.g. col 2 row 2)?

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
J. Doe
  • 151
  • 12

2 Answers2

1

i don´t find any way to change the "Cell padding" but here is a "way out":

  var body = DocumentApp.getActiveDocument().getFooter();
  body.clear();

  var cells = [
  ['', '', '', ''],
  ];

  var myT = body.appendTable(cells);

  var style ={};
  style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT;
  style[DocumentApp.Attribute.FONT_FAMILY] = 'Verdana';
  style[DocumentApp.Attribute.FONT_SIZE] = 6;

  myT.setAttributes(style);
  myT.setColumnWidth(0, 178.661);
  myT.setColumnWidth(1, 106.9681);
  myT.setColumnWidth(2, 74.6011);  

  //Col 1
  myT.getCell(0, 0).clear()
  var txt = myT.getCell(0, 0).editAsText();
  txt.setText("Text1\nText1\nText1");

  txt.setBold(0, 45, true);
  txt.setBold(91, 102, true);
  txt.setForegroundColor(150, txt.getText().length-1, '#82E600');

  //Col 2
  myT.getCell(0, 1).clear()
  var txt = myT.getCell(0, 1).editAsText();
  txt.setText("Text2\n\nText2\nText2");

  txt.setBold(0, 8, true);
  txt.setBold(52, 66, true);  

  //Col 3
  myT.getCell(0, 2).clear()
  var txt = myT.getCell(0, 2).editAsText();
  txt.setText("Text3\n\nText3");

  txt.setBold(0, 12, true);  

  //Col 4
  myT.getCell(0, 3).clear()
  var txt = myT.getCell(0, 3).editAsText();
  txt.setText("Text4\n\nText4");

  txt.setBold(0, 11, true);
}
J. Doe
  • 151
  • 12
0

It seems there's no methods for cell padding as mentioned in this google forum, however you can try their suggested workarounds. For changing cell color, there's setBackGroundColor and to to change font color, there's setFontColor.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • Hello, at first thanks for your answer. Do you have a very smply Sciptexample for mie? Do you have a simply file with the script for me? – J. Doe Aug 18 '17 at 11:42