In Google Sheets using Apps Script, I want to read in the font color in many cells, change some values (change colors) in the array, and write them back to the cells.
I have previously used `getFontColors()` and it worked, but it got deprecated so trying to update my script. I can read in the font colors using `getFontColorObjects()`, I can display them in the execution log (`outRngFontColors.asRgbColor().asHexString()` ), but I don't know how to change the values in the `Color[][]` array (ex. `#000000` to `#ff00ff`). So how do I do that? I only want to read the font colors once and then write them back out only once.
var ss = SpreadsheetApp.getActiveSpreadsheet();To change the font color, you should use the set method here:
Sets a rectangular grid of font colors (must match dimensions of this range). |
Or if changing font color of only one cell, use this:
Sets the font color in CSS notation (such as '#ffffff' or 'white'). |
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/e1e07a4e-0019-4244-b0a1-33071075e1den%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/jRBKQuRYWkM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/003801d98360%249d438fd0%24d7caaf70%24%40gmail.com.
Yeah they did deprecate the getFontColors method. Usage of the getFontColorObjects is more complex but provides a lot more options and supports the theme colors.
Perhaps you need to explain what you are trying to do.
First of all a Range is either one cell (means you provide just 2 parameters (Row and Column) or it is multiple cells where you need to provide 4 parameters (row, column, num of rows, and num of columns). In your example you are only giving 3 parameters, so you will need to correct that.
The getFontColorObjects method returns a 2 dimensional array of color objects. Each item in the 2 dimensional array is a color object and you need to use the methods on it to figure out what color it is.
How do you plan on using the colors it returns? Please explain so we can help you further.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAF7yU5k%2B-x1%3D5u0QMju9mmjhyB1eCfoT_WO86vEOiyg2PDhAxA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/004f01d98368%24e88618c0%24b9924a40%24%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAF7yU5mjN32swEArT%2B08vvWDM0JQcYaOGu%2BgSHJNiQSRWw2n%2Bw%40mail.gmail.com.
I put together a quick example of how you can get the font colors and write them back to a new range.
Perhaps this may help you:
function changeColor() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("B2:D4");
var results = range.getFontColorObjects();
var colors = [];var row = [];
for (var i in results) {
for (var j in results[i]) {
row.push(results[i][j].asRgbColor().asHexString());
}
colors.push(row);
row = [];
}
sheet.getRange("B5:D7").setFontColors(colors);
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAF7yU5mjN32swEArT%2B08vvWDM0JQcYaOGu%2BgSHJNiQSRWw2n%2Bw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/005e01d98376%247f9a0480%247ece0d80%24%40gmail.com.
You are welcome.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAF7yU5m5rFLri0z%3Drx3JHW5b5sWQgGhePqGkHbobybcUCgKW-Q%40mail.gmail.com.