Get Google Document as HTML

后端 未结 8 1983
无人及你
无人及你 2020-11-27 17:28

I had a wild idea that I could build a website blog for an unsophisticated user friend using Google Drive Documents to back it. I was able to create a contentService that c

相关标签:
8条回答
  • 2020-11-27 18:18

    Here is a little snipped for the new version of goole AOuth following the idea posted by Enrique:

    function exportAsHTML(){
      var forDriveScope = DriveApp.getStorageUsed(); //needed to get Drive Scope requested
      var docID = DocumentApp.getActiveDocument().getId();
      var url = "https://docs.google.com/feeds/download/documents/export/Export?id="+docID+"&exportFormat=html";
      var param = {
        method      : "get",
        headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
        muteHttpExceptions:true,
      };
      var html = UrlFetchApp.fetch(url,param).getContentText();
      return html; 
    
    }
    

    and then use the usual mailApp:

    function mailer(){
       var docbody = exportAsHTML();
       MailApp.sendEmail({
         to: "email@mail.com",
         subject: "document emailer",
         htmlBody:  docbody  });
    }
    

    Hope the new workaround helps

    JD

    0 讨论(0)
  • 2020-11-27 18:28

    Perhaps this would work for you...

    function doGet() {
      var blob = DriveApp.getFileById('myFileId').getAsHTML();
      return HtmlService.createHtmlOutput(blob);
    }
    
    0 讨论(0)
提交回复
热议问题