I new one in app-script, and I want just paste and align text using CardService.newTextParagraph()
CardService.newTextParagraph() .setText(text)
I want use something like this
CardService.newTextParagraph() .setText(text) .setAlignment(DocumentApp.HorizontalAlignment.CENTER);
But its function and enum available only in the Document app.
By default in addon text aligned to the left. I just want to align it in the center. Have anybody some advice or suggestion, how I can do it? Thanks
Advertisement
Answer
To align text can be used class Class Grid.
docs https://developers.google.com/apps-script/reference/card-service/grid
usage –
function buildCard() { const cardSection1GridItem = CardService.newGridItem() .setTitle('Title') .setSubtitle('Subtitle') .setTextAlignment(CardService.HorizontalAlignment.CENTER) .setLayout(CardService.GridItemLayout.TEXT_BELOW); const cardSectionGrid = CardService.newGrid() .setNumColumns(1) .setTitle('Grid') .addItem(cardSection1GridItem); const cardSection1 = CardService.newCardSection() .addWidget(cardSectionGrid); const card = CardService.newCardBuilder() .addSection(cardSection1) .build(); return card; }