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、德普之星辅助...
透视步骤!pokermaste... 透视步骤!pokermaster修改器(透视)aa poker辅助包(辅助)其实一直都是有神器(哔哩...
透视演示!we-poker软件... 透视演示!we-poker软件(德普之星私人局)一直真的有辅助脚本(哔哩哔哩)1、完成we-poke...
透视策略!聚星ai辅助工具激活... 您好,聚星ai辅助工具激活码这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】...
透视技法!wepoker破解工... 透视技法!wepoker破解工具(WePoKer透视脚本)原来存在有辅助攻略(哔哩哔哩)1、全新机制...
透视窍门!sohoo开挂辅助(... 透视窍门!sohoo开挂辅助(透视)werplan外卦神器(辅助)原来真的有神器(哔哩哔哩)1、we...
透视秘籍!德州局透视脚本免费版... 透视秘籍!德州局透视脚本免费版下载手机版(德普之星辅助软件)总是有辅助技巧(哔哩哔哩)1、上手简单,...
透视绝活!福建大菠萝万能辅助器... 透视绝活!福建大菠萝万能辅助器(透视)菠萝德普辅助器免费版在哪里(辅助)一贯真的有软件(哔哩哔哩)1...
透视手筋!wepoker透视底... 透视手筋!wepoker透视底牌(WePoKer系统)原来是真的有辅助脚本(哔哩哔哩)1、操作简单,...
透视举措!epoker免费透视... 透视举措!epoker免费透视脚本(透视)哈糖大菠萝万能挂(辅助)真是是有神器(哔哩哔哩)1、不需要...