I\'m importing data from JIRA into a Google Doc. One of the fields would be the description, which is basically HTML text.
Is there any way to \"add\" this HTML text on
I was able to create a new Doc with styled html content from the change mentioned in my comment in this post:
var blob = Utilities.newBlob(content, {mimeType:"text/html"});
var newfile = Drive.Files.insert(resource, blob, {"convert":"true"});
Thanks for your hint - based on this I found the following post: https://ctrlq.org/code/20102-convert-office-files-to-google-docs (plus http://scraping.pro/automaticly-converting-files-google-app-script/ which tells how to enable Drive API).
The following function works pretty well for me:
function convertHtmlToDocs(html) {
var uploadFile = JSON.parse(UrlFetchApp.fetch(
"https://www.googleapis.com/upload/drive/v2/files? uploadType=media&convert=true",
{
method: "POST",
contentType: "text/html",
payload: Utilities.newBlob("").setDataFromString(html, "UTF-8").getBytes(),
headers: {
"Authorization" : "Bearer " + ScriptApp.getOAuthToken()
},
muteHttpExceptions: true
}
).getContentText());
var doc = DocumentApp.openById(uploadFile.id);
var body = doc.getBody().copy();
DriveApp.removeFile(DriveApp.getFileById(doc.getId()));
return body;
}