我需要谷歌表格上的一个函数,当点击特定单元格时,它可以改变电子表格中单元格的颜色。它需要循环使用四种预定义的颜色。
我也需要移动设备上的这个功能,或者至少是 iPad。
我需要谷歌表格上的一个函数,当点击特定单元格时,它可以改变电子表格中单元格的颜色。它需要循环使用四种预定义的颜色。
我也需要移动设备上的这个功能,或者至少是 iPad。
下面是一个使用 UI 应用程序的示例,该应用程序反映了电子表格中的值。网格和小部件具有默认大小。基础数据假定值为 0 -3。例如,电子表格未更新 - 对于实际实现,如果需要并发更新,则需要使用锁定。这在 ipad 上按预期工作。
function doGet() {
var colours = ["white","green","blue","red"]; // background colour names referenced by offset 0,1,2,3
var app = UiApp.createApplication();
var grid = app.createFlexTable(); // the grid for ui
var ss=SpreadsheetApp.openById('your spreadsheet id here') ; // your spreadsheet
var data = ss.getSheets()[0].getDataRange().getValues(); // all the data on sheet 0 (valid values correspond to colour offset)
var handler = app.createServerHandler('myClickHandler');
// fill the grid with text widgets, all using same clickhandler, set colour according to current data value of cell, Tag carries value to server handler
for (i=0;i<data.length;i++){
for (j=0;j<data[i].length;j++){
var widget = app.createTextBox().setText(data[i][j]).addClickHandler(handler).setId("CellR"+i+"C"+j).setTag(data[i][j]).setStyleAttribute("background-color", colours[data[i][j]]);
grid.setWidget(i, j, widget);
}
}
app.add(grid);
return app;
// need to update the spreadsheet to match tag values before closing app!
}
function myClickHandler(e) {
var colours = ["white","green","blue","red"];
var app = UiApp.getActiveApplication();
var colourvalue = parseInt(e.parameter[e.parameter.source+"_tag"] )+ 1; // gets the current tag value of clicked widget and increments it
if (colourvalue > 3) {
colourvalue = 0; // reset at 4
};
// update the widget
app.getElementById(e.parameter.source).setStyleAttribute("background-color", colours[colourvalue]).setText(colourvalue).setTag(colourvalue);
return app;
}
使用数据验证创建一个下拉列表,并且只允许来自该列表的输入。然后使用条件格式使四个菜单项中的每一个都更改单元格的背景颜色。
转到您的电子表格并确保选择了所需的单元格。在菜单栏上,转到日期>验证。将条件更改为“列表中的项目”。输入列表项“红色、绿色、蓝色、橙色”。选中“在下拉菜单中显示项目列表”。取消选中“允许无效数据,但显示警告”。保存更改,并在单元格仍处于选中状态的情况下,在菜单栏上转到“格式”>“条件格式”。使用文本包含这样的条件...“文本包含”“{您将在此处输入,假设为红色}”然后在背景旁边打勾,然后在最后一个框中选择您希望单元格使用的颜色更改为(在本例中为红色)。您可以在此条件格式中添加更多行(即,为绿色、蓝色和橙色再次执行最后一部分)。