如何使用 AppsScript 检测 Google 表格单元格中的新行

发布于 2025-01-15 14:23:39 字数 716 浏览 3 评论 0原文

我正在使用这个 脚本 根据我的电子表格生成 json。

我的一些单元格中有一条新线,在单元格内不可见。
当我运行脚本时,新行显示为 ..mytext \nMytext 等,

我想将 \n 替换为
,所以我把它放在 第 44 行

text.replace('\n', "<br>")

根本不起作用,所以我'已将其更改为:

text.replace(/\n/g, "<br>"); 

这也不起作用, \n 仍然存在于 输出。

我相信它有不同的代码或其他东西,有什么想法如何解决吗?

Google 表格中的文本是从 Google 文档复制粘贴的

I am using this script to generate json based on my spreadsheet.

Some of my cells have a new line that no visible within a cell.
When I fun a script the new line appears like ..mytext \nMytext, etc

I want to replace \n with <br>, so I placed that at line 44

text.replace('\n', "<br>")

which is didn't work at all, so I've changed it to that:

text.replace(/\n/g, "<br>"); 

which didn't work either, the \n is still present within an output.

I believe it has a different code or something, any ideas how to fix?

The text to google sheet is copy-pasted from google docs

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼痛 2025-01-22 14:23:39

text.replace(/\n/g, "
");
也不起作用,\n 仍然存在于输出中。,既然如此,下面的修改如何?

From:

text.replace(/\n/g, "<br>"); 

To:

text.replace(/\\n/g, "<br>")
  • From 我想用
    替换 \n,所以我把它放在[第 44 行](https://gist.github.com/florentdescroix/9513cfd957f8b2cde7b832cf7170c84a#file-exportjson -js-L44)
    ,下面的修改如何?

     var output = HtmlService.createHtmlOutput("");
    
  • 当我在 makeJSON_ 看到您的展示脚本时,返回 var jsonString = JSON.stringify(object, null, 4);。由此,我认为需要将 text.replace(/\n/g, "
    ")
    修改为 text.replace(/\\n/g, “
    ”)

From text.replace(/\n/g, "<br>"); and which didn't work either, the \n is still present within an output., in this case, how about the following modification?

From:

text.replace(/\n/g, "<br>"); 

To:

text.replace(/\\n/g, "<br>")
  • From I want to replace \n with <br>, so I placed that at [line 44](https://gist.github.com/florentdescroix/9513cfd957f8b2cde7b832cf7170c84a#file-exportjson-js-L44), how about the following modification?

      var output = HtmlService.createHtmlOutput("<textarea style='width:100%;' rows='20'>" + text.replace(/\\n/g, "<br>") + "</textarea>");
    
  • When I saw your showing script, at makeJSON_, var jsonString = JSON.stringify(object, null, 4); is returned. By this, I thought that text.replace(/\n/g, "<br>") is required to be modified to text.replace(/\\n/g, "<br>").

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文