Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Convert Google Sheet page to image [closed]

$
0
0

Since Google Sheets cannot be saved as an image, I save it as a PDF which retains the painted cell colors and all design details like a image:

    SpreadsheetApp.flush();    var theurl = 'https://docs.google.com/a/mydomain.org/spreadsheets/d/'+'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'+'/export?format=pdf'+'&size=0'+'&portrait=true'+'&fitw=true'+'&top_margin=0'+'&bottom_margin=0'+'&left_margin=0'+'&right_margin=0'+'&sheetnames=false&printtitle=false'+'&pagenum=false'+'&gridlines=false'+'&fzr=FALSE'+'&gid='+'aaaaaaaaaaa';    var token = ScriptApp.getOAuthToken();    var docurl = UrlFetchApp.fetch(theurl, { headers: { 'Authorization': 'Bearer '+  token } });    var pdfBlob = docurl.getBlob();    //...get token and Blob (do not create the file);    var fileName = ss.getSheetByName("General").getRange("H2").getValue();    //Access or create the 'Archives' folder;    var folder;    var folders = DriveApp.getFoldersByName("Archives");    if(folders.hasNext()) {      folder = folders.next();    }else {      folder = DriveApp.createFolder("Archives");    }    //Remove duplicate file with the same name;    var existing = folder.getFilesByName(fileName);    if(existing.hasNext()) {      var duplicate = existing.next();      if (duplicate.getOwner().getEmail() == Session.getActiveUser().getEmail()) {        var durl = 'https://www.googleapis.com/drive/v3/files/'+duplicate.getId();        var dres = UrlFetchApp.fetch(durl,{          method: 'delete',          muteHttpExceptions: true,          headers: {'Authorization': 'Bearer '+token}        });        var status = dres.getResponseCode();        if (status >=400) {        } else if (status == 204) {          folder.createFile(pdfBlob.setName(fileName));        }      }    } else {      folder.createFile(pdfBlob.setName(fileName));    }

But is there any way to make this PDF become an image (PNG or JPG for example) saved in the Google Drive folder that I can do this via Google App Script?


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>