Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

DATA RANGE TO PDF FOLDER IN DRIVE- " TRIGER SHOWS 'RESPONSE ERROR - 400' OTHERWISE THE CODE IS WORKING FINE MANUALLY"

$
0
0
function exportRangeToPDf(range) {**strong text**  var blob,exportUrl,options,pdfFile,response,sheetTabNameToGet,sheetTabId,ss,ssID,url_base;  var currentDate = Date()  range = range ? range : "A1:J85";//Set the default to whatever you want  sheetTabNameToGet = "VIEW SHEET";//Replace the name with the sheet tab name for your situation  ss = SpreadsheetApp.getActiveSpreadsheet();//This assumes that the Apps Script project is bound to a G-Sheet  ssID = ss.getId();  sh = ss.getSheetByName(sheetTabNameToGet);  sheetTabId = sh.getSheetId();  url_base = ss.getUrl().replace(/edit$/,'');  //Logger.log('url_base: '+ url_base)  exportUrl = url_base +'export?exportFormat=pdf&format=pdf'+'&gid='+ sheetTabId +'&id='+ ssID +'&range='+ range +    //'&range=NamedRange +'&size=A4'+     // paper size'&portrait=true'+   // orientation, false for landscape'&fitw=true'+       // fit to width, false for actual size'&sheetnames=true&printtitle=false&pagenumbers=true'+ //hide optional headers and footers'&gridlines=false'+ // hide gridlines'&fzr=false';       // do not repeat row headers (frozen rows) on each page  //Logger.log('exportUrl: '+ exportUrl)  options = {    headers: {'Authorization': 'Bearer '+  ScriptApp.getOAuthToken(),    }  }  options.muteHttpExceptions = true;//Make sure this is always set  response = UrlFetchApp.fetch(exportUrl, options);  //Logger.log(response.getResponseCode())  if (response.getResponseCode() !== 200) {    console.log("Error exporting Sheet to PDF!  Response Code: " + response.getResponseCode());    return;  }  blob = response.getBlob();  blob.setName('STOCK UPDATE.pdf')  pdfFile =  DriveApp.getFolderById('10ZXCLT70JzHaURA5I92CAEEfb8J2qBbT')    .createFile(blob);//Create the PDF file  //Logger.log('pdfFile ID: '+pdfFile.getId())}

Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>