Google电子表格脚本从单元格读取后将逗号更改为句号吗? [英] google spreadsheet script changes comma to full-stop upon reading from a cell?

查看:80
本文介绍了Google电子表格脚本从单元格读取后将逗号更改为句号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试从Google Spreadsheet脚本的单元格中读取数据,这对我来说不合适.我做了一个快速测试函数,该函数从单元格中获取数据,将其转换为字符串并返回结果,如下所示:

So, I'm trying to read data from a cell in Google Spreadsheet's script and something's not right for me. I made a quick test function that takes the data from the cell, turns it to a string and returns the result, like so:

function TEST(str)
{
  return str.toString();
}

然后我制作了两个测试单元:

Then I made two test cells:

A1 with "17"
A2 with "135,136"
A3 with "1,11,29,43,68,74,109,122"

然后我打电话给我的函数,我对结果感到困惑

Then I called my function and I'm baffled by results

TEST(A1) returns "17"
TEST(A2) returns "135.136"
TEST(A3) returns "1,11,29,43,68,74,109,122"

因此,似乎如果有一个逗号,它将强制转换为句号,但是如果有多个,则没有一个将被替换.发生了什么?如何以100%的确定性以字符串形式从单元格中读取数据,该数据不会以任何方式被更改?

So it seems that if there is exactly one comma it gets cast to a full-stop instead but if there are multiple none of them get replaced. What is going on and how can I read data from a cell as a string with 100% certainty that it won't get changed in any way?

推荐答案

问题:

  • 某些位置使用作为小数点分隔符.因此, 135,136 是有效数字(= 135.136 ).但是 1,11,29,43,68,74,109,122 不是.有效数字默认情况下对齐到单元格的右侧(清除单元格格式以进行见证).
  • Issue:

    • Some locations use , as decimal separator. So, 135,136 is a valid number(=135.136). But, 1,11,29,43,68,74,109,122 is not. Valid numbers are by default aligned to the right of the cell(Clear cell formatting to witness).
      • 如果要使用作为逗号而不是用作小数点分隔符,请正确设置区域设置,或者
      • 以数字形式输入数字.在每个单元格中输入数据之前,请使用'.'135,136
      • 将输入发送为文本. = TEST(TO_TEXT(A1))
      • 改为使用 range#getDisplayValues().
      • Set your locale properly, if you're going to use ,s as commas and not as decimal separators OR
      • Input numbers as text. Use ' before inputting data in each cell. '135,136 OR
      • Send inputs as Text. =TEST(TO_TEXT(A1)) OR
      • Use range#getDisplayValues() instead.

      这篇关于Google电子表格脚本从单元格读取后将逗号更改为句号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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