You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Apps Script设置Google Docs表格左缩进?

How to Set Table Left Indent via Google Apps Script

Hey there, I feel your pain—trying to replicate that manual table indent via Apps Script can be frustrating, especially since the INDENT_FIRST_LINE and INDENT_START attributes don't work for tables at all. That's a known limitation with Google's Document Service right now; those attributes are designed for text paragraphs, not tables.

Workaround: Simulate Indent with Margin Adjustment

The good news is there's a solid workaround that mimics the exact indent effect you get from the Table Properties menu. Instead of using indent attributes, adjust the table's left margin directly. Here's the code to do that:

var body = DocumentApp.getActiveDocument().getBody();
var tableData = [["Row 1, Cell 1"], ["Row 2, Cell 1"]]; // Replace with your actual table data
var targetPosition = 0; // Update this to where you want the table inserted

// Insert the table into the document
var newTable = body.insertTable(targetPosition, tableData);

// Set left margin to match your desired indent (72 points = 1 inch, same as your original value)
newTable.setMarginLeft(72);

This will push the table to the right just like the manual indent setting, and it works reliably with the current Apps Script API.

Help Push for an Official Fix

This missing feature is tracked in an official Google issue. If you want to see proper table indent support added to Apps Script, head over to the relevant Google Issue Tracker entry and give it a thumbs up. More votes tell the team this is a high-priority request for developers.

内容的提问来源于stack exchange,提问作者Mithun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:35:44