Can no longer produce PDF from Google Sheets spreadsheet for some of the users

后端 未结 2 1585
野性不改
野性不改 2020-11-27 08:46

For almost a year we have been using the below code to export a Google Sheets sheet (held in theSheetName) to a PDF named as specified in InboundID

2条回答
  •  执笔经年
    2020-11-27 09:08

    I was having this exact problem. After some debugging I saw that my URL was being created incorrectly.

    My code was nearly identical to yours. Where I found the culprit was the following line:

    var url_base = theSpreadSheet.getUrl().replace(/edit$/,'');
    

    This was not actually clearing out the 'edit' to the end of the line like it had for years. I cannot say why this is, but the proof was in the logs. So, instead I crafted the url by hand:

    var   url = 'https://docs.google.com/spreadsheets/d/'+SpreadsheetApp.getActiveSpreadsheet().getId()+'/';
    

    This seemed to solve the problem. This is not a perfect futureproof resolution, because if Google changes how the URLs are crafted, this will fail. But it works for now.

    I hope this helps. You can send the url your code is creating to logs and check them to see if you have the same issue I did.

提交回复
热议问题