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
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With