2017-01-06 3 views
-1

私は少し助力をGoogleのスクリプト機能を記述する必要があります。 個々の行に異なる色が割り当てられているGoogleシートがあります。 私は、そのセル内の各行の最初のセルで見つかったhtmlカラーコードを書き留めるスクリプトが必要です。Googleのスクリプトノートの行の色Googleスクリプト行の色の検出器

たとえば、行1が緑色の行で、行2が青色の行であるとすると、セルA1は#00ff00、A2は#0000ffと表示されます。以下は私がこれまで持っていたものです。

function colorDetector() { 
    var startRow = 1; // First row of data to process 
    var numRows = 3; // Number of rows to process 
    var currentsheet = 'Production' // What sheet you would like to process (must be within ' ') 
    //This section prepares the document to be read 
    var ss = SpreadsheetApp.getActive(); 
    var sheet = ss.getSheetByName(currentsheet); 
    var dataRange = sheet.getRange(startRow, 1, numRows, 15) // Fetch values for each row in the Range (row, column, numRows, numColumns) 
    var data = dataRange.getValues(); 
    for (var i = 0; i < data.length; ++i) { 
    var row = data[i]; 

    //this is the section i cant seem to get working correctly 
    var color = row[0].getbackground(); //should set the variable "color" to the html color found in the first cell of the current row. 

    sheet.getRange(startRow + i, 1).setValue(color);  // notes the variable found 
    SpreadsheetApp.flush(); 

    } 
} 
+0

getbackgrounds(複数)とsetValuesの使用を検討しましたか?この方法では、 'for'ループは必要ありません。 – utphx

答えて

0

これは私が自分で考え出したものです。それは完全に動作します。

function colorDetector2() { 
    var startRow = 1; // First row of data to process 
    var currentsheet = 'sheet 4' // What sheet you would like to process (must be within ' ') 
    var ss = SpreadsheetApp.getActive(); 
    var sheet = ss.getSheetByName(currentsheet); 
    var numRows = 10; // Number of rows to process 
    var dataRange = sheet.getRange(startRow, 1, numRows, 20) // Fetch values for each row in the Range (row, column, numRows, numColumns) 
    var colordata = dataRange.getBackgrounds(); 
    var data = dataRange.getValues(); 
    for (var i = 0; i < data.length; ++i) { 
    var color = colordata[i] 
    var colorconv = String(color[1]); 
    if (colorconv == "#00ff00") { 
     //do something here; 
    } else { 
     //do something else here; 
    } 
    } 
} 
関連する問題