Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set Alignment for range on google spreadsheet with google-script?

Hello i want to set a center alignment on a range with google script but i don't know how can i do it.

I have already tried

sheet_destination.getRange(last_row_desti+1,1,1,4).setAlignment(DocumentApp.HorizontalAlignment.CENTER);

but the element setAlignment doesn't exist on a range

like image 710
JustinMartinDev Avatar asked Oct 28 '16 12:10

JustinMartinDev


People also ask

How do I change the alignment in Google Sheets?

Change paragraph alignmentOn your computer, open a document in Google Docs. Select the paragraph you want to change. At the top, choose an alignment option.

How do I find the range of a Google script?

Use the getDataRange() method to reference the range containing all of the data in a given sheet. This is one of the most common ways to read data from a Google Sheets spreadsheet using Apps Script.


1 Answers

Try like this:

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var s= ss.getActiveSheet()
  var lr = s.getLastRow()
  var r= s.getRange(1, 1, lr,4)
  var set=r.setHorizontalAlignment("center")
}

Reference: setHorizontalAlignment

like image 187
Ed Nelson Avatar answered Jan 04 '23 05:01

Ed Nelson