如何用App Script统一设置Google文档项目符号列表的字形样式
批量修复Google文档项目符号样式的App Script方案
核心逻辑:通过App Script遍历文档所有段落,识别列表项后统一设置项目符号样式,无需手动逐个调整。
代码实现:
function batchSetBulletStyles() { const targetDoc = DocumentApp.getActiveDocument(); const docBody = targetDoc.getBody(); const allParagraphs = docBody.getParagraphs(); allParagraphs.forEach(paragraph => { // 识别带列表结构的段落 if (paragraph.getListId()) { const listStyle = paragraph.getListStyle(); // 设置为圆点项目符号,可替换为其他类型 listStyle.setListType(DocumentApp.ListType.BULLET); // 配置缩进参数(72点=1英寸,可按需修改) listStyle.setIndentStart(72); listStyle.setIndentFirstLine(0); paragraph.setListStyle(listStyle); } }); }操作步骤:
- 打开目标Google文档,点击「扩展程序」→「Apps Script」进入脚本编辑器
- 替换默认代码为上述脚本
- 点击运行按钮,完成权限授权后等待执行
- 执行完毕后,文档内所有列表项会自动应用设置的项目符号样式
自定义选项:
- 更换符号类型:将
DocumentApp.ListType.BULLET替换为DocumentApp.ListType.SQUARE_BULLET(方形)或DocumentApp.ListType.DIAMOND_BULLET(菱形) - 调整缩进:修改
setIndentStart的数值来改变列表整体缩进量
- 更换符号类型:将
内容的提问来源于stack exchange,提问作者Mr. T
相关产品推荐
相关产品推荐

