i am trying to write Office Script to loop through table column range and check if Regex PAttern has match. If yes just mark red color:
function main(workbook: ExcelScript.Workbook) {
let worksheet = workbook.getWorksheet("Workstreams");
let usedColumn = worksheet.getTables()[0].getColumn("Last Update Time");
let regexPattern = "^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(23) ([1-9]|0[1-9]|1[0-2]):[0-5][0-9] ([AaPp][Mm])$"
}
how to
- loop through column?
- mark cell with red
Thank you for help, Michal
EDIT 02.02.2023: Code to try to get value from cell:
function main(workbook: ExcelScript.Workbook) {
let worksheet = workbook.getWorksheet("Workstreams");
let usedColumn = worksheet.getTables()[0].getColumn("Last Update Time");
let dataRange = usedColumn.getRangeBetweenHeaderAndTotal();
//const values = dataRange.getValues();
let regex = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(23) ([1-9]|0[1-9]|1[0-2]):[0-5][0-9] ([AaPp][Mm])$/;
for (let i = 0; i < dataRange.getValues().length; i++) {
let cRow: number = i;
let rowCell: ExcelScript.Range = dataRange.getCell(cRow, 0);
let rowValue: string = rowCell.getValue() as string;
console.log(rowValue);
}
}
and output is like: 44641.25 44713.21875 44587.1361111111 test
for these values in column: 3/21/22 6:00 AM 6/1/22 5:15 AM 1/26/22 3:16 AM test
so the issue is that JS is converting string to number somehow... Best, Michal