Google apps script 在不同数据之间插入行
我是来自意大利的安德鲁 我试图编写一个脚本,在电子表格中的一些数据之间插入一个空行 例如,我有以下数据集: 我想得到这样的东西: 换言之: 脚本应该检查所有行,当日期更改和名称更改时,必须添加一个空行 你知道吗? 我试图修改我在网上找到的一个脚本,该脚本删除了工作表中的空白行,但我无法得到任何结果 谢谢 (:我同意桑迪·古德的观点……我想,这里有一段代码可以让你开始:Google apps script 在不同数据之间插入行,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我是来自意大利的安德鲁 我试图编写一个脚本,在电子表格中的一些数据之间插入一个空行 例如,我有以下数据集: 我想得到这样的东西: 换言之: 脚本应该检查所有行,当日期更改和名称更改时,必须添加一个空行 你知道吗? 我试图修改我在网上找到的一个脚本,该脚本删除了工作表中的空白行,但我无法得到任何结果 谢谢 (:我同意桑迪·古德的观点……我想,这里有一段代码可以让你开始: function doSomething() { var spreadsheet = SpreadsheetApp.ope
function doSomething() {
var spreadsheet = SpreadsheetApp.openById('yourID'), // Get the spreadsheet
tab = spreadsheet.getSheets()[0], // Get the first tab
values = tab.getRange(2, 1, tab.getLastRow(), 3).getDisplayValues(), //Get the values beginning in the second row because of the headers
newValues = [], // Empty array where we're gonna push the new values
lastDate,
lastName;
// Loop through all the values
for(var i = 0; i <values.length; i++){
// If the last name is different from the current name or the last date is different from the current date add an empty "row" to the new array
if((lastDate != undefined && lastName != undefined) && (values[i][0] != lastDate || values[i][1] != lastName)){
newValues.push(['','','']);
}
//Add the current row to the new array
newValues.push(values[i]);
//Sets the lastDate and lastName to the current values for the next evaluation
lastDate = values[i][0];
lastName = values[i][1];
}
//Sets the new values
tab.getRange(2,1,newValues.length,3).setValues(newValues)
}
函数doSomething(){
var spreadsheet=SpreadsheetApp.openById('yourID'),//获取电子表格
tab=spreadsheet.getSheets()[0],//获取第一个选项卡
values=tab.getRange(2,1,tab.getLastRow(),3).getDisplayValues(),//由于标题的原因,获取从第二行开始的值
newValues=[],//我们将在其中推送新值的空数组
最后日期,
姓氏;
//循环遍历所有值
对于(var i=0;我将获取所有数据,对其进行处理,构建一个包含空行的新数据集,然后覆盖原始数据。@SandyGood感谢您的建议。我正在尝试编写一些内容,将单元格内容与前一个内容进行比较,如果不同,则添加一个空行。我不擅长编码。您有什么示例可以开始吗?谢谢s!这是一个很好的解决方案!如果我想根据列数自动更改“push参数”该怎么办?我尝试了for循环(写入“,””很多次列数),但它不起作用。我想我无法将变量推入数组。有什么建议吗?@anderavolontè您可以找到tab.getLastColumn()然后在此基础上创建一个空白值数组。有关示例,请参见。