前期准备:
(一)luckysheet插件,需要将对方项目打成一个dist包,除了index.html不要其他都要,是的,它有16M
1、在public放入dist,并引入官网给的要求
2、index.html中引入,defer是浏览器空闲时候加载(兼容性不是很好),卧槽,写到这的时候,是不是可以在进入页面的时候,手动创建…算了,继续吧,<%= BASE_URL %>是我总感觉部署会丢路径
(二)LuckyExcel
import LuckyExcel from 'luckyexcel'
你应该懂了,哈哈哈哈哈,npm install 一下这个
1、本地导入,官网给了
2、远程导入
url的
ClickUrl() {
let value = 'xxxxxx1.xlsx'
let name = '1111'
LuckyExcel.transformExcelToLuckyByUrl(value, name, function (exportJson, luckysheetfile) {
console.log(exportJson, luckysheetfile)
if (exportJson.sheets == null || exportJson.sheets.length == 0) {
alert('Failed to read the content of the excel file, currently does not support xls files!')
return
}
console.log(exportJson, luckysheetfile)
// mask.style.display = 'none'
window.luckysheet.destroy()
window.luckysheet.create({
container: 'luckysheet', //luckysheet is the container id
showinfobar: false,
data: exportJson.sheets,
title: exportJson.info.name,
userInfo: exportJson.info.name.creator,
})
})
},
本地的
demoHandler(evt) {
console.log(evt)
var files = evt.target.files
if (files == null || files.length == 0) {
alert('No files wait for import')
return
}
let name = files[0].name
let suffixArr = name.split('.'),
suffix = suffixArr[suffixArr.length - 1]
if (suffix != 'xlsx') {
alert('Currently only supports the import of xlsx files')
return
}
LuckyExcel.transformExcelToLucky(files[0], function (exportJson, luckysheetfile) {
console.log(exportJson)
if (exportJson.sheets == null || exportJson.sheets.length == 0) {
alert('Failed to read the content of the excel file, currently does not support xls files!')
return
}
window.luckysheet.destroy()
window.luckysheet.create({
container: 'luckysheet', //luckysheet is the container id
showinfobar: false,
data: exportJson.sheets,
title: exportJson.info.name,
userInfo: exportJson.info.name.creator,
})
})
},