Browse Source

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost

zhangyin 8 years ago
parent
commit
fccccb8f50

+ 194 - 29
modules/reports/util/rpt_excel_util.js

@@ -46,7 +46,7 @@ function writeApp(sheets) {
     rst.push('<ScaleCrop>false</ScaleCrop>');
     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:lpstr>工作�?</vt:lpstr></vt:variant>');
     rst.push('<vt:variant><vt:i4>' + sheets.length + '</vt:i4></vt:variant>');
     rst.push('</vt:vector>');
     rst.push('</HeadingPairs>');
@@ -79,7 +79,7 @@ function writeCore() {
     rst.push('<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">');
     rst.push('<dc:creator>SmartCost</dc:creator>');
     rst.push('<cp:lastModifiedBy>SmartCost</cp:lastModifiedBy>');
-    var dt = new Date(), dtStr = dt.getFullYear() + '-' + p_fillZero(dt.getMonth()) + '-' + p_fillZero(dt.getDate()) + 'T' +
+    var dt = new Date(), dtStr = dt.getFullYear() + '-' + p_fillZero(dt.getMonth()+1) + '-' + p_fillZero(dt.getDate()) + 'T' +
         p_fillZero(dt.getHours()) + ':' + p_fillZero(dt.getMinutes()) + ':' + p_fillZero(dt.getSeconds()) + 'Z';
     rst.push('<dcterms:created xsi:type="dcterms:W3CDTF">' + dtStr + '</dcterms:created>');
     rst.push('<dcterms:modified xsi:type="dcterms:W3CDTF">' + dtStr + '</dcterms:modified>');
@@ -122,23 +122,35 @@ function writeXlRels(sheets){
     return rst;
 }
 function writeTheme(){
-    var rst = fs.readFileSync('./excel_base_files/theme1.xml', 'utf8', 'r');
+    var rst = fs.readFileSync(__dirname + '/excel_base_files/theme1.xml', 'utf8', 'r');
     return rst;
 }
-function writeStyles(styleList){
+function writeStyles(stylesObj){
     //
 }
 function writeSharedString(sharedStrList){
-    //
+    var rst = [];
+    if (sharedStrList && sharedStrList.length > 0) {
+        rst.push(dftHeadXml + '\r\n');
+        rst.push('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="' + sharedStrList.length + '" uniqueCount="' + sharedStrList.length + '">');
+        for (var i = 0; i < sharedStrList.length; i++) {
+            rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
+        }
+        rst.push('</sst>');
+    }
+    return rst;
 }
-function writeSheets(pageData){
-    var rst = [], sharedStrList = [];
+function writeSheets(pageData, sharedStrList, stylesObj){
+    var rst = [];
     for (var i = 0; i < pageData.items.length; i++) {
-        //
+        rst.push(writeSheet(pageData.items[i], sharedStrList, stylesObj));
     }
+    return rst;
 }
-function writeSheet(sheetData, sharedStrList, styleList){
-    var rst = [], xPos = [0], yPos = [0], headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+function writeSheet(sheetData, sharedStrList, stylesObj){
+    var rst = [], xPos = [], yPos = [], headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+    xPos.push(0);
+    yPos.push(0);
     private_pre_analyze_pos = function(){
         var cell, pos;
         sheetData.cells.sort(function(cell1, cell2) {
@@ -154,6 +166,7 @@ function writeSheet(sheetData, sharedStrList, styleList){
                     rst = -1;
                 }
             }
+            return rst;
         });
         for (var i = 0; i < sheetData.cells.length; i++) {
             cell = sheetData.cells[i];
@@ -166,8 +179,14 @@ function writeSheet(sheetData, sharedStrList, styleList){
             pos = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
             if (yPos.indexOf(pos) < 0) yPos.push(pos);
         }
-        xPos.sort();
-        yPos.sort();
+        xPos.sort(private_array_sort);
+        yPos.sort(private_array_sort);
+    };
+    private_array_sort = function(i1, i2){
+        var rst = 0;
+        if (i1 > i2) {rst = 1} else
+        if (i1 < i2) rst = -1;
+        return rst;
     };
     private_getCellIdxStr = function(idx){
         var rst = 'A';
@@ -190,18 +209,132 @@ function writeSheet(sheetData, sharedStrList, styleList){
         }
         return rst;
     };
+    private_getFontId = function(cell) {
+        var rst = 0, hasFont = false;
+        if (!(stylesObj.fonts)) {
+            stylesObj.fonts = [];
+            //for (var i = 0; i < sheetData.font_collection)
+        }
+        var sheetFont = sheetData.font_collection[cell.font];
+        for (var i = 0; i < stylesObj.fonts.length; i++) {
+            var font = stylesObj.fonts[i];
+            if (sheetFont) {
+                if (font[JV.FONT_PROPS[0]] === sheetFont[JV.FONT_PROPS[0]] && font.size === Math.round(sheetFont[JV.FONT_PROPS[1]] * 3 / 4)) {
+                    hasFont = true;
+                    rst = i;
+                    break;
+                }
+            } else {
+                break;
+            }
+        }
+        if (!hasFont) {
+            var font = {};
+            font[JV.FONT_PROPS[0]] = sheetFont[JV.FONT_PROPS[0]];
+            font.size = Math.round(sheetFont[JV.FONT_PROPS[1]] * 3 / 4);
+            font.charset = 134;
+            font.scheme = "minor";
+            stylesObj.fonts.push(font);
+            rst = stylesObj.fonts.length - 1;
+        }
+        return rst;
+    };
+    private_checkBorder = function(border, sheetBorder) {
+        var rst = true, borderLineWidths = [], sheetBorderLineWidths = [];
+        borderLineWidths.push(border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]);
+        borderLineWidths.push(border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]);
+        borderLineWidths.push(border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]);
+        borderLineWidths.push(border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]);
+        if (sheetBorder[JV.PROP_LEFT] && sheetBorder[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]) {
+            sheetBorderLineWidths.push(parseInt(border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]));
+        } else {
+            sheetBorderLineWidths.push(0);
+        }
+        if (sheetBorder[JV.PROP_RIGHT] && sheetBorder[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]) {
+            sheetBorderLineWidths.push(parseInt(border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]));
+        } else {
+            sheetBorderLineWidths.push(0);
+        }
+        if (sheetBorder[JV.PROP_TOP] && sheetBorder[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]) {
+            sheetBorderLineWidths.push(parseInt(border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]));
+        } else {
+            sheetBorderLineWidths.push(0);
+        }
+        if (sheetBorder[JV.PROP_BOTTOM] && sheetBorder[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]) {
+            sheetBorderLineWidths.push(parseInt(border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]));
+        } else {
+            sheetBorderLineWidths.push(0);
+        }
+        for (var i = 0; i < 4; i++) {
+            if (borderLineWidths[i] != sheetBorderLineWidths[i]) {
+                rst = false;
+                break;
+            }
+        }
+        return rst;
+    };
+    private_getBorderId = function(cell) {
+        var rst = 0, hasBorder = false;
+        if (!(stylesObj.borders)) {
+            stylesObj.borders = [];
+        }
+        var sheetBorder = sheetData.style_collection[cell.style];
+        for (var i = 0; i < stylesObj.borders.length; i++) {
+            var border = stylesObj.borders[i];
+            if (private_checkBorder(border, sheetBorder)) {
+                hasBorder = true;
+                rst = i;
+                break;
+            }
+        }
+        if (!hasBorder) {
+            var border = {};
+            border[JV.PROP_LEFT] = {};
+            border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = 0;
+            border[JV.PROP_RIGHT] = {};
+            border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = 0;
+            border[JV.PROP_TOP] = {};
+            border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = 0;
+            border[JV.PROP_BOTTOM] = {};
+            border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = 0;
+            if (sheetBorder && sheetBorder[JV.PROP_LEFT]) {
+                border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = parseInt(sheetBorder[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]);
+            }
+            if (sheetBorder && sheetBorder[JV.PROP_RIGHT]) {
+                border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = parseInt(sheetBorder[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]);
+            }
+            if (sheetBorder && sheetBorder[JV.PROP_TOP]) {
+                border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = parseInt(sheetBorder[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]);
+            }
+            if (sheetBorder && sheetBorder[JV.PROP_BOTTOM]) {
+                border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = parseInt(sheetBorder[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]);
+            }
+            stylesObj.borders.push(border);
+            rst = stylesObj.borders.length - 1;
+        }
+        return rst;
+    };
     private_getStyleIdx = function(cell) {
-        var rst = 1;
-        //
+        var rst = 1, hasStyle = false;
+        if (!(stylesObj.cellXfs)) stylesObj.cellXfs = [];
+        for (var i = 0; i < stylesObj.cellXfs.length; i++) {
+            //check font and border
+            var fontId = private_getFontId(cell);
+            var cellStyle = stylesObj.cellXfs[i];
+        }
+        if (!hasStyle) {
+            //add new style
+        }
         return rst;
     };
     private_setCols = function(){
+        //remark: 1 excel width = 2.117 mm
         rst.push('<cols>');
         var w = 0;
         for (var i = 1; i < xPos.length; i++) {
-            w = 1.0 * (xPos[i] - xPos[i - 1]) / DPI;
+            w = 1.0 * (xPos[i] - xPos[i - 1]) / DPI * 25.4 / 2.117;
             w = Math.round(w * 1000) / 1000;
-            rst.push('<col min="1" max="1" width="' + w + '" customWidth="1"/>');
+            rst.push('<col min="' + i +'" max="' + i +'" width="' + w + '" customWidth="1"/>');
         }
         rst.push('</cols>');
     };
@@ -224,18 +357,19 @@ function writeSheet(sheetData, sharedStrList, styleList){
         rst.push('</mergeCells>');
     };
     private_setSheetData = function(){
+        //remark: 1 excel height = 0.3612 mm
         rst.push('<sheetData>');
         var spanX = xPos.length - 1, cellIdx = 0, h = 0,
             hasMoreCols = true, nextColIdx = -1,
             nextRowIdx = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
-        for (var i = 0; i < yPos.length - 1; i++) {
+        for (var i = 1; i < yPos.length - 1; i++) {
             if (i === 0) {
-                h = 1.0 * (yPos[i]) / DPI;
+                h = 1.0 * (yPos[i]) / DPI * 25.4 / 0.3612;
             } else {
-                h = 1.0 * (yPos[i] - yPos[i - 1]) / DPI;
+                h = 1.0 * (yPos[i] - yPos[i - 1]) / DPI * 25.4 / 0.3612;
             }
             h = Math.round(h * 1000) / 1000;
-            rst.push('<row r="' + (i+1) + '" spans="1:' + spanX + '" ht="' + h + '" customHeight="1">');
+            rst.push('<row r="' + i + '" spans="1:' + spanX + '" ht="' + h + '" customHeight="1">');
             //then put the cells of this row
             var colIdxStr = '';
             hasMoreCols = true;
@@ -257,33 +391,37 @@ function writeSheet(sheetData, sharedStrList, styleList){
                     if (nextColIdx == j) {
                         var styleIdx = private_getStyleIdx(sheetData.cells[cellIdx]);
                         if (strUtil.isEmptyString(sheetData.cells[cellIdx][JV.PROP_VALUE])) {
-                            rst.push('<c r="' + colIdxStr + (i+1) + '" s="' + styleIdx + '"/>');
+                            rst.push('<c r="' + colIdxStr + i + '" s="' + styleIdx + '"/>');
                             //should setup the right style instead!
                         } else {
                             var valIdx = private_getSharedStrIdx(sheetData.cells[cellIdx][JV.PROP_VALUE]);
-                            rst.push('<c r="' + colIdxStr + (i+1) + '" s="' + styleIdx + '">');
+                            rst.push('<c r="' + colIdxStr + i + '" s="' + styleIdx + '">');
                             rst.push('<v>' + valIdx + '</v>');
                             rst.push('</c>');
                         }
                         cellIdx++;
-                        nextRowIdx = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
-                        if (nextRowIdx > i) {
-                            hasMoreCols = false;
+                        if (cellIdx < sheetData.cells.length) {
+                            nextRowIdx = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
+                            if (nextRowIdx > i) {
+                                hasMoreCols = false;
+                            } else {
+                                nextColIdx = xPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_LEFT]);
+                            }
                         } else {
-                            nextColIdx = xPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_LEFT]);
+                            hasMoreCols = false;
                         }
                     } else if (nextColIdx < 0) {
                         //impossible!
                         console.log('has abnormal case!');
                         hasMoreCols = false;
                     } else {
-                        rst.push('<c r="' + colIdxStr + (i+1) + '" s="1"/>');
+                        rst.push('<c r="' + colIdxStr + i + '" s="1"/>');
                     }
                 } else {
-                    rst.push('<c r="' + colIdxStr + (i+1) + '" s="1"/>');
+                    rst.push('<c r="' + colIdxStr + i + '" s="1"/>');
                 }
             }
-            rst.push('</row');
+            rst.push('</row>');
         }
         //sheetData.cells.length
         rst.push('</sheetData>');
@@ -313,4 +451,31 @@ module.exports = {
     exportExcel: function (pageData, options) {
         var rptOptions = (options || {singlePage: false, fileName: 'report'});
     }
+    ,testWriteContentTypes: function(sheets) {
+        return writeContentTypes(sheets);
+    }
+    ,testWriteRootRels: function() {
+        return writeRootRels();
+    }
+    ,testWriteApp: function(sheets) {
+        return writeApp(sheets);
+    }
+    ,testWriteCore: function() {
+        return writeCore();
+    }
+    ,testWriteXlWorkBook: function(sheets) {
+        return writeXlWorkBook(sheets);
+    }
+    ,testWriteXlRels: function(sheets) {
+        return writeXlRels(sheets);
+    }
+    ,testWriteSheets: function(pageData, sharedStrList, styleList){
+        return writeSheets(pageData, sharedStrList, styleList);
+    }
+    ,testWriteSharedString: function(sharedStrList){
+        return writeSharedString(sharedStrList);
+    }
+    ,testWriteTheme: function() {
+        return writeTheme();
+    }
 }

+ 28 - 0
public/fsUtil.js

@@ -0,0 +1,28 @@
+/**
+ * Created by Tony on 2017/4/10.
+ */
+
+var fs = require('fs');
+
+module.exports = {
+    writeArrayToFile: function(arr, filePath) {
+        if (arr && filePath && Array.isArray(arr)) {
+            var chunks = [], len = 0;
+            for (var i = 0; i < arr.length; i++) {
+                var buffer = new Buffer(arr[i]);
+                chunks.push(buffer);
+                len += buffer.length;
+                //
+            }
+            var resultBuffer = new Buffer(len);
+            for(var i=0,size=chunks.length,pos=0;i<size;i++){
+                chunks[i].copy(resultBuffer,pos);
+                pos += chunks[i].length;
+            }
+            fs.writeFile(filePath, resultBuffer, function(err){
+                if(err) throw err;
+                console.log('Write file: ' + filePath + ' ok!');
+            });
+        }
+    }
+}

+ 31 - 0
public/stringUtil.js

@@ -8,5 +8,36 @@ module.exports = {
             rst = reg.test(str);
         }
         return rst;
+    },
+    convertNumToChinese : function(num, isCurrency) {
+        if (!/^\d*(\.\d*)?$/.test(num)) { return "Number is wrong!"; }
+        var AA, BB;
+        if (isCurrency) {
+            AA = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
+            BB = new Array("", "拾", "佰", "仟", "萬", "億", "点", "");
+        } else {
+            AA = ['零','一','二','三','四','五','六','七','八','九'];
+            BB = new Array("", "十", "百", "千", "万", "亿", "点", "");
+        }
+        //var AA = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
+        //var BB = new Array("", "拾", "佰", "仟", "萬", "億", "点", "");
+        var a = ("" + num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
+        for (var i = a[0].length - 1; i >= 0; i--) {
+            switch (k) {
+                case 0: re = BB[7] + re; break;
+                case 4: if (!new RegExp("0{4}\\d{" + (a[0].length - i - 1) + "}$").test(a[0]))
+                    re = BB[4] + re; break;
+                case 8: re = BB[5] + re; BB[7] = BB[5]; k = 0; break;
+            }
+            if (k % 4 == 2 && a[0].charAt(i + 2) != 0 && a[0].charAt(i + 1) == 0) re = AA[0] + re;
+            if (a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k % 4] + re; k++;
+        }
+
+        if (a.length > 1) //加上小数部分(如果有小数部分)
+        {
+            re += BB[6];
+            for (var i = 0; i < a[1].length; i++) re += AA[a[1].charAt(i)];
+        }
+        return re;
     }
 }

+ 3 - 12
public/web/idTree.js

@@ -205,16 +205,7 @@ var idTree = {
         };*/
         Node.prototype.serialNo = function () {
             return this.tree.items.indexOf(this);
-        }
-        /*Node.prototype.serialNo = function () {
-            if (this.preSibling) {
-                return this.preSibling.serialNo() + this.preSibling.posterityCount() + 1;
-            } else if (this.parent) {
-                return this.parent.serialNo() + 1;
-            } else {
-                return 0;
-            }
-        };*/
+        };
 
         Node.prototype.addChild = function (node) {
             var preSibling = this.children.length === 0 ? null : this.children[this.children.length - 1];
@@ -450,7 +441,7 @@ var idTree = {
             return success;
         };
 
-        Tree.prototype.editedData = function (field, id, newText) {
+        /*Tree.prototype.editedData = function (field, id, newText) {
             var node = this.findNode(id), result = {allow: false, nodes: []};
             if (this.event[this.eventType.editedData]) {
                 return this.event[this.eventType.editedData](field, node.data);
@@ -459,7 +450,7 @@ var idTree = {
                 result.allow = true;
                 return result;
             }
-        };
+        };*/
 
         Tree.prototype.bind = function (eventName, eventFun) {
             this.event[eventName] = eventFun;

+ 38 - 26
public/web/tree_sheet_controller.js

@@ -9,7 +9,7 @@ var TREE_SHEET_CONTROLLER = {
             this.sheet = sheet;
             this.setting = setting;
             this.event = {
-                treeSelectedChanged: null
+                refreshBaseActn: null
             }
         };
 
@@ -19,13 +19,10 @@ var TREE_SHEET_CONTROLLER = {
             TREE_SHEET_HELPER.showTreeData(this.setting, this.sheet, this.tree);
 
             this.sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e, info) {
-                that.tree.selected = that.tree.findNode(info.sheet.getTag(info.newSelections[0].row, info.newSelections[0].col));
-                if (that.event.treeSelectedChanged) {
-                    that.event.treeSelectedChanged(that.tree.selected);
-                }
+                that.setTreeSelected(that.tree.findNode(info.sheet.getTag(info.newSelections[0].row, info.newSelections[0].col)));
             });
 
-            this.sheet.bind(GC.Spread.Sheets.Events.EditEnded, function (sender, args) {
+            /*this.sheet.bind(GC.Spread.Sheets.Events.EditEnded, function (sender, args) {
                 var result = tree.editedData(setting.cols[args.col].data.field, args.sheet.getTag(args.row, args.col), args.editingText);
 
                 if (result.allow) {
@@ -33,35 +30,35 @@ var TREE_SHEET_CONTROLLER = {
                 } else {
                     TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [tree.findNode(args.sheet.getTag(args.row, args.col))], false);
                 };
-            });
+            });*/
         };
 
         controller.prototype.insert = function () {
-            var newNode = null, that = this;
-            if (this.tree && this.tree.selected) {
-                newNode = this.tree.insert(this.tree.selected.getParentID(), this.tree.selected.getNextSiblingID());
+            var newNode = null, that = this,  sels = this.sheet.getSelections();
+            if (this.tree) {
+                if (this.tree.selected) {
+                    newNode = this.tree.insert(this.tree.selected.getParentID(), this.tree.selected.getNextSiblingID());
+                } else {
+                    newNode = this.tree.insert();
+                }
                 if (newNode) {
                     TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
-                        var sels = that.sheet.getSelections();
-                        var iRow = sels[0].row, newNodeRow = iRow + that.tree.selected.posterityCount() + 1;
-                        that.sheet.addRows(newNodeRow, 1);
+                        that.sheet.addRows(newNode.serialNo(), 1);
                         TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [newNode], false);
-                        that.tree.selected = newNode;
+                        that.setTreeSelected(newNode);
                         that.sheet.setSelection(newNode.serialNo(), sels[0].col, 1, 1);
                         that.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center)
-                    })
+                    });
                 }
             }
         };
         controller.prototype.delete = function () {
-            var that = this;
+            var that = this, sels = this.sheet.getSelections();
             if (this.tree.selected) {
                 if (this.tree.delete(this.tree.selected)) {
                     TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
-                        var sels = that.sheet.getSelections();
-                        var iRow = sels[0].row;
-                        that.sheet.deleteRows(iRow, that.tree.selected.posterityCount() + 1);
-                        that.tree.selected = that.tree.findNode(that.sheet.getTag(iRow, 0, GC.Spread.Sheets.SheetArea.viewport));
+                        that.sheet.deleteRows(sels[0].row, that.tree.selected.posterityCount() + 1);
+                        that.setTreeSelected(that.tree.findNode(that.sheet.getTag(sels[0].row, 0, GC.Spread.Sheets.SheetArea.viewport)));
                     });
                 }
             }
@@ -73,6 +70,9 @@ var TREE_SHEET_CONTROLLER = {
                     TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
                         TREE_SHEET_HELPER.refreshNodesVisible([that.tree.selected], that.sheet, true);
                         that.sheet.showRow(that.tree.selected.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
+                        if (that.event.refreshBaseActn) {
+                            that.event.refreshBaseActn(that.tree);
+                        }
                     });
                 }
             }
@@ -84,37 +84,49 @@ var TREE_SHEET_CONTROLLER = {
                     TREE_SHEET_HELPER.massOperationSheet(that.sheet, function () {
                         TREE_SHEET_HELPER.refreshNodesVisible([that.tree.selected.parent], that.sheet, true);
                         that.sheet.showRow(that.tree.selected.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
+                        if (that.event.refreshBaseActn) {
+                            that.event.refreshBaseActn(that.tree);
+                        }
                     });
                 }
             }
         };
         controller.prototype.upMove = function () {
-            var that = this;
+            var that = this, sels = this.sheet.getSelections();
             if (this.tree.selected) {
                 if (this.tree.selected.upMove()) {
                     TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
-                        var sels = that.sheet.getSelections();
-                        var iRow = sels[0].row;
                         TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [that.tree.selected, that.tree.selected.nextSibling], true);
                         that.sheet.setSelection(that.tree.selected.serialNo(), sels[0].col, 1, 1);
+                        if (that.event.refreshBaseActn) {
+                            that.event.refreshBaseActn(that.tree);
+                        }
                     });
                 }
             }
         };
         controller.prototype.downMove = function () {
-            var that = this;
+            var that = this, sels = this.sheet.getSelections();
             if (this.tree.selected) {
                 if (this.tree.selected.downMove()) {
                     TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
-                        var sels = that.sheet.getSelections();
-                        var iRow = sels[0].row;
                         TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [that.tree.selected, that.tree.selected.preSibling], true);
                         that.sheet.setSelection(that.tree.selected.serialNo(), sels[0].col, 1, 1);
+                        if (that.event.refreshBaseActn) {
+                            that.event.refreshBaseActn(that.tree);
+                        }
                     });
                 }
             }
         };
 
+        controller.prototype.setTreeSelected = function (node) {
+            this.tree.selected = node;
+            if (this.event.refreshBaseActn) {
+                this.event.refreshBaseActn(this.tree);
+            }
+        }
+
         controller.prototype.bind = function (eventName, eventFun) {
             this.event[eventName] = eventFun;
         };

+ 7 - 2
test/demo/demo.js

@@ -29,8 +29,13 @@ test('', function(t){
 })
 
 test('default sorting...', function(t){
-    var arrSimple=new Array(1,8,7,6);
-    arrSimple.sort();
+    var arrSimple=new Array(1,8,7,6,10,11);
+    arrSimple.sort(function(i1, i2){
+        rst = 0;
+        if (i1 > i2) {rst = 1} else
+        if (i1 < i2) rst = -1;
+        return rst;
+    });
     console.log(arrSimple);
     t.pass('just pass');
     t.end();

+ 41 - 29
test/demo/stringTest.js

@@ -3,36 +3,48 @@
  */
 
 var test = require('tape');
+var strUtil = require('../../public/stringUtil');
 
-test('some string test cases', function (t) {
-    var reg = /^\s*$/;
-    var foo = "   ";
-    t.equal(reg.test(foo), true);
-    foo = null;
-    t.equal(reg.test(foo), true);
-    foo = undefined;
-    t.equal(reg.test(foo), true);
-    foo = "";
-    t.equal(reg.test(foo), true);
-    foo = 0;
-    t.equal(reg.test(foo), true);
-    t.end();
-});
+//test('some string test cases', function (t) {
+//    var reg = /^\s*$/;
+//    var foo = "   ";
+//    t.equal(reg.test(foo), true);
+//    foo = null;
+//    t.equal(reg.test(foo), true);
+//    foo = undefined;
+//    t.equal(reg.test(foo), true);
+//    foo = "";
+//    t.equal(reg.test(foo), true);
+//    foo = 0;
+//    t.equal(reg.test(foo), true);
+//    t.end();
+//});
+//
+//test('check if string type', function(t){
+//    var foo = "";
+//    t.equal(typeof foo, 'string');
+//    foo = " ";
+//    t.equal(typeof foo, 'string');
+//    foo = 0;
+//    t.equal(typeof foo, 'number');
+//    foo = true;
+//    t.equal(typeof foo, 'boolean');
+//    foo = {};
+//    t.equal(typeof foo, 'object');
+//    foo = function(){};
+//    t.equal(typeof foo, 'function');
+//    foo = [];
+//    t.equal(Array.isArray(foo), true);
+//    t.end();
+//})
 
-test('check if string type', function(t){
-    var foo = "";
-    t.equal(typeof foo, 'string');
-    foo = " ";
-    t.equal(typeof foo, 'string');
-    foo = 0;
-    t.equal(typeof foo, 'number');
-    foo = true;
-    t.equal(typeof foo, 'boolean');
-    foo = {};
-    t.equal(typeof foo, 'object');
-    foo = function(){};
-    t.equal(typeof foo, 'function');
-    foo = [];
-    t.equal(Array.isArray(foo), true);
+test('test number to Chinese', function(t){
+    //t.equal(strUtil.convertNumToChinese(1, true), '壹');
+    //t.equal(strUtil.convertNumToChinese(1, false), '一');
+    t.equal(strUtil.convertNumToChinese(11, false), '一十一');
+    t.equal(strUtil.convertNumToChinese(12, false), '一十二');
+    t.equal(strUtil.convertNumToChinese(21, false), '二十一');
+    //console.log(strUtil.convertNumToChinese(102, false));
+    t.equal(strUtil.convertNumToChinese(102, false), '一百零二');
     t.end();
 })

+ 1 - 1
test/unit/excel_export/fileReadWrite.js

@@ -29,7 +29,7 @@ fs.readFile('../../tmp_data/test_bills_data2.js',function(err,data){
         pos += chunks[i].length;
     }
 
-    fs.writeFile('../../../tmp/resut.text',resultBuffer,function(err){
+    fs.writeFile('../../../tmp/结果.text',resultBuffer,function(err){
         if(err) throw err;
         console.log('has finished');
     });

+ 1 - 0
test/unit/excel_export/privateFunctionTest.js

@@ -35,6 +35,7 @@ test('test private 1', function(t){
         return rst;
     };
     t.equal(private_getCellIdxStr2(0, ''), 'A');
+    t.equal(private_getCellIdxStr2(20, ''), 'U');
     t.equal(private_getCellIdxStr2(25, ''), 'Z');
     t.equal(private_getCellIdxStr2(26, ''), 'AA');
     t.equal(private_getCellIdxStr2(27, ''), 'AB');

+ 52 - 0
test/unit/excel_export/rpt_excel_export_test.js

@@ -0,0 +1,52 @@
+/**
+ * Created by Tony on 2017/4/10.
+ */
+var test = require('tape');
+var fs = require('fs');
+var fsUtil = require('../../../public/fsUtil');
+var rpt_xl_util = require('../../../modules/reports/util/rpt_excel_util');
+
+test('check excel output', function(t){
+    var data = fs.readFileSync('../../../tmp/07_1.page.js', 'utf8', 'r');
+    eval(data);
+    //console.log(testReport07_1);
+    var sheets = [];
+    for (var i = 0; i < testReport07_1.items.length; i++) {
+        sheets.push({sheetName: '第' + (i + 1) + '页'});
+    }
+    var ct = rpt_xl_util.testWriteContentTypes(sheets);
+    fsUtil.writeArrayToFile(ct, '../../../tmp/[Content_Types].xml');
+    t.pass('pass content types');
+    var rootRels = rpt_xl_util.testWriteRootRels();
+    fsUtil.writeArrayToFile(rootRels, '../../../tmp/.rels');
+    t.pass('pass root rels');
+    var app = rpt_xl_util.testWriteApp(sheets);
+    fsUtil.writeArrayToFile(app, '../../../tmp/app.xml');
+    t.pass('pass app');
+    var core = rpt_xl_util.testWriteCore(sheets);
+    fsUtil.writeArrayToFile(core, '../../../tmp/core.xml');
+    t.pass('pass core');
+    var xlWBs = rpt_xl_util.testWriteXlWorkBook(sheets);
+    fsUtil.writeArrayToFile(xlWBs, '../../../tmp/workbook.xml');
+    t.pass('pass workbook');
+    //workbook.xml.rels
+    var xlRels = rpt_xl_util.testWriteXlRels(sheets);
+    fsUtil.writeArrayToFile(xlRels, '../../../tmp/workbook.xml.rels');
+    t.pass('pass xl sheet rels');
+    var sharedStrList = [], styleList= [];
+    var sheetsArr = rpt_xl_util.testWriteSheets(testReport07_1, sharedStrList, styleList);
+    for (var i = 0; i < sheetsArr.length; i++) {
+        fsUtil.writeArrayToFile(sheetsArr[i], '../../../tmp/sheet' + (i + 1) + '.xml');
+        t.pass('pass sheet' + (i + 1));
+    }
+    var sharedStr = rpt_xl_util.testWriteSharedString(sharedStrList);
+    fsUtil.writeArrayToFile(sharedStr, '../../../tmp/sharedStrings.xml');
+    t.pass('pass shared string');
+    var theme = rpt_xl_util.testWriteTheme();
+    //console.log(theme);
+    var themeArr = [];
+    themeArr.push(theme)
+    fsUtil.writeArrayToFile(themeArr, '../../../tmp/theme1.xml');
+    t.pass('pass theme');
+    t.end();
+});

+ 1 - 1
tmp/07_1.page.js

@@ -1,4 +1,4 @@
-{
+var testReport07_1 = {
 	"control_collection": {
 		"Default": {
 			"Shrink": "T",

+ 9 - 6
web/main/html/main.html

@@ -515,6 +515,7 @@
     <script type="text/javascript" src="lib/ztree/jquery.ztree.excheck.js"></script>
     <!-- SpreadJs -->
     <script type="text/javascript" src="lib/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js"></script>
+    <script>GC.Spread.Sheets.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";</script>
     <!-- Model -->
     <script type="text/javascript" src="web/main/js/models/project.js"></script>
     <script type="text/javascript" src="web/main/js/models/bills.js"></script>
@@ -619,9 +620,10 @@
         project.Rations.loadDatas(drawing_data);
         project.mainTree.loadDatas(project.Bills.tree, project.Rations.datas);
 
-        controller = TREE_SHEET_CONTROLLER.createNew(project.mainTree, billsSpread.getActiveSheet(), BillsGridSetting);
+        //controller = TREE_SHEET_CONTROLLER.createNew(project.mainTree, billsSpread.getActiveSheet(), BillsGridSetting);
+        controller = TREE_SHEET_CONTROLLER.createNew(project.Bills.tree, billsSpread.getActiveSheet(), BillsGridSetting);
         controller.showTreeData();
-        controller.bind('treeSelectedChanged', function (selected) {
+        controller.bind('refreshBaseActn', function (tree) {
             var showButton = function (show, btn) {
                 if (show) {
                     btn.show();
@@ -629,10 +631,11 @@
                     btn.hide();
                 }
             };
-            showButton(selected.canUpLevel(), $('#upLevel'));
-            showButton(selected.canDownLevel(), $('#downLevel'));
-            showButton(selected.canUpMove(), $('#upMove'));
-            showButton(selected.canDownMove(), $('#downMove'));
+            showButton(tree.selected && tree.selected.canUpLevel(), $('#upLevel'));
+            showButton(tree.selected && tree.selected.canDownLevel(), $('#downLevel'));
+            showButton(tree.selected && tree.selected.canUpMove(), $('#upMove'));
+            showButton(tree.selected && tree.selected.canDownMove(), $('#downMove'));
+            showButton(tree.selected ? true : false, $('#delete'));
         });
 
         $('#insert').click(function () {

+ 15 - 4
web/main/js/models/cache_tree.js

@@ -2,7 +2,10 @@
  * Created by Mai on 2017/4/5.
  */
 var cacheTree = {
-    createNew: function () {
+    createNew: function (owner) {
+        var _eventType = {
+            afterSelectedChanged: 'afterSelectedChanged'
+        };
         var tools = {
             findNode: function (nodes, check) {
                 for (var i = 0; i < nodes.length; i++) {
@@ -286,11 +289,10 @@ var cacheTree = {
             return success;
         };
 
-        var Tree = function (setting) {
+        var Tree = function (owner) {
             this.nodes = {};
             this.roots = [];
             this.items = [];
-            this.setting = setting;
             this.prefix = 'id_';
             this.selected = null;
 
@@ -305,6 +307,11 @@ var cacheTree = {
                 } else {
                     _MaxID = Math.max(_MaxID, id);
                 }
+            };
+
+            var rootId = -1;
+            this.rootID = function () {
+                return rootId;
             }
         };
 
@@ -405,6 +412,10 @@ var cacheTree = {
             return success;
         };
 
-        return new Tree(setting);
+        Tree.prototype.editedData = function (field, id, newText) {
+            var node = this.findNode(id);
+        }
+
+        return new Tree(owner);
     }
 };

+ 1 - 1
web/main/js/models/project.js

@@ -8,7 +8,7 @@ var PROJECT = {
 
         // 所有通过this访问的属性,都不应在此单元外部进行写入操作
         var project = function () {
-            this.mainTree = cacheTree.createNew();
+            this.mainTree = cacheTree.createNew(this);
 
             this.Bills = Bills.createNew(this);
             this.Rations = Rations.createNew(this);