4

I have some html like this:

var html = '<h1>heading</h1><p>Lorem ipsum dolor sit amet<br>more text</p><ul><<li>Bulleted text</li></ul>'

And I want to convert this string into rich text in a google Doc. Any way I can do that?

0

1 Answer 1

6

For example, from your tag, if you want to achieve it using Google Apps Script, how about this sample script? I think that there are several solutions for your situation. So please think of this as just one of them.

When you use this script, please enable Drive API at Advanced Google Services and API console. You can see about this at here.

Sample script:

var html = '<h1>heading</h1><p>Lorem ipsum dolor sit amet<br>more text</p><ul><<li>Bulleted text</li></ul>';
var blob = HtmlService.createHtmlOutput(html).getBlob();
Drive.Files.insert({title: "fileName", mimeType: MimeType.GOOGLE_DOCS}, blob);

Note:

  • When you run this script after enable Drive API at Advanced Google Services and API console, new Document is created. When you open the Document, you can see the converted rich text from HTML.
  • This is a simple sample script. So please modify it for your situation.

Reference:

If this was not the result you want, I apologize.

Sign up to request clarification or add additional context in comments.

4 Comments

This worked but the styling is not adding. Texts that were bold or colored are not adding on the new version.
I've issued a new question. Please check the link below, your help will be a lifesaving. Thanks! stackoverflow.com/questions/56850971/…
@Shihan Khan Thank you for your response. I will check it. When I could understand about your situation and found the solution, I would like to answer it.
@Tanaike you save me. This chatgpt didn't know how to answer lol.

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.