So like as title mentioned, I want to generate PDF from google sheet. I found this reference.
and the following is my code:
function saveSheetsEachPDF(sheet){
let ss = sheet.getParent()
let ss_ID = ss.getId();
let sheet_ID = sheet.getSheetId();
let file_name = '生產單-'+sheet.getName();
const url_base = 'https://docs.google.com/spreadsheets/d/'+ss_ID;
const url_ext = 'export?format=pdf'
+ '&size=A4'
+ '&portrait=true'
+ '&fitw=true'
+ '&sheetnames=false&printtitle=false&pagenumbers=false'
+ '&gridlines=false'
+ '&fzr=false'
+ 'gid=' + sheet_ID
let options = {method:"GET", headers: {"authorization":"Bearer"+ScriptApp.getOAuthToken()}};
let response = UrlFetchApp.fetch(url_base+url_ext, options);
let blob = response.getBlob().setName(file_name+'.pdf')
const folder = DriveApp.getFoldersByName("生產單PDF").next();
folder.createFile(blob);
}
However I get this error that I have no clue what it means :
Exception: Request failed for https://docs.google.com returned code 404. Truncated server response: <meta name=”viewport” c… (use muteHttpExceptions option to examine full response)
New contributor
Agramerrday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1