|
@@ -154,7 +154,7 @@ function writeStyles(stylesObj){
|
|
|
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 = 'medium';
|
|
|
if (border[borderDirection][JV.PROP_LINE_WEIGHT] > 2) bW = 'thick';
|
|
|
rst.push('<' + borderDirection.toLowerCase() + ' style="' + bW + '">' + '<color indexed="64"/>' + '</' + borderDirection.toLowerCase() + '>');
|
|
|
}
|
|
@@ -320,29 +320,29 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
|
|
|
}
|
|
|
return rst;
|
|
|
};
|
|
|
- private_checkBorder = function(border, sheetBorder) {
|
|
|
+ private_checkBorder = function(cell, 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(sheetBorder[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]));
|
|
|
+ sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_LEFT));
|
|
|
} else {
|
|
|
sheetBorderLineWidths.push(0);
|
|
|
}
|
|
|
if (sheetBorder[JV.PROP_RIGHT] && sheetBorder[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]) {
|
|
|
- sheetBorderLineWidths.push(parseInt(sheetBorder[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]));
|
|
|
+ sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_RIGHT));
|
|
|
} else {
|
|
|
sheetBorderLineWidths.push(0);
|
|
|
}
|
|
|
if (sheetBorder[JV.PROP_TOP] && sheetBorder[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]) {
|
|
|
- sheetBorderLineWidths.push(parseInt(sheetBorder[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]));
|
|
|
+ sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_TOP));
|
|
|
} else {
|
|
|
sheetBorderLineWidths.push(0);
|
|
|
}
|
|
|
if (sheetBorder[JV.PROP_BOTTOM] && sheetBorder[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]) {
|
|
|
- sheetBorderLineWidths.push(parseInt(sheetBorder[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]));
|
|
|
+ sheetBorderLineWidths.push(private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_BOTTOM));
|
|
|
} else {
|
|
|
sheetBorderLineWidths.push(0);
|
|
|
}
|
|
@@ -354,41 +354,53 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
|
|
|
}
|
|
|
return rst;
|
|
|
};
|
|
|
+ private_chkAndGetMergeLine = function(cell, sheetBorder, borderStr) {
|
|
|
+ var rst = sheetBorder[borderStr][JV.PROP_LINE_WEIGHT], mergeBorder = pageData[JV.BAND_PROP_MERGE_BAND];
|
|
|
+ if (cell[JV.PROP_AREA][borderStr] == mergeBorder[borderStr]) {
|
|
|
+ var destStyle = pageData[JV.NODE_STYLE_COLLECTION][mergeBorder[JV.PROP_STYLE][JV.PROP_ID]];
|
|
|
+ rst = destStyle[borderStr][JV.PROP_LINE_WEIGHT];
|
|
|
+ }
|
|
|
+ return parseInt(rst);
|
|
|
+ };
|
|
|
+ private_getIniBorder = function() {
|
|
|
+ var rst = {};
|
|
|
+ rst[JV.PROP_LEFT] = {};
|
|
|
+ rst[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = 0;
|
|
|
+ rst[JV.PROP_RIGHT] = {};
|
|
|
+ rst[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = 0;
|
|
|
+ rst[JV.PROP_TOP] = {};
|
|
|
+ rst[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = 0;
|
|
|
+ rst[JV.PROP_BOTTOM] = {};
|
|
|
+ rst[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = 0;
|
|
|
+ return rst;
|
|
|
+ };
|
|
|
private_getBorderId = function(cell) {
|
|
|
var rst = 0, hasBorder = false;
|
|
|
if (!(stylesObj.borders)) {
|
|
|
stylesObj.borders = [];
|
|
|
}
|
|
|
- var sheetBorder = pageData.style_collection[cell.style];
|
|
|
+ var sheetBorder = pageData[JV.NODE_STYLE_COLLECTION][cell.style];
|
|
|
for (var i = 0; i < stylesObj.borders.length; i++) {
|
|
|
var border = stylesObj.borders[i];
|
|
|
- if (private_checkBorder(border, sheetBorder)) {
|
|
|
+ if (private_checkBorder(cell, 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;
|
|
|
+ var border = private_getIniBorder();
|
|
|
if (sheetBorder && sheetBorder[JV.PROP_LEFT]) {
|
|
|
- border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = parseInt(sheetBorder[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]);
|
|
|
+ border[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_LEFT);
|
|
|
}
|
|
|
if (sheetBorder && sheetBorder[JV.PROP_RIGHT]) {
|
|
|
- border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = parseInt(sheetBorder[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]);
|
|
|
+ border[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_RIGHT);
|
|
|
}
|
|
|
if (sheetBorder && sheetBorder[JV.PROP_TOP]) {
|
|
|
- border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = parseInt(sheetBorder[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]);
|
|
|
+ border[JV.PROP_TOP][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_TOP);
|
|
|
}
|
|
|
if (sheetBorder && sheetBorder[JV.PROP_BOTTOM]) {
|
|
|
- border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = parseInt(sheetBorder[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]);
|
|
|
+ border[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT] = private_chkAndGetMergeLine(cell, sheetBorder, JV.PROP_BOTTOM);
|
|
|
}
|
|
|
stylesObj.borders.push(border);
|
|
|
rst = stylesObj.borders.length - 1;
|
|
@@ -462,12 +474,71 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
|
|
|
rst[startIdx] = '<mergeCells count="' + cnt + '">';
|
|
|
rst.push('</mergeCells>');
|
|
|
};
|
|
|
+ private_getMergeBandBorderIdxs = function(leftColIdxStr, rightColIdxStr) {
|
|
|
+ var rst = [];
|
|
|
+ rst.push(leftColIdxStr);
|
|
|
+ rst.push(rightColIdxStr);
|
|
|
+ rst.push('' + yPos.indexOf(parseInt(pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_TOP])));
|
|
|
+ rst.push('' + yPos.indexOf(parseInt(pageData[JV.BAND_PROP_MERGE_BAND][JV.PROP_BOTTOM])));
|
|
|
+ return rst;
|
|
|
+ };
|
|
|
+ private_chkBorderStyle = function(preStyleId, mergedBorder, yIdx, colIdxStr){
|
|
|
+ var rst = preStyleId, preStyle = stylesObj.cellXfs[preStyleId], hasStyle = false, chkBorders = [],
|
|
|
+ mergeBorder = pageData[JV.BAND_PROP_MERGE_BAND],
|
|
|
+ destStyle = pageData[JV.NODE_STYLE_COLLECTION][mergeBorder[JV.PROP_STYLE][JV.PROP_ID]];
|
|
|
+ if (yIdx == mergedBorder[2]) {
|
|
|
+ chkBorders.push(JV.PROP_TOP);
|
|
|
+ } else if (yIdx == mergedBorder[3]) {
|
|
|
+ chkBorders.push(JV.PROP_BOTTOM);
|
|
|
+ }
|
|
|
+ if (colIdxStr == mergedBorder[0]) {
|
|
|
+ chkBorders.push(JV.PROP_LEFT);
|
|
|
+ } else if (colIdxStr == mergedBorder[0]) {
|
|
|
+ chkBorders.push(JV.PROP_RIGHT);
|
|
|
+ }
|
|
|
+ if (chkBorders.length > 0) {
|
|
|
+ for (var i = 0; i < stylesObj.cellXfs.length; i++) {
|
|
|
+ var border = stylesObj.borders[stylesObj.cellXfs[i].borderId];
|
|
|
+ var isMatch = true;
|
|
|
+ for (var j = 0; j < chkBorders.length; j++) {
|
|
|
+ if (border[chkBorders[j]][JV.PROP_LINE_WEIGHT] != destStyle[chkBorders[j]][JV.PROP_LINE_WEIGHT]) {
|
|
|
+ isMatch = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isMatch) {
|
|
|
+ hasStyle = true;
|
|
|
+ rst = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!hasStyle) {
|
|
|
+ var sheetControl = {};
|
|
|
+ sheetControl.fontId = preStyle.fontId;
|
|
|
+ var border = private_getIniBorder();
|
|
|
+ for (var j = 0; j < chkBorders.length; j++) {
|
|
|
+ border[chkBorders[j]][JV.PROP_LINE_WEIGHT] = destStyle[chkBorders[j]][JV.PROP_LINE_WEIGHT];
|
|
|
+ }
|
|
|
+ stylesObj.borders.push(border);
|
|
|
+ sheetControl.borderId = stylesObj.borders.length - 1;
|
|
|
+
|
|
|
+ for (var i = 0; i < JV.CONTROL_PROPS.length; i++) {
|
|
|
+ sheetControl[JV.CONTROL_PROPS[i]] = preStyle[JV.CONTROL_PROPS[i]];
|
|
|
+ }
|
|
|
+ stylesObj.cellXfs.push(sheetControl);
|
|
|
+ rst = stylesObj.cellXfs.length - 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+ };
|
|
|
private_setSheetData = function(){
|
|
|
//remark: 1 excel height = 0.3612 mm
|
|
|
rst.push('<sheetData>');
|
|
|
var 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 = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]),
|
|
|
+ mergedBorder = private_getMergeBandBorderIdxs('A', private_getCellIdxStr(spanX))
|
|
|
+ ;
|
|
|
for (var 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;
|
|
@@ -487,11 +558,13 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
|
|
|
hasMoreCols = false;
|
|
|
}
|
|
|
nextColIdx = xPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_LEFT]);
|
|
|
- for (var j = 1; j < xPos.length; j++) {
|
|
|
+ var preStyleIdx = 1;
|
|
|
+ for (var j = 1; j < xPos.length - 1; j++) {
|
|
|
colIdxStr = private_getCellIdxStr(j - 1);
|
|
|
if (hasMoreCols) {
|
|
|
if (nextColIdx == j) {
|
|
|
var 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!
|
|
@@ -517,10 +590,12 @@ function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
|
|
|
console.log('has abnormal case!');
|
|
|
hasMoreCols = false;
|
|
|
} else {
|
|
|
- rst.push('<c r="' + colIdxStr + i + '" s="1"/>');
|
|
|
+ //rst.push('<c r="' + colIdxStr + i + '" s="' + preStyleIdx + '"/>');
|
|
|
+ rst.push('<c r="' + colIdxStr + i + '" s="' + private_chkBorderStyle(preStyleIdx, mergedBorder, i, colIdxStr) + '"/>');
|
|
|
}
|
|
|
} else {
|
|
|
- rst.push('<c r="' + colIdxStr + i + '" s="1"/>');
|
|
|
+ //rst.push('<c r="' + colIdxStr + i + '" s="' + preStyleIdx + '"/>');
|
|
|
+ rst.push('<c r="' + colIdxStr + i + '" s="' + private_chkBorderStyle(preStyleIdx, mergedBorder, i, colIdxStr) + '"/>');
|
|
|
}
|
|
|
}
|
|
|
rst.push('</row>');
|