Skip to content

Get the theme

This article explains how to get the theme applied to a specific spreadsheet.

Spreadsheet.getSpreadsheetTheme();

Use getSpreadsheetTheme(), which is provided by the Spreadsheet class.

It returns a SpreadsheetTheme class object. If no theme is applied, null is returned.

With this class, you can use getFontFamily() to get the theme’s font family and getThemeColors() to get the types of colors available in the theme (an array of ThemeColorType). To get the actual colors, use getConcreteColor().

Because the script accesses the spreadsheet, you may need to authorize it the first time you run it.

/**
* ID of the target spreadsheet
* The xxx part of https://docs.google.com/spreadsheets/d/xxx/edit
*/
const SPREAD_SHEET_ID = '_______________';
/**
* Returns the theme of the spreadsheet
*/
const getSheetTheme = () => {
/** Target spreadsheet */
const ss = SpreadsheetApp.openById(SPREAD_SHEET_ID);
/** Theme information */
const theme = ss.getSpreadsheetTheme();
if (!theme) {
console.log('No theme is applied');
return null;
}
console.log(theme.getFontFamily());
console.log(theme.getThemeColors());
return theme;
};

When you run it, the spreadsheet’s theme is returned.

The theme’s font family and the types of colors available in the theme are written to the log.