2013-04-08 95 views
0

如何让Google电子表格自动突出显示我的表格的最后一行,通常是总计,使用不同的颜色?Google电子表格:突出显示最后一行

我收到以下错误: -

类型错误:无法找到对象85.函数setBackgroundColor(第19行,文件“守则”)

,我使用下面的脚本,没有运气。

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); 

var last_row = sheet.getLastRow() 
last_row.setBackgroundColor("green"); 

回答

2

getLastRow()返回一个整数,表示表单中最后一个填充行的数量,所以这只是开始。您需要get a range object using this number才能应用设置的方法。

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); 
var last_row = sheet.getLastRow(); //last populated row in sheet 
var last_col = sheet.getLastColumn(); // last populated column in sheet 
var range = sheet.getRange(last_row, 1, 1, last_col); //gets the range corresponding with the last populated row in the sheet 
range.setBackground("green"); 

顺便说一句,setBackgroundColor()现在已过时,使用setBackground()来代替。

+0

非常感谢你,即时创建我的完美电子表格! – bh06als 2013-04-09 09:02:34