Google APP Script get superscript/subscript of Text in a Google Doc paragraph

140 views
Skip to first unread message

Edward Ulle

unread,
May 11, 2019, 12:21:30 PM5/11/19
to Google Apps Script Community
How to get the superscript/subscript attribute of a portion of text in a Google Doc paragraph?

Tanaike

unread,
May 11, 2019, 9:56:26 PM5/11/19
to google-apps-sc...@googlegroups.com
How about using "getTextAlignment()" method? The sample script is as follows.

var body = DocumentApp.getActiveDocument().getBody();
var p = body.getParagraphs()[0]; // This sample retrieves 1st paragraph in the body.
var text = p.editAsText();
var textLen = text.getText().length;
for (var i = 0; i < textLen; i++) {
  var textAlignment = text.getTextAlignment(i);
  if (textAlignment) Logger.log("%s, %s", textAlignment, text.getText()[i])
}

If this was not the result you want, I apologize.


Edward Ulle

unread,
May 12, 2019, 9:15:30 AM5/12/19
to Google Apps Script Community
Thanks Tanaike, worked perfectly

Tanaike

unread,
May 12, 2019, 6:51:14 PM5/12/19
to Google Apps Script Community
Welcome. I'm glad your issue was resolved. Thank you, too.

Edward Ulle

unread,
May 15, 2019, 2:19:13 PM5/15/19
to Google Apps Script Community
Now I have another problem.  Text.findText(" ") throws and exception "Invalid argument: searchPattern".  I'm trying to find blank spaces in a Google Doc Text object.  I don't want to use a string search for certain reasons.

On Sunday, May 12, 2019 at 6:15:30 AM UTC-7, Edward Ulle wrote:
Thanks Tanaike, worked perfectly
Reply all
Reply to author
Forward
0 new messages