Google Apps 脚本 - SetText 以在列表或单独的行中显示数组元素
Google Apps Script - SetText to display array elements in a list or separate lines
我有以下工作代码
function notifyNo(array1,array2,array3) {
return CardService
.newCardBuilder()
.setHeader(
CardService.newCardHeader()
.setTitle('Draft Validation Check')
.setSubtitle("Please validate the below recipients before sending out this message")
.setImageStyle(CardService.ImageStyle.SQUARE)
.setImageUrl('https://i.imgur.com/4uNXq15.png')
)
.addSection(
CardService.newCardSection()
.setHeader('<b><font color="#FF0000">High-Risk Domains</font></b>')
.addWidget(
CardService.newTextParagraph().setText('<font color="#FF0000">'+array3.toString()+'</font>'))
)
.addSection(
CardService.newCardSection()
.setHeader('<b><font color="#CCCC00">Low-Risk Domains</font></b>')
.addWidget(CardService.newTextParagraph().setText('<font color="#CCCC00">'+array2.toString()+'</font>'))
)
.addSection(
CardService.newCardSection()
.setHeader('<b><font color="#006400">Safe Domains</font></b>')
.addWidget(CardService.newTextParagraph().setText('<font color="#006400">'+array1.toString()+'</font>'))
)
.build();
}
产生以下输出:
我愿意:
- 使元素以列表形式呈现,而不是以逗号分隔
- 无论如何我可以控制三个独立部分的背景颜色
您必须遍历每个数组中的每个值并为每个值创建一个段落小部件。
function notifyNo(array1, array2, array3)
{
var highRiskDomains = CardService.newCardSection().setHeader('<b><font color="#FF0000">High-Risk Domains</font></b>');
array3.forEach(function(value)
{
highRiskDomains.addWidget(CardService.newTextParagraph().setText('<font color="#FF0000">' + value + '</font>'));
});
var lowRiskDomains = CardService.newCardSection().setHeader('<b><font color="#CCCC00">Low-Risk Domains</font></b>');
array2.forEach(function(value)
{
lowRiskDomains.addWidget(CardService.newTextParagraph().setText('<font color="#CCCC00">' + value + '</font>'));
});
var safeDomains = CardService.newCardSection().setHeader('<b><font color="#006400">Safe Domains</font></b>');
array1.forEach(function(value)
{
safeDomains.addWidget(CardService.newTextParagraph().setText('<font color="#006400">' + value + '</font>'));
});
return CardService
.newCardBuilder()
.setHeader(
CardService.newCardHeader()
.setTitle('Draft Validation Check')
.setSubtitle("Please validate the below recipients before sending out this message")
.setImageStyle(CardService.ImageStyle.SQUARE)
.setImageUrl('https://i.imgur.com/4uNXq15.png')
)
.addSection(highRiskDomains)
.addSection(lowRiskDomains)
.addSection(safeDomains)
.build();
}
我有以下工作代码
function notifyNo(array1,array2,array3) {
return CardService
.newCardBuilder()
.setHeader(
CardService.newCardHeader()
.setTitle('Draft Validation Check')
.setSubtitle("Please validate the below recipients before sending out this message")
.setImageStyle(CardService.ImageStyle.SQUARE)
.setImageUrl('https://i.imgur.com/4uNXq15.png')
)
.addSection(
CardService.newCardSection()
.setHeader('<b><font color="#FF0000">High-Risk Domains</font></b>')
.addWidget(
CardService.newTextParagraph().setText('<font color="#FF0000">'+array3.toString()+'</font>'))
)
.addSection(
CardService.newCardSection()
.setHeader('<b><font color="#CCCC00">Low-Risk Domains</font></b>')
.addWidget(CardService.newTextParagraph().setText('<font color="#CCCC00">'+array2.toString()+'</font>'))
)
.addSection(
CardService.newCardSection()
.setHeader('<b><font color="#006400">Safe Domains</font></b>')
.addWidget(CardService.newTextParagraph().setText('<font color="#006400">'+array1.toString()+'</font>'))
)
.build();
}
产生以下输出:
我愿意:
- 使元素以列表形式呈现,而不是以逗号分隔
- 无论如何我可以控制三个独立部分的背景颜色
您必须遍历每个数组中的每个值并为每个值创建一个段落小部件。
function notifyNo(array1, array2, array3)
{
var highRiskDomains = CardService.newCardSection().setHeader('<b><font color="#FF0000">High-Risk Domains</font></b>');
array3.forEach(function(value)
{
highRiskDomains.addWidget(CardService.newTextParagraph().setText('<font color="#FF0000">' + value + '</font>'));
});
var lowRiskDomains = CardService.newCardSection().setHeader('<b><font color="#CCCC00">Low-Risk Domains</font></b>');
array2.forEach(function(value)
{
lowRiskDomains.addWidget(CardService.newTextParagraph().setText('<font color="#CCCC00">' + value + '</font>'));
});
var safeDomains = CardService.newCardSection().setHeader('<b><font color="#006400">Safe Domains</font></b>');
array1.forEach(function(value)
{
safeDomains.addWidget(CardService.newTextParagraph().setText('<font color="#006400">' + value + '</font>'));
});
return CardService
.newCardBuilder()
.setHeader(
CardService.newCardHeader()
.setTitle('Draft Validation Check')
.setSubtitle("Please validate the below recipients before sending out this message")
.setImageStyle(CardService.ImageStyle.SQUARE)
.setImageUrl('https://i.imgur.com/4uNXq15.png')
)
.addSection(highRiskDomains)
.addSection(lowRiskDomains)
.addSection(safeDomains)
.build();
}