I'm trying to figure out how to do a couple of things using Advanced Drive Services in Google Apps Script.
1) Creating a spreadsheet with x amount of rows and columns:
When creating a new spreadsheet, how could I make it only have 1 row and 6 columns? Right now, I create the spreadsheet using the function in #2 and then delete the rows and columns. But it would be better if I could just make the spreadsheet have a certain number of rows and columns instead.
2) Setting the title of the spreadsheet:
How would I set the title of the spreadsheet in the createFile function() to the value 'name'? Right now it creates the spreadsheet with the name 'untitled'.
var file = {
title: "",
mimeType: MimeType.GOOGLE_SHEETS,
parents: [{id: artistSpreadSheetsFolderId}] //I have the folder id
};
function createFile(name)
{
var fileJson = Drive.Files.insert(file);
var fileId = fileJson.id;
//how would I set the title of the spreadsheet to the value 'name'?
}
3) Getting the id of a file by the name:
If I pass a name into a function, how would I get the id of that spreadsheet using Advanced Drive Services? The files would be in a folder so I would have the id of that folder already.
function getFileId(name)
{
//get file by name
//get that files id
}
@Tanaike
For the first one, theres no way to do that using advanced drive services? If not, how would I go about adding an array of values into the 1st row? currently I have this: var headers = [["1", "2", "3", "4,", "5", "6"]];
and then I do sheet.getRange(range).setValues(headers);
. Is there a way to set these values in the properties part of the spreadsheet.create?
For the second, I have the var file outside of the function so multiple functions can call it. I wanted to set the name of the spreadsheet after it's created (after the var fileId) to the name thats being passed in, so like - .setTitle(name) or something like that. So in a function I can just do var file = Drive.Files.insert(file); and then do like var fileName = //set name here.
For the third, is that just a for loop? like for(var i = 0; i < drive.files.list.length; i++)?