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" />
|
<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" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Vite + Vue</title>
|
<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">
|
<link rel="stylesheet" href="/vue-office/examples/dist/assets/index-171e346f.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
import VueOfficeExcel from '../../../packages/excel/index'
|
import VueOfficeExcel from '../../../packages/excel/index'
|
||||||
import '../../../packages/excel/src/index.css'
|
import '../../../packages/excel/src/index.css'
|
||||||
import PreviewWrapper from '../common/PreviewWrapper.vue'
|
import PreviewWrapper from '../common/PreviewWrapper.vue'
|
||||||
|
function onError(e){
|
||||||
|
console.log('出差',e)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<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"
|
default-src="https://501351981.github.io/vue-office/examples/dist/static/test-files/test.xlsx"
|
||||||
>
|
>
|
||||||
<template v-slot="slotProps">
|
<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>
|
</template>
|
||||||
|
|
||||||
</PreviewWrapper>
|
</PreviewWrapper>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
</style>
|
</style>
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vue-office/excel",
|
"name": "@vue-office/excel",
|
||||||
"version": "0.2.2",
|
"version": "0.2.3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
@ -37,6 +37,7 @@ export function readExcelData(buffer){
|
|||||||
return wb.xlsx.load(buffer)
|
return wb.xlsx.load(buffer)
|
||||||
|
|
||||||
}catch (e){
|
}catch (e){
|
||||||
|
console.warn(e)
|
||||||
return Promise.reject(e)
|
return Promise.reject(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,9 +182,9 @@ function getStyle(cell){
|
|||||||
|
|
||||||
export function transferExcelToSpreadSheet(workbook, options){
|
export function transferExcelToSpreadSheet(workbook, options){
|
||||||
let workbookData = []
|
let workbookData = []
|
||||||
//console.log(workbook, 'workbook')
|
console.log(workbook, 'workbook')
|
||||||
workbook.eachSheet((sheet) => {
|
workbook.eachSheet((sheet) => {
|
||||||
//console.log(sheet,'sheet')
|
console.log(sheet,'sheet')
|
||||||
// 构造x-data-spreadsheet 的 sheet 数据源结构
|
// 构造x-data-spreadsheet 的 sheet 数据源结构
|
||||||
let sheetData = { name: sheet.name,styles : [], rows: {},cols:{}, merges:[],media:[] }
|
let sheetData = { name: sheet.name,styles : [], rows: {},cols:{}, merges:[],media:[] }
|
||||||
// 收集合并单元格信息
|
// 收集合并单元格信息
|
||||||
|
@ -25,6 +25,9 @@ export default defineComponent({
|
|||||||
let xs = null
|
let xs = null
|
||||||
function renderExcel(buffer){
|
function renderExcel(buffer){
|
||||||
readExcelData(buffer).then(workbook =>{
|
readExcelData(buffer).then(workbook =>{
|
||||||
|
if(!workbook._worksheets || workbook._worksheets.length === 0){
|
||||||
|
throw new Error('未获取到数据,可能文件格式不正确或文件已损坏')
|
||||||
|
}
|
||||||
const {workbookData, medias} = transferExcelToSpreadSheet(workbook, props.options)
|
const {workbookData, medias} = transferExcelToSpreadSheet(workbook, props.options)
|
||||||
xs.loadData(workbookData);
|
xs.loadData(workbookData);
|
||||||
emit('rendered')
|
emit('rendered')
|
||||||
@ -40,7 +43,7 @@ export default defineComponent({
|
|||||||
showToolbar: false,
|
showToolbar: false,
|
||||||
view: {
|
view: {
|
||||||
height: () => wrapperRef.value.clientHeight || 300,
|
height: () => wrapperRef.value.clientHeight || 300,
|
||||||
width: () => document.documentElement.clientWidth,
|
width: () => wrapperRef.value.clientWidth || 300,
|
||||||
},
|
},
|
||||||
}).loadData({});
|
}).loadData({});
|
||||||
if(props.src){
|
if(props.src){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user