使用Google Apps脚本设置单元格格式 [英] Set cell format with google apps script
本文介绍了使用Google Apps脚本设置单元格格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以使用
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)");
这篇关于使用Google Apps脚本设置单元格格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文