vue3 xlsx如何将表头加粗
时间: 2023-08-18 16:08:38 浏览: 99
你可以使用 `xlsx-style` 库来设置表头的样式,具体步骤如下:
1. 安装 `xlsx-style` 库:
```bash
npm install xlsx-style --save
```
2. 导入库并创建工作簿和工作表:
```javascript
import XLSX from 'xlsx-style';
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(data);
```
3. 设置表头样式:
```javascript
const headerStyle = {
font: {
bold: true,
},
};
ws["!cols"] = [{ width: 15 }, { width: 20 }, { width: 30 }]; // 设置列宽
ws["!rows"] = [{ height: 25 }]; // 设置行高
ws["A1"].s = headerStyle; // 设置 A1 单元格样式
ws["B1"].s = headerStyle; // 设置 B1 单元格样式
ws["C1"].s = headerStyle; // 设置 C1 单元格样式
```
4. 将工作表添加到工作簿中并导出:
```javascript
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "file.xlsx");
```
这样就可以在导出的 Excel 文件中将表头加粗了。
阅读全文
相关推荐













