@himail/xlsx 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +153 -0
- package/lib/index.d.ts +12 -0
- package/lib/script/postinstall.js +15 -0
- package/lib/script/switch-cli.js +14 -0
- package/lib/script/utils.js +31 -0
- package/lib/v3/index.css +838 -0
- package/lib/v3/index.js +1 -0
- package/lib/v3/xm-office-excel.css +2 -0
- package/lib/v3/xm-office-excel.mjs +4 -0
- package/lib/v3/xm-office-excel.umd.js +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# @xm/excel
|
|
2
|
+
|
|
3
|
+
Excel 文档预览组件,支持 Vue 2 和 Vue 3。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 📦 支持 Vue 2 和 Vue 3
|
|
8
|
+
- 🎯 支持多种 Excel 格式(.xlsx, .xls)
|
|
9
|
+
- 🔧 丰富的表格操作功能
|
|
10
|
+
- 🎨 现代化的 Apple 风格加载动画
|
|
11
|
+
- 📱 响应式设计
|
|
12
|
+
- 🌙 支持暗色模式
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
### 从 npm 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# 使用 npm
|
|
20
|
+
npm install @xm/excel
|
|
21
|
+
|
|
22
|
+
# 使用 yarn
|
|
23
|
+
yarn add @xm/excel
|
|
24
|
+
|
|
25
|
+
# 使用 pnpm
|
|
26
|
+
pnpm add @xm/excel
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 使用
|
|
30
|
+
|
|
31
|
+
### Vue 3
|
|
32
|
+
|
|
33
|
+
```vue
|
|
34
|
+
<template>
|
|
35
|
+
<div>
|
|
36
|
+
<XmExcel :src="excelFile" @load="onLoad" @error="onError" />
|
|
37
|
+
</div>
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
<script setup>
|
|
41
|
+
import { ref } from "vue";
|
|
42
|
+
import XmExcel from "@xm/excel";
|
|
43
|
+
|
|
44
|
+
const excelFile = ref("https://example.com/sample.xlsx");
|
|
45
|
+
|
|
46
|
+
const onLoad = () => {
|
|
47
|
+
console.log("Excel 加载完成");
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const onError = (error) => {
|
|
51
|
+
console.error("Excel 加载失败:", error);
|
|
52
|
+
};
|
|
53
|
+
</script>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Vue 2
|
|
57
|
+
|
|
58
|
+
```vue
|
|
59
|
+
<template>
|
|
60
|
+
<div>
|
|
61
|
+
<XmExcel :src="excelFile" @load="onLoad" @error="onError" />
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
|
|
65
|
+
<script>
|
|
66
|
+
import XmExcel from "@xm/excel";
|
|
67
|
+
|
|
68
|
+
export default {
|
|
69
|
+
components: {
|
|
70
|
+
XmExcel, // 注册组件 XmExcel
|
|
71
|
+
},
|
|
72
|
+
data() {
|
|
73
|
+
return {
|
|
74
|
+
excelFile: "https://example.com/sample.xlsx",
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
methods: {
|
|
78
|
+
onLoad() {
|
|
79
|
+
console.log("Excel 加载完成");
|
|
80
|
+
},
|
|
81
|
+
onError(error) {
|
|
82
|
+
console.error("Excel 加载失败:", error);
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
</script>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## API
|
|
90
|
+
|
|
91
|
+
### Props
|
|
92
|
+
|
|
93
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
94
|
+
| ------------- | ------------- | ----------- | -------------- |
|
|
95
|
+
| `src` | String | - | Excel 文件 URL |
|
|
96
|
+
| `width` | String/Number | '100%' | 组件宽度 |
|
|
97
|
+
| `height` | String/Number | '600px' | 组件高度 |
|
|
98
|
+
| `loading` | Boolean | false | 加载状态 |
|
|
99
|
+
| `loadingText` | String | '加载中...' | 加载文本 |
|
|
100
|
+
| `errorText` | String | '加载失败' | 错误文本 |
|
|
101
|
+
|
|
102
|
+
### Events
|
|
103
|
+
|
|
104
|
+
| 事件 | 说明 | 参数 |
|
|
105
|
+
| ---------- | -------- | ------------------ |
|
|
106
|
+
| `load` | 加载完成 | - |
|
|
107
|
+
| `error` | 加载失败 | 错误对象 |
|
|
108
|
+
| `progress` | 加载进度 | 进度百分比 (0-100) |
|
|
109
|
+
|
|
110
|
+
## 示例
|
|
111
|
+
|
|
112
|
+
### 基本使用
|
|
113
|
+
|
|
114
|
+
```vue
|
|
115
|
+
<XmOfficeExcel src="/path/to/excel.xlsx" />
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 带自定义样式
|
|
119
|
+
|
|
120
|
+
```vue
|
|
121
|
+
<XmOfficeExcel src="/path/to/excel.xlsx" width="800px" height="500px" />
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 监听事件
|
|
125
|
+
|
|
126
|
+
```vue
|
|
127
|
+
<XmOfficeExcel
|
|
128
|
+
src="/path/to/excel.xlsx"
|
|
129
|
+
@load="handleLoad"
|
|
130
|
+
@error="handleError"
|
|
131
|
+
@progress="handleProgress"
|
|
132
|
+
/>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 浏览器兼容性
|
|
136
|
+
|
|
137
|
+
- Chrome ✅
|
|
138
|
+
- Firefox ✅
|
|
139
|
+
- Safari ✅
|
|
140
|
+
- Edge ✅
|
|
141
|
+
|
|
142
|
+
## 许可证
|
|
143
|
+
|
|
144
|
+
MIT License
|
|
145
|
+
|
|
146
|
+
## 贡献
|
|
147
|
+
|
|
148
|
+
欢迎提交 Issue 和 Pull Request!
|
|
149
|
+
|
|
150
|
+
## 联系
|
|
151
|
+
|
|
152
|
+
- Author: 微信: _hit757_
|
|
153
|
+
- GitHub: [vue-office](https://github.com/501351981/vue-office)
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
minColLength?: number;
|
|
3
|
+
minRowLength?: number;
|
|
4
|
+
showContextmenu?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare const xmExcel: {
|
|
7
|
+
install?: (vue: any) => void;
|
|
8
|
+
src: string | ArrayBuffer | Blob;
|
|
9
|
+
requestOptions?: any;
|
|
10
|
+
options?: Options;
|
|
11
|
+
};
|
|
12
|
+
export default xmExcel;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { switchVersion, loadModule } = require('./utils');
|
|
2
|
+
const Vue = loadModule('vue');
|
|
3
|
+
if (!Vue || typeof Vue.version !== 'string') {
|
|
4
|
+
console.warn(
|
|
5
|
+
'[vue-office] Vue is not found. Please run "npm install vue" to install.'
|
|
6
|
+
);
|
|
7
|
+
} else if (Vue.version.startsWith('2.')) {
|
|
8
|
+
switchVersion(2);
|
|
9
|
+
} else if (Vue.version.startsWith('3.')) {
|
|
10
|
+
switchVersion(3);
|
|
11
|
+
} else {
|
|
12
|
+
console.warn(
|
|
13
|
+
`[vue-office] Vue version v${Vue.version} is not supported.`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { switchVersion } = require('./utils');
|
|
2
|
+
|
|
3
|
+
const version = process.argv[2];
|
|
4
|
+
|
|
5
|
+
if (version == '2') {
|
|
6
|
+
switchVersion(2);
|
|
7
|
+
} else if (version == '3') {
|
|
8
|
+
switchVersion(3);
|
|
9
|
+
} else {
|
|
10
|
+
console.warn(
|
|
11
|
+
`[vue-office] expecting version "2" or "3" but got "${version}"`
|
|
12
|
+
);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const dir = path.resolve(__dirname, '../');
|
|
4
|
+
function loadModule(name) {
|
|
5
|
+
try {
|
|
6
|
+
return require(name);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function copy(name, version) {
|
|
13
|
+
const src = path.join(dir, `v${version}`, name);
|
|
14
|
+
const dest = path.join(dir, name);
|
|
15
|
+
if(!fs.existsSync(src)){
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
let content = fs.readFileSync(src, 'utf-8');
|
|
19
|
+
try {
|
|
20
|
+
fs.unlinkSync(dest);
|
|
21
|
+
} catch (error) {}
|
|
22
|
+
fs.writeFileSync(dest, content, 'utf-8');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function switchVersion(version) {
|
|
26
|
+
copy('index.js', version);
|
|
27
|
+
copy('index.css', version);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports.loadModule = loadModule;
|
|
31
|
+
module.exports.switchVersion = switchVersion;
|