Docs Script - setSpacingBefore with ListItems

417 Views Asked by At

I'm having trouble creating a list item spacing via script.

I'm attempting to iterate through list items and apply a spacing before each, but the spacing is only honored on the first item in the list. MS Word has an option to not add space between paragraphs of the same style and it seems Google Docs defaults this way for lists.

When manually editing the doc it is possible to add space before and after each list item, but not from script.

Ex:

var listItems = document.getBody().getListItems();

for (var i = 0, len = listItems.length; i < len; i++) {

    paragraph.setLineSpacing(1.15);
    paragraph.setSpacingBefore(6);
    paragraph.setSpacingAfter(0);

}

Any ideas how to make this happen? (I realize that I could include a line-break in each list item to add space, but this not quite what I'm looking for)

1

There are 1 best solutions below

0
On

If a list item has had space added to it or removed from it in the UI then the setSpacingBefore and setSpacingAfter methods work as described. If they haven't then the method applies to the list itself and not the children.

I'd call this as a bug and I've added it to the issue tracker. Star it for attention.