Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在IE 11中下载Excel文件_Javascript_Excel_Internet Explorer_Download_Extjs4.1 - Fatal编程技术网

Javascript 在IE 11中下载Excel文件

Javascript 在IE 11中下载Excel文件,javascript,excel,internet-explorer,download,extjs4.1,Javascript,Excel,Internet Explorer,Download,Extjs4.1,我有一个ExtJS代码,用于将网格数据转换为Excel格式并写入文件,该代码最终将网格数据导出为可下载的Excel文件。这在firefox和chrome中非常有效,但在IE浏览器(IE 11)中无法正常工作 通过分析发现,代码最终会将下面的字符串发布到URL框中,URL框将下载excel文件 data:application/vnd.ms-excel;base64,<base64 encoded string follows here> 但是,如果我在IE 11中粘贴上述相同的字符

我有一个ExtJS代码,用于将网格数据转换为Excel格式并写入文件,该代码最终将网格数据导出为可下载的Excel文件。这在firefox和chrome中非常有效,但在IE浏览器(IE 11)中无法正常工作

通过分析发现,代码最终会将下面的字符串发布到URL框中,URL框将下载excel文件

data:application/vnd.ms-excel;base64,<base64 encoded string follows here>
但是,如果我在IE 11中粘贴上述相同的字符串,它将不会起任何作用。因此,我假设代码运行良好,但我可能需要做更多的工作,使其与IE浏览器兼容。但是我不知道我还能尝试什么

我们非常感谢任何一位指导员

下面是我的ExtJS代码,如果有帮助的话

    //here xmlString has the constructed xml string which holds 
    //grid column headers + grid rows with Table, Column, Cell and Worksheet tags.

    var ctx = {
        created : (new Date()).getTime(),
        worksheets : xmlString
    };

    var uri = 'data:application/vnd.ms-excel;base64,',
    tmplWorkbookXML = '<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">' + '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>BlahBlah</Author><Created>{created}</Created></DocumentProperties>' + '<Styles>' + '<Style ss:ID="columnHeader"><Font ss:Size="11" ss:Bold="1" /><Interior ss:Color="#CCFFCC" ss:Pattern="Solid"/> </Style>' + '</Styles>' + '{worksheets}</Workbook>',
        base64 = function(s) {
             return window.btoa(unescape(encodeURIComponent(s)));
    },
        format = function(s, c) {
        return s.replace(/{(\w+)}/g, function(m, p) {
            return c[p];
        });
    };

    var workbookXML = format(tmplWorkbookXML, ctx);
    var link = document.createElement("A");
    link.href = uri + base64(workbookXML);
    link.download = sheetName + " Level Report - " + Ext.Date.format(new Date(), 'Y-m-d H:i:s') + '.xls';
    link.target = '_blank';
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
//这里xmlString具有构造的xml字符串,该字符串包含
//网格列标题+带有表、列、单元格和工作表标记的网格行。
变量ctx={
已创建:(新建日期()).getTime(),
工作表:xmlString
};
var uri='数据:application/vnd.ms-excel;base64,',
tmplWorkbookXML='+'BlahBlah{created}'+'+'+'+''+'{worksheets}',
base64=函数{
返回窗口.btoa(unescape(encodeURIComponent));
},
格式=函数(s,c){
返回s.replace(/{(\w+)}/g,函数(m,p){
返回c[p];
});
};
var workbookXML=格式(tmplWorkbookXML,ctx);
var link=document.createElement(“A”);
link.href=uri+base64(workbookXML);
link.download=sheetName+“级别报告-”+Ext.Date.format(新日期(),'Y-m-d H:i:s')+'.xls';
link.target=''u blank';
document.body.appendChild(链接);
link.click();
document.body.removeChild(link);

PS:我在ExtJS V4.1和V6.0上都尝试过,但行为相同。

不要假设,点击F12,然后确定。我在调试器控制台中检查过,当我尝试逐步调试时,它不会显示任何错误。当控制器到达link.click()时,它将打开一个新选项卡,其中url填充了与文章中提到的相同的字符串。有什么我应该检查或查找的特定内容吗?不要假设,点击F12,然后确定。我在调试器控制台中进行了检查,当我尝试逐步调试时,它不会显示任何错误。当控制器到达link.click()时,它将打开一个新选项卡,其中url填充了与文章中提到的相同的字符串。有什么具体的我应该检查或寻找的吗?
    //here xmlString has the constructed xml string which holds 
    //grid column headers + grid rows with Table, Column, Cell and Worksheet tags.

    var ctx = {
        created : (new Date()).getTime(),
        worksheets : xmlString
    };

    var uri = 'data:application/vnd.ms-excel;base64,',
    tmplWorkbookXML = '<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">' + '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>BlahBlah</Author><Created>{created}</Created></DocumentProperties>' + '<Styles>' + '<Style ss:ID="columnHeader"><Font ss:Size="11" ss:Bold="1" /><Interior ss:Color="#CCFFCC" ss:Pattern="Solid"/> </Style>' + '</Styles>' + '{worksheets}</Workbook>',
        base64 = function(s) {
             return window.btoa(unescape(encodeURIComponent(s)));
    },
        format = function(s, c) {
        return s.replace(/{(\w+)}/g, function(m, p) {
            return c[p];
        });
    };

    var workbookXML = format(tmplWorkbookXML, ctx);
    var link = document.createElement("A");
    link.href = uri + base64(workbookXML);
    link.download = sheetName + " Level Report - " + Ext.Date.format(new Date(), 'Y-m-d H:i:s') + '.xls';
    link.target = '_blank';
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);