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> </script>
<style lang="less"> <style lang="less">
.ag-theme-alpine{ .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-foreground-color: white;
--ag-header-background-color: #5a81b7; --ag-header-background-color: #5a81b7;
--ag-header-cell-hover-background-color: #5a81b7; --ag-header-cell-hover-background-color: #5a81b7;
--ag-header-cell-moving-background-color: #5a81b7; --ag-header-cell-moving-background-color: #5a81b7;
--ag-border-color:#4d709f;
.ag-floating-filter-input .ag-input-field-input{ .ag-floating-filter-input .ag-input-field-input{
color:#333 !important color:#333 !important

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

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

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

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

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

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

Loading…
Cancel
Save