npm i xlsxnpm i xlsx- style- vite
const  dataSource =  ref ( [ ] )  const  columns =  [ { title :  '用户名' , key :  'userName' , width :  120 , } , { title :  '用户组' , key :  'userGroup' , width :  120 , } , { title :  '状态' , key :  'enable' , width :  100 , } , { title :  '余额' , key :  'balance' , width :  120 , } , { title :  'NB余额' , key :  'nbBalance' , width :  120 , } , { title :  '创建时间' , key :  'createTime' , width :  180 , } , { title :  '操作' , key :  'action' , width :  200 , fixed :  'right' , } , 
] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - const  transData  =  ( columns :  any,  tableList :  any)  =>  { const  obj =  columns. reduce ( ( acc :  any,  cur :  any)  =>  { if  ( ! acc. titles &&  ! acc. keys)  { acc. titles =  [ ] acc. keys =  [ ] } acc. titles. push ( cur. title) acc. keys. push ( cur. key) return  acc} ,  { } ) console. log ( 'obj=' ,  obj) const  tableBody =  tableList. map ( ( item :  any)  =>  { return  obj. keys. map ( ( key :  string)  =>  item[ key] ) } ) console. log ( 'tableBody=' ,  tableBody) return  [ obj. titles,  ... tableBody] 
} const  exportExcel  =  ( )  =>  { const  tableData =  transData ( columns,  dataSource. value) console. log ( 'tableData=' ,  tableData) const  ws =  XLSX . utils. aoa_to_sheet ( tableData) const  wb =  XLSX . utils. book_new ( ) ws[ '!ref' ]  =  ` A1:AI ${ tableData. length} ` [ '!cols' ]  =  [ {  wpx :  120  } ,  {  wpx :  100  } ,  {  wpx :  110  } ,  {  wpx :  110  } ,  {  wpx :  110  } ,  {  wpx :  110  } ] ws[ '!merges' ]  =  [ {  s :  {  r :  0 ,  c :  0  } ,  e :  {  r :  0 ,  c :  0  }  } ] XLSX . utils. book_append_sheet ( wb,  ws,  'Sheet1' ) XLSX . writeFile ( wb,  'tablename.xlsx' ) 
}