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

No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.

Related blog posts

Written guides about SpreadsheetApp.setHorizontalAlignment().

Browse the blog