使用 Google 脚本更改 Google 文档中的段落标题文本
我有一个具有以下样式的 Google 文档:
实际目录是:
您可以看到它有几种样式:
- 标题(14pt,蓝色,下划线)
- 副标题(12 点,黑色,下划线)
- 标题 1(11 点)
- 标题 2(10 点,粗体)
- 普通文本(10 点)
我想制作一个在活动文档上运行的脚本并存储每个标题的内容进行以下更改:
- 标题 1(14pt,蓝色,下划线)
- 标题 2(11pt)
- 普通文本(10pt,第一行包含“主题 n°)”,粗体)
运行脚本后的最终结果应该为:
新目录应如下所示:
所以主要的变化是将HEADER 2内容放入普通文本行,因此它从目录中消失。有没有办法编写一个脚本来解决这个问题?
I have a Google Docs with the following style:
The actual TOC is:
You can see it has a few styles:
- Title (14pt, in blue, underlined)
- Subtitle (12pt, in black, underlined)
- Header 1 (11pt)
- Header 2 (10pt, in bold)
- Normal text (10pt)
I would like to make a script that runs on the active document and store the content of each heading to make the following changes:
- Header 1 (14pt, in blue, underlined)
- Header 2 (11pt)
- Normal text (10pt, the first line contains "Topic nº)" in bold)
The final result after running the script should be:
The new TOC should look like:
So the main change is to put HEADER 2 content into a Normal text line so it dissapears from TOC. Is there any way to code a script that solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅下面的脚本:
脚本行为摘要:
T -> H1
、H1 -> H2
、H2 -> N
>)H2 -> N
直接变为粗体,因为您希望前 N 段为粗体。而当H2降级的时候,就变成了N,成为了第一个N。所以我们可以直接把H2降级的时候变成粗体。输出:
参考文献:
See script below:
Script Behavior Summary:
T -> H1
,H1 -> H2
,H2 -> N
)T -> H1
: 14PT, BLUE, UNDERLINEDH1 -> H2
: 11PTH2 -> N
: 11PT, BOLDH2 -> N
is directly turned to bold as you want the first N paragraph to be bold. And when H2 is demoted, it turns into N and becomes the first N. So we can directly turn H2 into bold when demoted.Output:
References: