How to Create a Sidebar in Google Sheets [AppScript]

How to Create a Sidebar in Google Sheets 22

  • The best way to Create a Sidebar in Google Sheets: Open your Google Sheets document > Go to “Extensions” > “Apps Script” > Clear any existing code and paste the provided App Script code > Save the code > Add an HTML file by clicking the plus sign (+) in the code editor’s sidebar and name it “Sidebar” > Add your HTML content within the file > Save the HTML file > Click “Review Permissions” to authorize the script to access your Google account > Access your custom sidebar by clicking the new menu item in Google Sheets and selecting “My Sidebar 1“.

In this article, we will learn how to create a sidebar in Google Sheets. Well, we all are aware of the sidebar and we also know that there is no built-in sidebar or its functionality in Google Sheets, then why this article? Well, you must have known or heard about App Script, really appreciable they are. And, yes you can do anything in Google Sheets, I repeat anything using the app script properly. Google has changed Sheets into Programmable software for anyone for free. Yes, you can use the original Google Sheets version, and if you need any additional function, you can create a custom function, custom formulas can also be made in Sheets, and guess what any feature you have seen anywhere in the world, you can create it into Google Sheets programmatically using app script.

So, that’s something very interesting and crazy, today we will learn how to create a sidebar in Google Sheets, and it will be very easy I promise.

Importance of using a Sidebar in Google Sheets

A sidebar is a visual element, it comes under so many of the user interface elements, it’s a small vertical area that appears normally to the left or the right in larger windows and on the top of the screen in narrow screens. You must have seen it on your laptop and mobile phone. Sidebars are pretty common they help to navigate users throughout a complete design, it can be a website, a series of tutorials, or anything that has more out of a single page view. The sidebar may have related content, may have resources to read, may have menu-like items, or anything that a developer wants to keep as per the owner’s guidelines. So, knowing that it’s a visual element, so how we are going to create it? Well, again app script can do more than this, believe me.

The sidebar in Google sheets is a user interface element, you can call it a panel that is displayed on the right-hand side of Google Sheets. Just like an add-on sidebar, you may have seen when using an add-on. Or when you customize charts, you have a sidebar on the right side where all the charts’ details are presented in a very organized manner.

Google Sheets provide an in-built script editor called Apps Script which can create various add-ons and elements for G-Suite applications. It’s a free tool developed by Google Developers to give everything they can imagine. It’s not wrong to know app script as a complete programming or scripting language, and a good thing is that it is pretty similar to JavaScript syntax and very easy to learn as there are so many resources online, and a large community that is increasing every day. So, let’s move ahead and learn how to create a sidebar in Google Sheets.

See also  How to Sort Alphabetically in Google Sheets (A-Z or Z-A)

How to Create a Sidebar in Google Sheets?

We need an app script code to write the functionality of the sidebar, and an HTML file to make the basic layout and a little design for our sidebar. So, from this section, we will learn and implement the steps and methods required to create a sidebar in Google Sheets. So, let’s get started.

How to Create a Sidebar in Google Sheets – App Script Code

In this first section, we will learn how to create a sidebar in Google Sheets, we will cover the app script code part, and then we will move forward. So firstly, for this step, we need a new spreadsheet file and an internet connection, and of course, I will provide you the code to copy and paste into your code editor.

Step 1

Open a Google Sheets file, or launch a new Sheet with a blank template

How to Create a Sidebar in Google Sheets 1

Step 2

Go to Extensions > Apps Script

How to Create a Sidebar in Google Sheets 2

Step 3

A new tab will open, and you will see your code editor here, with a blank function initiator.

How to Create a Sidebar in Google Sheets 3

Step 4

Remove the empty function, and copy and paste the below-provided app script code into your editor

How to Create a Sidebar in Google Sheets 4

How to Create a Sidebar in Google Sheets 5

Code for App Script code.gs file:

</pre>
function onOpen() {

SpreadsheetApp.getUi()

.createMenu('My New Menu')

.addItem('My sidebar 1', 'showSidebar')

.addToUi();

}



function showSidebar() {

var html = HtmlService.createHtmlOutputFromFile('Sidebar')

.setTitle('Calculation Sidebar');

SpreadsheetApp.getUi()

.showSidebar(html);

}

Pro Tip: Make sure you are in the code.gs tab from the sidebar.

How to Create a Sidebar in Google Sheets 6

Step 5

Save the code, and now we need one HTML file as well. So, let’s see that in the next section.

How to Create a Sidebar in Google Sheets 7

In the above app scrip file or the code in the Code.gs script; OnOpen() function creates a custom menu called ‘My Menu’ in the google sheets main menu bar. That menu can contain various items, but here I have added a single item which is a sidebar named “My Sidebar 1“. So, when you click this menu item, the showAdminSidebar() function the second function of our code will execute and it will open the sidebar we have created on the right-hand side of your Google Sheets file

Now, it’s 50% work done, now we need an HTML file to complete the sidebar, for that please see the next section and continue creating a sidebar in Google Sheets.

How to Create a Sidebar in Google Sheets – HTML Code

In this section, we will learn how to create a sidebar in Google Sheets, and we are learning how to integrate an HTML code with your app script code. So, for this, you need to have the previous section done, and you should have an HTML file. So, let’s see how to do that.

Step 1

Click on the Plus sign + in the sidebar of the code editor

How to Create a Sidebar in Google Sheets 8

Step 2

Click on the HTML

How to Create a Sidebar in Google Sheets 9

Step 3

It will ask to name your file, Name it “Sidebar“, and it’s crucial, if you use a different name then it will not work because this name has a connection with the previous code file in code.gs.

How to Create a Sidebar in Google Sheets 10

Step 4

Here, is your HTML file

How to Create a Sidebar in Google Sheets 11

Step 5

Add the following code inside the body element of your HTML file

How to Create a Sidebar in Google Sheets 12


<p> This is my new Sidebar</p>

<input type="button" value="Close" onclick="google.script.host.close()" />

Step 6

If you are not aware of basic HTML, you can copy the entire code below and paste it into your HTML file 

How to Create a Sidebar in Google Sheets 13


<!DOCTYPE html>

<html>

<head>

<base target="_top">

</head>

<body>

<p> This is my new Sidebar.</p>

<input type="button" value="Close" onclick="google.script.host.close()" />

</body>

</html>

Step 7

Click on the save button, and there will no errors.

How to Create a Sidebar in Google Sheets 14

Note that when you try to run this program, it will require access to your account, so you have to log in it with your Google Account. I have shown you so many times, how to authorize your Google account with the app script code editor, still you can check out the below steps to see how to authorize it.

How to Create a Sidebar in Google Sheets – Authorize Google Account with Apps Script

In this section, we will quickly learn how to create a sidebar in Google Sheets and how to authorize the app script code with your Google Account to continue executing the app script code.

Step 1

Click on the review permissions

How to Create a Sidebar in Google Sheets 15

Step 2

Choose a Google Account to continue

How to Create a Sidebar in Google Sheets 16

Step 3

It’s an unsafe page, the browser will block access to this site, if you want to proceed unsafe, please click on the Advanced button

How to Create a Sidebar in Google Sheets 17

Step 4

Then click on go to untitled project unsafe

How to Create a Sidebar in Google Sheets 18

Step 5

Click on allow after reading the privacy terms

How to Create a Sidebar in Google Sheets 19

As you click on the allow, you will be automatically synced to your current project with your Google Account.

I hope you find this section helpful.

How to Create a Sidebar in Google Sheets – Access Sidebar in Google Sheets

We have done all the required things to create a sidebar in Google Sheets. Now, it’s time to access our sidebar from the Sheets.

Step 1

A new menu item is added to your main menu with the name of the sidebar you chose in the code.

How to Create a Sidebar in Google Sheets 20

Step 2

Click on the sidebar name and then click on the first menu item “My Sidebar 1

How to Create a Sidebar in Google Sheets 21

Step 3

You can see your sidebar is opened on the right-hand side, you can see there is nothing inside the sidebar, only a button.

How to Create a Sidebar in Google Sheets 22

We only learned how to create a sidebar in Google Sheets, and not about its content and elements. That’s why it looks empty, but we can write some more codes to add content and beautiful elements inside our sidebar in some other tutorial.

Important Notes

  • Sidebars, Navbars, Scrollbars, and anything that exists on the web can be added to Google Sheets by properly writing a code.gs file in the Apps script section.
  • This sidebar is an empty sidebar with no meaningful content because the intent of this tutorial was only to make you understand how the sidebar is created from the scratch.

See also  How to Add Axis Labels in Google Sheets [Best Guide]

Frequently Asked Questions

Is it possible to add a Sidebar in Google Sheets?

Yes, It is possible to add a sidebar in Google sheets using AppScript.

How to add content to the Sidebar in Google Sheets?

You can add content inside the sidebar using an app script code only, there is no other way. Or, if you are a programmer, you can write entire new code that covers the code of the sidebar and also its components. We have added a single button here, you can add more buttons and beautify them using inline CSS.

See also  How to Use Sparkline in Google Sheets [4 Use Cases]

Conclusion

Wrapping up how to create a sidebar in Google Sheets. We learned how to use code to create the logic of the sidebar in Google Sheets, and then how to use or connect an HTML file with your app script code to create the body, visual elements, and buttons-like things inside your sidebar. I hope you find this article interesting and helpful. I will see you soon with more interesting and useful tutorials. Have a nice day!

Content Protection by DMCA.com

M. Shaiq Ansari

Hi, I am Shaiq, I am a highly skilled technical writer working full-time for Office Demy. I am specialized in Google Workspace and Microsoft Office applications. With a background in Software Engineering, I possess a deep understanding of the intricate functionalities and features of these productivity tools. Connect me on Linkedin https://www.linkedin.com/in/shaiq-ansari/

OfficeDemy.com - Free Tutorials for Microsoft Office & Google Workspace
Logo
Enable registration in settings - general