Export To Excel a div content using JavascriptJquery - Stack Overflow

I am trying to export div data which using JavaScript. It is exported to Excel but without css. No bord

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
Add a ment  | 

1 Answer 1

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

相关推荐

  • Export To Excel a div content using JavascriptJquery - Stack Overflow

    I am trying to export div data which using JavaScript. It is exported to Excel but without css. No bord

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信