AppScript:如何显示显示值而不是值?
创始人
2024-11-10 08:00:08
0

可以使用formattingRules和format函数来实现。

例如,想要将列A中的所有日期显示为“月份+日期”的格式。

  1. 在代码中,首先定义一个格式规则。

var formattingRules = SpreadsheetApp.newConditionalFormatRule() .whenDateBefore(new Date(2000, 1, 1)) .setBackground("#E57373") .setRanges([range]) .build();

  1. 接着,在format函数中使用该规则,并将日期转换为“月份+日期”格式。

var format = SpreadsheetApp.newTextStyle() .setFontSize(12) .setForegroundColor("#ffffff") .setBold(true) .build();

var displayValue = SpreadsheetApp.getActiveSpreadsheet() .getActiveSheet() .getRange("A1") .getValue();

var formattedValue = Utilities.formatDate(displayValue, Session.getScriptTimeZone(), "MMM dd");

var cell = SpreadsheetApp.getActiveSpreadsheet() .getActiveSheet() .getRange("B1");

cell.setValue(formattedValue) .setNumberFormat("@") .setDataValidation(SpreadsheetApp.newDataValidation() .requireNumberGreaterThan(0) .setAllowInvalid(false) .setHelpText("Enter a positive number") .build()) .setTextStyle(format) .setBackground("#4CAF50");

  1. 在此示例中,我们使用了两个函数:Utilities.formatDate和NumberFormattingRules。Utilities.formatDate是日期转换函数,将显示值转换为格式化值。NumberFormattingRules用于设置单元格格式,以便在单元格中以特定格式显示值。通过结合使用这两个函数,可以在Google表格中实现显示值而不是值的目的。

相关内容

热门资讯

透视软件!佛手大菠萝辅助(透视... 透视软件!佛手大菠萝辅助(透视)都是真的是有挂(详细辅助新版2025教程)1、许多玩家不知道辅助软件...
攻略讲解!智星德州可以透视吗,... 攻略讲解!智星德州可以透视吗,wepoker软件靠谱么,wepoke教程(有挂教程)1、许多玩家不知...
透视安卓版!we-poker有... 透视安卓版!we-poker有人玩吗(透视)原来是真的有挂(详细辅助教你攻略);辅助器中分为三种模型...
解密关于!wepoker软件靠... 解密关于!wepoker软件靠谱么,pokemmo辅助工具,微扑克教程(有挂教程);《WPK辅助透视...
透视能赢!aapoker免费透... 透视能赢!aapoker免费透视脚本(透视)竟然是真的有挂(详细辅助扑克教程);在进入aapoker...
免费测试版!xpoker辅助控... 免费测试版!xpoker辅助控制,德普辅助器辅助器怎么用,爆料教程(有挂辅助)科技教程也叫必备教程,...
透视智能ai!wepoker破... 透视智能ai!wepoker破解是真的还是假的(透视)真是有挂(详细辅助必胜教程)1、起透看视 透明...
分享一款!pokemmo辅助工... 分享一款!pokemmo辅助工具,佛手在线有挂吗,AI教程(有挂技巧)准备好在佛手在线有挂吗 ia的...
透视黑科技!wpk透视辅助(透... 透视黑科技!wpk透视辅助(透视)一贯有挂(详细辅助德州论坛)1、wpk透视辅助ai辅助优化,wpk...
总算清楚!拱趴大菠萝机器人,a... 1、总算清楚!拱趴大菠萝机器人,aapoker脚本怎么用,揭秘教程(有挂辅助)。2、拱趴大菠萝机器人...