jeudi 19 septembre 2019

Google App Script : "range.isBlank()" is false but "if(range.isBlank())" go through?

I'm using Google App Script. It's based on Javascript. I use a function range.isBlank() which respond with a false boolean. I checked in debug it's a false Boolean.

But with great surprise I discover statement "if(range.isBlank()) {...}" go through the code...

I tried some solution found in the site including using "===true". But nothing works.

To reproduce, create a spreadsheet and in the active sheet put some data like that :

   |       A         |   B   |   C   |   D   |  E   |
1     "Larry Page"       1       2       3
2     "Larry Page"       1       2
3     "Larry Page"       1    

In the script editor copy the code below and execute the function.

function DebugGoogle() {

    var ssheet = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ssheet.getActiveSheet()

// Get sheet dimension   
    var nbRow = sheet.getMaxRows();

// Loop on the rows
    for (var i=1; i<=nbRow; i++) {

// Start at the first column
        var range = sheet.getRange(i, 1);
        var nextRange = sheet.getRange(i, range.getLastColumn()+1);
        if (nextRange.isBlank()); {
            nextRange.setNote(nextRange.isBlank());
        }

// Go right As long as the next right cell is not empty
        while (!(nextRange.isBlank())) {
            range = nextRange;
            nextRange = sheet.getRange(i, range.getLastColumn()+1);
            if (nextRange.isBlank()); {
                nextRange.setNote(nextRange.isBlank());
            }
        }
    }
}

I expect a note only on the first empty cell of each line. D for line 1, C for line 2, B for line 3. Instead of that I also have note for non-empty cells. Which is odd because the note is "false" but the if statement enter ...

if (nextRange.isBlank()); {
    nextRange.setNote(nextRange.isBlank());
}

I was expected only note with true value...

Aucun commentaire:

Enregistrer un commentaire