3

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?

InSync
  • 4,851
  • 4
  • 8
  • 30
Yehuda Solomont
  • 108
  • 1
  • 7

1 Answers1

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.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • This worked but the styling is not adding. Texts that were bold or colored are not adding on the new version. – Shihan Khan Jul 01 '19 at 12:27
  • I've issued a new question. Please check the link below, your help will be a lifesaving. Thanks! https://stackoverflow.com/questions/56850971/convert-html-with-bold-style-to-google-doc-using-google-script – Shihan Khan Jul 02 '19 at 11:01
  • @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 Jul 02 '19 at 12:15
  • 1
    @Tanaike you save me. This chatgpt didn't know how to answer lol. – Renatto Machado Aug 18 '23 at 15:13