I new one in app-script, and I want just paste and align text using CardService.newTextParagraph()
JavaScript
x
3
1
CardService.newTextParagraph()
2
.setText(text)
3
I want use something like this
JavaScript
1
4
1
CardService.newTextParagraph()
2
.setText(text)
3
.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
4
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 –
JavaScript
1
21
21
1
function buildCard() {
2
const cardSection1GridItem = CardService.newGridItem()
3
.setTitle('Title')
4
.setSubtitle('Subtitle')
5
.setTextAlignment(CardService.HorizontalAlignment.CENTER)
6
.setLayout(CardService.GridItemLayout.TEXT_BELOW);
7
8
const cardSectionGrid = CardService.newGrid()
9
.setNumColumns(1)
10
.setTitle('Grid')
11
.addItem(cardSection1GridItem);
12
13
const cardSection1 = CardService.newCardSection()
14
.addWidget(cardSectionGrid);
15
16
const card = CardService.newCardBuilder()
17
.addSection(cardSection1)
18
.build();
19
20
return card;
21
}