Sets left, center, or right alignment for cells in a range.
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
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
-
.setVerticalAlignment()
Sets top, middle, or bottom alignment for cells in a range.
-
.setWrap()
Turns text wrapping on or off for cells in a range.
-
.setBackground()
Sets the background color of cells in a range.
-
.setNumberFormat()
Sets how numbers and dates display in a range.
-
.setFontColor()
Sets the text color of cells in a range.
More Apps Script
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().
What's Better Than Google Sheets?
Nothing is better than Google Sheets. You just need to learn more about the unlimited power of Google Sheets. Functions, Formulas, Apps Script and more.
Read post →How to Use Google Sheets as a Website Database
Did you know you can use Google Apps Script to turn a Google Sheet into a free, auto-syncing database for your website? This guide shows you exactly how to set it up. You’ll prepare your spreadsheet, write a few lines of code and publish your site. Don’t worry if you’re not a developer, we’ll walk you through it. Why Use Google Sheets as a Database? For small projects, Google Sheets offers many advantages over traditional databases: * Free hosting and storage * Easy to edit data without...
Read post →Spreadsheets Explained over 5 Levels of Difficulty
Master Google Sheets from simple text input to complex operations with our FREE tutorials, templates, and tools! Unleash the full power of spreadsheets now!
Read post →