el-table Excel导出
时间: 2023-05-24 14:07:33 浏览: 208
对于EL表格,可以使用以下方法将其导出为Excel文件:
1.使用xlsx插件
该插件支持将Vue.js中的数据和样式导出为.xlsx文件。安装插件后,可以通过以下代码将表格导出为Excel文件:
```
import { export_json_to_excel } from '@/excel/Export2Excel';
export function exportTableToExcel(tableId, fileName) {
const tableData = [];
const tableHeader = [];
const table = document.getElementById(tableId);
const rows = table.querySelectorAll('tr');
for (let i = 0; i < rows.length; i++) {
const rowData = [];
const cells = rows[i].querySelectorAll('td');
if (i === 0) {
// 处理表头数据
for (let j = 0; j < cells.length; j++) {
tableHeader.push(cells[j].textContent);
}
} else {
// 处理单元格数据
for (let j = 0; j < cells.length; j++) {
rowData.push(cells[j].textContent.trim());
}
tableData.push(rowData);
}
}
// 导出Excel
export_json_to_excel(tableHeader, tableData, fileName);
}
```
调用方法如下:
```
exportTableToExcel('myTable', 'myExcel.xlsx');
```
其中参数tableId为表格的id,fileName为导出的Excel文件名。
2.使用Bootstrap Table Export插件
该插件适用于使用Bootstrap Table插件的表格。安装插件后,可以通过以下代码将表格导出为Excel文件:
```
$('#myTable').tableExport({
type: 'excel',
fileName: 'myExcel',
worksheetName: 'Sheet1'
});
```
调用方法与普通Bootstrap Table插件相似,只需修改type参数为'excel'即可。其他参数与使用方法见插件文档。
注意:EL表格使用的是ElementUI插件,并非Bootstrap Table插件。使用Bootstrap Table Export插件需要先将表格转换为Bootstrap Table插件。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)