File tree Expand file tree Collapse file tree 2 files changed +42
-5
lines changed Expand file tree Collapse file tree 2 files changed +42
-5
lines changed Original file line number Diff line number Diff line change
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
+ -->
1
10
# 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可加载的数据。
Original file line number Diff line number Diff line change 2
2
* @page:
3
3
* @Author: Orts
4
4
* @Date: 2021-12-08 12:02:09
5
- * @LastEditTime: 2021-12-09 15:54:12
5
+ * @LastEditTime: 2021-12-09 17:58:31
6
6
* @LastEditors: Orts
7
7
* @Description:
8
8
* @FilePath: /xlsx-in-vue3/src/App.vue
@@ -26,11 +26,9 @@ onMounted(() => {
26
26
loadLocalDemo ();
27
27
});
28
28
29
- // console.log(require(test))
30
-
31
29
// ecel默认配置
32
30
const options = {
33
- mode: " read " , // edit | read 编辑/只读
31
+ mode: " edit " , // edit | read 编辑/只读
34
32
showToolbar: true ,
35
33
showGrid: true ,
36
34
showContextmenu: true ,
You can’t perform that action at this time.
0 commit comments