Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save linglung/bb7eceb8fa93cf6b92217fae2b07df46 to your computer and use it in GitHub Desktop.
Save linglung/bb7eceb8fa93cf6b92217fae2b07df46 to your computer and use it in GitHub Desktop.
Google apps script to set different fonts in the sheets.
/**
* Google Script - Add Fonts.
* Add other fonts in Google Spreadsheet.
*
* a) Open 'Script editor'
* b) Add this script
* c) Save and run 'onOpen'
* d) Go to some 'Spreadsheet' project
* e) Click to 'Font Editor' and then to 'Change Font'
*/
/**
* Display the popup fonts selector
* and set the selected font to selection.
*/
function setFont() {
var range = SpreadsheetApp.getActiveSheet().getActiveRange();
var font = Browser.inputBox('Type font name. (ex. Titillium Web)', Browser.Buttons.OK_CANCEL);
if (font != 'cancel') {
range.setFontFamily(font);
}
}
/**
* Add item to script's menu.
*/
function onOpen() {
var subMenus = [
{
name: 'Change Font',
functionName: 'setFont'
}
];
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.addMenu('Font Editor', subMenus);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment