This is very simple for someone that knows what they are doing.
I have a little script that pulls the current selection and formats the cell background to match the value (provided that the cell is a hex value). I'd like to make this work on any range selected. I'll have to do some checking that each string is a hex value etc but I'm blocked on iterating thru a range.
Any hints on how I would loop through a range selection with office.js?
Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
function (asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log(asyncResult.error.message);
} else {
// write the result to range selection variable
var rsel = asyncResult.value;
}
Excel.run(function(context) {
// convert to string
context.workbook.getSelectedRange().format.fill.color = rsel.toString();
return context.sync();
}).catch(function(error) {
console.log(error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
}
);