异常:请求失败,返回代码400(法语?)



我的回答是:

异常:的请求失败https://docs.google.com返回代码400。截断的服务器响应:<meta-nam。。。(使用muteHttpExceptions选项检查完整响应(

有人能帮我吗?非常感谢。(我是法国人…对不起;(

我的代码是:

function envoiCopieFeuillePDF()
{
DocumentApp.getActiveDocument();
DriveApp.getFiles();
// variables
const doc = SpreadsheetApp.getActive();
const docID = '1_Gt77USWTE3c-8dEzm-WGElxxxxxxxxxAA5bfX2vlHMrdo';
const feuilleID = 'xxxxXXXxxxx';
const email = 'xxx@xxx.fr';
const dossier = DriveApp.getFolderById('1-1cN_xxxxxxvjDwWtr-xFdb2UX_CW8RRz') ;
const d = Utilities.formatDate(new Date(), "GMT+1", "yyyyMMdd")
const fichier = 'Relevé de factures' + "-" + d + ".pdf"
const objet = 'TEST RELEVE pdf';
const corps = "Veuillez trouver ci-joint TEST ...";
// Création du fichier pdf
const url = 'https://docs.google.com/spreadsheets/d/' + docID + '/export?';
const exportOptions =
'exportFormat=pdf&format=pdf' + 
'&size=A4' + 
'&portrait=false' +                     // orientation portrait, false pour paysage
'&fitw=false' +                        // pas d'ajustement en largeur
'&sheetnames=false&printtitle=false' + // pas de nom ni de titre à l'impression
'&pagenumbers=false&gridlines=true' + // pas de numérotation, pas de grille
'&fzr=false' +                         // frozen rows = pas de répétition de l'en-tête
'&gid=' + feuilleID;
var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
var reponse = UrlFetchApp.fetch(url + exportOptions, params).getBlob();

在您的脚本中,如果docID的文件是电子表格,我认为const feuilleID = 'Fairlight Avocat';应该是工作表ID。我认为这可能是您出现问题的原因。如果要使用图纸名称,请进行以下修改?

发件人:

'&gid=' + feuilleID;

收件人:

'&gid=' + SpreadsheetApp.openById(docID).getSheetByName(feuilleID).getSheetId();

注:

  • 如果您可以直接使用工作表ID,请将const feuilleID = 'Fairlight Avocat';Fairlight Avocat修改为工作表ID。

  • 如果docID的文件不是谷歌电子表格,请将其修改为谷歌电子表格的文件ID。

参考文献:

  • getSheetByName(name(
  • getSheetId((

最新更新