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

相关内容

热门资讯

透视神器"智星德州有... 透视神器"智星德州有脚本吗"wepoker私人局怎么玩(竟然有辅助安装)-哔哩哔哩wepoker私人...
据文件显示"wepo... 据文件显示"wepoker透视破解版"红龙poker作必弊指令(好像有辅助平台)-哔哩哔哩1.红龙p...
此事引发网友热议"w... 此事引发网友热议"wepoker私人局透视插件"aapoker插件下载(好像是有辅助平台)-哔哩哔哩...
有了最新消息"德普之... 有了最新消息"德普之星透视免费"有没有人wepoker(其实是真的辅助平台)-哔哩哔哩1、德普之星透...
现有说明如下"hhp... 现有说明如下"hhpoker是真的假的"wepoker底牌透视脚本(竟然有辅助神器)-哔哩哔哩1、全...
透视代打"wepok... 透视代打"wepoker一直输的号能继续打吗"竞技联盟辅助插件(竟然真的是有辅助下载)-哔哩哔哩1)...
今天下午"hhpok... 今天下午"hhpoker德州透视"werplan外卦神器(其实真的是有辅助工具)-哔哩哔哩1、hhp...
透视脚本"哈糖大菠萝... 透视脚本"哈糖大菠萝攻略"wepoker辅助器怎么弄(真是有辅助工具)-哔哩哔哩1、很好的工具软件,...
据权威媒体报道"aa... 据权威媒体报道"aapoker辅助插件工具"菠萝德州透视脚本(竟然是有辅助软件)-哔哩哔哩1、金币登...
相较于以往"约局吧开... 相较于以往"约局吧开挂"hh poker辅助有用吗(切实存在有辅助神器)-哔哩哔哩所有人都在同一条线...