在使用layui框架导出页面数据时,如果我想要导出的数据为0000012,导出时被认为是数字格式,
导出到文件中后就变成了12,前缀的0就会丢失,
这个问题该怎么解决,求指点迷津
导出Excel内容其实是csv格式的内容,打开后是Excel自动去掉的。
换个这插件可以:
<!DOCTYPE html>
<!-- (C) 2013-present SheetJS http://sheetjs.com -->
<!-- vim: set ts=2: -->
<html>
<head>
<title>SheetJS JS-XLSX In-Browser Write Demo</title>
<meta charset="utf-8" />
</head>
<body>
<script type="text/javascript" src="https://unpkg.com/xlsx/dist/shim.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/xlsx/dist/xlsx.full.min.js"></script>
<script>
/* original data */
var filename = "write.xlsx";
var data = [['001', '002', '003'], [true, false, null, "sheetjs"], ["foo", "bar", new Date("2014-02-19T14:30Z"), "0.3"], ["baz", null, "qux"]]
var ws_name = "SheetJS";
if (typeof console !== 'undefined') console.log(new Date());
var wb = XLSX.utils.book_new(), ws = XLSX.utils.aoa_to_sheet(data);
/* add worksheet to workbook */
XLSX.utils.book_append_sheet(wb, ws, ws_name);
/* write workbook */
if (typeof console !== 'undefined') console.log(new Date());
XLSX.writeFile(wb, filename);
if (typeof console !== 'undefined') console.log(new Date());
</script>
</body>
</html>
让后端生成吧
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!