Google电子表格脚本未动态更新

时间:2013-07-26 03:26:09

标签: google-apps-script google-sheets

好的,我知道这已被问过很多次了,我知道原因。任何人都可以帮助我将其更新为自动更新字段。

这就是我想做的事情,就像这个人一样。

Google Spreadsheet Script not Updating Dynamic Info

好的,这是我正在使用的脚本。它会为我调出有条件格式的颜色总数。

function getColor( sheetrange ) { ////

 var shra = sheetrange.split("!") ;
 if (shra.length==1) shra[1]=shra[0], shra[0]="";  

 var sheetstring = shra[0].replace( /^'(.*)'$/g , "$1") // was: replace( /'/g , "") ; updated 2011-07-17 (ahab)
 var rangestring = shra[1] 

 var source = SpreadsheetApp.getActiveSpreadsheet()     
 if ( sheetstring.length==0 ) sheet = source.getSheets()[0] ;
 else sheet = source.getSheetByName( sheetstring ) ;

 return  sheet.getRange( rangestring ).getBackgroundColors()
 }

function rgb( r,g,b , useName) {

  var tmp = "#"+("0"+r.toString(16)).slice(-2)+("0"+g.toString(16)).slice(-2)+("0"+b.toString(16)).slice(-2) 
  if( (useName==null) || useName==true) return tmp=="#000000"?"white":tmp  
 else {  
    var htmlColorNames =  { 
"#f0f8ff":"aliceblue ",
"#faebd7":"antiquewhite ",
"#00ffff":"aqua ",
"#7fffd4":"aquamarine ",
"#f0ffff":"azure ",
"#f5f5dc":"beige ",
"#ffe4c4":"bisque ",
"#000000":"black ",
"#ffebcd":"blanchedalmond ",
"#0000ff":"blue ",
"#8a2be2":"blueviolet ",
"#a52a2a":"brown ",
"#deb887":"burlywood ",
"#5f9ea0":"cadetblue ",
"#7fff00":"chartreuse ",
"#d2691e":"chocolate ",
"#ff7f50":"coral ",
"#6495ed":"cornflowerblue ",
"#fff8dc":"cornsilk ",
"#dc143c":"crimson ",
"#00ffff":"cyan ",
"#00008b":"darkblue ",
"#008b8b":"darkcyan ",
"#b8860b":"darkgoldenrod ",
"#a9a9a9":"darkgray ",
"#a9a9a9":"darkgrey ",
"#006400":"darkgreen ",
"#bdb76b":"darkkhaki ",
"#8b008b":"darkmagenta ",
"#556b2f":"darkolivegreen ",
"#ff8c00":"darkorange ",
"#9932cc":"darkorchid ",
"#8b0000":"darkred ",
"#e9967a":"darksalmon ",
"#8fbc8f":"darkseagreen ",
"#483d8b":"darkslateblue ",
"#2f4f4f":"darkslategray ",
"#2f4f4f":"darkslategrey ",
"#00ced1":"darkturquoise ",
"#9400d3":"darkviolet ",
"#ff1493":"deeppink ",
"#00bfff":"deepskyblue ",
"#696969":"dimgray ",
"#696969":"dimgrey ",
"#1e90ff":"dodgerblue ",
"#b22222":"firebrick ",
"#fffaf0":"floralwhite ",
"#228b22":"forestgreen ",
"#ff00ff":"fuchsia ",
"#dcdcdc":"gainsboro ",
"#f8f8ff":"ghostwhite ",
"#ffd700":"gold ",
"#daa520":"goldenrod ",
"#808080":"gray ",
"#808080":"grey ",
"#008000":"green ",
"#adff2f":"greenyellow ",
"#f0fff0":"honeydew ",
"#ff69b4":"hotpink ",
"#cd5c5c":"indianred  ",
"#4b0082":"indigo  ",
"#fffff0":"ivory ",
"#f0e68c":"khaki ",
"#e6e6fa":"lavender ",
"#fff0f5":"lavenderblush ",
"#7cfc00":"lawngreen ",
"#fffacd":"lemonchiffon ",
"#add8e6":"lightblue ",
"#f08080":"lightcoral ",
"#e0ffff":"lightcyan ",
"#fafad2":"lightgoldenrodyellow ",
"#d3d3d3":"lightgray ",
"#d3d3d3":"lightgrey ",
"#90ee90":"lightgreen ",
"#ffb6c1":"lightpink ",
"#ffa07a":"lightsalmon ",
"#20b2aa":"lightseagreen ",
"#87cefa":"lightskyblue ",
"#778899":"lightslategray ",
"#778899":"lightslategrey ",
"#b0c4de":"lightsteelblue ",
"#ffffe0":"lightyellow ",
"#00ff00":"lime ",
"#32cd32":"limegreen ",
"#faf0e6":"linen ",
"#ff00ff":"magenta ",
"#800000":"maroon ",
"#66cdaa":"mediumaquamarine ",
"#0000cd":"mediumblue ",
"#ba55d3":"mediumorchid ",
"#9370d8":"mediumpurple ",
"#3cb371":"mediumseagreen ",
"#7b68ee":"mediumslateblue ",
"#00fa9a":"mediumspringgreen ",
"#48d1cc":"mediumturquoise ",
"#c71585":"mediumvioletred ",
"#191970":"midnightblue ",
"#f5fffa":"mintcream ",
"#ffe4e1":"mistyrose ",
"#ffe4b5":"moccasin ",
"#ffdead":"navajowhite ",
"#000080":"navy ",
"#fdf5e6":"oldlace ",
"#808000":"olive ",
"#6b8e23":"olivedrab ",
"#ffa500":"orange ",
"#ff4500":"orangered ",
"#da70d6":"orchid ",
"#eee8aa":"palegoldenrod ",
"#98fb98":"palegreen ",
"#afeeee":"paleturquoise ",
"#d87093":"palevioletred ",
"#ffefd5":"papayawhip ",
"#ffdab9":"peachpuff ",
"#cd853f":"peru ",
"#ffc0cb":"pink ",
"#dda0dd":"plum ",
"#b0e0e6":"powderblue ",
"#800080":"purple ",
"#ff0000":"red ",
"#bc8f8f":"rosybrown ",
"#4169e1":"royalblue ",
"#8b4513":"saddlebrown ",
"#fa8072":"salmon ",
"#f4a460":"sandybrown ",
"#2e8b57":"seagreen ",
"#fff5ee":"seashell ",
"#a0522d":"sienna ",
"#c0c0c0":"silver ",
"#87ceeb":"skyblue ",
"#6a5acd":"slateblue ",
"#708090":"slategray ",
"#708090":"slategrey ",
"#fffafa":"snow ",
"#00ff7f":"springgreen ",
"#4682b4":"steelblue ",
"#d2b48c":"tan ",
"#008080":"teal ",
"#d8bfd8":"thistle ",
"#ff6347":"tomato ",
"#40e0d0":"turquoise ",
"#ee82ee":"violet ",
"#f5deb3":"wheat ",
"#ffffff":"white ",
"#f5f5f5":"whitesmoke ",
"#ffff00":"yellow ",
  "#9acd32":"yellowgreen "}
 var name =htmlColorNames[ tmp ]    
 return name?name:tmp
 }

}

function test(){ //
  Browser.msgBox( getColor( "August _11!C3:D3" ) )
}  

我确实尝试过像我们这样的https://productforums.google.com/forum/#!topic/docs/u6dOeAtG0HY/discussion googleClock,但它也没有用。我也试过onEdit函数,但这也不起作用。我真正想要的是每60秒更新一次并不是一个大问题。其他一切都是我想要的。如果能让它发挥作用,我甚至会尝试另一个脚本。

脚本中是否有可能每分钟都无法正常工作?

以下是电子表格https://docs.google.com/spreadsheet/ccc?key=0AlYQqvtm8-TJdHhKSU10Qk9fay1EelBZd200VEZUMkE&usp=sharing

的链接

1 个答案:

答案 0 :(得分:0)

我尝试添加GoogleClock()参数,它似乎工作正常。例如,在D2中:

=COUNTIF(getColor("Neshig";GoogleClock()),"#00FF00")

这使得它在一分钟内更新。