2

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?

1 Answers1

5

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
  • 139,542
  • 10
  • 71
  • 111
  • 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
  • @Shihan Khan Thank you for replying. I'm glad your issue was resolved. About your new issue, can you post it as new question including the detail information? Because my answer is for ``I want to convert this string into rich text in a google Doc``, and I cannot understand about your current situation. By posting it as new question, users including me can think of your new question. At that time, [please close this question](https://stackoverflow.com/help/someone-answers). If you can cooperate to resolve your new issue, I'm glad. – Tanaike Jul 01 '19 at 22:24
  • 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