0

I want to export the HTML page to XLS using java script . I am able to do this in the following way using Active X in IE .

            window.clipboardData.setData("Text", vTable);
            var objExcel = new ActiveXObject("Excel.Application");
            objExcel.visible = false; 
            var objWorkbook = objExcel.Workbooks.Add; 
            var objWorksheet = objWorkbook.Worksheets(1); 
            objWorksheet.Paste; 
            objExcel.visible = true;

and following code is for MOzilla and Chrome

    var url='data:application/vnd.ms-excel,' + encodeURIComponent($('#divExport').html()) ;
    location.href=url;

But I want to know if there is a way that will work on all 3 latest version of browsers for creating XLS ?

Sudipto
  • 390
  • 1
  • 3
  • 18
  • How would this result in a valid XLS file: `encodeURIComponent($('#divExport').html())`? You should try to look into CSV - Excel can read and write it and it is easy to make with web pages and web technologies. – somethinghere Mar 08 '16 at 13:57
  • Yes I agree with you that CSV is a better way . But that does not work on IE . In IE i need active X controls. So is there any way were I an create the XLS in all the 3 browers ? – Sudipto Mar 08 '16 at 14:08
  • Why do you need the controls? IE can work with CSV just as well.. I'll be honest, I think using any ActiveX is inherently going to be very specific to IE or Edge, and it is discouraged in best practises. Try to find a universal solution. Can't help more than that... – somethinghere Mar 08 '16 at 14:14
  • Possible duplicate of [How can I export tables to excel from a webpage](http://stackoverflow.com/questions/5524143/how-can-i-export-tables-to-excel-from-a-webpage) – davidcondrey Mar 08 '16 at 14:22

1 Answers1

0

Set the page content-type to Content-type: application/vnd.ms-excel

or in the case of .xlxs use Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

davidcondrey
  • 34,416
  • 17
  • 114
  • 136