How To Download All Tabs as CSV in a Zip File
Learn how to download all tabs from a Google Sheet as CSV files in a zip file using Google Apps Script. This tutorial provides a simple solution to streamline the process and save time.
Here's a very interesting problem and a very simple solution with App Script . Basically, we wanna download all of the tabs as a CSV file, but when we go up to file, download A CSV , it's only going to download this exact tab that we're on. It's not gonna download every single CSV file for. So in order to do that, we need a little bit of script. Go up to Extensions app script . And I've written out all of this script for you so far, but we're gonna implement this into the sheet so it's super easy to use for a user. So just wanna explain the script a little bit before we implement it. We're getting the active sheet , we're getting all of the sheets, and then we're going to actually use URL FET app to go to the very specific URL, which is you
can add at the end of a spreadsheet file. URL you can add slash export question mark. Format equals CSV , and then you can combine that with the GID, which is the very specific ID of the tab. And now what it's going to do is going to save each of those URLs as a CSC file. Then it's going to zip it all up and save it to your Google Drive here, and at the end it's going to give us. A URL of a zip drive that's created on our Google Drive. So let's see that in action and then implement it in our sheet. So we're just gonna click run and over on our tab it's says Zip Created. And we're just gonna go to that URL. And here's the two files. I can download this as a zip file, but let's make this super easy to use.
I'm gonna go to better sheets.co snippets slash snippets, and I'm gonna grab this code here, which is a function on open. I'm gonna go back to my app script , go to the very top. Hit enter a few times. Make some space to paste this. I don't need document app or form app. I just need spreadsheet app, custom menu . I'm gonna call this download CSV menu. And the first item is, I'm gonna say download all Cs, all tabs as zip. And I'm gonna take the function name and put it right here. I'm actually gonna delete the second item. We only need one item. I'm gonna save it. Now, once it's saved, I'm gonna close my app script . I'm gonna go back to my sheet and I'm gonna refresh it, meaning I'm gonna open it again. I can close it and open it or refresh it.
Once that happens up at the top, next to extensions help, now there's download CSV menu. Click it and now I can click this. And run it from the sheet itself. And there we go. We just created another zip file with all the CSV files there. Pretty cool, right? And if you're a better sheets member and watching this on better sheets, go down below and you can get this exact sheet and this code directly. Download it. Enjoy it for free. If you're not watching this on Better Sheets. Become a better Sheets member today and get this code over@bettersheets.co. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before.
I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is gonna be your next Google sheet.