0

I tried the below code to open excel file using javascript. I tried in IE, Chrome, and Firefox but it's not opening the file.

<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("teste.xlsx");
  }
</script>
</body>
</html>

Thanks in Advance!

2
  • Is ActiveX enabled in the browser? I hope not, but... Commented Dec 6, 2017 at 8:55
  • thanks i enable that and its working now Commented Dec 6, 2017 at 9:59

2 Answers 2

2

Try using Absolute Path of the file you are trying to open

eg:

Excel.Workbooks.Open("E:\\test.xlsx");
Sign up to request clarification or add additional context in comments.

Comments

1

ActiveXObject is only supported by IE, other browsers don't support it.

Excel.Workbooks.Open("teste.xlsx");

There is no path specified for teste.xlsx, provide appropriate file path. The file should be accessed by the browser in the client system, so path should be set accordingly like C:\\Temp\\teste.xlsx (something similar with appropriate system drive).

1 Comment

The file should be in the client system and browser tries to access from client location only, so path should be set accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.