将 html 转换为 Google 文档

Yeh*_*ont 4 html google-docs google-apps-script

我有一些像这样的html:

var html = '<h1>heading</h1><p>Lorem ipsum dolor sit amet<br>more text</p><ul><<li>Bulleted text</li></ul>'
Run Code Online (Sandbox Code Playgroud)

我想将此字符串转换为谷歌文档中的富文本。我有什么办法可以做到这一点吗?

Tan*_*ike 6

例如,从您的标记中,如果您想使用 Google Apps 脚本来实现它,那么这个示例脚本怎么样?我认为针对您的情况有几种解决方案。所以请将此视为其中之一。

当您使用此脚本时,请在高级 Google 服务和 API 控制台中启用 Drive API。您可以在此处查看此内容

示例脚本:

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);
Run Code Online (Sandbox Code Playgroud)

笔记:

  • 当您在高级 Google 服务和 API 控制台启用 Drive API 后运行此脚本时,将创建新文档。当您打开文档时,您可以看到从 HTML 转换而来的富文本。
  • 这是一个简单的示例脚本。所以请根据您的情况进行修改。

参考:

如果这不是您想要的结果,我深表歉意。