I have a string str containing html and I want to save it in an opened google doc format file in a way like this: doc.getBody().appendParagraph(str);
How can I convert that string in a doc format?
-
Are you asking how to get the html to save in a rendered state in the doc?Spencer Easton– Spencer Easton2017-01-26 13:27:02 +00:00Commented Jan 26, 2017 at 13:27
-
Yes, you are rightasv– asv2017-01-26 13:51:46 +00:00Commented Jan 26, 2017 at 13:51
-
Unfortunately, AFAIK there is no function that would only get the text presented in the web page. But using the XML Service can be used to parse HTML and it can be a bit cumbersome to navigate through the DOM tree but I think this is the only way to write html string (rendered) to a doc. Hope this helps.Mr.Rebot– Mr.Rebot2017-01-26 15:03:28 +00:00Commented Jan 26, 2017 at 15:03
-
Ok, thank you. Can I save the html string in a html file and then (with some google file api) convert the whole html file in a doc file?asv– asv2017-01-26 15:44:08 +00:00Commented Jan 26, 2017 at 15:44
Add a comment
|
1 Answer
This worked fine for me
function html_to_doc()
{
var html = '<html><body><h1><i><b>HEADING</b></i></h1></body></html>';
var mediaData = Utilities.newBlob("").setDataFromString(html, "UTF-8").setContentType("text/html");
var resource = {
title: "Html_to_doc",
};
var optionalArgs = {
convert: true
};
var newFileId = Drive.Files.insert(resource, mediaData, optionalArgs);
}