| 
					
				 | 
			
			
				@@ -126,7 +126,69 @@ function writeTheme(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return rst; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 function writeStyles(stylesObj){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    var rst = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push(dftHeadXml + '\r\n'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //1. push fonts 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('<fonts count="' + stylesObj.fonts.length + '">') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (var i = 0; i < stylesObj.fonts.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var font = stylesObj.fonts[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rst.push('<font>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (strUtil.convertStrToBoolean(font[JV.FONT_PROPS[3]])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            rst.push('<b/>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rst.push('<sz val="' + font.size + '"/>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rst.push('<color indexed="' + font.colorIdx + '"/>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rst.push('<name val="' + font[JV.FONT_PROPS[0]] + '"/>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rst.push('<charset val="' + font.charset + '"/>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rst.push('</font>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('<fonts>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //2. push default fills 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('<fills count="2"><fill><patternFill patternType="none" /></fill><fill><patternFill patternType="gray125" /></fill></fills>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //3. push borders 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('<borders count="' + stylesObj.borders.length + '">') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private_setBorder = function(border, borderDirection) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (border[borderDirection][JV.PROP_LINE_WEIGHT] == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            rst.push('<' + borderDirection.toLowerCase() + '/>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var bW = 'thin'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (border[borderDirection][JV.PROP_LINE_WEIGHT] = 2) bW = 'medium'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (border[borderDirection][JV.PROP_LINE_WEIGHT] > 2) bW = 'thick'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            rst.push('<' + borderDirection.toLowerCase() + ' style="' + bW + '">' + '<color indexed="64"/>' + '</' + borderDirection.toLowerCase() + '>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (var i = 0; i < stylesObj.borders.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var border = stylesObj.borders[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        private_setBorder(border, JV.PROP_LEFT); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        private_setBorder(border, JV.PROP_RIGHT); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        private_setBorder(border, JV.PROP_TOP); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        private_setBorder(border, JV.PROP_BOTTOM); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('</borders>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //4. push cellStyleXfs 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"><alignment vertical="center"/></xf></cellStyleXfs>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //5. push cellXfs 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('<cellXfs count="' + stylesObj.cellXfs.length + '">'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (var i = 0; i < stylesObj.cellXfs.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var excelStyle = stylesObj.cellXfs[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rst.push('<xf numFmtId="0" fontId="' + excelStyle.fontId + '" fillId="0" borderId="' + excelStyle.borderId + '" xfId="0">'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var alignStr = '<alignment horizontal="' + excelStyle[JV.CONTROL_PROPS[2]] + '" vertical="' + excelStyle[JV.CONTROL_PROPS[3]] + '"'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (strUtil.convertStrToBoolean(excelStyle[JV.CONTROL_PROPS[1]])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            alignStr = alignStr + ' shrinkToFit="1"'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (strUtil.convertStrToBoolean(excelStyle[JV.CONTROL_PROPS[4]])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            alignStr = alignStr + ' wrapText="1"'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        alignStr = alignStr + '/>'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rst.push(alignStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rst.push('</xf>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('</cellXfs>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //6. others (xfl style / dxfs / tableStyles) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //.. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    rst.push('</styleSheet>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return rst; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 function writeSharedString(sharedStrList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     var rst = []; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -219,7 +281,7 @@ function writeSheet(sheetData, sharedStrList, stylesObj){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         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)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (font[JV.FONT_PROPS[0]] === sheetFont[JV.FONT_PROPS[0]] && font.size === Math.round(sheetFont[JV.FONT_PROPS[1]] * 3 / 4) && font[JV.FONT_PROPS[3]] == sheetFont[JV.FONT_PROPS[3]]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     hasFont = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     rst = i; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     break; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -230,10 +292,11 @@ function writeSheet(sheetData, sharedStrList, stylesObj){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!hasFont) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             var font = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            font[JV.FONT_PROPS[0]] = sheetFont[JV.FONT_PROPS[0]]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            font[JV.FONT_PROPS[0]] = sheetFont[JV.FONT_PROPS[0]]; //font name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             font.size = Math.round(sheetFont[JV.FONT_PROPS[1]] * 3 / 4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             font.charset = 134; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            font.scheme = "minor"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            font.colorIdx = "8"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            font[JV.FONT_PROPS[3]] = sheetFont[JV.FONT_PROPS[3]]; //font bold 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             stylesObj.fonts.push(font); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             rst = stylesObj.fonts.length - 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -314,16 +377,41 @@ function writeSheet(sheetData, sharedStrList, stylesObj){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return rst; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private_getStyleIdx = function(cell) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private_checkControl = function(cellControl, sheetControl) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var rst = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (var i = 0; i < JV.CONTROL_PROPS.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (cellControl[JV.CONTROL_PROPS[i]] != sheetControl[JV.CONTROL_PROPS[i]]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                rst = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return rst; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private_getStyleId = function(cell) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         var rst = 1, hasStyle = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!(stylesObj.cellXfs)) stylesObj.cellXfs = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var fontId = private_getFontId(cell); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var borderId = private_getBorderId(cell); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var cellControl = sheetData[JV.NODE_CONTROL_COLLECTION][cell[JV.PROP_CONTROL]]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (var i = 0; i < stylesObj.cellXfs.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //check font and border 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var fontId = private_getFontId(cell); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var cellStyle = stylesObj.cellXfs[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var sheetControl = stylesObj.cellXfs[i]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (sheetControl.fontId == fontId && sheetControl.borderId == borderId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (private_checkControl(cellControl, sheetControl)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    rst = i; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    hasStyle = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!hasStyle) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //add new style 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var sheetControl = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sheetControl.fontId = fontId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sheetControl.borderId = borderId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (var i = 0; i < JV.CONTROL_PROPS.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sheetControl[JV.CONTROL_PROPS[i]] = cellControl[JV.CONTROL_PROPS[i]]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stylesObj.cellXfs.push(sheetControl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            rst = stylesObj.cellXfs.length - 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return rst; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -389,7 +477,7 @@ function writeSheet(sheetData, sharedStrList, stylesObj){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 colIdxStr = private_getCellIdxStr(j); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (hasMoreCols) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     if (nextColIdx == j) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        var styleIdx = private_getStyleIdx(sheetData.cells[cellIdx]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        var styleIdx = private_getStyleId(sheetData.cells[cellIdx]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         if (strUtil.isEmptyString(sheetData.cells[cellIdx][JV.PROP_VALUE])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             rst.push('<c r="' + colIdxStr + i + '" s="' + styleIdx + '"/>'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             //should setup the right style instead! 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -469,8 +557,8 @@ module.exports = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ,testWriteXlRels: function(sheets) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return writeXlRels(sheets); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    ,testWriteSheets: function(pageData, sharedStrList, styleList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return writeSheets(pageData, sharedStrList, styleList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ,testWriteSheets: function(pageData, sharedStrList, stylesObj){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return writeSheets(pageData, sharedStrList, stylesObj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ,testWriteSharedString: function(sharedStrList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return writeSharedString(sharedStrList); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -478,4 +566,7 @@ module.exports = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ,testWriteTheme: function() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return writeTheme(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ,testWriteStyles: function(stylesObj) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return writeStyles(stylesObj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |