Skip to content

Commit 1852b3a

Browse files
committed
edit README
edit README
1 parent ccc7911 commit 1852b3a

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
1+
<!--
2+
* @page:
3+
* @Author: Orts
4+
* @Date: 2021-12-09 13:54:32
5+
* @LastEditTime: 2021-12-09 18:07:24
6+
* @LastEditors: Orts
7+
* @Description:
8+
* @FilePath: /xlsx-in-vue3/README.md
9+
-->
110
# xlsx-in-vue3
2-
嵌套在网页中的电子表格
11+
嵌套在网页中的电子表格
12+
vite+Vue3+element-plus+xlsx+x-data-spreadsheet
13+
14+
[demo](https://time-coding.github.io/xlsx-in-vue3/)
15+
16+
## 依赖
17+
核心依赖:
18+
- [SheetJs](https://github.com/SheetJS/sheetjs)
19+
- [x-data-spreadsheet](https://github.com/myliang/x-spreadsheet)
20+
21+
## 说明
22+
- 本代码只是**demo**
23+
- 初始化数据是test.xlsx文件,通过ajax访问本地文件来达到解析xlsx文件的目标。
24+
- 场景目前只有两种,一种是通过ajax请求文件,返回arraybuffer格式的文件。另一种是upload上传
25+
26+
```js
27+
const url = "test.xlsx";
28+
const request = new XMLHttpRequest();
29+
request.open("GET", url, true);
30+
request.responseType = "arraybuffer";
31+
request.send(null);
32+
request.onload = function () {
33+
if (request.status == 200) {
34+
const workbook = XLSX.read(request.response);
35+
s = new Spreadsheet("#xel", options);
36+
s.loadData(stox(workbook));
37+
}
38+
};
39+
```
40+
41+
- 代码中有两种Object,一个是workbook是sheet对象,另一种是Spreadsheet是样式渲染对象。workbook实例要想被使用,需要转化成Spreadsheet需要的格式,不能直接使用,`excel.js`提供了stox方法,可以将workbook实例转化成Spreadsheet可加载的数据。

src/App.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @page:
33
* @Author: Orts
44
* @Date: 2021-12-08 12:02:09
5-
* @LastEditTime: 2021-12-09 15:54:12
5+
* @LastEditTime: 2021-12-09 17:58:31
66
* @LastEditors: Orts
77
* @Description:
88
* @FilePath: /xlsx-in-vue3/src/App.vue
@@ -26,11 +26,9 @@ onMounted(() => {
2626
loadLocalDemo();
2727
});
2828
29-
// console.log(require(test))
30-
3129
// ecel默认配置
3230
const options = {
33-
mode: "read", // edit | read 编辑/只读
31+
mode: "edit", // edit | read 编辑/只读
3432
showToolbar: true,
3533
showGrid: true,
3634
showContextmenu: true,

0 commit comments

Comments
 (0)