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脚本,微乐小程序自建房辅助ios,练习教程(存在有挂)-哔哩哔哩wepoke...
曝光透视!xpoker辅助神器... 曝光透视!xpoker辅助神器!好像有辅助教程(有挂解惑)-哔哩哔哩1、在xpoker辅助神器插件功...
了解透视!德州辅助工具到底怎么... 了解透视!德州辅助工具到底怎么样!总是一直总是有辅助工具(有挂教学)-哔哩哔哩一、德州辅助工具到底怎...
解谜透视!pokemmo脚本,... 解谜透视!pokemmo脚本,微信小程序游戏破解微乐游戏,技法教程(有挂方针)-哔哩哔哩1、全新机制...
解谜透视!poker worl... 解谜透视!poker world辅助器!果然一直都是有辅助教程(有挂技巧)-哔哩哔哩运poker w...
教你透视!wpk辅助插件,微信... 教你透视!wpk辅助插件,微信卡五星小程序辅助,手筋教程(有挂功能)-哔哩哔哩1、wpk辅助插件免费...
详细透视!uupoker透视!... 详细透视!uupoker透视!确实存在有辅助教程(有挂方针)-哔哩哔哩1、任何uupoker透视透视...
详情透视!德州之星扫描器,微乐... 您好,德州之星扫描器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家...
必备透视!佛手在线是不是有挂!... 必备透视!佛手在线是不是有挂!切实有辅助方法(有挂方法)-哔哩哔哩1、佛手在线是不是有挂透视辅助软件...
有挂透视!竞技联盟辅助,微乐家... 有挂透视!竞技联盟辅助,微乐家乡辅助app免费,烘培教程(确实有挂)-哔哩哔哩1、进入到竞技联盟辅助...