John Smith
John Smith

Reputation: 397

Insert text at specific position in Google Docs

Trying to insert text to a Google Doc. I would like it to be formated as followed:

enter image description here

Text1

Space

Text2

Space

I have the following code:

function InsertText1() {
   var body = DocumentApp.getActiveDocument().getBody();
   var text = body.editAsText();
   text.insertText(1, 'This is ju for test, lorem ipsum!');         

}

function InsertText2(){
   var body = DocumentApp.getActiveDocument().getBody();
   var text = body.editAsText();
   text.insertText(10, 'What test?, lorem ipsum!'); 
}

The results from running this, gives us text-in-text and just a mess. enter image description here

Upvotes: 0

Views: 2440

Answers (1)

John Smith
John Smith

Reputation: 397

Use appendText instead of insertText, like this:

text.appendText('This is ju for test, lorem ipsum!\n');      

And add "\n" to add a 'new row'

Upvotes: 1

Related Questions