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

后端 未结 2 1677
-上瘾入骨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 00:50

    As David pointed out, the id of the same file is different in the Spreadsheet app and in the Drive app.

    Getting the spreadsheet file from the Drive app, using the Spreadsheet id, and then getting the id of the Drive file, following the example, will solve your problem.

    0 讨论(0)
  • 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())
     }
    
    0 讨论(0)
提交回复
热议问题