From 9f566afba9770cdfbcec40b9ca7503de031620d8 Mon Sep 17 00:00:00 2001 From: Abdel Date: Sat, 28 Jun 2014 10:28:12 +0000 Subject: [PATCH] Fill Formula in ather cells as in excel. Signed-off-by: Abdel --- jquery.sheet.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/jquery.sheet.js b/jquery.sheet.js index b5285a8..07b824f 100644 --- a/jquery.sheet.js +++ b/jquery.sheet.js @@ -3434,7 +3434,8 @@ jQuery = jQuery || window.jQuery; jS.cellSetActive(td, loc, true, jS.autoFillerNotGroup, function () { var highlighted = jS.highlighted(), hLoc = jS.getTdLocation(highlighted.last()); - jS.fillUpOrDown(hLoc.row < loc.row || hLoc.col < loc.col); + //jS.fillUpOrDown(hLoc.row < loc.row || hLoc.col < loc.col); + jS.fillCells(); jS.autoFillerGoToTd(td); jS.autoFillerNotGroup = false; }); @@ -5022,7 +5023,99 @@ jQuery = jQuery || window.jQuery; return false; }, + //OA + //====================================================================== + fillCells:function () { + + jS.evt.cellEditDone(); + cells =jS.highlighted(true); + + if (cells.length < 1) { + return false; + } + var activeTd = jS.obj.tdActive(), + last = new Date(); + + + var startLoc = jS.getTdLocation(activeTd[0]), + cellsLength = cells.length - 1, + formulaCell="", + formulaActiveTd = activeTd[0].jSCell.formula; + + if (cellsLength >= 0) + { + for(i=0;i<=cellsLength;i++) + { + + if(formula!="") + { + var cellLoc = jS.getTdLocation(cells[i].td); + if(cellLoc.row>startLoc.row) + { + currentRow=cellLoc.row-startLoc.row; + } + else + { + currentRow=startLoc.row-cellLoc.row; + } + if(cellLoc.col>startLoc.col) + { + currentCol=cellLoc.col-startLoc.col; + } + else + { + currentCol=startLoc.col-cellLoc.col; + } + formulaCell=jS.NouvelleFormula(formulaActiveTd,currentRow , cellLoc.col-startLoc.col); + } + + s.parent.one('sheetPreCalculation', function () { + cells[i].formula = formulaCell; + cells[i].value = activeTd[0].jSCell.value; + cells[i].td.data('formula', activeTd[0].jSCell.formula); + }); + + jS.calcDependencies.call(cells[i], last); + + } + return true; + } + + return false; + }, + //OA + //====================================================================== + NouvelleFormula: function(formula, rowOffset, colOffset) { + var charAt = []; + var col = ''; + var row = ''; + formula = formula.replace(jSE.regEx.cell, + function(ignored, colStr, rowStr, pos) { + charAt[0] = formula.charAt(pos - 1); + charAt[1] = formula.charAt(colStr.length + rowStr.length + 1); + + charAt[0] = (charAt[0] ? charAt[0] : ''); + charAt[1] = (charAt[1] ? charAt[1] : ''); + + if (colStr.toUpperCase() == "SHEET" || + charAt[0] == ':' || + charAt[1] == ':' + ) { + return ignored; + } else { + row = parseInt(rowStr) + rowOffset; + col = jSE.columnLabelIndex(colStr) + colOffset; + row = (row > 0 ? row : '1'); + col = (col > 0 ? col : '1'); + + return jSE.columnLabelString(col) + row; + } + } + ); + return formula; + }, + //====================================================================== /** * Turns values into a tab separated value * @param {Object} [cells]