Search code examples
google-apps-scriptgoogle-slides-apigoogle-slides

Google Slides: Create a multiline paragraph from Google Apps Script


I'm trying to insert multiple lines into a paragraph using the setText() method, but all newline characters \n are converted to new paragraphs (as when you press Enter in the editor) instead of new lines in a single paragraph (as when you press Shift+Enter in the editor). I tried also \r char, but it does nothing.

SlidesApp
 .getActivePresentation()
 .presentation.getSelection()
 .getCurrentPage( 
 .asSlide()
 .getPlaceholder(SlidesApp.PlaceholderType.BODY)
 .asShape()
 .getText()
 .setText('First line\nsecond line');

enter image description here

Is it somehow possible to insert multiline text to the shape without creating multiple paragraphs?


Solution

  • Using Shift+Enter in the editor inserts a vertical tab(soft enter/return) instead of a hard return. You can use

    \v
    

    instead of \n