我有一张包含8张纸的Google表格,需要在输入时对数据进行排序。 我已经能够修改一个脚本来自动排序每个单独的工作表,但是我需要从排序中排除行1和2。 我对使用脚本相当陌生,所以不胜感激。 基本上,当数据输入到主表中时,它被发送到事件页面(事件1-事件8)。 从页面中我希望数据按列A排序,但不包括第1行和第2行。
function AutoSortOnEdit() { var sheetNames = ["Event 1", "Event 2", "Event 3", "Event 4", "Event 5", "Event 6", "Event 7", "Event 8"]; var ss = SpreadsheetApp.getActiveSpreadsheet(); sheetNames.forEach(function(name) { var sheet = ss.getSheetByName(name); var range = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()); range.sort({column: 1, ascending: true}); });我希望每个工作表自动排序第1列,但排除前两行。 我已经能够获得大部分脚本,但无法弄清楚如何排除行1和行2。
我对此脚本的结果是每个工作表将排序,但它包括前两行
I have a google sheet that contains 8 sheets that needs data to be sorted upon entry. I have been able to modify a script to auto sort each individual sheet, but I need to exclude Rows 1 and 2 from the sort. I am fairly new to using scripts so any help is appreciated. Basically, as data is entered onto a Master Sheet it is sent to the Events Pages (Event 1-Event 8). From the pages I would like the data to be sorted by Column A, but exclude Rows 1 and 2.
function AutoSortOnEdit() { var sheetNames = ["Event 1", "Event 2", "Event 3", "Event 4", "Event 5", "Event 6", "Event 7", "Event 8"]; var ss = SpreadsheetApp.getActiveSpreadsheet(); sheetNames.forEach(function(name) { var sheet = ss.getSheetByName(name); var range = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()); range.sort({column: 1, ascending: true}); });I would like each sheet to auto sort Column 1, but exclude the first two rows. I have been able to get most of the script to work, but cannot figure out how to exclude Rows 1 and 2.
My result with this script is that each sheet will sort, but it includes the first two rows
最满意答案
这个修改怎么样?
如果要按列(A)排序排除每列的第1行和第2行的行,则范围为getRange(3, 1, sheet.getLastRow() - 1, sheet.getLastColumn()) 。 在getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()) ,仅排除第1行。那么你可以尝试下面的修改吗?
来自:
var range = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn());至 :
var range = sheet.getRange(3, 1, sheet.getLastRow() - 1, sheet.getLastColumn());参考:
getRange(row,column,numRows,numColumns)如果我误解了你的问题,我很抱歉。
How about this modification?
When you want to sort rows excluded row 1 and row 2 of each column by Column (A), the range is getRange(3, 1, sheet.getLastRow() - 1, sheet.getLastColumn()). In the case of getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()), only row 1 is excluded.So can you try the following modification?
From :
var range = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn());To :
var range = sheet.getRange(3, 1, sheet.getLastRow() - 1, sheet.getLastColumn());Reference :
getRange(row, column, numRows, numColumns)If I misunderstand your question, I'm sorry.
更多推荐
发布评论