文章介绍
资料链接
Luckysheet手册
Luckysheet的使用
依赖的生成与导入
https://github.com/mengshukeji/Luckysheet.git
npm install
npm install gulp -g
npm run dev
npm run build
<!-- 导入Luckysheet -->
<link rel='stylesheet' href='./plugins/css/pluginsCss.css' />
<link rel='stylesheet' href='./plugins/plugins.css' />
<link rel='stylesheet' href='./css/luckysheet.css' />
<link rel='stylesheet' href='./assets/iconfont/iconfont.css' />
<script src="./plugins/js/plugin.js"></script>
<script src="./luckysheet.umd.js"></script>
使用luckysheet
<template>
<div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:100%;height:100%;left: 0px;top: 20px;" />
</template>
<script>
export default {
data() {
return {
}
},
mounted() {
$(function() {
window.luckysheet.create({
container: 'luckysheet',
title: '测试Excel',
lang: 'zh',
showinfobar: false,
showsheetbar: true,
data: [
{
name: 'guistar的测试表格',
color: '#eee333',
index: 0,
status: 1,
order: 0,
hide: 0,
row: 30,
column: 17,
defaultRowHeight: 28,
defaultColWidth: 100,
celldata: [],
config: {
merge: {},
rowlen: {},
columnlen: {},
rowhidden: {},
colhidden: {},
borderInfo: {},
authority: {}
},
scrollLeft: 0,
scrollTop: 0,
luckysheet_select_save: [],
calcChain: [],
isPivotTable: false,
pivotTable: {},
filter_select: {},
filter: null,
luckysheet_alternateformat_save: [],
luckysheet_alternateformat_save_modelCustom: [],
luckysheet_conditionformat_save: {},
frozen: {},
chart: [],
zoomRatio: 1,
image: [],
showGridLines: 1,
dataVerification: {}
}
]
})
})
},
methods: {
}
}
</script>
<style lang="scss" scoped>
</style>
运行:http://localhost:8080/
如何保存到后端,及如何从后端去拿
原理:
保存到后端
<Button type="info" @click="upExcel">上传</Button>
async upExcel() {
var objsheet = luckysheet.getAllSheets()
options = objsheet
this.postsheet()
}
async postsheet() {
var strsheet = await JSON.stringify(options)
const sheetinfo = { id: 1, filename: strsheet }
await updata(sheetinfo)
},
import { updata, getdata } from '@/api/sheet'
// http://localhost:5086/api/sheet/updata/11111111111
export function updata(sheetstr) {
return request({
url: '/sheet/updata',
method: 'post',
data: sheetstr
})
}
// http://localhost:5086/api/sheet/sheet/1
export function getdata(sheetid) {
return request({
url: '/sheet/sheet/' + sheetid,
method: 'get'
})
}
public IActionResult info([FromBody] Sheet Sheet1)
{
Sheet sheet = new Sheet();
sheet.Filename = Sheet1.Filename;
EacContext.Sheet.AddRange(sheet);
EacContext.SaveChanges();
return Ok(new { msg = "上传成功" });
}
public class Sheet
{
public int Id { get; set; }
public string Filename { get; set; } = null!;
}
|