I've been working with both ChatGPT and Google Bard trying to learn how to do this.

It seems that sheet.setPrintArea is not a function nor does there seem to be one similar.

I did a search on developers.google with no results- am I missing an option or is this just not possible?

I'm trying to create this script because the number of rows changes every time I use this sheet.

function printRange() { // Declare variables var spreadsheet = SpreadsheetApp.openById("xxxxxx"); var sheet = spreadsheet.getSheetByName("Invoice"); var rng = sheet.getRange("A1"); var strStopPrint = "stop print";

// Find the cell that contains "stop print" var stopPrintCell = sheet.createTextFinder(strStopPrint).findNext();

// Get the range from A1 to the cell containing "stop print" var printRange = sheet.getRange(rng.getRow(), rng.getColumn(), stopPrintCell.getRow() - rng.getRow() + 1, stopPrintCell.getColumn());

// Set the range as the print area sheet.setPrintArea(printRange.getA1Notation());

// Print the sheet sheet.print(); }


1 Answer 1


There is no Sheet.setPrintArea() or Sheet.print() method. You need to generate a PDF file and upload or email it to some endpoint where it can be printed.

One good way to get started is to use Google's createPDF() sample code. The range to include in the PDF is specified with this line:

  const fr = 0, fc = 0, lc = 9, lr = 27;

See Apps Script at Stack Overflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.