mirror of
https://github.com/501351981/vue-office.git
synced 2025-07-25 07:41:42 +08:00
fix: excel格式不正确,抛出错误
This commit is contained in:
parent
0fc97a9f35
commit
76bf6a15f2
File diff suppressed because one or more lines are too long
2
examples/dist/index.html
vendored
2
examples/dist/index.html
vendored
@ -5,7 +5,7 @@
|
||||
<link rel="icon" type="image/svg+xml" href="/vue-office/examples/dist/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Vue</title>
|
||||
<script type="module" crossorigin src="/vue-office/examples/dist/assets/index-530c0352.js"></script>
|
||||
<script type="module" crossorigin src="/vue-office/examples/dist/assets/index-e6b861ed.js"></script>
|
||||
<link rel="stylesheet" href="/vue-office/examples/dist/assets/index-171e346f.css">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -2,7 +2,9 @@
|
||||
import VueOfficeExcel from '../../../packages/excel/index'
|
||||
import '../../../packages/excel/src/index.css'
|
||||
import PreviewWrapper from '../common/PreviewWrapper.vue'
|
||||
|
||||
function onError(e){
|
||||
console.log('出差',e)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -12,12 +14,13 @@ import PreviewWrapper from '../common/PreviewWrapper.vue'
|
||||
default-src="https://501351981.github.io/vue-office/examples/dist/static/test-files/test.xlsx"
|
||||
>
|
||||
<template v-slot="slotProps">
|
||||
<VueOfficeExcel :src="slotProps.src" style="flex: 1;height: 0"/>
|
||||
<VueOfficeExcel :src="slotProps.src" style="flex: 1;height: 0" @error="onError"/>
|
||||
</template>
|
||||
|
||||
</PreviewWrapper>
|
||||
</template>
|
||||
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vue-office/excel",
|
||||
"version": "0.2.2",
|
||||
"version": "0.2.3",
|
||||
"description": "",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
|
@ -37,6 +37,7 @@ export function readExcelData(buffer){
|
||||
return wb.xlsx.load(buffer)
|
||||
|
||||
}catch (e){
|
||||
console.warn(e)
|
||||
return Promise.reject(e)
|
||||
}
|
||||
}
|
||||
@ -181,9 +182,9 @@ function getStyle(cell){
|
||||
|
||||
export function transferExcelToSpreadSheet(workbook, options){
|
||||
let workbookData = []
|
||||
//console.log(workbook, 'workbook')
|
||||
console.log(workbook, 'workbook')
|
||||
workbook.eachSheet((sheet) => {
|
||||
//console.log(sheet,'sheet')
|
||||
console.log(sheet,'sheet')
|
||||
// 构造x-data-spreadsheet 的 sheet 数据源结构
|
||||
let sheetData = { name: sheet.name,styles : [], rows: {},cols:{}, merges:[],media:[] }
|
||||
// 收集合并单元格信息
|
||||
|
@ -25,6 +25,9 @@ export default defineComponent({
|
||||
let xs = null
|
||||
function renderExcel(buffer){
|
||||
readExcelData(buffer).then(workbook =>{
|
||||
if(!workbook._worksheets || workbook._worksheets.length === 0){
|
||||
throw new Error('未获取到数据,可能文件格式不正确或文件已损坏')
|
||||
}
|
||||
const {workbookData, medias} = transferExcelToSpreadSheet(workbook, props.options)
|
||||
xs.loadData(workbookData);
|
||||
emit('rendered')
|
||||
@ -40,7 +43,7 @@ export default defineComponent({
|
||||
showToolbar: false,
|
||||
view: {
|
||||
height: () => wrapperRef.value.clientHeight || 300,
|
||||
width: () => document.documentElement.clientWidth,
|
||||
width: () => wrapperRef.value.clientWidth || 300,
|
||||
},
|
||||
}).loadData({});
|
||||
if(props.src){
|
||||
|
Loading…
x
Reference in New Issue
Block a user