class SpreadsheetApp method .setHorizontalAlignment()

SpreadsheetApp is the Apps Script service.

.setHorizontalAlignment() is the method name you will see after a dot in your code.

What it does

Sets left, center, or right alignment for cells in a range.

Why it's used

  • Center headers or right-align number columns automatically.
  • Make printed reports line up cleanly.

Common errors

  • Forgetting parentheses on setHorizontalAlignment. Write SpreadsheetApp.setHorizontalAlignment(), not SpreadsheetApp.setHorizontalAlignment or setHorizontalAlignment by itself.
  • Skipping dots between chained calls. Each step needs a dot, like SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data').setHorizontalAlignment().
  • Adding spaces where they do not belong. Write SpreadsheetApp.setHorizontalAlignment(), not SpreadsheetApp .setHorizontalAlignment(), SpreadsheetApp.setHorizontalAlignment (), or SpreadsheetApp . setHorizontalAlignment().
  • Wrong capitalization. Use SpreadsheetApp and setHorizontalAlignment, not spreadsheetapp or sethorizontalalignment.

Explore

Related methods

Better Sheets tutorials

Visicalc 2023 Design Walkthrough

Visicalc 2023 Design Walkthrough

Design walkthrough of VisiCalc 2023. Watch this if you'd like to see the...
Visicalc 2023 Quick Walkthrough

Visicalc 2023 Quick Walkthrough

This is a fun template I created for April 1st. Take a quick walk throug...

Related blog posts

Written guides about SpreadsheetApp.setHorizontalAlignment().

Browse the blog