I have been looking for a way which can convert to HexColor into Color Name. I have searched online but no such thing is available online.
Your help will be much appreciated.
CodePudding user response:
If I understand correctly what you would like to do is to get the color name of a cell in text based on the Hex code of that color.
I do not think it is possible using regular formulas from Google Sheets, so as a workaround I created the following script in Google Apps Script as a sample, so you can modify it according to what you would like to do.
let hexCode = [
{
color: "indian red",
code: {
hex: "#B0171F"
},
id: 1
},
{
color: "crimson ",
code: {
hex: "#DC143C"
},
id: 2
},
];
function getColorName(input) {
var ss = SpreadsheetApp.getActiveSheet();
var range = ss.getRange('B2');
var bg = range.getBackground();
var colorIs;
for (var i = 0; i < hexCode.length; i ) {
if (colorIs = hexCode[i].code.hex.valueOf().toString().toLowerCase() === bg.valueOf()) {
return hexCode[i].color.valueOf();
}
}
}
Basically I created an array that contains the hex codes of the colors that I will be using and created a custom function so that when I call it in Google Sheets it gets the hex code of the color from the selected range and compares it to the list of colors from the array so that it returns the name of the color.
You can just modify the array adding the colors that you need using the same format and also change the range. I will also leave a screenshot so that you can see how it works.
CodePudding user response:
For example, how about using an external API? In this sample script, the API of