我想使用 Google Apps 脚本将字符串“1234”写入单元格。 (谷歌电子表格)

问题描述 投票:0回答:1

我有关于 Google 电子表格的问题。
当我在 Google Apps 脚本中执行以下代码时,控制台中显示“number”,而控制台中不显示“string”。

我想将字符串“1234”写入单元格。

function myFunction() {
  const spreadsheet = SpreadsheetApp.getActive();
  const sheet = spreadsheet.getActiveSheet();
  const cell = sheet.getRange(1, 1);
  cell.setValue(String(1234));
  let a = cell.getValue();
  console.log(typeof a);
}
string google-sheets google-apps-script numbers
1个回答
0
投票

尝试:

function myFunction() {
  const spreadsheet = SpreadsheetApp.getActive();
  const sheet = spreadsheet.getActiveSheet();
  const cell = sheet.getRange(1, 1);
  cell.setValue(1234).setNumberFormat('@');
  let a = cell.getValue();
  console.log(typeof a);
}

数字格式标记

© www.soinside.com 2019 - 2024. All rights reserved.