npm install xlsx -D
2、 创建html文件
<script lang="javascript" src="./node_modules/xlsx/xlsx.mini.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script type="text/javascript">
window.onload = function () {
$.ajax({
url: "https://xxx/biz.h5/home/progRing?channelNo=84322&progNo=240749&pageIndex=1&pageSize=10",
type: "GET",
dataType: "jsonp",
success: function (data) {
const filename = "file.xlsx";
const data1 = ['aWord', 'introduction', "listenTimes"]
var arrop = []
arrop.push(data1)
for (var i = 0; i < data.listRing.length; i++) {
let arr = []
arr.push(data.listRing[i].aWord)
arr.push(data.listRing[i].introduction)
arr.push(data.listRing[i].ringName)
arrop.push(arr)
var ws_name = "Sheet1";
var wb = XLSX.utils.book_new(),
ws = XLSX.utils.aoa_to_sheet(arrop);
XLSX.utils.book_append_sheet(wb, ws, ws_name);
XLSX.writeFile(wb, filename);
</script>
前端开发 @科大讯飞有限公司
粉丝