Browse Source

分页符位置问题

TonyKang 4 years ago
parent
commit
accbe80ce1
1 changed files with 26 additions and 14 deletions
  1. 26 14
      app/reports/util/rpt_excel_util.js

+ 26 - 14
app/reports/util/rpt_excel_util.js

@@ -335,21 +335,32 @@ function _setupPgBrks(pageData) {
     pageData.pageBreaks = [];
     let pgBrkIdx = 0;
     const pgBrk = [];
-    function _insertMaxBottom(pCells, targetBottomArr) {
+    function _insertMaxBottom(pCells, targetBottomArr, chkTop) {
         if (pCells) {
             for (const cell of pCells) {
-                if (targetBottomArr.indexOf(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) < 0) {
-                    targetBottomArr.push(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
+                let cb = parseFloat(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
+                if (targetBottomArr.indexOf(cb) < 0) {
+                    targetBottomArr.push(cb);
+                }
+                if (chkTop) {
+                    cb = parseFloat(cell[JV.PROP_AREA][JV.PROP_TOP]);
+                    if (targetBottomArr.indexOf(cb) < 0) {
+                        targetBottomArr.push(cb);
+                    }
                 }
             }
         }
     }
-    for (const page of pageData.items) {
+    // for (const page of pageData.items) {
+    // for (let i = 0; i < pageData.items.length - 1; i++) {
+    for (let i = 0; i < pageData.items.length; i++) {
+        const page = pageData.items[i];
         const maxBottomArr = [];
         _insertMaxBottom(page[JV.PROP_CELLS], maxBottomArr);
         _insertMaxBottom(page[JV.PROP_SIGNATURE_CELLS], maxBottomArr);
         _insertMaxBottom(page[JV.PROP_SIGNATURE_DATE_CELLS], maxBottomArr);
         _insertMaxBottom(page[JV.PROP_SIGNATURE_AUDIT_CELLS], maxBottomArr);
+        _insertMaxBottom(page[JV.PROP_WATERMARK_CELLS], maxBottomArr, true);
         pgBrkIdx += maxBottomArr.length;
         pgBrk.push(pgBrkIdx);
     }
@@ -984,16 +995,6 @@ function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, ap
     }
     rst.push('<pageSetup ' + pStr + ' fitToWidth="0" fitToHeight="0" orientation="' + orientationStr + '" />');
     rst.push('<headerFooter alignWithMargins="0"/>');
-    if (hasSignature && signSheetIdxArr[sheetIdx]) {
-        // let rIdx = 1;
-        // for (let ssIdx = 0; ssIdx < signSheetIdxArr.length; ssIdx++) {
-        //     if (signSheetIdxArr[ssIdx]) {
-        //         if (ssIdx < sheetIdx) rIdx++
-        //         else break;
-        //     }
-        // }
-        rst.push('<drawing r:id="rId1"/>');
-    }
     // 插入分页符---------------------------
     if (pageData.pageBreaks) {
         let pgBrks = [];
@@ -1011,6 +1012,17 @@ function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, ap
         }
     }
     // 插入分页符结束---------------------------
+    // 图形要放在最后,否则excel会报错(但WPS不会)
+    if (hasSignature && signSheetIdxArr[sheetIdx]) {
+        // let rIdx = 1;
+        // for (let ssIdx = 0; ssIdx < signSheetIdxArr.length; ssIdx++) {
+        //     if (signSheetIdxArr[ssIdx]) {
+        //         if (ssIdx < sheetIdx) rIdx++
+        //         else break;
+        //     }
+        // }
+        rst.push('<drawing r:id="rId1"/>');
+    }
     rst.push('</worksheet>');
     return rst;
 }