Reputation: 65
Is there a way to iterate through a range in using the excel javascript api? I have two columns and rows of data. In each row if one column has data in it the other should not. The other column should be 0 or null. I would like to highlight rows where both the columns have data. I have added an image of what I want to achieve.
Upvotes: 0
Views: 2222
Reputation: 11277
If you clean this up as need be, you should be able to do what you need to do.
const sheet = context.workbook.worksheets.getActiveWorksheet();
let dataRange = sheet.getRange("A1:B10").load(["rowCount", "values"]);
await context.sync();
for (var row = 0; row < dataRange.rowCount; row++) {
let column1 = dataRange.values[row][0];
let column2 = dataRange.values[row][1];
dataRange.getRow(row).format.fill.clear();
if (column1 !== "" && column2 !== "")
dataRange.getRow(row).format.fill.color = "Red";
}
await context.sync();
Upvotes: 1