Heres some code I wrote that may become useful to someone, I have seen many people wanting this type of code so here is my example.
-
<input type="text" id="showval"><input type="text" id="search" value="A:1"><input type="button" value="Show Value" onclick="ReadCell(document.getElementById('search').value, 'ExcelView')"><br><br>
-
<table border=1 id="ExcelView" name="ExcelView">
-
<tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td><td>Cell 4</td></tr>
-
<tr><td>Cell 5</td><td>Cell 6</td><td>Cell 7</td><td>Cell 8</td></tr>
-
<tr><td>Cell 9</td><td>Cell 10</td><td>Cell 11</td><td>Cell 12</td></tr>
-
</table>
-
<script language="javascript">
-
function ReadCell(val, tbl) {
-
val = val.toUpperCase();
-
var alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
var table = document.getElementById(tbl);
-
var sVal = val.split(":");
-
var col = sVal[0];
-
if (isnumeric(col)) { alphaconv = col } else { var alphaconv = alphabet.indexOf(col); }
-
var row = sVal[1]-1;
-
var gval = "";
-
if (sVal.length==2 && isnumeric(alphaconv) && isnumeric(row)) {
-
var rows = table.getElementsByTagName("TR");
-
if (row>=rows.length) { return false; } else { var cols = rows[row].getElementsByTagName("TD"); }
-
if (alphaconv>cols.length) { return false; } else { var gval = cols[alphaconv].innerHTML; }
-
if (gval!="") { document.getElementById("showval").value = gval; }
-
}
-
}
-
-
function isnumeric(sText) {
-
var ValidChars = "0123456789";
-
var IsNumber=true;
-
var Char;
-
for (i = 0; i < sText.length && IsNumber == true; i++)
-
{
-
Char = sText.charAt(i);
-
if (ValidChars.indexOf(Char) == -1)
-
{
-
IsNumber = false;
-
}
-
}
-
return IsNumber;
-
}
-
-
</script>
-