0
votes

I am writing a Google Sheets Script to save as Sheet file to a PDF. I want the File Name to be Cell A11 (which is a combination of texts from other cells). So I wrote this:

file.setName(Cell + '.pdf');

My question is: how can I define "Cell" to pull data from A11 from inside the spreadsheet.

1

1 Answers

0
votes

Here. Add this function to your script.

function getFilename() {

    var spreadsheet = SpreadsheetApp.getActive();

    var sheet = spreadsheet.getSheetByName('Sheet1');
    // Edit the sheet name as necessary

    var cell = sheet.getRange('A11');
    var filename = cell.getValue();

    return filename;
}

Then change

file.setName(Cell + '.pdf');

to

file.setName(getFilename() + '.pdf');