I am trying to export div data which using JavaScript. It is exported to Excel but without css. No border is showing in Excel format, even I am not able to give name of Excel file.
Here is my code:
function ExportToExcel() {
var contents = $(".divclass").html();
window.open('data:application/vnd.ms-excel,' + encodeURIComponent(contents));
}
I am trying to export div data which using JavaScript. It is exported to Excel but without css. No border is showing in Excel format, even I am not able to give name of Excel file.
Here is my code:
function ExportToExcel() {
var contents = $(".divclass").html();
window.open('data:application/vnd.ms-excel,' + encodeURIComponent(contents));
}
Share
Improve this question
edited Jul 31, 2017 at 13:47
hbulens
1,9693 gold badges24 silver badges51 bronze badges
asked Jul 31, 2017 at 13:09
SujeetSujeet
211 gold badge1 silver badge2 bronze badges
1
- 2 and your div is posed of? – Prabhakaran Commented Jul 31, 2017 at 13:12
1 Answer
Reset to default 2$("#btnExport").click(function(e) {
let file = new Blob([$('.divclass').html()], {type:"application/vnd.ms-excel"});
let url = URL.createObjectURL(file);
let a = $("<a />", {
href: url,
download: "filename.xls"}).appendTo("body").get(0).click();
e.preventDefault();
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744733871a4590625.html
评论列表(0条)