/** * Created by Tony on 2018/9/4. */ let virtualCommonOprObj = { getActPos: function (textNode, caclStr, typeStr, baseMea) { let rst = 0; if (caclStr === JV.CAL_TYPE[0]) { //percentage rst = Math.round(baseMea * textNode[JV.PROP_AREA][typeStr] / 100); } else { //abstract rst = Math.round(textNode[JV.PROP_AREA][typeStr] / 2.54 * 96); } return rst; }, getActPosEx: function (textNode, caclObj, typeStr, baseMea) { let me = this; if (typeof caclObj === 'string') { return me.getActPos(textNode, caclObj, typeStr, baseMea); } else { return me.getActPos(textNode, caclObj[typeStr], typeStr, baseMea); } }, pushPos: function (textNode, caclObj, typeStr, baseMea, posArr) { let me = this, pos = me.getActPosEx(textNode, caclObj, typeStr, baseMea); if (posArr.indexOf(pos) < 0) posArr.push(pos); }, getBandEx: function (bandName, rptTpl) { let me = this, rst; for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) { rst = me.getBand(bandName, band); if (rst !== null) { break; } } return rst; }, getBand: function (bandName, parentBand) { let me = this, rst = null; if (parentBand[JV.PROP_NAME] === bandName) { rst = parentBand; } else { if (parentBand[JV.BAND_PROP_SUB_BANDS] && parentBand[JV.BAND_PROP_SUB_BANDS].length > 0) { for (let subBand of parentBand[JV.BAND_PROP_SUB_BANDS]) { rst = me.getBand(bandName, subBand); if (rst !== null) { break; } } } } return rst; }, checkInSpan: function (spans, row, col) { let rst = false; for (let span of spans) { if (span.row <= row && row < (span.row + span.rowCount) && span.col <= col && col < (span.col + span.colCount)) { rst = true; break; } } return rst; }, createTxtNode: function (text, parentNode, colWidthArr, rowHeightArr) { let width = colWidthArr[colWidthArr.length - 1], height = rowHeightArr[rowHeightArr.length - 1]; let rst = dataInfoMapTreeOprObj.getDummyTextNode(parentNode); rst[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[text.col + text.colCount - 1] / width * 100).toFixed(2); if (text.col > 0) { rst[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[text.col - 1] / width * 100).toFixed(2); } else { rst[JV.PROP_AREA][JV.PROP_LEFT] = 0; } rst[JV.PROP_AREA][JV.PROP_BOTTOM] = (rowHeightArr[text.row + text.rowCount - 1] / height * 100).toFixed(2); if (text.row > 0) { rst[JV.PROP_AREA][JV.PROP_TOP] = (rowHeightArr[text.row - 1] / height * 100).toFixed(2); } else { rst[JV.PROP_AREA][JV.PROP_TOP] = 0; } if (stringUtil.isEmptyString(text[`text`])) { rst[JV.PROP_NAME] = ''; } else { rst[JV.PROP_NAME] = stringUtil.replaceAll(stringUtil.replaceAll(text[`text`].toString(), '\n', '|'), '\r', ''); } rst[JV.PROP_LABEL] = rst[JV.PROP_NAME]; return rst; }, collectSheetTxt: function (sheet, texts, colWidthArr, rowHeightArr) { let spans= sheet.getSpans(); let private_build_pre_text = function (row, col, rowCount, colCount) { texts.push({"row": row, "col": col, "rowCount": rowCount, "colCount": colCount, "text": sheet.getValue(row, col)}); }; for (let span of spans) { private_build_pre_text(span.row, span.col, span.rowCount, span.colCount); } for (let iRow = 0; iRow < sheet.getRowCount() - 1; iRow++) { rowHeightArr.push(sheet.getRowHeight(iRow)); if (iRow > 0) { rowHeightArr[iRow] = rowHeightArr[iRow] + rowHeightArr[iRow - 1]; } for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) { if (iRow === 0) { colWidthArr.push(sheet.getColumnWidth(jCol)); if (jCol > 0) { colWidthArr[jCol] = colWidthArr[jCol] + colWidthArr[jCol - 1]; } } if (!virtualCommonOprObj.checkInSpan(spans, iRow, jCol)) { private_build_pre_text(iRow, jCol, 1, 1); } } } texts.sort(function(t1, t2){ if (t1.col === t2.col) { return t1.row - t2.row; } else { return t1.col - t2.col; } }); } }