Click here to Skip to main content
15,888,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I loaded an excel sheet on the server and now I am trying to get the webpage to read certain cells to be place on a html page. How can I get single cells displayed on a webpage without Iframing, but using javascript.


thanks
Mike

What I have tried:

<!doctype html>


<meta charset="utf-8">
<title>Untitled Document











Javascript function




function my_function()
{
var Excel;
Excel = new ActiveXObject("Excel.Application");
Excel.Visible = false;
a=Excel.Workbooks.Open("C:/desktop/test_rates.xls").ActiveSheet.Cells(l,i).Value;
//Excel.Quit()
return a;
}

//where l is number of rows and i are columns...
var i=1;
var l=1;
do
{
a=my_function()
document.write("value is " +a+"\t");i++;
if (a=="");
{l++;
i=1;
document.write("\n");
}
}
while(a=="");
Posted
Updated 1-Feb-19 13:42pm
Comments
MadMyche 1-Feb-19 16:22pm    
You do realize that most browsers do not support ActiveX, correct?
Member 14137457 1-Feb-19 16:38pm    
I was not aware of that since I am a rookie at Javascript.
MadMyche 1-Feb-19 17:17pm    
ActiveX is a MS technology that came out in the 90's. It was only fully supported in IE.
MS Edge does not support it.
Chrome and Firefox had limited support at one time, not known if they still do.
Member 14137457 1-Feb-19 17:39pm    
What do you recommend to do so that I can parse a single cell onto a web page from an excel sheet. Both the excel and web page will be on the same domain.
Richard Deeming 4-Feb-19 13:06pm    
ActiveX in non Internet Explorer applications - Wikipedia[^]

Firefox:
The Mozilla plugin hasn't been updated since 2005, and only works in Firefox 1.5. There's an add-on that hasn't been updated for 11 years, which only works in 1.5—3.5. And there's a GitHub project that hasn't been updated in over five years, and almost certainly won't work in the latest version, even if you could persuade users to install it.

Chrome:
The only option appears to be "IETab", which runs Internet Explorer as a tab within the Chrome window. It's still being maintained, but it offers "in-app purchases", and it's still a cludge. Again, you'd have to convince users to install it.


Even in Internet Explorer, the Excel.Application ActiveX control is not marked as "safe for scripting". You'd have to convince the users to change their security settings and implicitly trust your site not to do anything bad with the added privileges.

1 solution

If the Excel file is on the server, the SERVER Code has to read the Excel sheet. Javascript code on the client will not be able to get at the file.

Having said that, your Javascript code needs to do something complete different. Instead of trying to use Excel, it just makes an AJAX call back to the server for the data it want, passing in whatever data you need to tell the server which cell to return. Once the call returns, you get the data and display the value in whatever HTML place holder you want.

Google for "Javascript ajax call" for the client side. For the server side, everything depends on what kind of web app you're writing for this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900