I could use some help. I have a function that opens an Excel spreadsheet to load data from it. The function is found inside <head> </head> and within that inside <script></script> (see below). The problem is that I need to write that data inside the row of a table in the <body>. How do I reference variables declared and assigned inside a script in the head section from the body of my page?

On a separate topic, how do I get rid of the error message (below) that pops up when the function which opens the Excel spreadsheet executes as follows:

<head>
<script>
var global_var="";
function loadexcel() {
var serverLoc = "http://mydomain.com/excel_folder/";
var serverFile = serverLoc+"my_excel.xls";

var ehandle = new ActiveXObject("Excel.Application");
var eWBhandle = ehandle.Workbooks.Open(serverFile);
var eShandle = eWBhandle.ActiveSheet;
global_var = eShandle.Cells(1,1).Value;
eWBhandle.Close();
}
</script>
</head>
<body>
......
<table>
<td>
<tr>
<script>
document.write(global_var); // writes ""
</script>
</tr>
</td>
</table>
......
</body>

The error message I get every time I open the page when I run the page on my local machine (vs loaded on a server and run there) is:

An ActiveX control on this page might be unsafe to
interact with other parts of the page. Do you want to
allow this interaction? Yes/No

On the server, I get a Microsoft error in the yellow error message bar at the top of the page saying the web page wants to run an add-on with no name and ca ontrol with no name. So you appear to be able to respond once to that then it doesn't bother you again.

So when running on my client, is there any way to suppress the above error message? When running on the server, for first time visitors, how do I name the add-on and control so it's a little more palatable (vs something called "unknown")?

MS

Well. I just answered one of my questions. For anyone else out there trying to figure out how to dynamically write text based on some test condition, I did the following.

Instead of using tables in the body, I used span as in:

<span id="dynamic_block">
</span>

In my case, everything to go inside the span block would be dynamic so it literally was "empty" as in the above.

In the <head> section inside my loadexcel() function at the very end (or at least after I've defined the content of my variable to be written inside my span block), I added the following at the very end:

document.getElementById('dynamic_block').innerHTML = global_var;

I've obviously simplified. If you want the full example, please post a reply and I will extract the entire code.

But I still need help with naming my add-on and control that pops up in response to the open of an excel object. I have to believe there is a parameter or something that can be added to the open that will provide something other than "unknown" in the message.

So I still need your help!

MS

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.