使用谷歌应用脚本将单元格格式设置为文本 [英] Set cell format to text with google apps script
问题描述
可以使用谷歌应用程序脚本将数字格式设置为单元格,如
cell.setNumberFormat(0.000) ;
我需要将单元格格式设置为文本,以便任何类似日期的值不会自动转换。
我该怎么做? setNumberFormat 功能没有完整记录。此函数接受单个字符串中的大量参数,可用于指定一系列单元格的格式。
所以这里是关于如何设置setNumberFormat函数。
作为单个单元格的纯文本:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
//单个单元格
var cell = sheet.getRange(B2);
//纯文本
cell.setNumberFormat(@);
截止日期为单列:
//单列
var column = sheet.getRange(B2:B);
//简单日期格式
column.setNumberFormat(M / d / yy);
作为整张表的货币:
//整个工作表
var range = sheet.getRange(1,1,sheet.getMaxRows(),sheet.getMaxColumns());
//金钱格式
range.setNumberFormat($#,## 0.00; $(#,## 0.00));
It is possible to set number format to a cell with google apps script like
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?
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.
So here is the different example on how to set the setNumberFormat function.
As plain text for a single cell:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Single cell
var cell = sheet.getRange("B2");
// Plain text
cell.setNumberFormat("@");
As date for single column:
// Single column
var column = sheet.getRange("B2:B");
// Simple date format
column.setNumberFormat("M/d/yy");
As currency for entire sheet:
// Entire sheet
var range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns());
// Money format
range.setNumberFormat("$#,##0.00;$(#,##0.00)");
Source: Cell Number Formatting with Google Apps Script
这篇关于使用谷歌应用脚本将单元格格式设置为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!