Google电子表格:查找有条件格式的颜色并复制行 [英] Google Spreadsheets: Find a conditionally formatted colour and copy row

查看:822
本文介绍了Google电子表格:查找有条件格式的颜色并复制行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用文档电子表格来管理项目。每行代表一项任务,日期包含在单个单元格中,并根据日期接近度进行条件格式化。



我想搜索该颜色并复制其中的任何行该彩色单元出现在新页面上的一行中。

例如。
如果今天=红色,明天=绿色,我希望能够将今天发生的所有任务拖到不同的页面。



这里的任何帮助都很棒。我很欣赏这可能是不可能的:< / p>

解决方案

这很容易,在这个论坛上搜索应该会带给你一些例子...无论如何,这里有一种方式来获得它,我选择了绿色测试......你可以很容易地改变/组合更多的颜色。

 函数copyGreenRows(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getActiveSheet();
var colors = sh.getDataRange()。getBackgrounds(); //获取颜色
var data = sh.getDataRange()。getValues(); //获得相应的数据
var datatoCopy = [];
Logger.log(colors);
for(var c in colour){
var rowcolors = colors [c] .toString();
if(rowcolors.indexOf('#00ff00')!= - 1){//检查这个颜色是否在这一行
datatoCopy.push(data [c]); //如果是,将数据复制到数组
}
}
var newsheet = ss.insertSheet()。getRange(1,1,datatoCopy.length,datatoCopy [0] .length).setValues(datatoCopy ); //批量写入新工作表
}

注意: 查看主表中的颜色,查看显示脚本中使用的所有单元格颜色代码的记录器。


I use a docs spreadsheet to manage projects. Each row represents a task and the date is contained in single cell conditionally formatted according to the date proximity.

I would like to search for that colour and copy any rows in which that coloured cell occurs to a row on a new page.

Eg. If Today = red and Tomorrow = green, I'd like to be able to pull through all the tasks that occur today to different page.

Any help here would be amazing. I appreciate that it might not be possible :<

解决方案

this is quite easy and a search on this forum should have bring you some examples... anyway, here is a way to get it, I chosed green to test... you could easily change/combine more colors.

function copyGreenRows() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getActiveSheet();
  var colors = sh.getDataRange().getBackgrounds();// get the colors
  var data =  sh.getDataRange().getValues(); // get corresponding data
  var datatoCopy = [];
  Logger.log(colors);
  for(var c in colors){
  var rowcolors = colors[c].toString();
    if(rowcolors.indexOf('#00ff00')!=-1){ // check if this color is in this row
      datatoCopy.push(data[c]);// if so, copy the data to an array
      }
      }
var newsheet = ss.insertSheet().getRange(1,1,datatoCopy.length,datatoCopy[0].length).setValues(datatoCopy);// bulk write to the new sheet
}

Note : to see the colors in your main sheet, look at the logger that shows all the cells color codes used in the script.

这篇关于Google电子表格:查找有条件格式的颜色并复制行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆