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

相关内容

热门资讯

透视普及!德扑之心免费透视(透... 透视普及!德扑之心免费透视(透视)哈糖大菠萝挂,教程秘籍(有挂教程)-哔哩哔哩1、下载好德扑之心免费...
透视透视!hhpoker辅助软... 透视透视!hhpoker辅助软件下载(透视)hhpoker真的有透视吗,教程方案(了解有挂)-哔哩哔...
透视有挂!hhpoker德州透... 透视有挂!hhpoker德州透视(透视)hhpoker透视工具,教程方针(有挂秘笈)-哔哩哔哩在进入...
透视教你!hhpoker俱乐部... 透视教你!hhpoker俱乐部是干嘛的(透视)德普辅助软件,教程阶段(真实有挂)-哔哩哔哩1、点击下...
透视详情!德州hhpoker是... 透视详情!德州hhpoker是真的吗(透视)aa poker辅助包,教程操作(有挂教学)-哔哩哔哩1...
透视揭露!newpoker脚本... 透视揭露!newpoker脚本(透视)聚星ai辅助工具激活码,教程技法(有挂教程)-哔哩哔哩1)聚星...
透视详情!菠萝德普辅助器免费版... 透视详情!菠萝德普辅助器免费版在哪里(透视)wepoker私人局透视插件,教程教材(有挂教学)-哔哩...
透视开挂!we-poker有人... 透视开挂!we-poker有人玩吗(透视)pokemmo脚本,教程练习(有挂细节)-哔哩哔哩1、we...
透视揭幕!wpk系统是否存在透... 透视揭幕!wpk系统是否存在透视行为(透视)wpk德州局怎么透视,教程策略(有挂教程)-哔哩哔哩该软...
透视辅助!epoker透视(透... 透视辅助!epoker透视(透视)约局吧开挂,教程举措(新版有挂)-哔哩哔哩该软件可以轻松地帮助玩家...