Create backup of spreadsheet with values and format only in specific subfolder - google-apps-script

I have been trying to combine two scripts to create a script that i can run on demand by using a custom menu. I would like the script to do the following:
Make a copy with values and format only (no formulas and importrange), of a existing spreadsheet.
Name the copy the same as the original spreadsheet + timestamp in "yyyy-mm-dd" format.
Place the copy in a specific subfolder.
Also to be able to create the copy on demand, using a custom menu button to do so.
And lastly to have a custom menu button for easy access to said subfolder.
So far i have found two scripts that can do parts of this task but have not been able to combine them to a single script. Is this possible?
See the code below for the two scripts:
SCRIPT 1
// Program: Archive GSheet with Date Stamp
// Programmer: Michael Fryar
// Date: 19 September 2017
// Google Apps Script to copy Google Sheet to subfolder with date stamp in name
// Add Custom Menu
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Archive')
.addItem('Archive a copy with timestamp', 'archiveCopy')
.addItem('Open folder', 'openArchive')
.addToUi();
}
// Define function to copy sheet to subfolder with date stamp in name
// Building on https://gist.github.com/abhijeetchopra/99a11fb6016a70287112
function archiveCopy() {
// Replace "spreadsheetId" with the ID of the Google Sheet you wish to copy
var file = DriveApp.getFileById("ID")
// Replace "folderId" with the ID of the folder where you want the copy saved
var destination = DriveApp.getFolderById("ID");
// Get timezone for datestamp
var timeZone = Session.getScriptTimeZone();
// Generate datestamp and store in variable formattedDate as year-month-date
var formattedDate = Utilities.formatDate(new Date(), timeZone , "yyyy-MM-dd");
// Replace "file_name" with the name you want to give the copy
var name = formattedDate + " Copy";
// Archive copy of "file" with "name" at the "destination"
file.makeCopy(name, destination);
}
// Define function to open archive folder in new tab
// Building on https://www.youtube.com/watch?v=2y7Y5hwmPc4
function openArchive() {
// Replace "folderId" with the ID of the folder where you want copies saved
var url = "https://drive.google.com/drive/folders/"
// HTML to open folder url in new tab and then close dialogue window in sheet
var html = "<script>window.open('" + url + "');google.script.host.close();</script>";
// Push HTML into user interface
var userInterface = HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModalDialog(userInterface, 'Opening Archive Folder');
}
SCRIPT 2
function copyEntireSpreadsheet() {
var id = "ID"; // Please set the source Spreadsheet ID.
var ss = SpreadsheetApp.openById(id);
var srcSheets = ss.getSheets();
var tempSheets = srcSheets.map(function(sheet, i) {
var sheetName = sheet.getSheetName();
var dstSheet = sheet.copyTo(ss).setName(sheetName + "_temp");
var src = dstSheet.getDataRange();
src.copyTo(src, {contentsOnly: true});
return dstSheet;
});
var destination = ss.copy(ss.getName() + " - " + new Date().toLocaleString());
tempSheets.forEach(function(sheet) {ss.deleteSheet(sheet)});
var dstSheets = destination.getSheets();
dstSheets.forEach(function(sheet) {
var sheetName = sheet.getSheetName();
if (sheetName.indexOf("_temp") == -1) {
destination.deleteSheet(sheet);
} else {
sheet.setName(sheetName.slice(0, -5));
}
});
}
UPDATE!
I found another script that could do the parts that i needed and was finally able to combine them together. Posting script below to benefit others in search of something similar:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Archive')
.addItem('Archive copy with timestamp', 'Archive')
.addItem('Open folder', 'openArchive')
.addToUi();
}
function Archive() {
var spreadsheetId = "###"; // Please set the source Spreadsheet ID.
var destFolderId = "###"; // Please set the destination folder ID.
// Copy each sheet in the source Spreadsheet by removing the formulas as the temporal sheets.
var ss = SpreadsheetApp.openById(spreadsheetId);
var tempSheets = ss.getSheets().map(function(sheet) {
var dstSheet = sheet.copyTo(ss).setName(sheet.getSheetName() + "_temp");
var src = dstSheet.getDataRange();
src.copyTo(src, {contentsOnly: true});
return dstSheet;
});
// Get timezone for datestamp
var timeZone = Session.getScriptTimeZone();
// Generate datestamp and store in variable formattedDate as year-month-date
var formattedDate = Utilities.formatDate(new Date(), timeZone , "yyyy-MM-dd");
// Copy the source Spreadsheet.
var destination = ss.copy(ss.getName() + " " + formattedDate);
// Delete the temporal sheets in the source Spreadsheet.
tempSheets.forEach(function(sheet) {ss.deleteSheet(sheet)});
// Delete the original sheets from the copied Spreadsheet and rename the copied sheets.
destination.getSheets().forEach(function(sheet) {
var sheetName = sheet.getSheetName();
if (sheetName.indexOf("_temp") == -1) {
destination.deleteSheet(sheet);
} else {
sheet.setName(sheetName.slice(0, -5));
}
});
// Move file to the destination folder.
var file = DriveApp.getFileById(destination.getId());
DriveApp.getFolderById(destFolderId).addFile(file);
file.getParents().next().removeFile(file);
}
// Define function to open archive folder in new tab
// Building on https://www.youtube.com/watch?v=2y7Y5hwmPc4
function openArchive() {
// Replace "folderId" with the ID of the folder where you want copies saved
var url = "https://drive.google.com/drive/folders/folderid"
// HTML to open folder url in new tab and then close dialogue window in sheet
var html = "<script>window.open('" + url + "');google.script.host.close();</script>";
// Push HTML into user interface
var userInterface = HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModalDialog(userInterface, 'Opening Archive Folder');
}

Related

Script To Write Auto-Gen'd Google Doc URL To Spreadsheet

I have a Google Form that does two things upon hitting the Submit button. First, it dumps that data into a Spreadsheet, then it autofills a Google Doc Template with the info from the Form.
In my script to autofill the Google Doc, I've grabbed the URL for the Google Doc. But I need to write this URL into the last row of Column J in my Google Sheet. Correction: using the getActiveSheet functions are fine, I forgot this script is running from the (Active) Google Sheet (apologies!).
Can anyone assist with this? Here's a snippet of the script to get the URL:
function autoFillGoogleDocFromForm(e) {
//e.values is an array of form values
var TimeStamp = e.values[0];
var Technician = e.values[1];
var Vendor = e.values[2];
var xxx = e.values[3];
var yyy = e.values[4];
var SerialNumber = e.values[5];
var AssetTag = e.values[6];
var TicketNumber = e.values[7];
var HostName = e.values[8];
var DocumentLink = e.values[9];
var Return = e.values[10];
var Platform = e.values[11];
var Summary = e.values[12];
var URL = "";
//file is the template file, and you get it by ID
var file = DriveApp.getFileById('aaa');
//Put auto filled Google Doc into the appropriate Vendor Folder
//file.makeCopy will return a Google Drive file object
if (Vendor == "111") {
var folder = DriveApp.getFolderById('bbb')
var copy = file.makeCopy(TicketNumber + ' - ' + SerialNumber, folder);
}
if (Vendor == "222") {
var folder = DriveApp.getFolderById('ccc')
var copy = file.makeCopy(TicketNumber + ' - ' + SerialNumber, folder);
}
if (Vendor == "333") {
var folder = DriveApp.getFolderById('ddd')
var copy = file.makeCopy(TicketNumber + ' - ' + SerialNumber, folder);
}
//Once we've got the new file created, we need to open it as a document by using its ID
var doc = DocumentApp.openById(copy.getId());
//Get the url of the newly created Google Doc
var url = doc.getUrl();
//Script to write this URL into the Shared Google Sheet will go here
//Since everything we need to change is in the body, we need to get that
var body = doc.getBody();
//Then we call all of our replaceText methods
body.replaceText('{{EmailAddress}}', Technician);
body.replaceText('{{TicketNumber}}', TicketNumber);
body.replaceText('{{HostName}}', HostName);
body.replaceText('{{SerialNumber}}', SerialNumber);
body.replaceText('{{AssetTag}}', AssetTag);
body.replaceText('{{Summary}}', Summary);
body.replaceText('{{Vendor}}', Vendor);
body.replaceText('{{URL}}', url);
//Lastly we save and close the document to persist our changes
doc.saveAndClose();
Thanks in advance!
From your following situation in your question,
Also this is a shared Google Sheet, so I can't use the getActiveSheet function, I'd need to reference the Google Sheet URL, I believe.
If you have the permission to write the values to the shared Google Spreadsheet, how about the following modification?
From:
var url = doc.getUrl();
//Script to write this URL into the Shared Google Sheet will go here
To:
var url = doc.getUrl();
//Script to write this URL into the Shared Google Sheet will go here
var sheet = SpreadsheetApp.openById("### Spreadsheet ID ###").getSheetByName("### sheet name ###");
sheet.appendRow([url]);
In this modification, please set the Spredsheet ID and sheet name. By this, the value of url is appended to the next row of the last row of the sheet in the Google Spreadsheet.
If you want to use the Spreadsheet URL instead of Spreadsheet ID, please modify openById("### Spreadsheet ID ###") to openByUrl("### Spreadsheet URL ###").
References:
openById(id)
openByUrl(url)
appendRow(rowContents)
Edit:
From the following replying,
That doesn't seem to work to insert the URL into the last row of column J unfortunately. It looks like this script can use the Active Sheet afterall, I'll edit the OP.
In this case, how about the following modification?
From:
var url = doc.getUrl();
//Script to write this URL into the Shared Google Sheet will go here
To:
var url = doc.getUrl();
//Script to write this URL into the Shared Google Sheet will go here
// var sheet = SpreadsheetApp.openById("### Spreadsheet ID ###").getSheetByName("### sheet name ###");
var sheet = SpreadsheetApp.getActiveSheet(); // or SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheetname")
sheet.getRange("J" + (sheet.getLastRow() + 1)).setValue(url);
Or
var url = doc.getUrl();
//Script to write this URL into the Shared Google Sheet will go here
// This is from https://stackoverflow.com/a/44563639/7108653
Object.prototype.get1stEmptyRowFromTop = function (columnNumber, offsetRow = 1) {
const range = this.getRange(offsetRow, columnNumber, 2);
const values = range.getDisplayValues();
if (values[0][0] && values[1][0]) {
return range.getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow() + 1;
} else if (values[0][0] && !values[1][0]) {
return offsetRow + 1;
}
return offsetRow;
};
// var sheet = SpreadsheetApp.openById("### Spreadsheet ID ###").getSheetByName("### sheet name ###");
var sheet = SpreadsheetApp.getActiveSheet(); // or SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheetname")
sheet.getRange("J" + sheet.get1stEmptyRowFromTop(10)).setValue(url);
Suggestion:
If you need to write the URL value into the last row of Column J in a shared Google Spreadsheet file, you can try this sample below:
function sample() {
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/SHEET_ID_IS_HERE/edit#gid=0');
var sheet = ss.getSheets()[0]; // access first sheet
var activeSheet = ss.setActiveSheet(sheet);
//Sample setValue() action to the shared sheet file
activeSheet.getRange("A1").setValue("URL");
}
NOTE: You would need to have an editor permission on the Shared Google Sheet file that you're accessing
References:
openByUrl(url)
getSheets()
setActiveSheet(sheet)
Here's the code that ended up working for me.
//Get the url of the newly created Google Doc
var url = doc.getUrl();
// var sheet = SpreadsheetApp.openById("### Spreadsheet ID ###").getSheetByName("### sheet name ###");
var sheet = SpreadsheetApp.getActiveSheet(); // or SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheetname")
sheet.getRange("J" + (sheet.getLastRow())).setValue(url);

On Edit (Google Script)

function onEdit(e)
{
var datum = Utilities.formatDate(new Date(), "GMT+1", "dd.MM.YYYY");
var ss = SpreadsheetApp.getActive();
var newas = SpreadsheetApp.create("Sperren");
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sperren');
sheet.activate();
var temp = ss.duplicateActiveSheet();
range = temp.getDataRange();
range.copyTo(range, {contentsOnly: true});
temp.copyTo(newas);
ss.deleteSheet(temp);
newas.getSheetByName('Sperren');
newas.deleteActiveSheet();
var folderID = "Sperr Material";
var folderID2 = "Prozess";
var datei = newas.getRange("C3").getValues();
// var dateid = newas.getRange("G6").getValues();
var folder = DriveApp.getFoldersByName(folderID);
var theblob = newas.getBlob().setName(datei +" "+ datum);
var newFile = folder.next().createFolder(folderID2 +" "+ datei + " "+ datum).createFile(theblob);
}
/* #Process Form */
function processForm(formObject)
{
var url = "https://https://docs.google.com/spreadsheets/d/1v03Se_BaW-SqFJpN8TU9oEhT2eSvMRHvqwnh3s14lPY/edit#gid=645028893";
var as = SpreadsheetApp.openByUrl(url);
var ws = as.getSheetByName("Test");
/*ws.appendRow([formObject.material,
formObject.stückzahl,
formObject.label,
formObject.datum,
formObject.grund,
formObject.lgort,
formObject.name,
formObject.sgrund]);*/
ws.getRange("A2").setValue(formObject.material);
ws.getRange("B2").setValue(formObject.stückzahl);
ws.getRange("C2").setValue(formObject.label);
ws.getRange("D2").setValue(formObject.datum);
ws.getRange("E2").setValue(formObject.grund);
ws.getRange("F2").setValue(formObject.lgort);
ws.getRange("G2").setValue(formObject.name);
ws.getRange("H2").setValue(formObject.sgrund);
}
Can anyone help me here, i have Html Formular which sends the values to Google Sheet and Sheet should save on one column.
After that it should be transfer the value to another sheet, where is a specific Table, after that it should be save this table to Drive App with informations.
The first column will be changed by either request and by new change should Google Sheet save a new Datei.
but my OnEdit code will not work
if there is a new change should Google save it to a Folder in Drive APP.
But this onEdit code will not work :)

Copy Spreadsheet to a new file, specify tabs

I am copying a new instance of my spreadsheet without formulas into a folder. I found a script that works great here:
Copy an entire Spreadsheet, Just Preserve the Values.
I was trying to define a specific tab to copy but no luck.
var sheet = ss.getSheetByName('tab to dowload');
and
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheets()[2]);
function myFunction() {
var spreadsheetId = "###"; // Please set the source Spreadsheet ID.
var destFolderId = "###"; // Please set the destination folder ID.
// Copy each sheet in the source Spreadsheet by removing the formulas as the temporal sheets.
var ss = SpreadsheetApp.openById(spreadsheetId);
var tempSheets = ss.getSheets().map(function(sheet) {
var dstSheet = sheet.copyTo(ss).setName(sheet.getSheetName() + "_temp");
var src = dstSheet.getDataRange();
src.copyTo(src, {contentsOnly: true});
return dstSheet;
});
// Copy the source Spreadsheet.
var destination = ss.copy(ss.getName() + " - " + new Date().toLocaleString());
// Delete the temporal sheets in the source Spreadsheet.
tempSheets.forEach(function(sheet) {ss.deleteSheet(sheet)});
// Delete the original sheets from the copied Spreadsheet and rename the copied sheets.
destination.getSheets().forEach(function(sheet) {
var sheetName = sheet.getSheetName();
if (sheetName.indexOf("_temp") == -1) {
destination.deleteSheet(sheet);
} else {
sheet.setName(sheetName.slice(0, -5));
}
});
// Move file to the destination folder.
var file = DriveApp.getFileById(destination.getId());
DriveApp.getFolderById(destFolderId).addFile(file);
file.getParents().next().removeFile(file);
}
Explanation:
Your goal is to pass selected sheets, based on their name, to the newly created file.
You can do that by defining a list with the selected sheets:
var selected_sheets = ['Sheet1','Sheet5'];
and then instead of using ss.getSheets() which gets every sheet, use this to get the sheet object of the selected sheet names:
var tempSheets = selected_sheets.map(sn=>ss.getSheetByName(sn))
.map(function(sheet) {
var dstSheet = sheet.copyTo(ss).setName(sheet.getSheetName() + "_temp");
var src = dstSheet.getDataRange();
src.copyTo(src, {contentsOnly: true});
return dstSheet;
});
Solution:
Please modify this list: var selected_sheets = ['Sheet1','Sheet5']; and replace Sheet1, Sheet5 to the name of your sheets. You can also have one sheet: e.g. var selected_sheets = ['Sheet1'];.
function myFunction() {
var spreadsheetId = "###"; // Please set the source Spreadsheet ID.
var destFolderId = "###"; // Please set the destination folder ID.
// Copy each sheet in the source Spreadsheet by removing the formulas as the temporal sheets.
var ss = SpreadsheetApp.openById(spreadsheetId);
var selected_sheets = ['Sheet1','Sheet5']; // Add the sheets you want to copy here!
var tempSheets = selected_sheets.map(sn=>ss.getSheetByName(sn))
.map(function(sheet) {
var dstSheet = sheet.copyTo(ss).setName(sheet.getSheetName() + "_temp");
var src = dstSheet.getDataRange();
src.copyTo(src, {contentsOnly: true});
return dstSheet;
});
// Copy the source Spreadsheet.
var destination = ss.copy(ss.getName() + " - " + new Date().toLocaleString());
// Delete the temporal sheets in the source Spreadsheet.
tempSheets.forEach(function(sheet) {ss.deleteSheet(sheet)});
// Delete the original sheets from the copied Spreadsheet and rename the copied sheets.
destination.getSheets().forEach(function(sheet) {
var sheetName = sheet.getSheetName();
if (sheetName.indexOf("_temp") == -1) {
destination.deleteSheet(sheet);
} else {
sheet.setName(sheetName.slice(0, -5));
}
});
// Move file to the destination folder.
var file = DriveApp.getFileById(destination.getId());
DriveApp.getFolderById(destFolderId).addFile(file);
file.getParents().next().removeFile(file);
}

Google Pass script How to run onEdit() when any value is pasted on certain cell

I want to run a trigger whenever I paste any values on sheet 'Temp' Cell C2
How can I do this ?
--
This is the code I have
function onEdit(e) {
if(e.range.getSheet().getName()!='Temp')return;
if(e.range.getA1Notation()!='C2')return;
e.source.toast('You enter: ' + e.range.getValue());
// what I want to run when any value is pasted on C2
Script();
}
I want to notice, it works when I copy and paste only in C2 but im taking a whole range, and pasting it , so maybe that's the reason why is not working for me ?, maybe I have to change something that indicates when I paste a range ?
--
This is the script function I want to run when I paste the range
function Script(){
// Gets Temp Sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName("Temp");
// Change file name
ss.rename(sh.getRange('Q4').getValue());
// Hide Sheet "Temp"
sh.hideSheet();
// Paste as values dates from sheet Temp
var range ="AL3:AL5";
sh.getRange(range).copyTo(sh.getRange(range), {contentsOnly:true})
// Hides blank rows in sheets 1,2,3
Hide();
// Creates the File in Drive
var sheetId = ss.getId();
var folder = DriveApp.getFolderById("ID"); // The File is stored in this folder
var name = ss.getName() + ".xlsx"; // The name of the new file
var url = "https://docs.google.com/spreadsheets/d/" + sheetId + "/export?format=xlsx&access_token=" + ScriptApp.getOAuthToken();
var blob = UrlFetchApp.fetch(url).getBlob().setName(name); // Modified
folder.createFile(blob);
Reset();
}
/*
After the file is generated
*/
function Reset() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Temp');
// Unhide Sheet "Temp"
sheet.showSheet();
// Resets Sheet Temp
sheet.getRange('A1:AI').clearContent();
sheet.getRange('AL3').setFormula('=AL1');
sheet.getRange('AL4').setFormula('=WORKDAY(AL3,1)');
sheet.getRange('AL5').setFormula('=WORKDAY(AL4,1)');
// Reset the file name
ss.rename('_'+'TEMPLATE');
// Set the cursor to move to Temp
SpreadsheetApp.setActiveSheet(ss.getSheetByName('Temp'))
// Unhides Rows from sheets 1,2,3
Unhide();
}
This this:
function onEdit(e) {
if(e.range.getSheet().getName()!='Temp')return;
if(e.range.rowStart==2 && e.range.columnStart==3) {
Script();
}
}

Downloading a PDF version of the open spreadsheet in Google Drive via scripts

I've been reading up on how to save a spreadsheet to PDF via Google Docs Scripting. Most suggestions I've come across reference using something like:
theOutputFile.saveAndClose();
DocsList.createFile(theOutputFile.getAs('application/pdf')).rename(theOutputName+".pdf");
That is, they reference the saveAndClose() function. I don't want to save or close my spreadsheet - but I do want to download the current sheet as a PDF.
Any suggestions? Thanks.
For saving the current sheet as a PDF, you can hide all the other sheets, save the current, & then show all sheets again.
The pdf creation might start before the end of the sheets' hiding and then will include 2 sheets - the current & the last sheets - in the pdf file.
Adding a sleep or a confirmation msgbox, between showOneSheet & createPdf eliminated the problem.
This answer is a variation of Marco Zoqui's answer: "To send a single sheet you may hide all other before sending" in Google Apps Script to Email Active Spreadsheet
var sheet = SpreadsheetApp.getActiveSheet();
var sheetToSave = sheet.getName();
showOneSheet(sheetToSave);
Utilities.sleep(2000);
createPdf("TestFolder", "TestPDF");
showAllSheets();
function showOneSheet(SheetToShow) {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for(var i in sheets){
if (sheets[i].getName()==SheetToShow){
sheets[i].showSheet();
}
else {
sheets[i].hideSheet();
}
}
}
function showAllSheets() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for(var i in sheets){
sheets[i].showSheet();
}
}
function createPdf(saveToFolder, fileName){
var ssa = SpreadsheetApp.getActiveSpreadsheet();
var pdf = ssa.getAs("application/pdf");
try {
var folder = DocsList.getFolder(saveToFolder);
}
//Create Folder if not exists
catch(error){
folder = DocsList.createFolder(saveToFolder);
}
var file = folder.createFile(pdf);
file.rename(fileName);
return file;
}
I was able to get it to work using #hsgv's answer, however, this is the version I ended up using based on this.
// global save to folder variable:
var folderName = "My/Special/Folder";
function createInvoiceInGoogleDrive(){
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();
// getting some values from the spreadhseet for the file name
var invoiceNumber = sheet.getRange("E3").getValue();
var vendor = sheet.getRange("A9").getValue();
var fileName = invoiceNumber + ' - ' + vendor + " - Invoice.pdf";
var pdfBlob = sheetToPDF(spreadsheet, sheet);
pdfBlob.setName(fileName);
var folder = getOrCreateFolder(folderName);
var matchingFileList = folder.find(fileName);
if ( matchingFileList.length > 0 ) {
Browser.msgBox("ERROR: New invoice not created. " + fileName + " already exists at " + folderName);
return false;
} else {
var f = folder.createFile(pdfBlob);
spreadsheet.toast('Created a new invoice on Google Drive!');
return true;
}
}
// thanks: https://gist.github.com/gregorynicholas/9008572
function sheetToPDF(spreadsheet, sheet) {
var ssID = spreadsheet.getId();
var gid = sheet.getSheetId();
// &gid=x at the end of above url if you only want a particular sheet
var url2 = "http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=" + ssID +
"&gid=" + gid +
"&fmcmd=12&size=7&fzr=true&portrait=true&fitw=true&locale=en&gridlines=false&printtitle=false&sheetnames=false&pagenum=UNDEFINED&attachment=true";
// AUTH TOKEN required to access the UrlFetchApp call below. You can receive it
// from https://appscripts.appspot.com/getAuthToken
var AUTH_TOKEN = "{GET YOUR OWN AUTH TOKEN}";
var auth = "AuthSub token=\"" + AUTH_TOKEN + "\"";
var res = UrlFetchApp.fetch(url2, {headers: {Authorization: auth}}).getBlob();
return res;
}
/**
* Get or create a folder based on its name/path
*/
function getOrCreateFolder(folderName) {
try {
var theFolder = DocsList.getFolder(folderName);
} catch(error){
var theFolder = DocsList.createFolder(folderName);
}
return theFolder;