Browse Source

导出excel封装更改

faster_AG_grid
安虹睿 11 months ago
parent
commit
62b0df0313
  1. 7
      PC/UI.WinIn.FasterZ.AgGridReport/src/components/AgTable/index.vue
  2. 157
      PC/UI.WinIn.FasterZ.AgGridReport/src/components/exportExcel/index.vue
  3. 37
      PC/UI.WinIn.FasterZ.AgGridReport/src/components/reportPageHeader/index.vue
  4. 1
      PC/UI.WinIn.FasterZ.AgGridReport/src/views/inventoryAndAge.vue

7
PC/UI.WinIn.FasterZ.AgGridReport/src/components/AgTable/index.vue

@ -105,10 +105,17 @@ export default {
</script>
<style lang="less">
.ag-theme-alpine{
// --ag-header-foreground-color: white;
// --ag-header-background-color: #5a81b7;
// --ag-header-cell-hover-background-color: #5a81b7;
// --ag-header-cell-moving-background-color: #5a81b7;
// --ag-border-color:#4d709f;
--ag-header-foreground-color: white;
--ag-header-background-color: #5a81b7;
--ag-header-cell-hover-background-color: #5a81b7;
--ag-header-cell-moving-background-color: #5a81b7;
--ag-border-color:#4d709f;
.ag-floating-filter-input .ag-input-field-input{
color:#333 !important

157
PC/UI.WinIn.FasterZ.AgGridReport/src/components/exportExcel/index.vue

@ -1,5 +1,5 @@
<template>
<div><el-button @click="exportExcel" size="small" type="warning">导出数据2</el-button></div>
<div><el-button @click="exportExcel" size="small" type="warning">导出数据</el-button></div>
</template>
<script>
import XLSX from "xlsx";
@ -7,6 +7,23 @@ import XLSXS from "xlsx-style";
import FileSaver from "file-saver";
export default {
name: "exportExcel",
props:{
//
title:{
type: String,
default: null
},
//
reportName:{
type: String,
default: '导出'
},
//
excelData:{
type: Array,
default: null
},
},
data () {
return {
@ -20,89 +37,95 @@ export default {
return buf;
},
exportExcel(){
//
let _head = []
for(let item in this.excelData[0]){
_head.push(item)
}
//
let _title = [this.title]
for(let i =0;i<_head.length - 1;i++){
_title.push(null)
}
//
let excelAllData = [
_title,//
_head, //
]
//
let excelData = [
["幼儿园课表", null, null, null], //
["序号", "课程名称", "教师名称", "上课地点"], //
["11.1234", "11,211.1234", "11.1234", "操场"],
["11.1234", "11,211.1234", "11.1234", "操场"],
["11.1234", "11,211.1234", "11.1234", "操场"],
["11.1234", "11,211.1234", "11.1234", "操场"],
["11.1234", "11,211.1234", "11.1234", "操场"],
];
this.excelData.forEach((item,key)=>{
let _row = []
_head.forEach(head_item=>{
_row.push(item[head_item])
})
excelAllData.push(_row)
})
// excel
const filename = "幼儿园课程表.xlsx";
const filename = this.reportName+".xlsx";
// Excelsheet
const ws_name = "Sheet1";
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet(excelData);
const ws = XLSX.utils.aoa_to_sheet(excelAllData);
XLSX.utils.book_append_sheet(wb, ws, ws_name); //
//
// sstart, eend, rrow, ccolumn
// --00,03
ws["!merges"] = [{ s: { r: 0, c: 0 }, e: { r: 0, c: 3 } }];
ws["!merges"] = [{ s: { r: 0, c: 0 }, e: { r: 0, c: _head.length - 1 } }];
//
ws["!cols"] = [
{
wpx: 40,
},
{
wpx: 100,
},
{
wpx: 100,
},
{
wpx: 100,
},
];
/*
设置单元格其他样式
这里列举一部分,其他样式大同小异,自行网上搜索
*/
// ws["!cols"] = [
// {wpx: 40,},
// {wpx: 100,},
// {wpx: 100,},
// {wpx: 100,},
// ];
// ,
console.log(91,ws)
// ,
for (let i in ws) {
if (i === "B2") {
ws[i].s = {
//
alignment: {
horizontal: "center",
vertical: "center",
wrapText: true,
},
//
font: {
name: "仿宋",
sz: 14,
bold: true,
},
};
} else if (i === "B3") {
ws[i].s = {
//
border: {
top: {
style: "thin",
},
bottom: {
style: "thin",
},
left: {
style: "thin",
},
right: {
style: "thin",
},
},
};
//
if(i == "A1"){
ws[i].s = {
alignment: {
horizontal: "center",
vertical: "center",
wrapText: true,
},
};
}
// if (i === "B2") {
// ws[i].s = {
// //
// font: {
// name: "仿",
// sz: 14,
// bold: true,
// },
// };
// } else if (i === "B3") {
// ws[i].s = {
// //
// border: {
// top: {
// style: "thin",
// },
// bottom: {
// style: "thin",
// },
// left: {
// style: "thin",
// },
// right: {
// style: "thin",
// },
// },
// };
// }
}
// Excel, XLSXS

37
PC/UI.WinIn.FasterZ.AgGridReport/src/components/reportPageHeader/index.vue

@ -1,5 +1,7 @@
<template>
<div class="reportPageHeader">
<!-- 报表名称 -->
<div class="reportTitle" v-if="showReportTitle">{{reportName}}</div>
<!-- 搜索条件及按钮 -->
<div class="FormHeader">
<!-- 左侧查询 -->
@ -55,25 +57,19 @@
</div>
<!-- 右侧按钮 -->
<div class="headerRightBtn">
<downloadExcel
:data="downloadData"
:fields="downloadFields"
:name="reportName"
:title="downloadExcelTitle"
<exportExcel
v-if="downloadData && downloadData.length > 0"
class="output-excel"
type="xls"
>
<el-button size="small" type="warning">导出数据</el-button>
</downloadExcel>
<exportExcel></exportExcel>
:reportName="reportName"
:excelData="downloadData"
:title="downloadExcelTitle()"
></exportExcel>
<columnFilter
:columnList="columnList"
@columnFliterCallback="columnFliterCallback"
></columnFilter>
</div>
</div>
<!-- 报表名称 -->
<div class="reportTitle" v-if="showReportTitle">{{reportName}}</div>
</div>
</template>
<script>
@ -129,11 +125,9 @@ export default {
},
data () {
return {
downloadFields:{},//
};
},
mounted(){
this.initDownloadFields()
this.initSearchConfig()
},
methods: {
@ -168,12 +162,6 @@ export default {
}
})
},
//
initDownloadFields(){
this.columnList.forEach(item=>{
this.downloadFields[item.field] = item.headerName || item.field
})
},
//
columnFliterCallback(data){
this.$emit("columnFliterCallback",data)
@ -196,6 +184,7 @@ export default {
</script>
<style scope lang="less">
.reportPageHeader{
background:#2d568e;
.FormHeader{
padding:20px 20px 0;
@ -210,16 +199,20 @@ export default {
margin-right:10px
}
}
.el-form-item__label{
color:#fff
}
}
.reportTitle{
background:#2d568e;
color:#fff;
line-height:40px;
text-align:center;
font-size:16px;
font-weight:bold;
letter-spacing:2px
letter-spacing:2px;
border-bottom: #4d709f solid 1px;
}
}
</style>

1
PC/UI.WinIn.FasterZ.AgGridReport/src/views/inventoryAndAge.vue

@ -6,6 +6,7 @@
:reportName="'库存库龄报表'"
:BottomFixedItem="BottomFixedItem"
:procName="'Proc_Zheng_库存库龄'"
:showReportTitle="false"
></reportPage>
</template>

Loading…
Cancel
Save