当我从JavaScript中导出html表时,我的项目不会显示000 [英] My items din't display 000 when i export from html's table in JavaScript

查看:112
本文介绍了当我从JavaScript中导出html表时,我的项目不会显示000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我之前有一些物品可以开始000(例如:001110011577,001110011580,001110015862 ...)。

在html表中,它显示正确的格式(001110011577,001110011580,001110015862 ...)。

但是当我导出到excel时,项目代码显示不正确的格式(1110011577,1110011580,1110015862 .. )。这意味着前面的所有00都将自动切断excel。

这是我导出到excel的源代码:

Hi all experts,

I have some items that start 000 before (ex:001110011577,001110011580,001110015862...).
In html's table, it display correct format (001110011577,001110011580,001110015862...).
but when i export to excel, the item code displays incorrect format(1110011577,1110011580,1110015862...). it means that all 00 in front will cut off automatic by excel.
Here is my source code to export to excel:

var tableToExcel = (function () {
        var uri = 'data:application/vnd.ms-excel;base64,'
        , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
        , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
        , format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
        return function (table, filename) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = { worksheet: 'Worksheet', table: table.innerHTML }
            document.getElementById("dlink").href = uri + base64(format(template, ctx));
            document.getElementById("dlink").download = filename + '.xls';
            document.getElementById("dlink").click();
        }
    })





有人知道如何显示我的项目,就像显示html的表格一样吗? br $>


谢谢



Does anybody know how to display my item like what it displays html's table?

Thanks

推荐答案

tabletoexcel('GrdAccountTypesListView','AccountTypesListView','AccountTypesListView.xlsx')

var tabletoexcel =(function(){





var uri ='data:application / vnd.ms -excel; base64,'

,template ='< html xmlns:o =urn:schemas-microsoft-com:office:officexmlns:x =urn:schemas-microsoft-com :office:excelxmlns =http://www.w3.org/TR/REC-html40>< head><! - [if gte mso 9]>< xml>< x :excelworkbook xmlns:x =#unknown>< x:excelworksheets>< x:excelworksheet>< x:name> {worksheet}< x:worksheetoptions>< x:displaygridlines>< / xml> <![endif] - >< / head>< body> {table}
< / body>< / html>'

,base64 = func (s){return window.btoa(unescape(encodeURIComponent(s)))}

,format = function(s,c){return s.replace(/ {(\ w +)} / g,function(m,p){return c [p]; })

返回函数(表,名称,文件名){





if(!table。 nodeType)table = document.getElementById(tables)



var ctx = {worksheet:name || '工作表',表:tables.innerHTML}

document.getElementById(dlink)。href = uri + base64(格式(模板,ctx));

文件.getElementById(dlink)。download = filename;

document.getElementById(dlink)。click();



}



})()
tabletoexcel('GrdAccountTypesListView', 'AccountTypesListView', 'AccountTypesListView.xlsx')
var tabletoexcel = (function () {


var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:excelworkbook xmlns:x="#unknown"><x:excelworksheets><x:excelworksheet><x:name>{worksheet}<x:worksheetoptions><x:displaygridlines></xml><![endif]--></head><body>{table}
</body></html>'
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
return function (table, name, filename) {


if (!table.nodeType) table = document.getElementById(tables)

var ctx = { worksheet: name || 'Worksheet', table: tables.innerHTML }
document.getElementById("dlink").href = uri + base64(format(template, ctx));
document.getElementById("dlink").download = filename;
document.getElementById("dlink").click();

}

})()


这篇关于当我从JavaScript中导出html表时,我的项目不会显示000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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