安装
npm install better-xlsx --save
使用
- 以下是基本使用的解释,具体下载表格的内容需按自己的需求做
import React from 'react';
import xlsx from 'better-xlsx';
import saveAs from 'jszip/vendor/FileSaver';
const Demo = ()=>{
const download = () =>{
const file = new xlsx.File();
const sheet = file.addSheet('文件名');
const header = sheet.addRow();
header.setHeightCM(rowHeight);
const cell = header.addCell();
sheet.col(0).width = 15;
cell.value = '第一个单元格的数据';
cell.style.fill.patternType = 'solid';
cell.style.fill.fgColor = '00FEFF00';
cell.style.align.h = 'center';
cell.style.align.v = 'center';
cell.style.border.top = 'thin';
cell.style.border.topColor = 'ff7e6a54';
cell._style.font.bold = true;
file.saveAs('blob').then((content) => {
saveAs(content, 'demo.xlsx');
});
}
renter <span onclick={()=> download}>Download</span>
}

文档地址
文档地址
gitHub地址
使用Demo
PS
- 指导更多使用 better-xlsx 的知识可以在下方留言
- 刘师兄的微信:LMT0797 ,备注:掘金