假设我有一个范围,"A3:C5“,这样:
我希望在Google工作表中重新格式化
换句话说,我希望数据只按字母顺序排序。我无法在我的生活中找到如何在谷歌应用程序脚本中做到这一点,有人能帮上忙吗?
发布于 2017-03-15 01:26:03
快速谷歌搜索:
function sortHorizontal()
{
var startCol = 1; // left-most column to where the sort will be applied; A = 1, B = 2, C = 3 etc
var startRow = 1; // first row to apply the sort
var sheetName = 'Sheet1'; // name of sheet in which sort will be applied
var s = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var d = s.getDataRange().getValues();
var output = [], temp;
for (var i = startRow - 1; i < d.length; i++)
{
temp = d[i].slice(startCol - 1);
temp.sort(ascSort); // change to descSort for Z -> A sort
output.push(temp);
}
s.getRange(startRow, startCol, output.length, output[0].length).setValues(output);
}
function ascSort(a, b)
{
return ((a == b) ? 0 : (a && (!b || a < b)) ? -1 : 1);
}
function descSort(a, b)
{
return ((a == b) ? 0 : (a > b) ? -1 : 1);
}
https://stackoverflow.com/questions/42799325
复制相似问题