google-apps-scriptgoogle-sheetsgoogle-docslistitem

How to get value of List Items using Google Apps Script


I have google document which contains list items. Now I want to get the values of those list items. For example, document contains this:

  1. Text New
  2. Text Old

How can I get list items (1,2)?

I used the following code, but it just gives me an array of list item objects but not the values of these list items.

function docFunction() {
  var doc = DocumentApp.getActiveDocument();
  var docBody = doc.getBody();
  var docText = docBody.getListItems();
 
   Logger.log(docText);
 
}

Solution

  • There is not way to retrieve the values you are needing.

    Moreover, ListItem refers to the item in the list itself, not the Glyph.

    The closest thing to getting the information you want is by using the getGlyphType which will return the type of glyph you are using, in this case NUMBER.

    Reference