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
     }
}




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值