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表格中实现显示值而不是值的目的。

相关内容

热门资讯

透视策略!pokermaste... 透视策略!pokermaster脚本(透视)拱趴大菠萝有挂吗(辅助)一直一直总是有教程(哔哩哔哩)1...
透视模板!wepokerplu... 透视模板!wepokerplus开挂(WePoKer工具)切实真的是有辅助技巧(哔哩哔哩)1、完成w...
透视经验!约局吧app有挂吗(... 透视经验!约局吧app有挂吗(透视)哈糖大菠萝怎么挂(辅助)本来真的是有插件(哔哩哔哩)1、透视经验...
透视举措!hhpoker辅助挂... 透视举措!hhpoker辅助挂(AApoker辅助插件)竟然真的是有辅助软件(哔哩哔哩)1、点击下载...
透视手册!pokemmo辅助器... 透视手册!pokemmo辅助器脚本下载(透视)哈糖大菠萝有没有挂(辅助)一直有app(哔哩哔哩)po...
透视妙招!wpk透视辅助(WP... 透视妙招!wpk透视辅助(WPK链接)切实有辅助脚本(哔哩哔哩)1、任何wpk透视辅助透视是真的假的...
透视经验!fishpoker透... 透视经验!fishpoker透视底牌(透视)德州透视是真的假的(辅助)其实真的有教程(哔哩哔哩)1、...
透视手册!aapoker如何设... 透视手册!aapoker如何设置胜率(HHpoker德州)原来真的是有辅助app(哔哩哔哩)一、aa...
透视阶段!云扑克有透视吗(透视... 透视阶段!云扑克有透视吗(透视)智星德州可以透视吗(辅助)确实有方法(哔哩哔哩)1、让任何用户在无需...
透视项目!wepoker好友房... 透视项目!wepoker好友房开挂(WPK透视)好像真的有辅助攻略(哔哩哔哩)1、操作简单,无需we...