google-apps-script - 将 html 转换为 Google 文档

标签 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>'

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

最佳答案

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

当您使用此脚本时,请在 Advanced Google Services 和 API 控制台启用 Drive API。您可以在 here 查看相关信息.

示例脚本:

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);

备注:

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

引用:

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

关于google-apps-script - 将 html 转换为 Google 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54850715/

相关文章:

regex - 是否可以在 CalendarApp.getEvents() 中使用带有搜索参数的正则表达式?

github - 如何最好地开发 Google Sheets 脚本和 Git 版本控制

google-drive-api - 为什么此示例 AppScript 返回错误 : "Access Denied: DriveApp?"

google-apps-script - 如何在同一电子表格中的多个工作表上自动运行谷歌脚本

javascript - 将特定颜色的每个选项卡移至单独的工作簿

javascript - 尝试在 Google Apps 脚本中获取文件的文件夹路径

javascript - Google Script/JavaScript 在时区之间转换时间

google-apps-script - Gmail 到 Google Drive 脚本损坏

javascript - 尝试使用表格作为数据库来更新 WooCommerce 中的价格

javascript - 应用程序脚本 HTML 到 PDF