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

相关内容

热门资讯

透视插件!wpk模拟器是什么(... 透视插件!wpk模拟器是什么(透视)开挂辅助方法(真是是有挂)-哔哩哔哩1、游戏颠覆性的策略玩法,独...
透视科技!wepoker俱乐部... 透视科技!wepoker俱乐部辅助器,拱趴大菠萝十三水辅助,指南教程(本来存在有挂)-哔哩哔哩拱趴大...
透视存在!aapoker能控制... 透视存在!aapoker能控制牌吗,微信小程序辅助器免费,其实是真的挂(专业技巧教程)-哔哩哔哩1、...
透视规律!wepoker私人局... 透视规律!wepoker私人局俱乐部怎么进(透视)开挂辅助工具(原来真的是有挂)-哔哩哔哩;1、we...
透视脚本!wepoker正确养... 透视脚本!wepoker正确养号方法,德普之星透视辅助软件是真的吗,窍门教程(竟然存在有挂)-哔哩哔...
透视好牌!wepoker高级辅... 透视好牌!wepoker高级辅助,789大菠萝插件功能,原来真的是有挂(专业解说技巧)-哔哩哔哩1)...
透视安卓版本!wpk德州局透视... 透视安卓版本!wpk德州局透视(透视)开挂辅助app(确实有挂)-哔哩哔哩1)wpk德州局透视辅助挂...
透视真的!hhpoker脚本下... 透视真的!hhpoker脚本下载,hh poker软件,手段教程(确实真的是有挂)-哔哩哔哩1、hh...
透视私人局!如何下载wepok... 透视私人局!如何下载wepoker安装包,手游挂机辅助免费版,好像真的有挂(必备介绍教程)-哔哩哔哩...
透视小程序!aapoker辅助... 透视小程序!aapoker辅助工具安全吗(透视)开挂辅助插件(本来是真的挂)-哔哩哔哩1、超多福利:...