using newPosition() with Google Document -
i’m having problem document.newposition(element,offest). according api spec., https://developers.google.com/apps-script/reference/document/document#newposition(element,integer),
the element contain new position; must either text element or container element paragraph
i’ve tried both .gettext , .editastext text element:
var d=documentapp.getactivedocument(); var t1=d.getbody().editastext(); var t2=d.getbody().gettext();
and then
var position = d.newposition(t1,ix); var position = d.newposition(t2,ix);
where ix integer within text size.
using t1 (editastext), :
we're sorry, server error occurred. please wait bit , try again. (line 32, file "testcode”)
where line 32 “var position=... line.
using t2 (gettext), get:
cannot find method newposition(string,number). (line 32, file "testcode")
does know how newposition text element?
from docs appear method should work, know, throws errors. have several other options choose according document looks like.
remember newposition()
creates position relative specific element - either text element or container element. since getting entire body text element throws error, use body container element.
var d=documentapp.getactivedocument(); var body = d.getbody(); var ix = 2; // position of 2nd element in body container var position = d.newposition(body,ix);
option 2 grab child element body:
var child = body.getchild(2); // if 2nd child paragraph, new position @ end of paragraph // number greater 1 reference position of next // child , throw error. var position = d.newposition(child, 1)
.
what looks trying put cursor x
spaces in particular element. in case, need specific element. text element within paragraph within body.
var body = d.getbody(); var partwo = body.getchild(2); var childtwo = partwo.getchild(0); var position = d.newposition(childtwo, ix);
Comments
Post a Comment