admin管理员组文章数量:1426102
I want to export my data to excel or pdf but then it's not working in IE. I tried to export it in Chrome and its working fine. But most of the people who'll use my project are using internet explorer. Can anyone take a look on my codes and maybe suggest me what to do ?
Here's my Angular function :
scope.exportData = function () {
var date = new Date();
var d = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
var blob = new Blob([document.getElementById('exportable').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Report_" + d + ".xls");
};
scope.exportDataItems = function () {
var date = new Date();
var d = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
var blob = new Blob([document.getElementById('exportablePRItems').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Items_"+ d +".xls");
};
}]);
I am actually using Blob.js.
I want to export my data to excel or pdf but then it's not working in IE. I tried to export it in Chrome and its working fine. But most of the people who'll use my project are using internet explorer. Can anyone take a look on my codes and maybe suggest me what to do ?
Here's my Angular function :
scope.exportData = function () {
var date = new Date();
var d = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
var blob = new Blob([document.getElementById('exportable').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Report_" + d + ".xls");
};
scope.exportDataItems = function () {
var date = new Date();
var d = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
var blob = new Blob([document.getElementById('exportablePRItems').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Items_"+ d +".xls");
};
}]);
I am actually using Blob.js.
Share Improve this question asked Mar 19, 2015 at 2:46 AnaiahAnaiah 6337 silver badges20 bronze badges 1- What version of IE is this not working in? – nweg Commented Mar 19, 2015 at 3:19
3 Answers
Reset to default 2We can implement export to excel using JSONCSVConverter Steps involved
- JSONtoCSVConverter javascript file.
- JSON Data
- Jquery
This line is important JSONToCSVConvertor(data, "Blog Report", true);
1st parameter accepts data 2nd parameter we specify the file name 3rd paramter we spcecify whether we need label
Reference
Blog
Plunker
<!DOCTYPE html>
<html>
<head>
<title>Internet explorer download</title>
<script src="http://code.jquery./jquery-1.11.0.min.js"></script>
<script src="http://code.jquery./jquery-migrate-1.2.1.min.js"></script>
</head>
<body>
<div align="center">
<h3><u>Enter JSON data</u></h3>
<div class="mydiv">
<textarea cols="100" rows="15" class="txtarea" id="txt">[{"Blog Name":"PrathapKudupusBlog","Date":"30 Jul 2013 09:24 AM","Type":"Technical","Author"
:"Prathap Kudupu"},
{"Blog Name":"ABCBlog","Date":"30 Jul 2011 09:24 AM","Type":"Technical","Author"
:"ABC"},
{"Blog Name":"XYZBlog","Date":"30 Jul 2011 09:24 AM","Type":"Technical","Author"
:"XYZ"}]</textarea> <br>
<h3><u>Click below button to download <strong>CSV</strong> file for internet explorer and other browsers</u></h3>
<br>
<button class="download">Download CSV</button>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$('button').click(function(){
var data = $('#txt').val();
if(data == '')
return;
JSONToCSVConvertor(data, "Blog report", true);
});
});
function JSONToCSVConvertor(JSONData,title, ShowLabel) {
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
var CSV = '';
if (ShowLabel) {
var row = "";
for (var index in arrData[0]) {
row += index + ',';
}
row = row.slice(0, -1);
CSV += row + '\r\n';
}
for (var i = 0; i < arrData.length; i++) {
var row = "";
for (var index in arrData[i]) {
var arrValue = arrData[i][index] == null ? "" : '="' + arrData[i][index] + '"';
row += arrValue + ',';
}
row.slice(0, row.length - 1);
CSV += row + '\r\n';
}
if (CSV == '') {
growl.error("Invalid data");
return;
}
var fileName = title;
if (msieversion()) {
var IEwindow = window.open();
IEwindow.document.write('sep=,\r\n' + CSV);
IEwindow.document.close();
IEwindow.document.execCommand('SaveAs', true, fileName + ".csv");
IEwindow.close();
} else {
var uri = 'data:application/csv;charset=utf-8,' + escape(CSV);
var link = document.createElement("a");
link.href = uri;
link.style = "visibility:hidden";
link.download = fileName + ".csv";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
function msieversion() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie != -1 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer, return version number
{
return true;
} else { // If another browser,
return false;
}
}
</script>
Use alasql. It works with IE9
https://github./agershun/alasql/wiki/Angular.js
Change xlsx to xls.
Maybe this would be of a little help. :)
scope.exportDataNew = function () {
var d = new Date();
var mont = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
if (typeof scope.filter_fromDate == 'undefined') {
scope.filter_fromDate = mont[d.getMonth()] + ' ' + d.getDate().toString() + ", " + d.getFullYear().toString();
}
if (typeof scope.filter_toDate == 'undefined') {
scope.filter_toDate = mont[d.getMonth()] + ' ' + d.getDate().toString() + ", " + d.getFullYear().toString();
}
if (typeof scope.EntityID == 'undefined') {
scope.EntityID = "";
}
if (typeof scope.DepartmentID == 'undefined') {
scope.DepartmentID = "";
}
location.href = 'ExportExcel?from=' + scope.filter_fromDate + '&to=' + scope.filter_toDate + '&EntityID=' + scope.EntityID + '&DepartmentID=' + scope.DepartmentID;
};
scope.exportData = function () {
var date = new Date();
var d = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
var blob = new Blob([document.getElementById('exportable').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Report_" + d + ".xls");
};
本文标签: javascriptAngularjs export to excel not working in IEStack Overflow
版权声明:本文标题:javascript - Angularjs export to excel not working in IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745463509a2659429.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论