I have google document which contains list items. Now I want to get the values of those list items. For example, document contains this:
- Text New
- 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);
}
CodePudding user response:
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
-
the following result is obtained.
[ '1.', '2.', 'ii.', '(A)', '1.3' ]
Unfortunately, I couldn't find the method for identifying
I
ofI1.
andI2.
. By this, the glyph ofFactory Floor
becomes1.3
.Note:
In the current stage, in my proposed script, I couldn't find the method for identifying
I
ofI1.
andI2.
. When I could find the method, I would like to update my sample script.This is just my try. I'm not sure whether this method can be used for all situations. So please be careful about this.
When you want to retrieve the glyphs for all list items, please modify the above script as follows.
From
const searchText = ["One One One", "Two Two Two", "ii ii ii ii ii", "C", "Factory Floor"];
To
const searchText = DocumentApp.getActiveDocument().getBody().getListItems().map(e => e.getText().trim());
References: