Browse Source

code sync

TonyKang 8 years ago
parent
commit
3e1564f1ee

+ 5 - 2
modules/reports/controllers/rpt_controller.js

@@ -62,15 +62,18 @@ module.exports = {
         let rpt_id = req.body.ID;
         let pageSize = req.body.pageSize;
         getAllPagesCommon(req, res, rpt_id, pageSize, function(pageRst){
+            //fs.writeFileSync('D:/GitHome/ConstructionOperation/tmp/testRpt.js', JSON.stringify(pageRst));
             callback(req, res, null, pageRst);
         })
     },
     getExcel: function(req, res) {
         let rpt_id = req.params.id,
             pageSize = req.params.size,
-            rptName = req.params.rptName;
+            rptName = req.params.rptName,
+            isOneSheet = req.params.isOneSheet;
+        ;
         getAllPagesCommon(req, res, rpt_id, pageSize, function(pageRst){
-            rpt_xl_util.exportExcel(pageRst, rptName, null, function(newName){
+            rpt_xl_util.exportExcel(pageRst, pageSize, rptName, isOneSheet, function(newName){
                 res.setHeader('Content-Type', 'application/vnd.openxmlformats');
                 res.setHeader("Content-Disposition", "attachment; filename=" + strUtil.getPinYinCamelChars(rptName) + ".xlsx");
                 let filestream = fs.createReadStream(__dirname.slice(0, __dirname.length - 28) + '/tmp/' + newName + '.xlsx');

+ 37 - 0
modules/reports/models/rpt_tpl_data.js

@@ -0,0 +1,37 @@
+/**
+ * Created by Tony on 2017/7/24.
+ */
+
+let mongoose = require('mongoose');
+let dbm = require("../../../config/db/db_manager");
+let smartcostdb = dbm.getCfgConnection("scConstruct");
+let Schema = mongoose.Schema;
+
+let rptTplPrjSchema = new Schema({
+    "ID": Number,
+    "ParentID": Number,
+    "NextSiblingID": Number,
+    "name": String,         //项目名称
+    "location": String,     //工程地点
+    "constructor": String,  //建设单位
+    "supervisor": String,   //监理
+    "auditor": String       //审核
+});
+
+let rptTplBillsSchema = new Schema({
+
+});
+
+let rptTplRationSchema = new Schema({
+
+});
+
+let tplPrjData = smartcostdb.model("temp_tpl_data", rptTplPrjSchema, "projects");
+let tplBillsData = smartcostdb.model("temp_tpl_data", rptTplBillsSchema, "bills");
+let tplRationData = smartcostdb.model("temp_tpl_data", rptTplRationSchema, "ration");
+
+module.exports = {
+    prjMdl: tplPrjData,
+    billsMdl: tplBillsData,
+    rationMdl: tplRationData
+};

+ 1 - 1
modules/reports/routes/report_router.js

@@ -7,6 +7,6 @@ let rptRouter = express.Router();
 let reportController = require('./../controllers/rpt_controller');
 
 rptRouter.post('/getReport', reportController.getReportAllPages);
-rptRouter.get('/getExcel/:id/:size/:rptName', reportController.getExcel);
+rptRouter.get('/getExcel/:id/:size/:rptName/:isOneSheet', reportController.getExcel);
 
 module.exports = rptRouter;

+ 8 - 3
modules/reports/util/rpt_data_util.js

@@ -11,7 +11,7 @@ class Rpt_Common{
 class Rpt_Data_Extractor {
     initialize(Projects) {
         this.Projects = Projects;
-        //Projects对象从前端传送过来,无需在后端重复查询及构建
+        //Projects对象应该从前端传送过来,无需在后端重复查询及构建
         /* 结构:
          {
             currentPrjId: int,
@@ -35,9 +35,14 @@ class Rpt_Data_Extractor {
          */
     };
 
-    prepare($CURRENT_RPT) {
+    prepareData($CURRENT_RPT) {
         //在报表提取数据前的准备工作,主要有:
-        //1. 确认指标数据的类型,
+        //1. 确认指标数据的类型(离散/主/从)
+        //2. 根据类型提取数据,排序
+        // 2.1. header类型
+        // 2.2. 章类型
+        // 2.3. detail类型
+        // 2.4. 排序
     };
 
 }

+ 242 - 137
modules/reports/util/rpt_excel_util.js

@@ -9,7 +9,7 @@ let jpcCmnHelper = require('../rpt_component/helper/jpc_helper_common');
 let DPI = jpcCmnHelper.getScreenDPI()[0];
 const dftHeadXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
 
-function writeContentTypes(sheets) {
+function writeContentTypes(sheets, isSinglePage) {
     let rst = [];
     rst.push(dftHeadXml + '\r\n');
     rst.push('<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">');
@@ -21,8 +21,12 @@ function writeContentTypes(sheets) {
     rst.push('<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>');
     rst.push('<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>');
     rst.push('<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>');
-    for (let i = 0; i < sheets.length; i++) {
-        rst.push('<Override PartName="/xl/worksheets/sheet' + (i + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>')
+    if (isSinglePage) {
+        rst.push('<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>')
+    } else {
+        for (let i = 0; i < sheets.length; i++) {
+            rst.push('<Override PartName="/xl/worksheets/sheet' + (i + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>')
+        }
     }
     rst.push('<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>');
     rst.push('</Types>');
@@ -38,7 +42,7 @@ function writeRootRels(){
     rst.push('</Relationships>');
     return rst;
 }
-function writeApp(sheets) {
+function writeApp(sheets, isSinglePage) {
     let rst = [];
     rst.push(dftHeadXml + '\r\n');
     rst.push('<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">');
@@ -48,13 +52,19 @@ function writeApp(sheets) {
     rst.push('<HeadingPairs>');
     rst.push('<vt:vector size="2" baseType="variant">');
     rst.push('<vt:variant><vt:lpstr>工作表</vt:lpstr></vt:variant>');
-    rst.push('<vt:variant><vt:i4>' + sheets.length + '</vt:i4></vt:variant>');
+    if (isSinglePage) rst.push('<vt:variant><vt:i4>1</vt:i4></vt:variant>')
+    else rst.push('<vt:variant><vt:i4>' + sheets.length + '</vt:i4></vt:variant>');
     rst.push('</vt:vector>');
     rst.push('</HeadingPairs>');
     rst.push('<TitlesOfParts>');
-    rst.push('<vt:vector size="' + sheets.length + '" baseType="lpstr">');
-    for (let i = 0; i < sheets.length; i++) {
-        rst.push('<vt:lpstr>' + sheets[i].sheetName + '</vt:lpstr>')
+    if (isSinglePage) {
+        rst.push('<vt:vector size="1" baseType="lpstr">');
+        rst.push('<vt:lpstr>' + sheets[0].sheetName + '</vt:lpstr>')
+    } else {
+        rst.push('<vt:vector size="' + sheets.length + '" baseType="lpstr">');
+        for (let i = 0; i < sheets.length; i++) {
+            rst.push('<vt:lpstr>' + sheets[i].sheetName + '</vt:lpstr>')
+        }
     }
     rst.push('</vt:vector>');
     rst.push('</TitlesOfParts>');
@@ -88,7 +98,7 @@ function writeCore() {
     rst.push('</cp:coreProperties>');
     return rst;
 }
-function writeXlWorkBook(sheets){
+function writeXlWorkBook(sheets, isSinglePage){
     let rst = [];
     rst.push(dftHeadXml + '\r\n');
     rst.push('<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
@@ -96,8 +106,12 @@ function writeXlWorkBook(sheets){
     rst.push('<workbookPr defaultThemeVersion="124226"/>');
     rst.push('<bookViews><workbookView xWindow="360" yWindow="345" windowWidth="14655" windowHeight="4305"/></bookViews>');
     rst.push('<sheets>');
-    for (let i = 0; i < sheets.length; i++) {
-        rst.push('<sheet name="' + sheets[i].sheetName + '" sheetId="' + (i + 1) + '" r:id="rId' + (i + 1) + '"/>')
+    if (isSinglePage) {
+        rst.push('<sheet name="' + sheets[0].sheetName + '" sheetId="1" r:id="rId1"/>');
+    } else {
+        for (let i = 0; i < sheets.length; i++) {
+            rst.push('<sheet name="' + sheets[i].sheetName + '" sheetId="' + (i + 1) + '" r:id="rId' + (i + 1) + '"/>');
+        }
     }
     rst.push('</sheets>');
     rst.push('<calcPr calcId="124519"/>');
@@ -105,13 +119,18 @@ function writeXlWorkBook(sheets){
     rst.push('</workbook>');
     return rst;
 }
-function writeXlRels(sheets){
+function writeXlRels(sheets, isSinglePage){
     let rst = [], idx = 1;
     rst.push(dftHeadXml + '\r\n');
     rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
-    for (let i = 0; i < sheets.length; i++) {
-        rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet' + (i + 1) + '.xml"/>')
+    if (isSinglePage) {
+        rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>')
         idx++;
+    } else {
+        for (let i = 0; i < sheets.length; i++) {
+            rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet' + (i + 1) + '.xml"/>')
+            idx++;
+        }
     }
     rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>');
     idx++;
@@ -213,7 +232,7 @@ function writeSharedString(sharedStrList){
     }
     return rst;
 }
-function writeSheets(pageData, sharedStrList, stylesObj){
+function writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage){
     let rst = [];
     private_pushDftFont = function(){
         let font = {};
@@ -221,52 +240,73 @@ function writeSheets(pageData, sharedStrList, stylesObj){
             stylesObj.fonts = [];
         }
         font[JV.FONT_PROPS[0]] = "宋体"; //font name
-        font.size = 11;
+        font.size = 12;
         font.charset = 134;
         font.colorIdx = "8";
         stylesObj.fonts.push(font);
     };
     private_pushDftFont();
-    for (let i = 0; i < pageData.items.length; i++) {
-        rst.push(writeSheet(pageData, pageData.items[i], sharedStrList, stylesObj));
+    if (isSinglePage) {
+        rst.push(writeSheet(pageData, null, paperSize, sharedStrList, stylesObj));
+    } else {
+        for (let i = 0; i < pageData.items.length; i++) {
+            rst.push(writeSheet(pageData, pageData.items[i], paperSize, sharedStrList, stylesObj));
+        }
     }
     return rst;
 }
-function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
-    let rst = [], xPos = [], yPos = [], headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj){
+    let rst = [], xPos = [], yPos = [], yMultiPos = [], headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     let cacheBorderCell = {};
-    xPos.push(0);
-    yPos.push(0);
     private_pre_analyze_pos = function(){
         let cell, pos;
-        sheetData.cells.sort(function(cell1, cell2) {
-            let rst = 0;
-            if (cell1[JV.PROP_AREA][JV.PROP_TOP] > cell2[JV.PROP_AREA][JV.PROP_TOP]) {
-                rst = 1;
-            } else if (cell1[JV.PROP_AREA][JV.PROP_TOP] < cell2[JV.PROP_AREA][JV.PROP_TOP]) {
-                rst = -1;
-            } else {
-                if (cell1[JV.PROP_AREA][JV.PROP_LEFT] > cell2[JV.PROP_AREA][JV.PROP_LEFT]) {
+        self_analyze_sheet_pos = function (theShtData, theXPos, theYPos) {
+            theShtData.cells.sort(function(cell1, cell2) {
+                let rst = 0;
+                if (cell1[JV.PROP_AREA][JV.PROP_TOP] > cell2[JV.PROP_AREA][JV.PROP_TOP]) {
                     rst = 1;
-                } else if (cell1[JV.PROP_AREA][JV.PROP_LEFT] < cell2[JV.PROP_AREA][JV.PROP_LEFT]) {
+                } else if (cell1[JV.PROP_AREA][JV.PROP_TOP] < cell2[JV.PROP_AREA][JV.PROP_TOP]) {
                     rst = -1;
+                } else {
+                    if (cell1[JV.PROP_AREA][JV.PROP_LEFT] > cell2[JV.PROP_AREA][JV.PROP_LEFT]) {
+                        rst = 1;
+                    } else if (cell1[JV.PROP_AREA][JV.PROP_LEFT] < cell2[JV.PROP_AREA][JV.PROP_LEFT]) {
+                        rst = -1;
+                    }
                 }
+                return rst;
+            });
+            for (let i = 0; i < theShtData.cells.length; i++) {
+                cell = theShtData.cells[i];
+                pos = cell[JV.PROP_AREA][JV.PROP_LEFT];
+                if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
+                pos = cell[JV.PROP_AREA][JV.PROP_RIGHT];
+                if (theXPos.indexOf(pos) < 0) theXPos.push(pos);
+                pos = cell[JV.PROP_AREA][JV.PROP_TOP];
+                if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
+                pos = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
+                if (theYPos.indexOf(pos) < 0) theYPos.push(pos);
+            }
+        };
+        xPos.push(0);
+        if (sheetData) {
+            //current sheet data
+            yPos.push(0);
+            self_analyze_sheet_pos(sheetData, xPos, yPos);
+            xPos.sort(private_array_sort);
+            yPos.sort(private_array_sort);
+        } else {
+            //total data in one sheet
+            for (let shtItemData of pageData.items) {
+                let tmpPos = [];
+                tmpPos.push(0);
+                self_analyze_sheet_pos(shtItemData, xPos, tmpPos);
+                tmpPos.sort(private_array_sort);
+                yMultiPos.push(tmpPos);
             }
-            return rst;
-        });
-        for (let i = 0; i < sheetData.cells.length; i++) {
-            cell = sheetData.cells[i];
-            pos = cell[JV.PROP_AREA][JV.PROP_LEFT];
-            if (xPos.indexOf(pos) < 0) xPos.push(pos);
-            pos = cell[JV.PROP_AREA][JV.PROP_RIGHT];
-            if (xPos.indexOf(pos) < 0) xPos.push(pos);
-            pos = cell[JV.PROP_AREA][JV.PROP_TOP];
-            if (yPos.indexOf(pos) < 0) yPos.push(pos);
-            pos = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
-            if (yPos.indexOf(pos) < 0) yPos.push(pos);
-        }
-        xPos.sort(private_array_sort);
-        yPos.sort(private_array_sort);
+            xPos.sort(private_array_sort);
+            yPos = yMultiPos[0];
+        }
     };
     private_array_sort = function(i1, i2){
         let rst = 0;
@@ -466,15 +506,28 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
         let cell, idxR, idxL, idxT, idxB, cnt = 0;
         rst.push('<mergeCells count="?">');
         let startIdx = rst.length - 1;
-        for (let i = 0; i < sheetData.cells.length; i++) {
-            cell = sheetData.cells[i];
-            idxR = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_RIGHT]);
-            idxL = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_LEFT]);
-            idxB = yPos.indexOf(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
-            idxT = yPos.indexOf(cell[JV.PROP_AREA][JV.PROP_TOP]);
-            if (idxR - idxL > 1 || idxB - idxT > 1) {
-                rst.push('<mergeCell ref="' + private_getCellIdxStr(idxL - 1) + idxT + ':' + private_getCellIdxStr(idxR - 2) + (idxB - 1) + '"/>');
-                cnt++;
+        self_setMergedCells = function (theData, theYPos, offsetY) {
+            for (let i = 0; i < theData.cells.length; i++) {
+                cell = theData.cells[i];
+                idxR = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_RIGHT]);
+                idxL = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_LEFT]);
+                idxB = theYPos.indexOf(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
+                idxT = theYPos.indexOf(cell[JV.PROP_AREA][JV.PROP_TOP]);
+                if (idxR - idxL > 1 || idxB - idxT > 1) {
+                    rst.push('<mergeCell ref="' + private_getCellIdxStr(idxL - 1) + (idxT + offsetY) + ':' + private_getCellIdxStr(idxR - 2) + (idxB - 1 + offsetY) + '"/>');
+                    cnt++;
+                }
+            }
+        }
+        if (sheetData) {
+            self_setMergedCells(sheetData, yPos, 0);
+        } else {
+            let osY = 0;
+            for (let i = 0; i < pageData.items.length; i++) {
+                let shtItemData = pageData.items[i];
+                let tmpPos = yMultiPos[i];
+                self_setMergedCells(shtItemData, tmpPos, osY);
+                osY += tmpPos.length;
             }
         }
         rst[startIdx] = '<mergeCells count="' + cnt + '">';
@@ -482,10 +535,10 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
     };
     private_chkIfNeedCacheCell = function(cell){
         let rst = false;
-        if (cell[JV.PROP_AREA][JV.PROP_LEFT] == pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_LEFT] ||
-            cell[JV.PROP_AREA][JV.PROP_RIGHT] == pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_RIGHT] ||
-            cell[JV.PROP_AREA][JV.PROP_TOP] == pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_TOP] ||
-            cell[JV.PROP_AREA][JV.PROP_BOTTOM] == pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_BOTTOM]){
+        if (cell[JV.PROP_AREA][JV.PROP_LEFT] === pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_LEFT] ||
+            cell[JV.PROP_AREA][JV.PROP_RIGHT] === pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_RIGHT] ||
+            cell[JV.PROP_AREA][JV.PROP_TOP] === pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_TOP] ||
+            cell[JV.PROP_AREA][JV.PROP_BOTTOM] === pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_BOTTOM]){
             if (cell[JV.PROP_AREA][JV.PROP_LEFT] >= pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_LEFT] &&
                 cell[JV.PROP_AREA][JV.PROP_RIGHT] <= pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_RIGHT] &&
                 cell[JV.PROP_AREA][JV.PROP_TOP] >= pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_TOP] &&
@@ -497,22 +550,35 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
     };
     private_cacheMergeBandBorderIdxs = function() {
         let cell, idxR, idxL, idxT, idxB;
-        for (let i = 0; i < sheetData.cells.length; i++) {
-            cell = sheetData.cells[i];
-            idxR = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_RIGHT]);
-            idxL = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_LEFT]);
-            idxB = yPos.indexOf(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
-            idxT = yPos.indexOf(cell[JV.PROP_AREA][JV.PROP_TOP]);
-            if (idxR - idxL > 1 || idxB - idxT > 1) {
-                if (private_chkIfNeedCacheCell(cell)) {
-                    for (let xi = idxL; xi < idxR; xi++) {
-                        for (let yj = idxT; yj < idxB; yj++) {
-                            cacheBorderCell[private_getCellIdxStr(xi - 1) + yj] = cell;
+        self_cachMergeIdxs = function (theData, theYPos, offsetY) {
+            for (let i = 0; i < theData.cells.length; i++) {
+                cell = theData.cells[i];
+                idxR = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_RIGHT]);
+                idxL = xPos.indexOf(cell[JV.PROP_AREA][JV.PROP_LEFT]);
+                idxB = theYPos.indexOf(cell[JV.PROP_AREA][JV.PROP_BOTTOM]);
+                idxT = theYPos.indexOf(cell[JV.PROP_AREA][JV.PROP_TOP]);
+                if (idxR - idxL > 1 || idxB - idxT > 1) {
+                    if (private_chkIfNeedCacheCell(cell)) {
+                        for (let xi = idxL; xi < idxR; xi++) {
+                            for (let yj = idxT; yj < idxB; yj++) {
+                                cacheBorderCell[private_getCellIdxStr(xi - 1) + yj + offsetY] = cell;
+                            }
                         }
                     }
                 }
             }
         }
+        if (sheetData) {
+            self_cachMergeIdxs(sheetData, yPos, 0);
+        } else {
+            let osY = 0;
+            for (let i = 0; i < pageData.items.length; i++) {
+                let shtItemData = pageData.items[i];
+                let tmpPos = yMultiPos[i];
+                self_cachMergeIdxs(shtItemData, tmpPos, osY);
+                osY += tmpPos.length;
+            }
+        }
     };
     private_getMergedCellStyleId = function(preStyleId, colIdxStr) {
         let rst = preStyleId;
@@ -526,80 +592,98 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
         rst.push('<sheetData>');
         let spanX = xPos.length - 2, cellIdx = 0, h = 0,
             hasMoreCols = true, nextColIdx = -1,
-            nextRowIdx = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP])
+            nextRowIdx = 0
             ;
-        private_cacheMergeBandBorderIdxs();
-        for (let i = 1; i < yPos.length - 1; i++) {
-            h = 1.0 * (yPos[i+1] - yPos[i]) / DPI * 25.4 / 0.3612;
-            h = Math.round(h * 1000) / 1000;
-            rst.push('<row r="' + i + '" spans="1:' + spanX + '" ht="' + h + '" customHeight="1">');
-            //then put the cells of this row
-            let colIdxStr = '';
-            hasMoreCols = true;
-            while (nextRowIdx < i) {
-                if (cellIdx >= sheetData.cells.length || nextRowIdx > i) {
-                    break;
-                } else {
-                    cellIdx++;
-                    nextRowIdx = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
-                }
-            }
-            if (nextRowIdx > i) {
-                hasMoreCols = false;
-            }
-            nextColIdx = xPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_LEFT]);
-            let preStyleIdx = 1;
-            for (let j = 1; j < xPos.length - 1; j++) {
-                colIdxStr = private_getCellIdxStr(j - 1);
-                if (hasMoreCols) {
-                    if (nextColIdx == j) {
-                        let styleIdx = private_getStyleId(sheetData.cells[cellIdx]);
-                        preStyleIdx = styleIdx;
-                        if (strUtil.isEmptyString(sheetData.cells[cellIdx][JV.PROP_VALUE])) {
-                            rst.push('<c r="' + colIdxStr + i + '" s="' + styleIdx + '"/>');
-                            //should setup the right style instead!
-                        } else {
-                            let valIdx = private_getSharedStrIdx(sheetData.cells[cellIdx][JV.PROP_VALUE]);
-                            rst.push('<c r="' + colIdxStr + i + '" s="' + styleIdx + '" t="s">');
-                            rst.push('<v>' + valIdx + '</v>');
-                            rst.push('</c>');
-                        }
+        self_setData = function (theShtData, theYPos, offsetY) {
+            for (let i = 1; i < theYPos.length - 1; i++) {
+                h = (theYPos[i+1] - theYPos[i]) / DPI * 25.4 / 0.3612;
+                h = Math.round(h * 1000) / 1000;
+                rst.push('<row r="' + (i + offsetY) + '" spans="1:' + spanX + '" ht="' + h + '" customHeight="1">');
+                let colIdxStr = '';
+                hasMoreCols = true;
+                while (nextRowIdx < i) {
+                    if (cellIdx >= theShtData.cells.length || nextRowIdx > i) {
+                        break;
+                    } else {
                         cellIdx++;
-                        if (cellIdx < sheetData.cells.length) {
-                            nextRowIdx = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
-                            if (nextRowIdx > i) {
-                                hasMoreCols = false;
+                        nextRowIdx = theYPos.indexOf(theShtData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
+                    }
+                }
+                if (nextRowIdx > i) {
+                    hasMoreCols = false;
+                }
+                nextColIdx = xPos.indexOf(theShtData.cells[cellIdx][JV.PROP_AREA][JV.PROP_LEFT]);
+                let preStyleIdx = 1;
+                for (let j = 1; j < xPos.length - 1; j++) {
+                    colIdxStr = private_getCellIdxStr(j - 1);
+                    if (hasMoreCols) {
+                        if (nextColIdx == j) {
+                            let styleIdx = private_getStyleId(theShtData.cells[cellIdx]);
+                            preStyleIdx = styleIdx;
+                            if (strUtil.isEmptyString(theShtData.cells[cellIdx][JV.PROP_VALUE])) {
+                                rst.push('<c r="' + colIdxStr + (i + offsetY) + '" s="' + styleIdx + '"/>');
+                                //should setup the right style instead!
                             } else {
-                                nextColIdx = xPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_LEFT]);
+                                let valIdx = private_getSharedStrIdx(theShtData.cells[cellIdx][JV.PROP_VALUE]);
+                                rst.push('<c r="' + colIdxStr + (i + offsetY) + '" s="' + styleIdx + '" t="s">');
+                                rst.push('<v>' + valIdx + '</v>');
+                                rst.push('</c>');
                             }
-                        } else {
+                            cellIdx++;
+                            if (cellIdx < theShtData.cells.length) {
+                                nextRowIdx = theYPos.indexOf(theShtData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
+                                if (nextRowIdx > i) {
+                                    hasMoreCols = false;
+                                } else {
+                                    nextColIdx = xPos.indexOf(theShtData.cells[cellIdx][JV.PROP_AREA][JV.PROP_LEFT]);
+                                }
+                            } else {
+                                hasMoreCols = false;
+                            }
+                        } else if (nextColIdx < 0) {
+                            //impossible!
+                            console.log('has abnormal case!');
                             hasMoreCols = false;
+                        } else {
+                            //rst.push('<c r="' + colIdxStr + (i + offsetY) + '" s="' + preStyleIdx + '"/>');
+                            rst.push('<c r="' + colIdxStr + (i + offsetY) + '" s="' + private_getMergedCellStyleId(preStyleIdx, colIdxStr + i + offsetY) + '"/>');
                         }
-                    } else if (nextColIdx < 0) {
-                        //impossible!
-                        console.log('has abnormal case!');
-                        hasMoreCols = false;
                     } else {
-                        //rst.push('<c r="' + colIdxStr + i + '" s="' + preStyleIdx + '"/>');
-                        rst.push('<c r="' + colIdxStr + i + '" s="' + private_getMergedCellStyleId(preStyleIdx, colIdxStr + i) + '"/>');
+                        //rst.push('<c r="' + colIdxStr + (i + offsetY) + '" s="' + preStyleIdx + '"/>');
+                        rst.push('<c r="' + colIdxStr + (i + offsetY) + '" s="' + private_getMergedCellStyleId(preStyleIdx, colIdxStr + i + offsetY) + '"/>');
                     }
-                } else {
-                    //rst.push('<c r="' + colIdxStr + i + '" s="' + preStyleIdx + '"/>');
-                    rst.push('<c r="' + colIdxStr + i + '" s="' + private_getMergedCellStyleId(preStyleIdx, colIdxStr + i) + '"/>');
                 }
+                rst.push('</row>');
+            }
+        }
+        private_cacheMergeBandBorderIdxs();
+        if (sheetData) {
+            //current sheet data
+            nextRowIdx = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
+            self_setData(sheetData, yPos, 0);
+        } else {
+            //total data in one sheet
+            let cnt = 0;
+            for (let i = 0; i < pageData.items.length; i++) {
+                let shtItemData = pageData.items[i];
+                let tmpPos = yMultiPos[i];
+                cellIdx = 0;
+                nextRowIdx = tmpPos.indexOf(shtItemData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
+                self_setData(shtItemData, tmpPos, cnt);
+                cnt += tmpPos.length;
             }
-            rst.push('</row>');
         }
-        //sheetData.cells.length
         rst.push('</sheetData>');
     };
+
     private_pre_analyze_pos();
     rst.push(dftHeadXml + '\r\n');
     rst.push('<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
     let colStr = private_getCellIdxStr(xPos.length - 3);
     rst.push('<dimension ref="A1:' + colStr + '' + yPos.length + '"/>');
     rst.push('<sheetViews><sheetView tabSelected="1" workbookViewId="0">');
-    rst.push('<selection sqref="A1:' + colStr + '1"/>');
+    //rst.push('<selection sqref="A1:' + colStr + '1"/>');
+    rst.push('<selection sqref="A1:A1"/>');
     rst.push('</sheetView></sheetViews>');
     rst.push('<sheetFormatPr defaultRowHeight="13.5"/>');
     private_setCols();
@@ -607,23 +691,37 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
     private_setMergedCells();
     rst.push('<phoneticPr fontId="1" type="noConversion"/>');
     rst.push('<pageMargins left="0.315" right="0.215" top="0.315" bottom="0.315" header="0" footer="0"/>');
-    //rst.push('<pageSetup paperSize="9" fitToWidth="0" fitToHeight="0" orientation="landscape" horizontalDpi="300" verticalDpi="300"/>');
+    let paperSizeIdx = JV.PAGES_SIZE_STR.indexOf(paperSize);
+    let pStr = '';
+    if (paperSizeIdx >= 0) {
+        pStr = 'paperSize="' + JV.PAGES_SIZE_IDX[paperSizeIdx] + '"';
+    }
+    let orientationStr = (pageData[JV.NODE_PAGE_INFO][0] > pageData[JV.NODE_PAGE_INFO][1])?'landscape':'portrait';
+    rst.push('<pageSetup ' + pStr + ' fitToWidth="0" fitToHeight="0" orientation="' + orientationStr + '" />');
     rst.push('<headerFooter alignWithMargins="0"/>');
     rst.push('</worksheet>');
-    //rst.push('');
     return rst;
 }
 
 module.exports = {
-    exportExcel: function (pageData, fName, options, callback) {
-        let rptOptions = (options || {singlePage: false, fileName: 'report'});
+    exportExcel: function (pageData, paperSize, fName, options, callback) {
+        let rptOptions = ({singlePage: false, fileName: 'report'});
+        if (options === 'true') {
+            rptOptions.singlePage = true;
+        }
+        let isSinglePage = rptOptions.singlePage;
         let sheets = [];
+        if (isSinglePage) {
+            //
+        } else {
+            //
+        }
         for (let i = 0; i < pageData.items.length; i++) {
             sheets.push({sheetName: '第' + (i + 1) + '页'});
         }
         //1.
         let file = '[Content_Types].xml';
-        let data = writeContentTypes(sheets);
+        let data = writeContentTypes(sheets, isSinglePage);
         let zip = new JSZip();
         zip.file(file, data.join(''), {compression: 'DEFLATE'});
         //2.
@@ -634,7 +732,7 @@ module.exports = {
         //3.
         let zip_docProps = zip.folder('docProps');
         file = 'app.xml';
-        data = writeApp(sheets);
+        data = writeApp(sheets, isSinglePage);
         zip_docProps.file(file, data.join(''), {compression: 'DEFLATE'});
         file = 'core.xml';
         data = writeCore();
@@ -642,11 +740,11 @@ module.exports = {
         //4.
         let zip_xl = zip.folder('xl');
         file = 'workbook.xml';
-        data = writeXlWorkBook(sheets);
+        data = writeXlWorkBook(sheets, isSinglePage);
         zip_xl.file(file, data.join(''), {compression: 'DEFLATE'});
         let zip_rels2 = zip_xl.folder('_rels');
         file = 'workbook.xml.rels';
-        data = writeXlRels(sheets);
+        data = writeXlRels(sheets, isSinglePage);
         zip_rels2.file(file, data.join(''), {compression: 'DEFLATE'});
         //5.
         let zip_theme = zip_xl.folder('theme');
@@ -656,10 +754,17 @@ module.exports = {
         //6.
         let zip_worksheets = zip_xl.folder('worksheets');
         let sharedStrList = [], stylesObj = {};
-        data = writeSheets(pageData, sharedStrList, stylesObj);
-        for (let i = 0; i < data.length; i++) {
-            file = 'sheet' + (i + 1) + '.xml';
-            zip_worksheets.file(file, data[i].join(''), {compression: 'DEFLATE'});
+        data = writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage);
+        if (isSinglePage) {
+            for (let i = 0; i < 1; i++) {
+                file = 'sheet' + (i + 1) + '.xml';
+                zip_worksheets.file(file, data[i].join(''), {compression: 'DEFLATE'});
+            }
+        } else {
+            for (let i = 0; i < data.length; i++) {
+                file = 'sheet' + (i + 1) + '.xml';
+                zip_worksheets.file(file, data[i].join(''), {compression: 'DEFLATE'});
+            }
         }
         file = 'sharedStrings.xml';
         data = writeSharedString(sharedStrList);

+ 1 - 0
public/web/rpt_value_define.js

@@ -188,6 +188,7 @@ let JV = {
     PAGE_SELF_DEFINE: "自定义",
 
     PAGES_SIZE_STR: ["A3", "A4", "A5", "B5", "LETTER", "LEGAL", "EXECUTIVE", "16K"],
+    PAGES_SIZE_IDX: [8, 9, 11, 13, 1, 5, 7, 93],
     PAGES_SIZE: [[11.69, 16.54], [8.27, 11.69], [5.83, 8.27], [6.93, 9.84], [8.5, 11.0], [8.5, 14.0], [7.25, 10.5], [7.25, 10.5]],
 
     HUNDRED_PERCENT : 100.0,