如何使用javascript document.execcommand保存excel文件('saveas''1'null)

问题描述:

嗨我无法保存excel文件PLZ帮帮我









hi im not able to save excel file plz help me




function exportToExcel() {

            //copy innerHTML of YourTable to strCopy Variable.
        debugger;
            var strCopy = document.getElementById("anil").outerHTML;
            // clickExcel
            //copy strCopy to clipboardData, this
            window.clipboardData.setData("Text", strCopy);

            var objExcel = new ActiveXObject("Excel.Application");

            objExcel.visible = true;

            var objWorkbook = objExcel.Workbooks.Add;

            var objWorksheet = objWorkbook.Worksheets(1);
             objWorksheet.Paste;



             var element = document.getElementById("Bdy1");
               if (element) {
                   if (document.execCommand) {
                       var oWin = window.open("about:blank", "_blank");
                       oWin.document.write(element.innerHTML);
                       oWin.document.close();
                       //objWorksheet.execCommand('SaveAs', null, 'fileName');
                       var success = oWin.document.execCommand('SaveAs', true, 'fileName.xls');
                       oWin.close();
                       if (!success)
                           alert("Sorry, your browser does not support this feature");
                   }
               }





}



}