使用javascript将html表导出为ex​​cel [英] Export html table to excel using javascript

查看:112
本文介绍了使用javascript将html表导出为ex​​cel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想使用JavaScript将html表导出到excel并且我已经完成了。

但是当我导出它时会直接显示到excel页面,实际上我想要它首先它应该显示一个打开,保存和取消选项的对话框。但我无法找到解决方案。请帮帮我。

JavaScript代码如下:

Hi All ,
I want to export html table to excel using JavaScript and i am done .
But when i am exporting it is directly showing to excel page, actually i want it to first it should show a dialog box with "Open","Save" and "Cancel" option . But i am not able to find the solution . please help me out for this .
JavaScript code is given below :

function write_to_excel() {
    str = "";
    var mytable = document.getElementById("tbExport");
    var rowCount = mytable.rows.length;
    var colCount = mytable.getElementsByTagName("tr")[0].getElementsByTagName("th").length;
    var ExcelApp = new ActiveXObject("Excel.Application");
    var ExcelSheet = new ActiveXObject("Excel.Sheet");
    //ExcelSheet.Application.Visible = true;
    for (var i = 0; i < rowCount; i++) {
        for (var j = 0; j < colCount; j++) {
            if (i == 0) {
                str = mytable.getElementsByTagName("tr")[i].getElementsByTagName("th")[j].innerText;
            }
            else {
                str = mytable.getElementsByTagName("tr")[i].getElementsByTagName("td")[j].innerText;
            }
            ExcelSheet.ActiveSheet.Cells(i + 1, j + 1).Value = str;
        }
    }
    ExcelSheet.autofit;
    ExcelSheet.Application.Visible = true;
    DisplayAlerts = true;
    CollectGarbage();
}



谢谢&问候


Thanks & Regards

推荐答案

以下讨论应该有所帮助:如何使用javascript将html表导出为ex​​cel [ ^ ]
Following discussion should help: How to export html table to excel using javascript[^]


你怎么能错过 Google [ ^ ]?



请参阅类似讨论的链接:

http://stackoverflow.com/questions/6566831/how-to-export-html-table-to-excel-using-javascript [ ^ ]

http://stackoverflow.com/questions/11084564/export- html-table-to-excel -javascript-function-special-characters-changed [ ^ ]

http://stackoverflow.com/questions/5524143/how-can-i-export-tables-to-excel -from-a-pagepage [ ^ ]

http://stackoverflow.com/questions/6955627/export-dynamic-html-table-to-excel-in-javascript-in-firefox-browser [ ^ ]







--Amit
How could you miss Google[^]?

Refer the links for similar discussions:
http://stackoverflow.com/questions/6566831/how-to-export-html-table-to-excel-using-javascript[^]
http://stackoverflow.com/questions/11084564/export-html-table-to-excel-javascript-function-special-characters-changed[^]
http://stackoverflow.com/questions/5524143/how-can-i-export-tables-to-excel-from-a-webpage[^]
http://stackoverflow.com/questions/6955627/export-dynamic-html-table-to-excel-in-javascript-in-firefox-browser[^]



--Amit


您好,



此链接将帮助您通过ASP创建Excel。



9将数据导出到Excel for ASP.NET的解决方案 [ ^ ]



现在创建一个Asp页面,您将发送一个Http X请求到该特定页面



并获得响应并在javascript弹出窗口中写入。



如果任何问题都会让我回复。



[更新]



http://stackoverflow.com/questions/ 2274173 / how-to-pull-data-and-export-to-excel-in-ajax-framework?answertab = votes#tab-top [ ^ ]

http://npoi.cod eplex.com/ [ ^ ]
Hi,

This link will help you in creating Excel via ASP.

9 Solutions to Export Data to Excel for ASP.NET[^]

Now create a Asp page where you will send a Http X request to that particular page

and get the response and write it on a javascript popup.

If any problem revert me.

[Update]

http://stackoverflow.com/questions/2274173/how-to-pull-data-and-export-to-excel-within-an-ajax-framework?answertab=votes#tab-top[^]
http://npoi.codeplex.com/[^]

这篇关于使用javascript将html表导出为ex​​cel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆