【问题标题】:How to make text-align: center in google app-script (Calendar)?如何使文本对齐:在谷歌应用脚​​本(日历)中居中?
【发布时间】:2021-06-16 15:35:51
【问题描述】:

我在 app-script 中新建了一个,我只想使用 CardService.newTextParagraph() 粘贴和对齐文本

CardService.newTextParagraph()
        .setText(text)

我想用这样的东西

CardService.newTextParagraph()
        .setText(text)
        .setAlignment(DocumentApp.HorizontalAlignment.CENTER);

但它的函数和枚举仅在 Document 应用中可用。

默认情况下,插件文本左对齐。我只想将它对齐在中心。 有人有什么建议或建议,我该怎么做? 谢谢

【问题讨论】:

  • textParagraph类中没有.setAlignment()方法
  • 我知道,但很难过。你知道我该怎么做吗?
  • 我认为 google 希望保持对页面样式的控制。
  • 我明白了,谢谢你的时间,我想也许有人有同样的问题

标签: javascript google-apps-script google-calendar-api


【解决方案1】:

对齐文本可以使用class Class Grid。

文档https://developers.google.com/apps-script/reference/card-service/grid

用法-

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 2015-01-08
    • 1970-01-01
    相关资源
    最近更新 更多