如何通过Google Apps Script设置Google Docs表格左缩进?
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

