我有一个 Google 表格文档,其中从第三行开始包含以下信息:A 列中的名称、B 列中的时间和 C 列中的组。我试图按时间升序对所有这些信息进行排序,但遇到了一个问题。我遇到的问题是,当时间中有冒号时,有时无法正确排序。例如,10:05.63 放在 9:49.28 之前。
这是我到目前为止所拥有的:
// Getting the range to sort (from A3 to the end of the used range)
var range = sheet.getRange(3, 1, sheet.getLastRow() - 2, sheet.getLastColumn());
// Sorting the range ascending by column B
range.sort({column: 2, ascending: true});
例如,输入:
name one |9:49.28 |group1
name two |10:05.63 |group2
name three |9:52.57 |group3
应替换为:
name one |9:49.28 |group1
name three |9:52.57 |group3
name two |10:05.63 |group2
您引用的
9:49.28
之类的值很可能不是数字持续时间,而是看起来像持续时间的文本字符串。文本字符串按字典顺序排序,其中“10
”位于“9
”之前。
要使其发挥作用:
查看这些资源: