I have some code that imports an image and converts it to an excel spreadsheet pixel by pixel. However, I've only been able to write the RGB into the cell and want to colour the cell instead.
I'm using html and javascript. My code is copied below. I haven't found much in the way of googling, but if I've missed something obvious please let me know!
function createExcelWorkbook(imageData, width, height) {
const wb = XLSX.utils.book_new();
const wsData = [];
for (let y = 0; y < height; y++) {
const rowData = [];
for (let x = 0; x < width; x++) {
const pixelIndex = (y * width + x) * 4; // Each pixel has 4 values (R, G, B, A)
const red = imageData[pixelIndex];
const green = imageData[pixelIndex + 1];
const blue = imageData[pixelIndex + 2];
rowData.push(`RGB(${red}, ${green}, ${blue})`);
}
wsData.push(rowData);
}
You can use the fill property in the style of each cell. You'll need to modify the code to include the style information for each cell.
If you need to download you can create blob after converting the data a worksheet like this