0

I was able to create the XLS file using JavaScript using Active X controls.

For IE I did the following :

    var objExcel = new ActiveXObject("Excel.Application");
    objExcel.visible = false; 
    var objWorkbook = objExcel.Workbooks.Add; 
    var objWorksheet = objWorkbook.Worksheets(1); 
    objWorksheet.Paste; 
    objExcel.visible = true;

But to use ActiveX controls I need to go to Internet Option -> Security ->Custom Level ->Enable Initialize and script ActiveX controls not marked as safe for scripting . After enabling this only I am able to create the XLS file.

Is there any other way to create the XLS file in IE-11 apart from active X I tried to use the following

var vDiv = document.getElementById('dvData');
                    vDiv.innerHTML = vTable;
                    var url='data:application/vnd.ms-excel,' + encodeURIComponent($('#dvData').html()) ;

but its not working in IE-11. I need to use pure javascript.

Thanks in advance

2
  • 1
    If you need to do it in pure javascript, then ActiveX is not the way to go! Commented Jun 27, 2016 at 7:14
  • @Endless : Which way can i do this . I am very new to JS and I am having a feeling that without Active X we cannot create XLS on IE-11. Please advice Commented Jun 27, 2016 at 7:42

1 Answer 1

1

First you need to convert the table to a way that excel can understand it.
Expecting a html code to work out of the box in excel is wrong.

Once you got the data in the right format you should create a Blob and download that, one good lib to help out with saving blob is FileSaver.js

var chunk = '<?xml version="1.0"?>...'
var blob = new Blob([chunk], {type: 'application/vnd.ms-excel'})
saveAs(blob, 'filename.xls') // using FileSaver.js
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Endless I was able to create the XLS file i wanted .

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.