vue3导出excel表格
时间: 2023-09-14 08:08:38 浏览: 103
可以使用第三方库`exceljs`来进行导出:
1. 安装依赖库:`npm install exceljs --save`
2. 引入库和样式:
```javascript
import * as Excel from 'exceljs';
import 'exceljs/dist/exceljs.min.css';
```
3. 编写导出方法:
```javascript
exportExcel() {
const workbook = new Excel.Workbook();
const sheet = workbook.addWorksheet('Sheet Name');
const title = ['列1', '列2', '列3'];
sheet.addRow(title);
const rows = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
rows.forEach((row) => {
sheet.addRow(row);
});
workbook.xlsx.writeBuffer().then((buffer) => {
const blob = new Blob([buffer], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
const fileName = 'export.xlsx';
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click();
});
}
```
4. 在页面中调用导出方法:`<button @click="exportExcel()">导出Excel</button>`
希望能对你有所帮助~
阅读全文
相关推荐
















