Excel中的单元格参考

我在EXTJS 4中有一个combobox和一个文本框。

else if (record.get("type") === "CELL_VALUE" && record.get("apply_before") === true) { Ext.Msg.alert("Field Validation", "I am Validating the CELL VALUE COMBO VALUE"); //alert message for testing only, this is where validation will occur } 

在这种情况下,“type”是一个标准combobox,“appy_before”是一个checkbox。 如果type = Cell Value和apply_before被选中,我需要validation一个文本框(range_from)包含一个有效的excel单元位置,第二个文本框(range_to)是空的,如果validation通过,则设置isValid = true,否则isValid =假。

我知道它的一部分应该如下:

 else if (record.get("type") === "CELL_VALUE" && record.get("apply_before") === true) { if (rangeFrom != (A1 - XFD1048576)**problem here**) || (rangeTo != null) isValid = false; } 

任何人都可以请提供更多的方向请,因为我不知道如何检查细胞的范围可以是任何

 A1 (first possible valid cell) to XFD1048576 (the last possible valid cell) 

我为你加了一个validation函数:

 function validateRange(coordinate) { // A little input validation if (typeof coordinate != "string" || !coordinate.length) return false; // Find the first occurrence of a digit var startIndex = coordinate.search(/[\d+]/); // The column is the part from the beginning up until the first digit var column = coordinate.substring(0, startIndex).toUpperCase(); // The row is the remainder of the string var row = parseInt(coordinate.substring(startIndex), 10); // The column is sortable alphabetically so we can check its range, // and the row is numeric so we can check it's range as well return (column >= "A" && row >= 1) && (column <= "XFD" && row <= 1048576); } 

给它一个旋转:

 var str = "XFD100000"; var result = validateRange(str); 

适用于您的情况:

 if (!validateRange(rangeFrom)) { 

我不知道这是多么的愚蠢,但也许这会给你一个很好的起点。

演示

 function validateRange(coordinate) { if (typeof coordinate != "string" || !coordinate.length) return false; var startIndex = coordinate.search(/[\d+]/); var column = coordinate.substring(0, startIndex).toUpperCase(); var row = parseInt(coordinate.substring(startIndex), 10); return (column >= "A" && ((column.length<3 && column <= "ZZ") ||(column.length==3 && column <= "XFD")) && (row >= 1 && row <= 1048576)); }