From 3281de5e6f563ccded8fd38fbb89dfe7d53a7385 Mon Sep 17 00:00:00 2001 From: Ian Scriven Date: Mon, 18 Dec 2017 11:21:28 +1000 Subject: [PATCH] reverse iteration order in updateMarkedCellValues to ensure updated cell values are used for conditional formatting --- .../addon/spreadsheet/CellValueManager.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/vaadin-spreadsheet/src/main/java/com/vaadin/addon/spreadsheet/CellValueManager.java b/vaadin-spreadsheet/src/main/java/com/vaadin/addon/spreadsheet/CellValueManager.java index b5e92583f..fe6ba8fc9 100644 --- a/vaadin-spreadsheet/src/main/java/com/vaadin/addon/spreadsheet/CellValueManager.java +++ b/vaadin-spreadsheet/src/main/java/com/vaadin/addon/spreadsheet/CellValueManager.java @@ -1156,14 +1156,17 @@ protected void updateMarkedCellValues() { // update all cached formula cell values on client side, because they // might have changed. also make sure all marked cells are updated - Iterator rows = sheet.rowIterator(); + + // iterate from bottom to top, right to left, so that conditional + // formatting isn't evaluated before the cell value (due to border + // locations) spreadsheet.getConditionalFormatter().evaluateBatch(formatter -> { - while (rows.hasNext()) { - final Row r = rows.next(); - final Iterator cells = r.cellIterator(); - while (cells.hasNext()) { - final Cell cell = cells.next(); - int rowIndex = cell.getRowIndex(); + for (int rowIndex = sheet.getLastRowNum(); rowIndex >= 0; rowIndex--) { + final Row r = sheet.getRow(rowIndex); + if (r == null) continue; // skip null rows + for (int colIndex = r.getLastCellNum(); colIndex >= 0; colIndex--) { + final Cell cell = r.getCell(colIndex); + if (cell == null) continue; // skip null cells int columnIndex = cell.getColumnIndex(); final String key = SpreadsheetUtil.toKey(columnIndex + 1, rowIndex + 1);