Browse Source

导出评分

11wqe1 1 week ago
parent
commit
3e54340366
1 changed files with 25 additions and 23 deletions
  1. 25 23
      src/components/pages/test/examine/conpoments/personPage.vue

+ 25 - 23
src/components/pages/test/examine/conpoments/personPage.vue

@@ -395,6 +395,7 @@
 
 <script>
 import shareBox from "./shareBox/index";
+import XLSX from 'xlsx-js-style'
 export default {
   directives: {
     stopMousewheel: {
@@ -547,10 +548,12 @@ export default {
     let headers = [
       ['一级指标', '二级指标', '评价方法', '分值', '自评', '自评概述', '认定', '认定概述']
     ];
-     var XLSX = require("xlsx");
+    let info = [['姓名:'+this.digUsername ,'','','','','自评分数:'+this.DigSelfSco,'','认定分数:'+this.computedSco]]
+    //  var XLSX = require("xlsx");
      let data = [
+      ...info,
       ...headers,
-      ...this.PageBaseData.flatMap(parent =>
+      ...this.PageBaseData.flatMap(parent => 
         parent.children.map(child => [
           parent.name, // 一级指标
           child.name,  // 二级指标
@@ -581,19 +584,13 @@ const commonStyle = {
   }
 };
 
-// 定义表头特殊样式
-const headerStyle = {
-  ...commonStyle,
-  fill: { fgColor: { rgb: "FFFF00" } },
-  font: { ...commonStyle.font, bold: true, sz: 14 }
-};
 
 // 应用样式到所有单元格
 for (let r = 0; r < data.length; ++r) {
   for (let c = 0; c < data[r].length; ++c) {
     const cellRef = XLSX.utils.encode_cell({ r, c });
     ws[cellRef] = ws[cellRef] || {};
-    ws[cellRef].s = r === 0 ? headerStyle : commonStyle;
+    ws[cellRef].s =  commonStyle;
   }
 }
 
@@ -611,17 +608,17 @@ ws['!cols'] = [
 
 // 设置行高
 ws['!rows'] = [
-    { hpx: 30 }, // 表头行
+    { hpx: 25 }, // 表头行
     { hpx: 25 }, // 其他行的默认高度
     // 根据需要继续添加行高设置
 ];
-    console.log('kk',data);
+  console.log('kk',data);
     // 合并单元格
   ws['!merges'] = [];
 
 
   // 记录合并单元格的逻辑
-  let startRow = 1; // 数据开始行
+  let startRow = 2; // 数据开始行
   let previousParentName = null;
   let count = 0; // 计数连续相同的一级指标行
 
@@ -644,15 +641,20 @@ ws['!rows'] = [
 
       previousParentName = currentParentName; // 更新前一个一级指标
   }
-
-      // 检查最后一组
-      if (count > 0) {
-          ws['!merges'].push({
-              s: { r: startRow, c: 0 },
-              e: { r: startRow + count, c: 0 }
-          });
-      }
-
+  ws['A1'].s = { alignment: { horizontal: 'left' } }
+  ws['F1'].s = { alignment: { horizontal: 'left' } }
+  ws['H1'].s = { alignment: { horizontal: 'left' } }
+  // 检查最后一组
+  if (count > 0) {
+      ws['!merges'].push({
+          s: { r: startRow, c: 0 },
+          e: { r: startRow + count, c: 0 }
+      });
+  }
+  ws['!merges'].push( { s: { r: 0, c: 0 }, e: { r: 0, c: 4 } },  // 合并姓名部分(A1-E1)
+    { s: { r: 0, c: 5 }, e: { r: 0, c: 6 } },  // 单独保留自评分数(G1)
+    { s: { r: 0, c: 7 }, e: { r: 0, c: 7 } }   // 单独保留认定分数(H1));
+)
 
       XLSX.utils.book_append_sheet(wb, ws, "sheet1"); //把sheet添加到workbook里,第三个参数是sheet名
       XLSX.writeFile(wb, this.digUsername +'-'+ (this.digType == 1 ? '班主任考核' :'专任教师')+".xlsx");
@@ -878,11 +880,11 @@ ws['!rows'] = [
     remindExamine() {
       this.remDig = true;
     },
-
+  
     // 下载excel
     getExcel() {
       var res = this.tableData;
-
+      
       // console.log('导出数据',res);
       //如果value的json字段的key值和想要的headers值不一致时,可做如下更改
       //将和下面的Object.fromEntries结合,将json字段的key值改变为要求的excel的header值