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

Endless
  • 34,080
  • 13
  • 108
  • 131
Sudipto
  • 390
  • 1
  • 3
  • 18
  • 1
    If you need to do it in pure javascript, then ActiveX is not the way to go! – Endless Jun 27 '16 at 07: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 – Sudipto Jun 27 '16 at 07:42

1 Answers1

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
Community
  • 1
  • 1
Endless
  • 34,080
  • 13
  • 108
  • 131