From bf61c70730758418f2b836d22a7c122a2190a861 Mon Sep 17 00:00:00 2001
From: "Dmitry.Shahtanov" <Dmitry.Shahtanov@OnlyOffice.com>
Date: Mon, 31 Aug 2015 11:46:55 +0000
Subject: [PATCH] =?UTF-8?q?fix:=20Bug=2030186=20-=20[NamedRange]=20=D0=A3?=
 =?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=B8=D1=81?=
 =?UTF-8?q?=D1=82=D0=B0=20=D1=81=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2?=
 =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D0=BC=20=D0=B4=D0=B8=D0=B0=D0=BF=D0=B0?=
 =?UTF-8?q?=D0=B7=D0=BE=D0=BD=D0=BE=D0=BC,=20=D0=BE=D0=BF=D1=80=D0=B5?=
 =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B=D0=BC=20=D1=82=D0=BE?=
 =?UTF-8?q?=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=BD=D0=B0=20=D1=8D=D1=82=D0=BE?=
 =?UTF-8?q?=D0=BC=20=D0=BB=D0=B8=D1=81=D1=82=D0=B5,=20=D0=BD=D0=B5=20?=
 =?UTF-8?q?=D0=BE=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82=D0=B2=D0=BB=D1=8F?=
 =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F=20=D0=B8=20=D0=B2=D1=8B=D0=B7=D1=8B?=
 =?UTF-8?q?=D0=B2=D0=B0=D0=B5=D1=82=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83?=
 =?UTF-8?q?=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D0=B8=20(http:?=
 =?UTF-8?q?//bugzserver/show=5Fbug.cgi=3Fid=3D30186)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@64408 954022d7-b5bf-4e40-9824-e11837661b57
---
 Excel/model/Workbook.js | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/Excel/model/Workbook.js b/Excel/model/Workbook.js
index 7f770af8d..4f992f1a7 100644
--- a/Excel/model/Workbook.js
+++ b/Excel/model/Workbook.js
@@ -949,35 +949,40 @@ DependencyGraph.prototype = {
     removeDefNameBySheet:function ( sheetId ) {
 
         /*var ws = this.wb.getWorksheet( sheetId );
-        ws ? sheetId = ws.getId() : null;*/
+         ws ? sheetId = ws.getId() : null;*/
 
         var nodesList = this.defNameList, retRes = {}, defN, seUndoRedo = [], nSE, wsIndex;
 
-        for( var id in nodesList ){
-
-            if( !nodesList[id].isTable && nodesList[id].parsedRef.removeSheet(sheetId) ){
+        for ( var id in nodesList ) {
+            /*if ( nodesList[id].isTable ) {
+                if ( nodesList[id].sheetTableId == sheetId ) {
+                    nodesList[id].Ref = null;
+                }
+                continue;
+            }*/
+            if ( !nodesList[id].isTable && nodesList[id].parsedRef && nodesList[id].parsedRef.removeSheet( sheetId ) ) {
                 seUndoRedo = [];
                 defN = nodesList[id];
                 nSE = defN.getSlaveEdges();
-                for( var nseID in nSE ){
-                    seUndoRedo.push(nseID);
+                for ( var nseID in nSE ) {
+                    seUndoRedo.push( nseID );
                 }
 
-                wsIndex = this.wb.getWorksheetById(defN.sheetId);
+                wsIndex = this.wb.getWorksheetById( defN.sheetId );
 
                 History.Add( g_oUndoRedoWorkbook, historyitem_Workbook_DefinedNamesDelete, null, null,
                     new UndoRedoData_DefinedNames( defN.Name, defN.Ref, wsIndex ? wsIndex.getIndex() : undefined, defN.isTable, seUndoRedo ) );
 
-                if( defN.sheetId == sheetId ){
+                if ( defN.sheetId == sheetId ) {
 
                     defN.Ref = null;
                     defN.parsedRef = null;
                     retRes[id] = defN;
 
                 }
-                else{
+                else {
 
-                    defN.Ref = defN.parsedRef.Formula  = defN.parsedRef.assemble(true);
+                    defN.Ref = defN.parsedRef.Formula = defN.parsedRef.assemble( true );
                     retRes[id] = defN;
 
                 }
@@ -1598,7 +1603,7 @@ DefNameVertex.prototype = {
 
     returnCell:function () {
         //todo
-        if ( null == this.cell && this.wb && !this.isArea ) {
+        if ( null == this.cell && this.wb && !this.isArea && this.Ref !== null && this.Ref !== undefined ) {
             var ws = this.wb.getWorksheetById( this.sheetId );
             if ( ws )
                 this.cell = ws._getCellNoEmpty( this.bbox.r1, this.bbox.c1 );
@@ -2174,13 +2179,14 @@ Workbook.prototype.removeWorksheet=function(nIndex, outputParams){
 	}
 	if(bEmpty)
 		return -1;
-	
+
 	var removedSheet = this.getWorksheet(nIndex);
 	if(removedSheet)
 	{
 		History.Create_NewPoint();
 		var removedSheetId = removedSheet.getId();
 		lockDraw(this);
+        var retRes = this.dependencyFormulas.removeDefNameBySheet( removedSheetId ), nSE, se, seUndoRedo = [];
 		var a = this.dependencyFormulas.getNodeBySheetId(removedSheetId);
 		for(var i = 0; i < a.length; i++)
 		{
@@ -2198,14 +2204,12 @@ Workbook.prototype.removeWorksheet=function(nIndex, outputParams){
 				}
 			}
 		}
+
 	    //по всем удаленным листам пробегаемся и удаляем из workbook.cwf (cwf - cells with forluma) элементы с названием соответствующего листа.
 		this.dependencyFormulas.removeNodeBySheetId(removedSheetId);
 		var _cwf = this.cwf[removedSheetId];
 		delete this.cwf[removedSheetId];
 
-
-        var retRes = this.dependencyFormulas.removeDefNameBySheet( removedSheetId ), nSE, se, seUndoRedo = [];
-
         if ( retRes ) {
             /*
              * #1. поменяли название - перестроили формулу. нужно вызвать пересборку формул в ячейках, в которыйх есть эта именованная ссылка.
-- 
2.30.9