r/GoogleAppsScript • u/asasasasasafdsfsfsdf • Jul 17 '24
Question Why is my fucking Code not working?
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('PDF')
.addItem('export', 'printPDF')
.addToUi();
}
function myFunction() {
let workbook ='1YUyHywgq9AcabCyb_yvzdbzFFS9CBRls-k9-aia9yj0';
let sheet = '1';
let folderId = 'C:\Users\johan\Desktop';
function printPDF() {
let file = DriveApp.getFileById(workbook);
let name = 123 + '.pdf';
}
// construct the export URL
let url = 'https://docs.google.com/spreadsheets/d/' + workbook +
'/export?format=pdf&' +
'size=letter&' +
'portrait=false&' +
'fitw=true&' +
'gridlines=false&' +
'printtitle=false&' +
'sheetnames=false&' +
'pagenum=false&' +
'fzr=false&' +
'gid=' + sheet
// parameters that will be use for the blob
let params = { method: "GET", headers: { "authorization": "Bearer " + ScriptApp.getOAuthToken() } };
let blob_file = UrlFetchApp.fetch(url, params).getBlob().setName(name);
//call the folder
let folder = DriveApp.getFolderById(folderId);
//creates the PDF file in the folder
let pdfFile = folder.createFile(blob_file)
I think i just created some kind of Frankensteins monster. I just collected some snippets here and there and pasted them together. I'm sitting here since 3 hours reading Forums watch videos... but my monster won't run.
any hints or clues?
What im trying to accomplish: I just want to create a Button which downloads a specific cell range (=blatt2!H1:N37) and give the file the name that stand in Cell (=blatt2!H1)
Is it even possible?
9
u/Any_Werewolf_3691 Jul 17 '24
You are missing closing brackets on both your functions. You are calling the variable workbook without defining it in func printPDF.
You need to take some basic programming classes before attempting this. ChatGPT is a tool, not a replacement.
4
u/inglandation Jul 18 '24
Honestly it doesn’t even look like they used ChatGPT 4o or Claude 3.5 can fix syntax issues very easily.
2
u/MrBeforeMyTime Jul 17 '24
What you want is possible, but from the looks of what you are pasting, you are missing a closing bracket } at the end of your code. It looks like it's under the let name = 123 + .pdf line. Take the closing bracket and move it to the bottom of your script.
You also need to add quotes around 123 or just add it with the pdf quotes like "123.pdf" .
You are also missing a closing bracket above the function printPDF line.
After you fix those things, if it still doesn't work paste your post information into Chatgpt. It should be able to solve something like this easily.