2

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?

4
  • Are you asking how to get the html to save in a rendered state in the doc? Commented Jan 26, 2017 at 13:27
  • Yes, you are right Commented 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. Commented 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? Commented Jan 26, 2017 at 15:44

1 Answer 1

2

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.