-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用SheetJS实现纯前端解析、生成Excel #248
Labels
Comments
download = '商品列表.xls'; 應該是 download = '商品列表.xlsx'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
title: 使用SheetJS实现纯前端解析、生成Excel
date: 2018-03-28
使用SheetJS实现纯前端解析、生成Excel
前言
目前大多数后台系统的导入、导出功能都是在后端解析、生成Excel,前端只是负责搬运。其实纯前端也是可以实现解析、创建Excel的,通过笔者的调研,自认为SheetJS是当前最成熟的处理Excel的javascript插件。
下面简单介绍下这个插件的用法。
如何生成Excel
开始介绍之前,我们需要先理清两个概念:
1. 创建workbook
SheetJS提供了多个创建workbook的方法,这里只列举浏览器端常用的方法,高级用法以及node端的用法暂不列举,有兴趣可以自行查阅,更多用法:
2. 创建worksheet
同上,SheetJS提供了多个创建worksheet的方法,这里只列举浏览器端常用的方法,高级用法以及node端的用法暂不列举,有兴趣可以自行查阅,更多用法:
3. 将worksheet添加进workbook
4. 生成Excel文件
解析Excel示例:
总结
纯前端解析、导出Excel的关键在于调用了Blob、FileReader、URL.createObjectURL这几个API,SheetJS在此基础上进行了更深层次的封装,针对IE等老旧浏览器进行了兼容,并且支持node等环境使用,提供了丰富的API,本文只列举了浏览器端常规使用的方法,更多细节需自行查阅官方文档。
参考资源:
SheetJS
SheetJS docs
纯前端实现excel表格导入导出
The text was updated successfully, but these errors were encountered: