使用谷歌应用程序脚本设置单元格格式 [英] Set cell format with google apps script

查看:29
本文介绍了使用谷歌应用程序脚本设置单元格格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用像

cell.setNumberFormat("0.000");

我需要将单元格格式设置为文本,以便不会自动转换任何类似日期的值.
我该怎么做?

I need to set cell format to a text, so that any date-like values were not automatically converted.
How can I do this?

推荐答案

setNumberFormat 函数没有详细记录.此函数在单个字符串中接受多种参数,可用于指定一系列单元格的格式.

The setNumberFormat function in the Google Apps Script is not well documented. This function accepts a wide range of parameters in a single string that can be used to specify the format for a range of cells.

这里是关于如何设置 setNumberFormat 函数的不同示例.

So here is the different example on how to set the setNumberFormat function.

作为单个单元格的纯文本:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Single cell
var cell = sheet.getRange("B2");

// Plain text
cell.setNumberFormat("@");

作为单列的日期:

// Single column
var column = sheet.getRange("B2:B");

// Simple date format
column.setNumberFormat("M/d/yy");

作为整个工作表的货币:

// Entire sheet
var range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns());

// Money format
range.setNumberFormat("$#,##0.00;$(#,##0.00)");

来源:Cell使用 Google Apps 脚本设置数字格式

这篇关于使用谷歌应用程序脚本设置单元格格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆