aknath

Google

Jul 22nd, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. function BGFunction() {
  2.   var I_INDEX = 1;
  3.   var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Jul 14");
  4.   var dataRange = sheet.getDataRange();
  5.   var dataValues = dataRange.getValues();
  6.   for (var i=29; i<=dataRange.getNumRows(); i++) {
  7.     var row = sheet.getRange(i, 1, 1, 7);
  8.     if (dataValues[i-1][I_INDEX-1] != '') {
  9.       //sheet.getRange('D31').setValue(dataValues[i-1][I_INDEX-1]);
  10.       row.setBackground("#DEF7A7");
  11.     }
  12.     else
  13.       row.setBackground("#fff");
  14.   }
  15. }
  16.  
  17. function onEdit(event) {
  18.   BGFunction();
  19. }
  20.  
  21. /**
  22.  * Retrieves all the rows in the active spreadsheet that contain data and logs the
  23.  * values for each row.
  24.  * For more information on using the Spreadsheet API, see
  25.  * https://developers.google.com/apps-script/service_spreadsheet
  26.  */
  27. function readRows() {
  28.   var sheet = SpreadsheetApp.getActiveSheet();
  29.   var rows = sheet.getDataRange();
  30.   var numRows = rows.getNumRows();
  31.   var values = rows.getValues();
  32.  
  33.   for (var i = 0; i <= numRows - 1; i++) {
  34.     var row = values[i];
  35.     Logger.log(row);
  36.   }
  37. };
  38.  
  39. /**
  40.  * Adds a custom menu to the active spreadsheet, containing a single menu item
  41.  * for invoking the readRows() function specified above.
  42.  * The onOpen() function, when defined, is automatically invoked whenever the
  43.  * spreadsheet is opened.
  44.  * For more information on using the Spreadsheet API, see
  45.  * https://developers.google.com/apps-script/service_spreadsheet
  46.  */
  47. function onOpen() {
  48.   var sheet = SpreadsheetApp.getActiveSpreadsheet();
  49.   var entries = [{
  50.     name : "Read Data",
  51.     functionName : "readRows"
  52.   }];
  53.   sheet.addMenu("Script Center Menu", entries);
  54. };
Add Comment
Please, Sign In to add comment