1

Creating an embedded Google App Script in a Google Spreadsheet and once again hit a roadblock. There were some general questions asked about CSV export (like this one ) in the past and that is so much easier to do than exporting the complexities of an html file which has formatting but specifically nothing touched creating an html file or a zipped html file which has a css. I can actually parse my file cell by cell and create an html file manually which would be tedious because I have formulas and hyperlinks but again I don't want to recreate what's already built into the Google App Spreadsheet.

Very surprised there is no way of just calling it as is or (with the parameter of what I'd like to call the exported file.) Specifically in the FILE menu in a Google spreadsheet there is an option Download as -> Web page (.html zipped) which I can't figure how to run from from a script. I've tried this:

function exportAsHTML(documentId){
  var forDriveScope = DriveApp.getStorageUsed(); //needed to get Drive Scope requested
  var url = "https://www.googleapis.com/drive/v3/files/"+documentId+"/export";
  var param = {
    method      : "get",
    headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
    mimeType    : "application/zip",
    muteHttpExceptions:true
  };
  var html = UrlFetchApp.fetch(url,param).getContentText();
  var file = DriveApp.createFile("myExportedHTML.zip", html,MimeType.ZIP);
  return file.getUrl();
}

I'm getting the following error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required parameter: mimeType",
    "locationType": "parameter",
    "location": "mimeType"
   }
  ],
  "code": 400,
  "message": "Required parameter: mimeType"
 }
}

According to the Test API dialog on the right side of this Google documentation, it seems it does create a zip file with my sample spreadsheet but I can't figure out if I'm going about it wrong but it seems like it would be easier since it's right in the Spreadsheet File menu. Also note that something has happened in the Google API in the last couple years that a bunch of the old documentation is deprecated which makes it harder to find newer working examples (specifically on html)

Mickey D
  • 347
  • 2
  • 12
  • 1
    Possible duplicate of [How To Download / Export Sheets In Spreadheet Via Google Apps Script](https://stackoverflow.com/questions/17644554/how-to-download-export-sheets-in-spreadheet-via-google-apps-script) – Rubén Oct 19 '17 at 14:31

0 Answers0