New tab for google sheet
On the left-hand side of the Google Sheets documentation, under "Classes", you’ll notice we have a Range class.Ĭlicking on that reveals a selection of methods we can use on a specific range of cells.
We need some way to set the values for a particular range of cells. To do that, let’s go back to the Google Sheets documentation to find some more code. Now, we need to extend our function to actually set the values of the header row.
#New tab for google sheet code#
However, if you had multiple functions in your code project, you could individually select the function you want to run. For now, we only have one function to run. In the toolbar, you should see a play icon just to the left of a menu item with the function name we set ( createHeaders).
#New tab for google sheet mac#
Let’s copy that code and use it in our function:Ĭlick the disk icon in the toolbar or press the Save keyboard shortcut (Command+S on a Mac or Ctrl+S on Windows) to save the project. Var ss = SpreadsheetApp.getActiveSpreadsheet() If we’re setting up column headers in the top row of the spreadsheet, it would be helpful to freeze that row so it’s always available, no matter how far we scroll down. If you scroll down, you’ll notice a method called setFrozenRows that we can use. This documentation tells you exactly how you can manipulate Google Sheets with Apps Script. To get this code, let’s head over to the documentation for Google Sheets. Now, we need to put some code inside those curly braces (the characters you'll notice after the function name) that will make this function do what we want. Let’s change the function name from myFunction to createHeaders, since this script will be creating column headers for us. Just like our project title, we want our function name to describe what the code is actually doing. This will be the framework for our first function. Google has given us a starting block that looks like this: Often there's functions you can copy and use on your own with minimal editing, which is what we'll use here. On a basic level, Apps Scripts are a combination of JavaScript functions-blocks of code designed to perform a certain task.