Copy and pasted Microsoft example of Javascript to check value in cell,
but fails to work
I have been staring at the code below for hours, and I am not sure where
to begin on how to fix the problem. In advance, I believe this is more of
a javascript problem on my end then a Microsoft Web API problem, since I
am literally copying and pasting their code.
I am trying to use Microsoft Excel's Web API to embed an embed an excel
sheet on my web page. More specifically, I am trying to have, when
highlighted on a cell, it displays the value of the selected cell.
Here is their working example with code
http://www.excelmashup.com/APIBrowser#example105
Simply change the tab from "Output" to "HTML" in the bottom right to see
the same code as below:
<html>
<head>
<script type="text/javascript"
src="http://r.office.microsoft.com/r/rlidExcelWLJS?v=1&kip=1"></script>
<script type="text/javascript">
// run the Excel load handler on page load
if (window.attachEvent) {
window.attachEvent("onload", loadEwaOnPageLoad);
} else {
window.addEventListener("DOMContentLoaded", loadEwaOnPageLoad, false);
}
function loadEwaOnPageLoad() {
var fileToken =
"SDBBABB911BCD68292!110/-4923638281765748078/t=0&s=0&v=!ALTlXd5D3qSGJKU";
var props = {
uiOptions: {
showGridlines: false,
selectedCell: "'Sheet1'!C9",
showRowColumnHeaders: false,
showParametersTaskPane: false
},
interactivityOptions: {
allowTypingAndFormulaEntry: false,
allowParameterModification: false,
allowSorting: false,
allowFiltering: false,
allowPivotTableInteractivity: false
}
};
Ewa.EwaControl.loadEwaAsync(fileToken, "myExcelDiv", props,
onEwaLoaded);
}
function onEwaLoaded() {
document.getElementById("loadingdiv").style.display = "none";
}
// This sample gets the value in the highlighted cell.
// Try clicking on different cells then running the sample.
function execute()
{
// Get unformatted range values (getValuesAsync(1,...) where 1 =
Ewa.ValuesFormat.Formatted)
ewa.getActiveWorkbook().getActiveCell().getValuesAsync(1,getRangeValues,null);
}
function getRangeValues(asyncResult)
{
// Get the value from asyncResult if the asynchronous operation was
successful.
if (asyncResult.getCode() == 0)
{
// Get the value in active cell (located at row 0, column 0 of the
// range which consists of a single cell (the "active cell")).
alert("Result: " + asyncResult.getReturnValue()[0][0]);
}
else
{
alert("Operation failed with error message " +
asyncResult.getDescription() + ".");
}
}
</script>
</head>
<body>
<input type="button" onclick="execute();">Execute Sample</input>
<<<<<Here is the problem
<div id="myExcelDiv" style="width: 402px; height: 346px"></div>
</body>
</html>
When I change the above to onclick="alert('hello')" it works fine, but it
does not alert the value of the cell when I click execute(); . Maybe
someone could copy and past the code into an .html file and see if it is
just a problem on my end and whether the Microsoft code works for them.
I truly appreciate any help.
No comments:
Post a Comment