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透视底牌脚本,wpk透视插件,揭秘攻略(从前存在有挂)1、每一步都需要思考,...
透视安卓版!德普之星辅助器,拱... WePoker透视辅助版本解析‌,透视安卓版!德普之星辅助器,拱趴大菠萝万能辅助器,扑克教程(本然有...
透视透视!德普之星怎么作弊,w... 大家肯定在之前wepoker辅助器安装包或者wepoker辅助器安装包中玩过透视透视!德普之星怎么作...
透视插件!wpk透视表,德普之... 透视插件!wpk透视表,德普之星透视辅助插件,必备教程(先前是真的有挂)是一款可以让一直输的玩家,快...
透视总结!aapoker辅助工... 透视总结!aapoker辅助工具免费下载,wepoker私人局外卦,必胜教程(真是真的有挂),亲,有...
透视线上!德普之星透视辅助,智... 透视线上!德普之星透视辅助,智星菠萝可以辅助吗,新2025教程(果然存在有挂);致您一封信;亲爱智星...
透视安装!德普之星辅助器,hh... 相信很多朋友都在电脑上玩过德普之星辅助器吧,但是很多朋友都在抱怨用电脑玩起来不方便。为此小编给大家带...
透视规律!wepoker辅助透... 透视规律!wepoker辅助透视软件,拱趴大菠萝有挂吗,科技教程(确实是有挂) 科技详细教程;Q群1...
透视ai!wpk脚本是什么,w... 透视ai!wpk脚本是什么,wepokerplus开挂,必胜教程(素来真的有挂);(需添加指定Q群1...
透视了解!wepoker透视脚... 1、透视了解!wepoker透视脚本苹果,wepoker透视最简单三个步骤,技巧教程(总是真的有挂)...