Apps Script - AppendListItem with Correct GlyphType

后端 未结 2 731
無奈伤痛
無奈伤痛 2021-01-15 20:44

I\'m trying to copy a ListItem with its associated GlyphType with the following code.

if( type == DocumentApp.ElementType.LIST_ITEM ) {
    Logger.log(\"Glyp         


        
相关标签:
2条回答
  • 2021-01-15 21:14

    I assume from your code that you are trying to copy over elements from one document to another. I really think the Google Apps Scripts lacks a lot of functionality - and it shows strange behaviours.

    From what I have identified the call to appendListItem resets the glyphType. I found that this (sort of) works, when listItem is a list item copied from another document:

    // Appending the list item to the body breaks the glyph type.
    glyphType = listItem.getGlyphType();
    body.appendListItem(listItem);
    listItem.setGlyphType(glyphType);
    
    0 讨论(0)
  • 2021-01-15 21:21

    GlyphType is an ENUM object (basically, a load of IDs referenced by names) belonging to the DocumentApp class, and is accessed as any other static property.

    So, if you wanted to set the bullets to be uppercase letters, you'd say something like:

    myDocBody.appendListItem( "List item text" )
             .setGlyphType( DocumentApp.GlyphType.LATIN_UPPER );
    

    A list of the possible options is available at https://developers.google.com/apps-script/reference/document/glyph-type

    0 讨论(0)
提交回复
热议问题