I have been asked to pull data from an Excel online spreadsheet on Sharepoint into Power BI to create a dashboard - no problem, right? Well, one of the 'data points' is actually fill colour of the cell indicating status. I did some googling and managed to write an Office Script that translates the fill colour to the status and got everything to work but I was still running the Office Script manually (and it was taking 3 hours to run).
So I turned to Power Automate and scheduled it to run the script, but it fails every time and I think it's to do with how long the Office Script takes to run because when I reduce the range that it's running over (significantly) it works. Any help to solve this will be greatly appreciated. Here's my code:
function main(workbook: ExcelScript.Workbook)
{
//disable auto calculation mode
workbook.getApplication().setCalculationMode(ExcelScript.CalculationMode.manual);
let selectedSheet = workbook.getWorksheet("ProjectsColourFill");
let projects = workbook.getWorksheet("Projects");
// Paste range at 1:1048576 on selectedSheet from 1:1048576 on projects
selectedSheet.getRange("1:1048576").copyFrom(projects.getRange("1:1048576"), ExcelScript.RangeCopyType.all, false, false);
let sheet1 = workbook.getWorksheet("Sheet1");
// Paste range at E3 on selectedSheet from E1:NP1 on sheet1
selectedSheet.getRange("E3").copyFrom(sheet1.getRange("E1:NP1"), ExcelScript.RangeCopyType.values, false, false);
selectedSheet.getRange("3:3").setNumberFormatLocal("dd/mm/yyyy;@");
let cell = selectedSheet.getRange("H7");
let format = cell.getFormat().getFill().getColor();
let range = selectedSheet.getRange("H7:NP320");
// Get the size boundaries of the range.
let rows = range.getRowCount();
let cols = range.getColumnCount();
// Iterate over the range.
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
if (range.getCell(row, col).getValue() != "") {
// Get colour of current cell
// If colour is one of the three status, fill with status
if (range.getCell(row, col).getFormat().getFill().getColor() == '#DA9694') {
range.getCell(row,col).setValue("Planned Dates TBC");
}
if (range.getCell(row, col).getFormat().getFill().getColor() == '#92D050') {
range.getCell(row, col).setValue("Booked");
}
if (range.getCell(row, col).getFormat().getFill().getColor() == '#E26B0A') {
range.getCell(row, col).setValue("Prospective");
}
}
// console.log(range.getCell(row,col).getAddress());
}
}
//turn it back on
workbook.getApplication().setCalculationMode(ExcelScript.CalculationMode.automatic);
}