【发布时间】:2019-06-20 04:50:35
【问题描述】:
我目前正在开发一个项目的导出功能。 (我是刚毕业的学生)
我已经成功地完成了这个功能。我现在面临的问题是excel会自动转换(或格式化?)我的初始值到另一种形式。我可以知道是否有任何解决方案可以阻止 excel 执行自动转换为值?
场景:原号码为7778362019198430,导出后显示 7.77836E+15
这是我的导出函数的代码
function fnExcelReport(tableID) {
var downloadLink;
var dataType = 'application/vnd.ms-excel';
var tableSelect = document.getElementById(tableID);
var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
// Specify file name
var d = new Date();
var todaysDate = d.getFullYear() + '-' + d.getMonth() + '-' +
d.getDate();
filename = 'CashCard_' + todaysDate + '.xls';
// Create download link element
downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if(navigator.msSaveOrOpenBlob){
var blob = new Blob(['\ufeff', tableHTML], {
type: dataType
});
navigator.msSaveOrOpenBlob( blob, filename);
}else{
// Create a link to the file
downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
// Setting the file name
downloadLink.download = filename;
//triggering the function
downloadLink.click();
}
}
预期的输出应该和原来的值一样是7778362019198430,但是excel会自动转换,导出后的输出会自动转换成7.77836E+15。
有什么办法可以阻止吗?非常感谢。
【问题讨论】:
标签: javascript c# jquery html export-to-excel