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怎么下载游戏(透视)竟然真的是有挂(详细辅助2025新版总结)1、完成的残局...
揭秘关于!wpk辅助器,hhp... 揭秘关于!wpk辅助器,hhpoker哪个俱乐部靠谱,大神讲解(有挂技巧)1、许多玩家不知道hhpo...
透视实锤!we-poker辅助... 透视实锤!we-poker辅助软件教程(透视)其实真的有挂(详细辅助揭秘教程);所有人都在同一条线上...
技巧知识分享!wejoker免... 技巧知识分享!wejoker免费脚本,hhpoker可以控制吗,AI教程(有挂辅助)1、不需要AI权...
透视私人局!wepoker免费... 透视私人局!wepoker免费脚本弱密码(透视)真是是有挂(详细辅助透明挂教程)1、游戏颠覆性的策略...
必备教程!wepoker轻量版... 必备教程!wepoker轻量版辅助,newpoker脚本,爆料教程(有挂方法);1.wepoker轻...
透视免费!steampoker... 透视免费!steampokermaster辅助(透视)切实有挂(详细辅助AI教程);辅助器中分为三种...
六分钟了解!模拟器打开hhpo... 六分钟了解!模拟器打开hhpoker,wpk私人辅助,解密教程(有挂技巧)1、点击下载安装,微扑克w...
重磅来袭!wpk辅助插件,we... 自定义wepoker数据分析工具系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅...
透视玄学!hhpoker到底可... 透视玄学!hhpoker到底可以作弊吗(透视)确实真的有挂(详细辅助软件教程);该软件可以轻松地帮助...