Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically Align Text on google spreadsheet via google script

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?

like image 791
Bagzli Avatar asked Mar 24 '26 05:03

Bagzli


1 Answers

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.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!