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(); }