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

相关内容

热门资讯

总结透视!aapoker透视脚... 总结透视!aapoker透视脚本下载,微信小程序辅助器免费版,指引教程(有挂教程)-哔哩哔哩暗藏猫腻...
解密透视!聚星ai辅助工具激活... 解密透视!聚星ai辅助工具激活码,微乐自建房辅助下载,攻略教程(真是有挂)-哔哩哔哩1、在聚星ai辅...
关于透视!wepoker辅助器... 关于透视!wepoker辅助器安装包,微乐南昌辅助神器,策略教程(确实有挂)-哔哩哔哩1、在wepo...
解密透视!wepoker透视脚... 解密透视!wepoker透视脚本视频,微信微乐自建房脚本免费下载,策略教程(有挂解密)-哔哩哔哩该软...
必备透视!wepoker如何设... 必备透视!wepoker如何设置透视,微乐自建房脚本下载,举措教程(证实有挂)-哔哩哔哩wepoke...
总结透视!newpoker脚本... 总结透视!newpoker脚本,微乐小程序微乐家乡辅助器,步骤教程(有挂教程)-哔哩哔哩1、下载好n...
曝光透视!sohoo辅助,微乐... 曝光透视!sohoo辅助,微乐卡五星有挂吗,绝活儿教程(有挂详细)-哔哩哔哩运sohoo辅助辅助工具...
推荐透视!智星德州插件最新版本... 推荐透视!智星德州插件最新版本更新内容详解,小程序微乐辅助器ios,大纲教程(有挂教学)-哔哩哔哩1...
必备透视!wpk辅助器是真的吗... 必备透视!wpk辅助器是真的吗,手机微信小程序游戏破解器下载,绝活教程(有挂透视)-哔哩哔哩1、金币...
推荐透视!wepoker私人定... 推荐透视!wepoker私人定制透视,微乐小程序辅助工具哪里下载,办法教程(有挂教学)-哔哩哔哩1、...