我试图获取以下代码,我错过了什么?最重要的是,我需要在文件夹中移动或创建新的电子表格。但似乎我需要一个ID,我似乎可以拉。 谢谢! 鲁迪
var ss =SpreadsheetApp.create('Credit Card Issues with EZ-Pay')
Logger.log('CREATING FILE.');
//var folder = DocsList.getFolder("EZ-Pay Reports");
//var sheet = ss.getSheetByName('Sheet1');
var sheet = ss.getSheets()[0];
Logger.log(ss.getSheetId('Sheet1'));
var ssID = ss.getSheetId('Sheet1');
DocsList.getFileById(ssID).addToFolder(DocsList.getFolder("Credit Card Issues with EZ-Pay/EZ-Pay Reports"));
答案 0 :(得分:0)
代码更简单:
function createInFolder(){
var ss =SpreadsheetApp.create('Credit Card Issues with EZ-Pay')
DocsList.getFileById(ss.getId()).addToFolder(DocsList.getFolder("Credit Card Issues with EZ-Pay/EZ-Pay Reports"));
DocsList.getFileById(ss.getId()).removeFromFolder(DocsList.getRootFolder());
}
答案 1 :(得分:0)
不推荐使用DocsList服务。改为使用Drive Service:
var ss = SpreadsheetApp.create("Credit Card Issues with EZ-Pay");
var id = ss.getId();
var file = DriveApp.getFileById(id);
DriveApp.addFile(file); // adds to the root folder
您也可以将文件添加到根目录以外的文件夹中:
var folder = DriveApp.getFolderbyId(id);
folder.addFile(file);
如果您不知道文件夹的ID:
var folderIter = DriveApp.getFoldersByName("My Folder");
while (folderIter.hasNext()) { // returns true if the collection has a next item
var folder = folderIter.next(); // throws an exception if there's no next item
}
folder.addFile(file);