首页 > 解决方案 > Create Google Apps Script file with DriveApp

问题描述

Code to create an appscript file using appscript editor. for example you type this:

     function msWordExt() {
        var ss = SpreadsheetApp.openById('1MUwH0Cm1cwHcTWSCGPp2SePbzs_4QQmtjwOEWOrOkMw');
        var sheetName = ss.getSheetByName("Sheet2");
         var get = sheetName.getRange(2,3).getValue();
        var folder = DriveApp.getFolderById("1rsicZccurujGp5Ye5HUecBIAPf3_h5Pc");
        folder.createFile("PLAIN TEXT",get,MimeType.MICROSOFT_WORD);}

So the above code creates a MS Word extension file inside a persons Google Drive.

Now I want to try creating a google appscript file extension using code as well, for example the below code doesn't work but it will help give the gist of what I wish to accomplish:

function appScript() {
    var ss = SpreadsheetApp.openById('1MUwH0Cm1cwHcTWSCGPp2SePbzs_4QQmtjwOEWOrOkMw');
    var sheetName = ss.getSheetByName("Sheet2");
     var get = sheetName.getRange(2,3).getValue();
    var folder = DriveApp.getFolderById("1rsicZccurujGp5Ye5HUecBIAPf3_h5Pc");
    folder.createFile("This is an appscript file",get,MimeType.GOOGLE_APPS_SCRIPTS);
}

标签: google-apps-scriptgoogle-sheetsgoogle-drive-api

解决方案


Considerations

You can't use the Drive API to create a Google Apps Scripts Project. Here you can see it's already been reported to Google.

Proposed workaround

You can use the Apps Script API to manage your Apps Script projects. Here is a link to the guide: https://developers.google.com/apps-script/api/samples/manage

Reference

Managing Apps Script Projects


推荐阅读