If you want to check the format of the cell number or range, you can use the getNumberFormat() or getNumberFormats() method. NOTE. At the end there is an āsā and the other not. The second is a two-dimensional array of formats of several cells. If you want to check only one cell, use a single form. This method works in a range, so you first need to get a link to the cell or range that you want to check.
Google Documentation - getNumberFormats ()
If you want to evaluate what type of data data is in your code, you can use typeof() .
Mozilla JavaScript documentation - typeof
There are situations when JavaScript will force one data type to another depending on usage.
Even if the name is "getNumberFormats ()", you can still check the text. But the value returned for the text is an empty string. You can use this test function to verify that the cell number format is formatted as plain text.
function test() { var activeSheet = SpreadsheetApp.getActiveSpreadsheet(); var theRange = activeSheet.getRange("A2"); var theType = theRange.getNumberFormat(); Logger.log(theType); if (theType === "") { Logger.log("It text"); }; };
Your code is as follows:
}else if(predVal[row].getNumberFormat == "number"){
Must be:
}else if(predVal[row].getNumberFormat == ""){
source share