Is there a way to save html text to a file in goog

2019-02-14 15:09发布

问题:

Is there a way to save html text to a file in google drive using apps script? My app sends back an html string, which I want to save as an .html file into drive, as if I'd uploaded an HTML file to drive. I then intend on opening this .html file as a google doc, which will convert it to a doc format. I've tried this procedure manually, and it works well. Just need to do it in a script.

More to the point, I'd love a direct way to convert HTML into a google doc.

回答1:

var url = 'YOUR PAGE;
var p = SitesApp.getPageByUrl(url);
var html = p.getHtmlContent();
var blob = DriveApp.createFile('dummy',html, 'text/html').getBlob();
var resource = {
  title: 'YOUR FILE NAME',
  convert: true,
  mimeType: 'application/vnd.google-apps.document' 
};
Drive.Files.insert(resource,blob);