i have 30 columns , 1000 rows, compare column1 column. if value dont match colour red. below small dataset in spreadsheet:
b c d e f ... 1 name sname email 2 3 . n
because have large dataset , want storing columns in array, first row heading. have done, when testing empty result, can correct me doing wrong?
var index = []; var sheet = spreadsheetapp.getactivesheet(); function col(){ var data = sheet.getdatarange().getvalues(); (var = 1; <= data.length; i++) { te = index[i] = data[1]; logger.log(columnindex[i]) if (data[3] != data[7]){ // column_id.setfontcolor('red'); <--- can set background } } }
from code can see scanning whole spreadsheet data[1] heading , in if loop (data[3] != data[7])
compare 2 columns. have work on colour variable can done once data need.
try check tutorial if can problem. tutorial use google appsscript compare 2 columns. if differences found, script should point these out. if no differences found @ all, script should put out text "[id]". customize code own function.
here code used achieve kind of comparison
function stringcomparison(s1, s2) { // lets test both variables same object type if not throw error if (object.prototype.tostring.call(s1) !== object.prototype.tostring.call(s2)){ throw("both values need array of cells or individual cells") } // if looking @ 2 arrays of cells make sure sizes match , 1 column wide if( object.prototype.tostring.call(s1) === '[object array]' ) { if (s1.length != s2.length || s1[0].length > 1 || s2[0].length > 1){ throw("arrays of cells need same size , 1 column wide"); } // since working array intialise return var out = []; (r in s1){ // loop on rows , find differences using diff sub function out.push([diff(s1[r][0], s2[r][0])]); } return out; // return response } else { // working 2 cells return diff return diff(s1, s2) } } function diff (s1, s2){ var out = "[ "; var notid = false; // loop match each character (var n = 0; n < s1.length; n++){ if (s1.charat(n) == s2.charat(n)){ out += "–"; } else { out += s2.charat(n); notid = true; } out += " "; } out += " ]" return (notid) ? out : "[ id. ]"; // if notid(entical) return output or [id.] }
for more information, check tutorial link above , so question on how compare 2 spreadsheets.
Comments
Post a Comment