Vertically Align Text on google spreadsheet via go

2019-09-16 18:14发布

I am trying to figure out how to align text in the middle vertically. According to the documentation I have found my following example should work:

var form = FormApp.getActiveForm();
var ss = SpreadsheetApp.openById(form.getDestinationId()); 
var sheet = ss.getSheets()[0];
var fullRange = sheet.getRange("A1:Z1001");

fullRange.setHorizontalAlignment(DocumentApp.HorizontalAlignment.CENTER);
fullRange.setVerticalAlignment(DocumentApp.VerticalAlignment.CENTER);

The interesting thing I find is that the Horizontal Alignment works, but the vertical one does not. Am I possibly using out dated methods? Is there a better way to accomplish this?

1条回答
forever°为你锁心
2楼-- · 2019-09-16 18:49

Just use middle as the parameter for setVerticalAlignment() :

fullRange.setHorizontalAlignment("center").setVerticalAlignment("middle");

You're using the Enum for the DocumentApp intended for Google Docs tables and cells and you're using Spreadsheets.

查看更多
登录 后发表回答