Get the spreadsheet key that is in the URL. Not ss.getId()

后端 未结 2 1684
-上瘾入骨i
-上瘾入骨i 2020-12-22 00:33

How to get the spreadsheet ID that is in the URL. I know about using SpreadsheetApp.getActiveSpreadsheet().getId() and SpreadsheetApp.getActiveSpreadsheet().getUrl()

<
2条回答
  •  情书的邮戳
    2020-12-22 01:04

    You don't show the code that is not working for you, but the following works ok for me

    function myFunction() {
    // create a new spreadsheet workbook
    var ss = SpreadsheetApp.create("Test");
    var id = ss.getId();
    Logger.log(id)
    // get the ss file through Drive using spreadsheet id
    var file = DriveApp.getFileById(id);
    var driveid = file.getId();
    Logger.log(driveid)
    // open the spreadsheet using id of file
    var ssfromdrive = SpreadsheetApp.openById(driveid);
    Logger.log(ssfromdrive.getName())
     }
    

提交回复
热议问题