Google Sheet App Script - For Specific Sheet Hide Rows that are empty then export to PDF -
updated working script
i having little bit difficulty figuring how hide ranges of rows. notice not using updated api ui messages.
uiapp api deprecated.expand file: printorder line: 28 anchor api deprecated.expand file: printorder line: 31 uiinstance api deprecated.expand file: printorder line: 28
i have sheet("printorder" pulls data sheet("salesorder")
my plan link script button on salesorder prints or exports pdf printorder.
now hide empty rows not filled in between row 41 row 76. here mangled script far:
function printorder() { spreadsheetapp.flush(); var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheetbyname("printorder"); var gid = sheet.getsheetid(); //start number row, start number column, number of rows , number of columns var range = sheet.getrange(41, 1, 36,10); //get values rows var values = range.getvalues(); logger.log(values) (var i=0; i<values.length; i++) { if(values[i][0] === ""){ sheet.hiderow(sheet.getrange(i+41,1));1 } } // getting 'name' pdf cell g5 var name = sheet.getrange("g5").getvalue()+".pdf"; // setting output options var pdfopts = '&size=letter' + '&fzr=true'+ '&portrait=true'+ '&fitw=true'+ '&gridlines=false'+ '&printtitle=false'+ '&sheetnames=false'+ '&pagenum=center'+ '&attachment=false'+ '&gid='; // retrieving url link download of pdf var url = ss.geturl().replace(/edit$/, '') + 'export?exportformat=pdf&format=pdf' + pdfopts + sheet.getsheetid(); // simple ui popup allow user click-download pdf var app = uiapp.createapplication().setwidth(200).setheight(50); app.settitle('print sheet'); var link = app.createanchor('download pdf', url).settarget('_new'); app.add(link); ss.show(app); }
thank guidance.
cheers,
mars
initiate i
@ zero, when use hiderows()
method, need add 41 hide correct row:
sheet.hiderows(i+41);
i think line has issue:
for (var i=41; i<values.length; i++) {
the values
array has row 41 data in array index zero. can print contents of values
array logger.log('array: ' + array);
statement. add logger statement, run code, , in view menu, choose logs.
the range values retrieved starts in row 41, loop through data, i
needs start @ zero.
for (var i=0; i<values.length; i++) {
you can start counter number @ number want, you'd need subtract number 0 first loop.
var thisloopvalue; (var i=41; i<values.length; i++) { thisloopvalue = values[i-41]; //on first iteration, index needs zero. 41 - 41 0
Comments
Post a Comment