mickael
mickael

Reputation: 2095

Google apps script: How to create a downloadable html file?

Starting with 'google apps script'. I've created a simple script that logs some information with 'Logger.log("message");' with this lines being in a loop, so the log message is quite large.

I'd like now to create an html file with that same information and either being able to download that file locally or have it downloaded to my google drive.

Any idea how that could be achieved? I've tried looking examples for a while but I cannot have anything working...

Many thanks!

Upvotes: 0

Views: 2239

Answers (1)

iJay
iJay

Reputation: 4273

Yes you can, you should read first. Have a look this documentation

function createMyHTMLlog()
{
  var folders = DriveApp.getFoldersByName('ff');// ff:your folder name on drive

  if (folders.hasNext()) 
  {
    var folder = folders.next(); //select the folder
    folder.createFile('Log','<b> your message here </b>', MimeType.HTML); //create the file
  }
}

Update: Add more content later

function logUpdate()
{
  var children = folder.getFilesByName('Log');// log is the created file name
  if (children.hasNext()) 
  {
   var file = children.next();
   var logContent = file.getAs('text/plain').getDataAsString();// get available msg
   logContent = logContent.concat('<br>your<b> updated message </b> here'); // combine with new msg
   file.setContent(logContent);
 }
}

Upvotes: 2

Related Questions