Files
easygoadmin-wiki/EasyGoAdmin_Gin_AntdVue/zh/frontend/excel-components.md
T
2026-10-25 17:24:27 +08:00

46 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 9.12 Excel 导入导出组件
:::tip 概述
Excel 能力分前后端两半:后端 excelize 读写([7.4 数据导入导出](/zh/tools/excel.html)),前端 Excel/importFile 组件承担交互与浏览器侧解析,downloadFile 工具负责落盘。
:::
## 前端组件
| 组件/工具 | 职责 |
|---|---|
| Excel | 基于 xlsx 库的前端解析/生成(纯前端表格处理场景) |
| importFile | 导入交互:选文件 → 上传到模块导入接口 → 展示结果汇总 |
| utils/downloadFile | 拿到导出 URL 后触发浏览器下载 |
## 导入流(对接后端 Import 契约)
```text
点击导入 → importFile 选择 xls/xlsx
→ FormData 提交 POST /{模块}/import(UnmarshalBody 契约)
→ 后端逐行校验写入
→ 前端展示 ResMsg 提示语 + 失败原因列表( Reasons 含行号)
```
## 导出流(对接后端 Export 契约)
```text
点击导出 → 带当前查询条件 GET /{模块}/export
→ 后端过滤写出 xlsx,返回文件 URL
→ downloadFile 触发下载
```
导出条件与列表分页同参数——"所见即所导"。
## 导入模板
模板经文件模板管理([6.21](/zh/modules/file-template.html))下载(ByCode 接口),列头与后端解析顺序一致——改模板要同步改解析代码。
## 约定
- 大文件导入无事务逐行写,失败行不影响成功行(结果汇总呈现)
- 前端 Excel 组件不替代后端导入(后端校验才是边界),只做轻量场景补充
## 相关
- [7.4 数据导入导出](/zh/tools/excel.html)