maleta
maleta

Reputation: 425

How can I set custom document table row height with apps script?

I am trying with following code to set custom row height but it never gets applied. Document 'Test report' has 1 row and that row have default height. What's the problem?

  var targetDoc = DocumentApp.create('Test report');
  var body = targetDoc.getBody();
  body.setAttributes({MARGIN_LEFT: 15,
                      MARGIN_RIGHT: 15,
                      MARGIN_TOP: 15,
                      MARGIN_BOTTOM: 15,
                      PAGE_WIDTH: 595,
                      PAGE_HEIGHT: 842});

  var t1 = body.appendTable([['1','2','3','4']]);
  t1.setBorderColor('#FFFFFF');
  var attrs = {};
  attrs[DocumentApp.Attribute.MINIMUM_HEIGHT] = 35;
  t1.setAttributes(attrs);

Upvotes: 3

Views: 2338

Answers (1)

Vytautas
Vytautas

Reputation: 2286

please reffer to the documentation here:

MINIMUM_HEIGHT Enum The minimum height setting in points, for table row elements.

In your code you are setting this as a Table property. You need to do this instead t1.getRow(0).setMinimumHeight(35);. So a working code would look like this:

function test() {
  var targetDoc = DocumentApp.create('Test report');
  var body = targetDoc.getBody();
  body.setAttributes({MARGIN_LEFT: 15,
                      MARGIN_RIGHT: 15,
                      MARGIN_TOP: 15,
                      MARGIN_BOTTOM: 15,
                      PAGE_WIDTH: 595,
                      PAGE_HEIGHT: 842});

  var t1 = body.appendTable([['1','2','3','4']]);
  t1.setBorderColor('#FFFFFF');
  t1.getRow(0).setMinimumHeight(35);

  return;
}

Note that you are setting the height in points, not centimeters or whatever else the table properties will show on the doc!

Upvotes: 2

Related Questions