Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. /**
  2. * Get values in range
  3. *
  4. * @param {String} rangeA1 The range in A1 notation
  5. *
  6. * @return {Array} array with non-filtered values
  7. */
  8. function getValues (rangeA1) {
  9.  
  10. // Get range
  11. var range = SpreadsheetApp.getActiveSheet().getRange(rangeA1);
  12.  
  13. // Get values
  14. var values = range.getValues();
  15.  
  16. // Prepare an array for the non-filtered values.
  17. var v = [];
  18.  
  19. // Get the font color of each cell in our range.
  20. var oldColors = range.getFontColors();
  21.  
  22. // Create a new array with different font colors.
  23. var colors = [];
  24. for (var r = 0; r < oldColors.length; r++) {
  25.  
  26. colors[r] = oldColors[r].slice(0);
  27.  
  28. // Modify the color slightly from black
  29. // (I figure that's the most common color)
  30. for (var c = 0; c < colors[r].length; c++) {
  31. colors[r][c] = (oldColors[r][c] == '#000001') ? '#000002' : '#000001';
  32. }
  33. }
  34.  
  35. // Set the font colors to the generated colors.
  36. range.setFontColors(colors);
  37.  
  38. // Get the font colors at this point.
  39. // They should have changed. If they haven't that means
  40. // the cell was filtered!
  41. var newColors = range.getFontColors();
  42.  
  43. // Check filter status cell for cell
  44. for (var r = 0; r < colors.length; r++) {
  45. for (var c = 0; c < colors[r].length; c++) {
  46.  
  47. // Store the value if it wasn't filtered
  48. if ((oldColors[r][c] != newColors[r][c])) {
  49. v.push(values[r][c]);
  50. }
  51.  
  52. }
  53. }
  54.  
  55. // Change the background colors back to what they were initially
  56. range.setFontColors(oldColors);
  57.  
  58. return v;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement