table_to_book的用法
const XLSX = require('xlsx')
let elt0 = document.getElementById('')
let wb = XLSX.utils.table_to_book(elt0,{sheet:'sheet 1',raw:true})
//设置通用样式
let font = {
sz:'10',
bold:false
}
let borderAll={
top:{style:'thin'},
bottom:{style:'thin'},
left:{style:'thin'},
right:{style:'thin'}
}
//添加表头zuo
wb.Sheets['Sheet 1']['A1']={t:'s',v:'丫丫',s:{border:borderAll,font{bole:true},fill:{fgColor:{rgb:'cccccc'}}}}
wb.Sheets['Sheet 1']['B1']={t:'s',v:'丫丫',s:{border:borderAll,font{bole:true},fill:{fgColor:{rgb:'cccccc'}}}}
//循环添加数据
shuju.forEach((item,index)=>{
wb.Sheets['Sheet 1']['A'+(index+2)]={t:'s',v:item.name,s:{border:borderAll,fill:{fgColor:{rgb:'cccccc'}}}}
wb.Sheets['Sheet 1']['B'+(index+2)]={t:'s',v:item.title,s:{border:borderAll,fill:{fgColor:{rgb:'cccccc'}}}}
})
//添加表头you
wb.Sheets['Sheet 1']['G1']={t:'s',v:'丫丫',s:{border:borderAll,font{bole:true},fill:{fgColor:{rgb:'cccccc'}}}}
wb.Sheets['Sheet 1']['H2']={t:'s',v:'丫丫',s:{border:borderAll,font{bole:true},fill:{fgColor:{rgb:'cccccc'}}}}
//循环添加数据
shuju2.forEach((item,index)=>{
wb.Sheets['Sheet 1']['G'+(index+2)]={t:'s',v:item.name,s:{border:borderAll,fill:{fgColor:{rgb:'cccccc'}}}}
wb.Sheets['Sheet 1']['H'+(index+2)]={t:'s',v:item.name,s:{border:borderAll,fill:{fgColor:{rgb:'cccccc'}}}}
})
wb.Sheets['Sheet 1']['!fullref']='A1:H'+(shuju.length+1)
wb.Sheets['Sheet 1']['!ref']='A1:H'+(shuju.length+1)
wb.Sheets['Sheet 1']['!cols']=[{wch:40},{wch:5}]
var wopts={bookType:'xlsx',bookSST:false,type:'binary'}
var wbout =XLSXStyle.weite(wb,wopts)
FileSaver.saveAs(new Blob([this.s2ab(wbout )],{type:''}),`标的名字${}.xls`)
s2ab(s){
var buf=new ArrayBuffer(s.length)
var view=new Uint8Array(buf)
for(var i=0;i!==s.length;i++){
view[i]=s.charCodeAt(i)&0xff
}
}