Skip to content

Instantly share code, notes, and snippets.

@eruffaldi
Created April 5, 2024 16:15
Show Gist options
  • Save eruffaldi/aa97ce3202caef3ba844d07d9e286712 to your computer and use it in GitHub Desktop.
Save eruffaldi/aa97ce3202caef3ba844d07d9e286712 to your computer and use it in GitHub Desktop.
Excel Vacations
function main(workbook: ExcelScript.Workbook) {
// Specify the worksheet name
let worksheetNameS = "Foglio2"; // Adjust the sheet name as necessary
let worksheetS = workbook.getWorksheet(worksheetNameS);
// Specify the worksheet name
let worksheetNameD = "Foglio1"; // Adjust the sheet name as necessary
let worksheetD = workbook.getWorksheet(worksheetNameD);
// Starting and ending cells in the column containing the range addresses
let startCell = "I2";
let endCell = "I62"; // Adjust the end cell according to your needs
// Specify the color you want to use
let color = "#FFFF00"; // This is yellow. You can change the color as needed.
// Get the range containing the addresses
let addressRange = worksheetS.getRange(`${startCell}:${endCell}`);
let addresses = addressRange.getValues();
// Loop through each cell in the column to get the range addresses and color those ranges
addresses.forEach((row) => {
let rangeAddress = row[0]; // Assuming each address is in the first column of the row array
console.log(`Apply ${rangeAddress}`);
if (rangeAddress) {
// Check if the address is not empty
try {
// Get the range and apply the color
let rangeToColor = worksheetD.getRange(rangeAddress);
rangeToColor
.getFormat()
.getFill()
.setColor(color);
} catch (error) {
console.log(`Failed to color range "${rangeAddress}": ${error}`);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment