Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I would like to know how can i
open/edit/save excel sheet from browser using javascript without getting the excel popup asking to open or save

What I have tried:

<pre>var Excel = new ActiveXObject("Excel.Application");
        Excel.Visible = true;
        Excel.Workbooks.Open("store_funnel.xlsx");
Posted
Updated 20-Sep-18 0:14am
Comments
Richard Deeming 4-Apr-17 10:05am    
That code will only work in Internet Explorer on Windows, and only if the user has Office installed, and only if the user has changed their settings to allow your site to "initialize and script ActiveX controls not marked as safe for scripting".

Unless you're creating an intranet site, where you have complete control over your users' computers, it's extremely unlikely that your script will ever work.

And since, as you mentioned in the comments below, you're trying to edit a file on the user's local filesystem, there isn't a solution. Javascript does not have access to the user's filesystem, because that would be a major security vulnerability.

function write_to_excel()
{
str="D:\test1\test\Email_Far";

var mytable = document.getElementsByTagName("table")[0];

var row_Count = mytable.rows.length;
var col_Count =6;

var ExcelApp = new ActiveXObject("Excel.Application");
ExcelApp.Visible=true;
var ExcelSheet=ExcelApp.Workbooks.Open("D:\\test1\\test\\Email_Far");



for(var i=0; i < row_Count ; i++)
{
for(var j=0; j < col_Count; j++)
{
str= mytable.getElementsByTagName("tr")[i].getElementsByTagName("td")[j].innerHTML;
ExcelSheet.ActiveSheet.Cells(i+1,j+1).Value = str;
}
}
ExcelSheet.Save("D:\\test1\\test\\Email_Far.xlsx");

}


This code will open the Excel file and write the data from Html page. Please try..
Note: This is just the script, so you just need to design a html page such as it has a table in it from which the data need to be pulled and pushed into excel.
 
Share this answer
 
Comments
Richard Deeming 20-Sep-18 8:56am    
Exactly the same problem as the question:

That code will only work in Internet Explorer on Windows, and only if the user has Office installed, and only if the user has changed their settings to allow your site to "initialize and script ActiveX controls not marked as safe for scripting".
Quote:
open/edit/save excel sheet from browser using javascript without getting the excel popup asking to open or save
Quote:
I actually need to open a local excel file

This kind of action is forbidden by today's browsers for security reasons.
Internet Explorer is probably the only one that allow this activity with the help of an activex, the problem is that by default, activex is deactivated and IE is not so popular these days.

I fear you have to find another way.
 
Share this answer
 
This works in IE:

<html>

  <body>

    <form name="form1">
      <input type=button onClick="test()" value="Open File">
      <br><br>
    </form>

    <script type="text/javascript">
      function test() {
        var Excel = new ActiveXObject("Excel.Application");
        Excel.Visible = true;
        Excel.Workbooks.Open("http://go.microsoft.com/fwlink/?LinkID=521962");
      }
    </script>
  </body>
</html>


You might also need to mess with the Security but it opens the Excel spreadsheet in a separate window..
 
Share this answer
 
Comments
Member 13092275 4-Apr-17 2:40am    
I actually need to open a local excel file
var newwindow=window.open("url of .xls","window1","");


Make sure that the permissions for 'directory' (755) and 'file (644)' access are set to at least 'read' for all users for the .xls you wish to download.
 
Share this answer
 
Comments
Member 13092275 3-Apr-17 16:43pm    
Would this allow the excel to open in the browser?
Or would it prompt to open/save excel sheet?
Member 13036251 3-Apr-17 17:07pm    
Just tried it..it downloads it but it doesnt open it..I read alittle on the web but it seems you dont want ActiveX to come up..
Member 13092275 3-Apr-17 17:12pm    
I am ok with any approach that would open the excel in the browser.
ActiveX is not working for me. Got a hint?
Member 13036251 3-Apr-17 19:04pm    
Active X not working. What do you mean?

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