Commit b76ab09c authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

git-svn-id:...

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@53688 954022d7-b5bf-4e40-9824-e11837661b57
parent ce49693e
var g_sMainServiceLocalUrl = "/CanvasService.ashx";var g_sResourceServiceLocalUrl = "/ResourceService.ashx?path=";var g_sUploadServiceLocalUrl = "/UploadService.ashx";var g_sSpellCheckServiceLocalUrl = "/SpellChecker.ashx";var g_sTrackingServiceLocalUrl = "/TrackingService.ashx";var g_nMaxJsonLength = 2097152;var g_nMaxJsonLengthChecked = g_nMaxJsonLength / 1000; function fSortAscending(a, b){return a - b;}function fSortDescending(a, b){return b - a;} function test_ws_name(){ var self = new XRegExp( "[^\\p{L}(\\p{L}\\d._)*]" ); self.regexp_letter = new XRegExp( "^\\p{L}[\\p{L}\\d.]*$" ); self.regexp_left_bracket = new XRegExp("\\["); self.regexp_right_bracket = new XRegExp("\\]"); self.regexp_left_brace = new XRegExp("\\{"); self.regexp_right_brace = new XRegExp("\\}"); self.regexp_number_mark = new XRegExp(""); self.regexp_special_letters = new XRegExp("[\\'\\*\\[\\]\\\\:\\/]"); self.sheet_name_character_special = new XRegExp("('')|[^\\'\\*\\[\\]\\:/\\?]"); self.sheet_name_start_character_special = new XRegExp("^[^\\'\\*\\[\\]\\:/\\?]"); self.sheet_name_end_character_special = new XRegExp("[^\\'\\*\\[\\]\\:/\\?]$"); self.sheet_name_character = new XRegExp("[-+*/^&%<=>:\\'\\[\\]\\?\\s]"); self.book_name_character_special = self.book_name_start_character_special = new XRegExp("[^\\'\\*\\[\\]\\:\\?]"); self.apostrophe = new XRegExp("'"); self.srt_left_bracket = "["; self.srt_right_bracket = "]"; self.srt_left_brace = "{"; self.srt_right_brace = "}"; self.srt_number_letter = ""; self.matchRec = function(str,left,right){ return XRegExp.matchRecursive(str,"\\"+left,"\\"+right,"g") } self.test = function ( str ) { var matchRec, splitStr = str; if ( this.regexp_left_bracket.test( str ) || this.regexp_right_bracket.test( str ) ) { try { if ( str[0] != "[" ) return false; matchRec = this.matchRec( str, this.srt_left_bracket, this.srt_right_bracket ); if ( matchRec.length > 1 ){ return false; } else if ( matchRec[0] == "" ) { return false; } else if ( this.regexp_special_letters.test( matchRec[i] ) ) { return false; } splitStr = str.split( "[" + matchRec[0] + "]" )[1]; } catch( e ) { return false; } } return this.sheet_name_start_character_special.test(splitStr) && this.sheet_name_end_character_special.test(splitStr) && !XRegExp.test( splitStr, this ); } return self;} var c_oEditorId = { Word : 0, Speadsheet : 1, Presentation : 2}; var PostMessageType = { UploadImage : 0, ExtensionExist :1}; var c_oAscServerError = { NoError : 0, Unknown : -1, ReadRequestStream : -3, TaskQueue : -20, TaskResult : -40, Storage : -60, StorageFileNoFound : -61, StorageRead : -62, StorageWrite : -63, StorageRemoveDir : -64, StorageCreateDir : -65, StorageGetInfo : -66, Convert : -80, ConvertDownload : -81, ConvertUnknownFormat : -82, ConvertTimeout : -83, ConvertReadFile : -84, ConvertMS_OFFCRYPTO : -85, Upload : -100, UploadContentLength : -101, UploadExtension : -102, UploadCountFiles : -103, VKey : -120, VKeyEncrypt : -121, VKeyKeyExpire : -122, VKeyUserCountExceed : -123} var c_oAscImageUploadProp = {//Не все браузеры позволяют получить информацию о файле до загрузки(например ie9), меняя параметры здесь надо поменять аналогичные параметры в web.common MaxFileSize:25000000, //25 mb SupportedFormats:[ "jpg", "jpeg", "jpe", "png", "gif", "bmp"] }; function ValidateUploadImage(files){ var nRes = c_oAscServerError.NoError; if(1 === files.length ) { var file = files[0]; //проверяем расширение файла var sName = file.fileName || file.name; if(sName) { var bSupported = false; var nIndex = sName.lastIndexOf("."); if(-1 != nIndex) { var ext = sName.substring(nIndex + 1).toLowerCase(); for(var i = 0, length = c_oAscImageUploadProp.SupportedFormats.length; i < length; i++) { if(c_oAscImageUploadProp.SupportedFormats[i] == ext) { bSupported = true; break; } } } if(false == bSupported) nRes = c_oAscServerError.UploadExtension; } if(c_oAscError.ID.No == nRes) { var nSize = file.fileSize || file.size; if(nSize && c_oAscImageUploadProp.MaxFileSize < nSize) nRes = c_oAscServerError.UploadContentLength; } } else nRes = c_oAscServerError.UploadCountFiles; return nRes; } function CanDropFiles(event) { var bRes = false; if (event.dataTransfer.types) { for(var i = 0, length = event.dataTransfer.types.length; i < length; ++i) { var type = event.dataTransfer.types[i]; if(type == "Files") { if(event.dataTransfer.items) { var item = event.dataTransfer.items[0]; for(var j = 0, length2 = c_oAscImageUploadProp.SupportedFormats.length; j < length2; j++) { if(item.type && -1 != item.type.indexOf(c_oAscImageUploadProp.SupportedFormats[j])) { bRes = true; break; } } } else bRes = true; break; } } } return bRes; } function GetUploadIFrame(){ var sIFrameName = "apiImageUpload"; var oImageUploader = document.getElementById(sIFrameName); if(!oImageUploader) { var frame = document.createElement("iframe"); frame.name = sIFrameName; frame.id = sIFrameName; frame.setAttribute("style", "position:absolute;left:-2px;top:-2px;width:1px;height:1px;z-index:-1000;"); document.body.appendChild(frame); } return window.frames[sIFrameName]; } /*Functions that checks of an element in formula*/ var rx_operators = new RegExp( "^ *[-+*/^&%<=>:] *" ), rx_LG = new RegExp( "^ *[<=>]+ *" ), rx_Lt = new RegExp( "^ *< *" ), rx_Le = new RegExp( "^ *<= *" ), rx_Gt = new RegExp( "^ *> *" ), rx_Ge = new RegExp( "^ *>= *" ), rx_Ne = new RegExp( "^ *<> *" ), rg = new RegExp( "^([\\w\\d.]+ *)[-+*/^&%<=>:;\\(\\)]" ), rgRange = new RegExp( "^\\$?[A-Za-z]+\\$?\\d+:\\$?[A-Za-z]+\\$?\\d+" ), rgCols = new RegExp( "^\\$?[A-Za-z]+:\\$?[A-Za-z]+" ), rgRows = new RegExp( "^\\$?\\d+:\\$?\\d+" ), rx_ref = new RegExp( "^ *(\\$?[A-Za-z]{1,3}\\$?(\\d{1,7}))([-+*/^&%<=>: ;),]|$)" ), rx_refAll = new RegExp( "^(\\$?[A-Za-z]+\\$?(\\d+))([-+*/^&%<=>: ;),]|$)" ), rx_ref3D_non_quoted = new XRegExp( "^(?<name_from>[\\p{L}\\d.]+)(:(?<name_to>[\\p{L}\\d.]+))?!" ), rx_ref3D_quoted = new XRegExp( "^'(?<name_from>(?:''|[^\\[\\]'\\/*?:])*)(?::(?<name_to>(?:''|[^\\[\\]'\\/*?:])*))?'!" ), rx_ref3D = new RegExp( "^\\D*[\\D\\d]*\\!" ), rx_before_operators = new RegExp( "^ *[,()]" ), rx_space = new RegExp( " " ), rx_number = new RegExp( "^[+-]?\\d*(\\d|\\.)\\d*([eE][+-]?\\d+)?" ), rx_LeftParentheses = new RegExp( "^ *\\( *" ), rx_RightParentheses = new RegExp( "^ *\\)" ), rx_Comma = new RegExp( "^ *[,;] *" ), rx_error = new RegExp( "^(#NULL!|#DIV\\/0!|#VALUE!|#REF!|#NAME\\?|#NUM!|#UNSUPPORTED_FUNCTION!|#N\\/A|#GETTING_DATA)" ), rx_bool = new RegExp( "^(TRUE|FALSE|true|false)([-+*/^&%<=>: ;),]|$)" ), rx_string = new RegExp( "^\"((\"\"|[^\"])*)\"" ), rx_name = new XRegExp( "^(?<name>\\w[\\w\\d.]*)([-+*/^&%<=>: ;),]|$)" ), rx_test_ws_name = new test_ws_name(), rx_LeftBrace = new RegExp( "^ *\\{ *" ), rx_RightBrace = new RegExp( "^ *\\}" ), rx_array = new RegExp( "^\\{(([+-]?\\d*(\\d|\\.)\\d*([eE][+-]?\\d+)?)?(\"((\"\"|[^\"])*)\")?(#NULL!|#DIV\\/0!|#VALUE!|#REF!|#NAME\\?|#NUM!|#UNSUPPORTED_FUNCTION!|#N\\A|#GETTING_DATA|FALSE|TRUE|true|false)?[,;]?)*\\}" ); //вспомогательный объект для парсинга формул и проверки строки по регуляркам указанным выше. function parserHelper() { } parserHelper.prototype = { _reset:function () { delete this.operand_str; delete this.pCurrPos; }, isOperator:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var str = formula.substring( start_pos ) var match = str.match( rx_operators ); if ( match == null || match == undefined ) return false; else { var mt = str.match( rx_LG ) if ( mt ) match = mt; this.operand_str = match[0].replace( /\s/g, "", "" ); this.pCurrPos += match[0].length; return true; } return false; }, isFunc:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var frml = formula.substring( start_pos ); var match = (frml).match( rg ); if ( match != null && match != undefined ) { if ( match.length == 2 ) { this.pCurrPos += match[1].length; this.operand_str = match[1]; return true; } } this.operand_str = null; return false; }, isArea:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); var match = subSTR.match( rgRange ) || subSTR.match( rgCols ) || subSTR.match( rgRows ); if ( match != null || match != undefined ) { this.pCurrPos += match[0].length; this.operand_str = match[0]; return true; } this.operand_str = null; return false; }, isRef:function ( formula, start_pos, allRef ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_ref ); if ( match != null || match != undefined ) { if ( match.length >= 3 && g_oCellAddressUtils.colstrToColnum( match[1].substr( 0, (match[1].length - match[2].length) ) ) <= g_oCellAddressUtils.colstrToColnum( "XFD" ) && parseInt( match[2] ) <= 1048576 ) { this.pCurrPos += match[0].indexOf(" ")>-1 ? match[0].length-1 : match[1].length; this.operand_str = match[1]; return true; } else if ( allRef ) { match = (formula.substring( start_pos )).match( rx_refAll ); if ( (match != null || match != undefined) && match.length >= 3 ) { this.pCurrPos += match[1].length; this.operand_str = match[1]; return true; } } } this.operand_str = null; return false; }, is3DRef:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); var match = rx_ref3D_quoted.xexec( subSTR ) || rx_ref3D_non_quoted.xexec( subSTR ); if ( match != null || match != undefined ) { this.pCurrPos += match[0].length; this.operand_str = match[1]; return [ true, match["name_from"] ? match["name_from"].replace( /''/g, "'" ) : null, match["name_to"] ? match["name_to"].replace( /''/g, "'" ) : null ]; } this.operand_str = null; return [false, null, null]; }, isNextPtg:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); return ( ( subSTR.match( rx_before_operators ) != null || subSTR.match( rx_before_operators ) != undefined ) && ( subSTR.match( rx_space ) != null || subSTR.match( rx_space ) != undefined ) ) }, isNumber:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_number ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0]; this.pCurrPos += match[0].length; return true; } return false; }, isLeftParentheses:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_LeftParentheses ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0].replace( /\s/, "" ); this.pCurrPos += match[0].length; return true; } return false; }, isRightParentheses:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_RightParentheses ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0].replace( /\s/, "" ); this.pCurrPos += match[0].length; return true; } return false; }, isComma:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_Comma ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0]; this.pCurrPos += match[0].length; return true; } return false; }, isError:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_error ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0]; this.pCurrPos += match[0].length; return true; } return false; }, isBoolean:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_bool ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[1]; this.pCurrPos += match[1].length; return true; } return false; }, isString:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_string ); if ( match != null || match != undefined ) { this.operand_str = match[1].replace( "\"\"", "\"" ); this.pCurrPos += match[0].length; return true; } return false; }, isName:function ( formula, start_pos, wb ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); var match = rx_name.xexec( subSTR ); if ( match != null || match != undefined ) { var name = match["name"]; if ( name && name.length != 0 && wb.DefinedNames && wb.isDefinedNamesExists( name ) ) { this.pCurrPos += name.length; this.operand_str = name; return [ true, name ]; } } return [false]; }, isArray:function ( formula, start_pos, wb ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); var match = (formula.substring( start_pos )).match( rx_array ); if ( match != null || match != undefined ) { this.operand_str = match[0].substring( 1, match[0].length - 1 ); this.pCurrPos += match[0].length; return true; } return false; }, isLeftBrace:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_LeftBrace ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0].replace( /\s/, "" ); this.pCurrPos += match[0].length; return true; } return false; }, isRightBrace:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_RightBrace ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0].replace( /\s/, "" ); this.pCurrPos += match[0].length; return true; } return false; }, // Парсим ссылку на диапазон в листе parse3DRef:function ( formula ) { // Сначала получаем лист var is3DRefResult = this.is3DRef( formula, 0 ); if ( is3DRefResult && true === is3DRefResult[0] ) { // Имя листа в ссылке var sheetName = is3DRefResult[1]; // Ищем начало range var indexStartRange = formula.indexOf( "!" ) + 1; if ( this.isArea( formula, indexStartRange ) ) { if ( this.operand_str.length == formula.substring( indexStartRange ).length ) return {sheet:sheetName, range:this.operand_str}; else return null; } else if ( this.isRef( formula, indexStartRange ) ) { if ( this.operand_str.length == formula.substring( indexStartRange ).length ) return {sheet:sheetName, range:this.operand_str}; else return null; } } // Возвращаем ошибку return null; } } var parserHelp = new parserHelper(); var g_sMainServiceLocalUrl = "/CanvasService.ashx";var g_sResourceServiceLocalUrl = "/ResourceService.ashx?path=";var g_sUploadServiceLocalUrl = "/UploadService.ashx";var g_sSpellCheckServiceLocalUrl = "/SpellChecker.ashx";var g_sTrackingServiceLocalUrl = "/TrackingService.ashx";var g_nMaxJsonLength = 2097152;var g_nMaxJsonLengthChecked = g_nMaxJsonLength / 1000; function fSortAscending(a, b){return a - b;}function fSortDescending(a, b){return b - a;} function test_ws_name(){ var self = new XRegExp( "[^\\p{L}(\\p{L}\\d._)*]" ); self.regexp_letter = new XRegExp( "^\\p{L}[\\p{L}\\d.]*$" ); self.regexp_left_bracket = new XRegExp("\\["); self.regexp_right_bracket = new XRegExp("\\]"); self.regexp_left_brace = new XRegExp("\\{"); self.regexp_right_brace = new XRegExp("\\}"); self.regexp_number_mark = new XRegExp(""); self.regexp_special_letters = new XRegExp("[\\'\\*\\[\\]\\\\:\\/]"); self.sheet_name_character_special = new XRegExp("('')|[^\\'\\*\\[\\]\\:/\\?]"); self.sheet_name_start_character_special = new XRegExp("^[^\\'\\*\\[\\]\\:/\\?]"); self.sheet_name_end_character_special = new XRegExp("[^\\'\\*\\[\\]\\:/\\?]$"); self.sheet_name_character = new XRegExp("[-+*/^&%<=>:\\'\\[\\]\\?\\s]"); self.book_name_character_special = self.book_name_start_character_special = new XRegExp("[^\\'\\*\\[\\]\\:\\?]"); self.apostrophe = new XRegExp("'"); self.srt_left_bracket = "["; self.srt_right_bracket = "]"; self.srt_left_brace = "{"; self.srt_right_brace = "}"; self.srt_number_letter = ""; self.matchRec = function(str,left,right){ return XRegExp.matchRecursive(str,"\\"+left,"\\"+right,"g") } self.test = function ( str ) { var matchRec, splitStr = str; if ( this.regexp_left_bracket.test( str ) || this.regexp_right_bracket.test( str ) ) { try { if ( str[0] != "[" ) return false; matchRec = this.matchRec( str, this.srt_left_bracket, this.srt_right_bracket ); if ( matchRec.length > 1 ){ return false; } else if ( matchRec[0] == "" ) { return false; } else if ( this.regexp_special_letters.test( matchRec[i] ) ) { return false; } splitStr = str.split( "[" + matchRec[0] + "]" )[1]; } catch( e ) { return false; } } return this.sheet_name_start_character_special.test(splitStr) && this.sheet_name_end_character_special.test(splitStr) && !XRegExp.test( splitStr, this ); } return self;} var c_oEditorId = { Word : 0, Speadsheet : 1, Presentation : 2}; var PostMessageType = { UploadImage : 0, ExtensionExist :1}; var c_oAscServerError = { NoError : 0, Unknown : -1, ReadRequestStream : -3, TaskQueue : -20, TaskResult : -40, Storage : -60, StorageFileNoFound : -61, StorageRead : -62, StorageWrite : -63, StorageRemoveDir : -64, StorageCreateDir : -65, StorageGetInfo : -66, Convert : -80, ConvertDownload : -81, ConvertUnknownFormat : -82, ConvertTimeout : -83, ConvertReadFile : -84, ConvertMS_OFFCRYPTO : -85, Upload : -100, UploadContentLength : -101, UploadExtension : -102, UploadCountFiles : -103, VKey : -120, VKeyEncrypt : -121, VKeyKeyExpire : -122, VKeyUserCountExceed : -123} var c_oAscImageUploadProp = {//Не все браузеры позволяют получить информацию о файле до загрузки(например ie9), меняя параметры здесь надо поменять аналогичные параметры в web.common MaxFileSize:25000000, //25 mb SupportedFormats:[ "jpg", "jpeg", "jpe", "png", "gif", "bmp"] }; function ValidateUploadImage(files){ var nRes = c_oAscServerError.NoError; if(1 === files.length ) { var file = files[0]; //проверяем расширение файла var sName = file.fileName || file.name; if(sName) { var bSupported = false; var nIndex = sName.lastIndexOf("."); if(-1 != nIndex) { var ext = sName.substring(nIndex + 1).toLowerCase(); for(var i = 0, length = c_oAscImageUploadProp.SupportedFormats.length; i < length; i++) { if(c_oAscImageUploadProp.SupportedFormats[i] == ext) { bSupported = true; break; } } } if(false == bSupported) nRes = c_oAscServerError.UploadExtension; } if(c_oAscError.ID.No == nRes) { var nSize = file.fileSize || file.size; if(nSize && c_oAscImageUploadProp.MaxFileSize < nSize) nRes = c_oAscServerError.UploadContentLength; } } else nRes = c_oAscServerError.UploadCountFiles; return nRes; } function CanDropFiles(event) { var bRes = false; if (event.dataTransfer.types) { for(var i = 0, length = event.dataTransfer.types.length; i < length; ++i) { var type = event.dataTransfer.types[i]; if(type == "Files") { if(event.dataTransfer.items) { var item = event.dataTransfer.items[0]; for(var j = 0, length2 = c_oAscImageUploadProp.SupportedFormats.length; j < length2; j++) { if(item.type && -1 != item.type.indexOf(c_oAscImageUploadProp.SupportedFormats[j])) { bRes = true; break; } } } else bRes = true; break; } } } return bRes; } function GetUploadIFrame(){ var sIFrameName = "apiImageUpload"; var oImageUploader = document.getElementById(sIFrameName); if(!oImageUploader) { var frame = document.createElement("iframe"); frame.name = sIFrameName; frame.id = sIFrameName; frame.setAttribute("style", "position:absolute;left:-2px;top:-2px;width:1px;height:1px;z-index:-1000;"); document.body.appendChild(frame); } return window.frames[sIFrameName]; } /*Functions that checks of an element in formula*/ var rx_operators = new RegExp( "^ *[-+*/^&%<=>:] *" ), rx_LG = new RegExp( "^ *[<=>]+ *" ), rx_Lt = new RegExp( "^ *< *" ), rx_Le = new RegExp( "^ *<= *" ), rx_Gt = new RegExp( "^ *> *" ), rx_Ge = new RegExp( "^ *>= *" ), rx_Ne = new RegExp( "^ *<> *" ), rg = new RegExp( "^([\\w\\d.]+ *)[-+*/^&%<=>:;\\(\\)]" ), rgRange = new RegExp( "^\\$?[A-Za-z]+\\$?\\d+:\\$?[A-Za-z]+\\$?\\d+" ), rgCols = new RegExp( "^\\$?[A-Za-z]+:\\$?[A-Za-z]+" ), rgRows = new RegExp( "^\\$?\\d+:\\$?\\d+" ), rx_ref = new RegExp( "^ *(\\$?[A-Za-z]{1,3}\\$?(\\d{1,7}))([-+*/^&%<=>: ;),]|$)" ), rx_refAll = new RegExp( "^(\\$?[A-Za-z]+\\$?(\\d+))([-+*/^&%<=>: ;),]|$)" ), rx_ref3D_non_quoted = new XRegExp( "^(?<name_from>[\\p{L}\\d.]+)(:(?<name_to>[\\p{L}\\d.]+))?!" ), rx_ref3D_quoted = new XRegExp( "^'(?<name_from>(?:''|[^\\[\\]'\\/*?:])*)(?::(?<name_to>(?:''|[^\\[\\]'\\/*?:])*))?'!" ), rx_ref3D = new RegExp( "^\\D*[\\D\\d]*\\!" ), rx_before_operators = new RegExp( "^ *[,()]" ), rx_space = new RegExp( " " ), rx_number = new RegExp( "^[+-]?\\d*(\\d|\\.)\\d*([eE][+-]?\\d+)?" ), rx_LeftParentheses = new RegExp( "^ *\\( *" ), rx_RightParentheses = new RegExp( "^ *\\)" ), rx_Comma = new RegExp( "^ *[,;] *" ), rx_error = new RegExp( "^(#NULL!|#DIV\\/0!|#VALUE!|#REF!|#NAME\\?|#NUM!|#UNSUPPORTED_FUNCTION!|#N\\/A|#GETTING_DATA)" ), rx_bool = new RegExp( "^(TRUE|FALSE|true|false)([-+*/^&%<=>: ;),]|$)" ), rx_string = new RegExp( "^\"((\"\"|[^\"])*)\"" ), rx_name = new XRegExp( "^(?<name>\\w[\\w\\d.]*)([-+*/^&%<=>: ;),]|$)" ), rx_test_ws_name = new test_ws_name(), rx_LeftBrace = new RegExp( "^ *\\{ *" ), rx_RightBrace = new RegExp( "^ *\\}" ), rx_array = new RegExp( "^\\{(([+-]?\\d*(\\d|\\.)\\d*([eE][+-]?\\d+)?)?(\"((\"\"|[^\"])*)\")?(#NULL!|#DIV\\/0!|#VALUE!|#REF!|#NAME\\?|#NUM!|#UNSUPPORTED_FUNCTION!|#N\\A|#GETTING_DATA|FALSE|TRUE|true|false)?[,;]?)*\\}" ); rx_space_g = /\s/g, rx_space = /\s/; //вспомогательный объект для парсинга формул и проверки строки по регуляркам указанным выше. function parserHelper() { } parserHelper.prototype = { _reset:function () { delete this.operand_str; delete this.pCurrPos; }, isOperator:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var str = formula.substring( start_pos ) var match = str.match( rx_operators ); if ( match == null || match == undefined ) return false; else { var mt = str.match( rx_LG ) if ( mt ) match = mt; this.operand_str = match[0].replace( rx_space_g, "" ); this.pCurrPos += match[0].length; return true; } return false; }, isFunc:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var frml = formula.substring( start_pos ); var match = (frml).match( rg ); if ( match != null && match != undefined ) { if ( match.length == 2 ) { this.pCurrPos += match[1].length; this.operand_str = match[1]; return true; } } this.operand_str = null; return false; }, isArea:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); var match = subSTR.match( rgRange ) || subSTR.match( rgCols ) || subSTR.match( rgRows ); if ( match != null || match != undefined ) { this.pCurrPos += match[0].length; this.operand_str = match[0]; return true; } this.operand_str = null; return false; }, isRef:function ( formula, start_pos, allRef ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_ref ); if ( match != null || match != undefined ) { if ( match.length >= 3 && g_oCellAddressUtils.colstrToColnum( match[1].substr( 0, (match[1].length - match[2].length) ) ) <= g_oCellAddressUtils.colstrToColnum( "XFD" ) && parseInt( match[2] ) <= 1048576 ) { this.pCurrPos += match[0].indexOf(" ")>-1 ? match[0].length-1 : match[1].length; this.operand_str = match[1]; return true; } else if ( allRef ) { match = (formula.substring( start_pos )).match( rx_refAll ); if ( (match != null || match != undefined) && match.length >= 3 ) { this.pCurrPos += match[1].length; this.operand_str = match[1]; return true; } } } this.operand_str = null; return false; }, is3DRef:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); var match = rx_ref3D_quoted.xexec( subSTR ) || rx_ref3D_non_quoted.xexec( subSTR ); if ( match != null || match != undefined ) { this.pCurrPos += match[0].length; this.operand_str = match[1]; return [ true, match["name_from"] ? match["name_from"].replace( /''/g, "'" ) : null, match["name_to"] ? match["name_to"].replace( /''/g, "'" ) : null ]; } this.operand_str = null; return [false, null, null]; }, isNextPtg:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); return ( ( subSTR.match( rx_before_operators ) != null || subSTR.match( rx_before_operators ) != undefined ) && ( subSTR.match( rx_space ) != null || subSTR.match( rx_space ) != undefined ) ) }, isNumber:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_number ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0]; this.pCurrPos += match[0].length; return true; } return false; }, isLeftParentheses:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_LeftParentheses ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0].replace( rx_space, "" ); this.pCurrPos += match[0].length; return true; } return false; }, isRightParentheses:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_RightParentheses ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0].replace( rx_space, "" ); this.pCurrPos += match[0].length; return true; } return false; }, isComma:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_Comma ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0]; this.pCurrPos += match[0].length; return true; } return false; }, isError:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_error ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0]; this.pCurrPos += match[0].length; return true; } return false; }, isBoolean:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_bool ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[1]; this.pCurrPos += match[1].length; return true; } return false; }, isString:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_string ); if ( match != null || match != undefined ) { this.operand_str = match[1].replace( "\"\"", "\"" ); this.pCurrPos += match[0].length; return true; } return false; }, isName:function ( formula, start_pos, wb ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); var match = rx_name.xexec( subSTR ); if ( match != null || match != undefined ) { var name = match["name"]; if ( name && name.length != 0 && wb.DefinedNames && wb.isDefinedNamesExists( name ) ) { this.pCurrPos += name.length; this.operand_str = name; return [ true, name ]; } } return [false]; }, isArray:function ( formula, start_pos, wb ) { if ( this instanceof parserHelper ) { this._reset(); } var subSTR = formula.substring( start_pos ); var match = (formula.substring( start_pos )).match( rx_array ); if ( match != null || match != undefined ) { this.operand_str = match[0].substring( 1, match[0].length - 1 ); this.pCurrPos += match[0].length; return true; } return false; }, isLeftBrace:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_LeftBrace ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0].replace( /\s/, "" ); this.pCurrPos += match[0].length; return true; } return false; }, isRightBrace:function ( formula, start_pos ) { if ( this instanceof parserHelper ) { this._reset(); } var match = (formula.substring( start_pos )).match( rx_RightBrace ); if ( match == null || match == undefined ) return false; else { this.operand_str = match[0].replace( rx_space, "" ); this.pCurrPos += match[0].length; return true; } return false; }, // Парсим ссылку на диапазон в листе parse3DRef:function ( formula ) { // Сначала получаем лист var is3DRefResult = this.is3DRef( formula, 0 ); if ( is3DRefResult && true === is3DRefResult[0] ) { // Имя листа в ссылке var sheetName = is3DRefResult[1]; // Ищем начало range var indexStartRange = formula.indexOf( "!" ) + 1; if ( this.isArea( formula, indexStartRange ) ) { if ( this.operand_str.length == formula.substring( indexStartRange ).length ) return {sheet:sheetName, range:this.operand_str}; else return null; } else if ( this.isRef( formula, indexStartRange ) ) { if ( this.operand_str.length == formula.substring( indexStartRange ).length ) return {sheet:sheetName, range:this.operand_str}; else return null; } } // Возвращаем ошибку return null; } } var parserHelp = new parserHelper();
\ No newline at end of file \ No newline at end of file
......
...@@ -859,7 +859,7 @@ ...@@ -859,7 +859,7 @@
oParser = new parserFormula( "SUMIF(A12:A17,\"\",C12:C17)", "A22", ws ); oParser = new parserFormula( "SUMIF(A12:A17,\"\",C12:C17)", "A22", ws );
ok( oParser.parse() ); ok( oParser.parse() );
notEqual( oParser.calculate().getValue(), 400 ); strictEqual( oParser.calculate().getValue(), 400 );
} ) } )
......
...@@ -136,6 +136,7 @@ Math.binomCoeff = function ( n, k ) { ...@@ -136,6 +136,7 @@ Math.binomCoeff = function ( n, k ) {
Math.permut = function ( n, k ) { Math.permut = function ( n, k ) {
return Math.floor( this.fact( n ) / this.fact( n - k ) + .5 ); return Math.floor( this.fact( n ) / this.fact( n - k ) + .5 );
} }
var _func = [];//для велосипеда а-ля перегрузка функций. var _func = [];//для велосипеда а-ля перегрузка функций.
_func[cElementType.number] = []; _func[cElementType.number] = [];
_func[cElementType.string] = []; _func[cElementType.string] = [];
...@@ -147,86 +148,96 @@ _func[cElementType.array] = []; ...@@ -147,86 +148,96 @@ _func[cElementType.array] = [];
_func[cElementType.number][cElementType.number] = function ( arg0, arg1, what ) { _func[cElementType.number][cElementType.number] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" ) {
case ">": return new cBool( arg0.getValue() > arg1.getValue() );
return new cBool( arg0.getValue() > arg1.getValue() ); }
case ">=": else if ( what == ">=" ) {
return new cBool( arg0.getValue() >= arg1.getValue() ); return new cBool( arg0.getValue() >= arg1.getValue() );
case "<": }
return new cBool( arg0.getValue() < arg1.getValue() ); else if ( what == "<" ) {
case "<=": return new cBool( arg0.getValue() < arg1.getValue() );
return new cBool( arg0.getValue() <= arg1.getValue() ); }
case "=": else if ( what == "<=" ) {
return new cBool( arg0.getValue() == arg1.getValue() ); return new cBool( arg0.getValue() <= arg1.getValue() );
case "<>": }
return new cBool( arg0.getValue() != arg1.getValue() ); else if ( what == "=" ) {
case "-": return new cBool( arg0.getValue() == arg1.getValue() );
return new cNumber( arg0.getValue() - arg1.getValue() ); }
case "+": else if ( what == "<>" ) {
return new cNumber( arg0.getValue() + arg1.getValue() ); return new cBool( arg0.getValue() != arg1.getValue() );
case "/": }
if ( arg1.getValue() != 0 ) else if ( what == "-" ) {
return new cNumber( arg0.getValue() / arg1.getValue() ); return new cNumber( arg0.getValue() - arg1.getValue() );
else }
return new cError( cErrorType.division_by_zero ); else if ( what == "+" ) {
case "*": return new cNumber( arg0.getValue() + arg1.getValue() );
return new cNumber( arg0.getValue() * arg1.getValue() ); }
else if ( what == "/" ) {
if ( arg1.getValue() != 0 )
return new cNumber( arg0.getValue() / arg1.getValue() );
else
return new cError( cErrorType.division_by_zero );
}
else if ( what == "*" ) {
return new cNumber( arg0.getValue() * arg1.getValue() );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.number][cElementType.string] = function ( arg0, arg1, what ) { _func[cElementType.number][cElementType.string] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" || what == ">=" ) {
case ">": return new cBool( false );
case ">=": }
return new cBool( false ); else if ( what == "<" || what == "<=" ) {
case "<": return new cBool( true );
case "<=": }
return new cBool( true ); else if ( what == "=" ) {
case "=": return new cBool( false );
return new cBool( false ); }
case "<>": else if ( what == "<>" ) {
return new cBool( true ); return new cBool( true );
case "-": }
case "+": else if ( what == "-" || what == "+" || what == "/" || what == "*" ) {
case "/": return new cError( cErrorType.wrong_value_type );
case "*":
return new cError( cErrorType.wrong_value_type );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.number][cElementType.bool] = function ( arg0, arg1, what ) { _func[cElementType.number][cElementType.bool] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" || what == ">=" ) {
case ">": return new cBool( false );
case ">=": }
return new cBool( false ); else if ( what == "<" || what == "<=" ) {
case "<": return new cBool( true );
case "<=": }
return new cBool( true ); else if ( what == "=" ) {
case "=": return new cBool( false );
return new cBool( false ); }
case "<>": else if ( what == "<>" ) {
return new cBool( true ); return new cBool( true );
case "-": }
var _arg = arg1.tocNumber(); else if ( what == "-" ) {
if ( _arg instanceof cError ) return _arg; var _arg = arg1.tocNumber();
return new cNumber( arg0.getValue() - _arg.getValue() ); if ( _arg instanceof cError ) return _arg;
case "+": return new cNumber( arg0.getValue() - _arg.getValue() );
var _arg = arg1.tocNumber(); }
if ( _arg instanceof cError ) return _arg; else if ( what == "+" ) {
return new cNumber( arg0.getValue() + _arg.getValue() ); var _arg = arg1.tocNumber();
case "/": if ( _arg instanceof cError ) return _arg;
var _arg = arg1.tocNumber(); return new cNumber( arg0.getValue() + _arg.getValue() );
if ( _arg instanceof cError ) return _arg; }
if ( _arg.getValue() != 0 ) else if ( what == "/" ) {
return new cNumber( arg0.getValue() / _arg.getValue() ); var _arg = arg1.tocNumber();
else if ( _arg instanceof cError ) return _arg;
return new cError( cErrorType.division_by_zero ); if ( _arg.getValue() != 0 )
case "*": return new cNumber( arg0.getValue() / _arg.getValue() );
var _arg = arg1.tocNumber(); else
if ( _arg instanceof cError ) return _arg; return new cError( cErrorType.division_by_zero );
return new cNumber( arg0.getValue() * _arg.getValue() ); }
else if ( what == "*" ) {
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
return new cNumber( arg0.getValue() * _arg.getValue() );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
...@@ -236,134 +247,150 @@ _func[cElementType.number][cElementType.error] = function ( arg0, arg1, what ) { ...@@ -236,134 +247,150 @@ _func[cElementType.number][cElementType.error] = function ( arg0, arg1, what ) {
}; };
_func[cElementType.number][cElementType.empty] = function ( arg0, arg1, what ) { _func[cElementType.number][cElementType.empty] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" ) {
case ">": return new cBool( arg0.getValue() > 0 );
return new cBool( arg0.getValue() > 0 ); }
case ">=": else if ( what == ">=" ) {
return new cBool( arg0.getValue() >= 0 ); return new cBool( arg0.getValue() >= 0 );
case "<": }
return new cBool( arg0.getValue() < 0 ); else if ( what == "<" ) {
case "<=": return new cBool( arg0.getValue() < 0 );
return new cBool( arg0.getValue() <= 0 ); }
case "=": else if ( what == "<=" ) {
return new cBool( arg0.getValue() == 0 ); return new cBool( arg0.getValue() <= 0 );
case "<>": }
return new cBool( arg0.getValue() != 0 ); else if ( what == "=" ) {
case "-": return new cBool( arg0.getValue() == 0 );
return new cNumber( arg0.getValue() - 0 ); }
case "+": else if ( what == "<>" ) {
return new cNumber( arg0.getValue() + 0 ); return new cBool( arg0.getValue() != 0 );
case "/": }
return new cError( cErrorType.division_by_zero ); else if ( what == "-" ) {
case "*": return new cNumber( arg0.getValue() - 0 );
return new cNumber( 0 ); }
else if ( what == "+" ) {
return new cNumber( arg0.getValue() + 0 );
}
else if ( what == "/" ) {
return new cError( cErrorType.division_by_zero );
}
else if ( what == "*" ) {
return new cNumber( 0 );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.string][cElementType.number] = function ( arg0, arg1, what ) { _func[cElementType.string][cElementType.number] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" || what == ">=" ) {
case ">": return new cBool( true );
case ">=": }
return new cBool( true ); else if ( what == "<" || what == "<=" || what == "=" ) {
case "<": return new cBool( false );
case "<=": }
case "=": else if ( what == "<>" ) {
return new cBool( false ); return new cBool( true );
case "<>": }
return new cBool( true ); else if ( what == "-" || what == "+" || what == "/" || what == "*" ) {
case "-": return new cError( cErrorType.wrong_value_type );
case "+":
case "/":
case "*":
return new cError( cErrorType.wrong_value_type );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.string][cElementType.string] = function ( arg0, arg1, what ) { _func[cElementType.string][cElementType.string] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" ) {
case ">": return new cBool( arg0.getValue() > arg1.getValue() );
return new cBool( arg0.getValue() > arg1.getValue() ); }
case ">=": else if ( what == ">=" ) {
return new cBool( arg0.getValue() >= arg1.getValue() ); return new cBool( arg0.getValue() >= arg1.getValue() );
case "<": }
return new cBool( arg0.getValue() < arg1.getValue() ); else if ( what == "<" ) {
case "<=": return new cBool( arg0.getValue() < arg1.getValue() );
return new cBool( arg0.getValue() <= arg1.getValue() ); }
case "=": else if ( what == "<=" ) {
return new cBool( arg0.getValue() === arg1.getValue() ); return new cBool( arg0.getValue() <= arg1.getValue() );
case "<>": }
return new cBool( arg0.getValue() !== arg1.getValue() ); else if ( what == "=" ) {
case "-": return new cBool( arg0.getValue() === arg1.getValue() );
var _arg0 = arg0.tocNumber(), }
_arg1 = arg1.tocNumber(); else if ( what == "<>" ) {
if ( _arg0 instanceof cError ) return _arg0; return new cBool( arg0.getValue() !== arg1.getValue() );
if ( _arg1 instanceof cError ) return _arg1; }
return new cNumber( _arg0.getValue() - _arg1.getValue() ); else if ( what == "-" ) {
case "+": var _arg0 = arg0.tocNumber(),
var _arg0 = arg0.tocNumber(), _arg1 = arg1.tocNumber();
_arg1 = arg1.tocNumber(); if ( _arg0 instanceof cError ) return _arg0;
if ( _arg0 instanceof cError ) return _arg0; if ( _arg1 instanceof cError ) return _arg1;
if ( _arg1 instanceof cError ) return _arg1; return new cNumber( _arg0.getValue() - _arg1.getValue() );
return new cNumber( _arg0.getValue() + _arg1.getValue() ); }
case "/": else if ( what == "+" ) {
var _arg0 = arg0.tocNumber(), var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber(); _arg1 = arg1.tocNumber();
if ( _arg0 instanceof cError ) return _arg0; if ( _arg0 instanceof cError ) return _arg0;
if ( _arg1 instanceof cError ) return _arg1; if ( _arg1 instanceof cError ) return _arg1;
if ( _arg1.getValue() != 0 ) return new cNumber( _arg0.getValue() + _arg1.getValue() );
return new cNumber( _arg0.getValue() / _arg1.getValue() ); }
return new cError( cErrorType.division_by_zero ); else if ( what == "/" ) {
case "*": var _arg0 = arg0.tocNumber(),
var _arg0 = arg0.tocNumber(), _arg1 = arg1.tocNumber();
_arg1 = arg1.tocNumber(); if ( _arg0 instanceof cError ) return _arg0;
if ( _arg0 instanceof cError ) return _arg0; if ( _arg1 instanceof cError ) return _arg1;
if ( _arg1 instanceof cError ) return _arg1; if ( _arg1.getValue() != 0 )
return new cNumber( _arg0.getValue() * _arg1.getValue() ); return new cNumber( _arg0.getValue() / _arg1.getValue() );
return new cError( cErrorType.division_by_zero );
}
else if ( what == "*" ) {
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg0 instanceof cError ) return _arg0;
if ( _arg1 instanceof cError ) return _arg1;
return new cNumber( _arg0.getValue() * _arg1.getValue() );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.string][cElementType.bool] = function ( arg0, arg1, what ) { _func[cElementType.string][cElementType.bool] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" || what == ">=" ) {
case ">": return new cBool( false );
case ">=": }
return new cBool( false ); else if ( what == "<" || what == "<=" ) {
case "<": return new cBool( true );
case "<=": }
return new cBool( true ); else if ( what == "=" ) {
case "=": return new cBool( false );
return new cBool( false ); }
case "<>": else if ( what == "<>" ) {
return new cBool( false ); return new cBool( false );
case "-": }
var _arg0 = arg0.tocNumber(), else if ( what == "-" ) {
_arg1 = arg1.tocNumber(); var _arg0 = arg0.tocNumber(),
if ( _arg0 instanceof cError ) return _arg0; _arg1 = arg1.tocNumber();
if ( _arg1 instanceof cError ) return _arg1; if ( _arg0 instanceof cError ) return _arg0;
return new cNumber( _arg0.getValue() - _arg1.getValue() ); if ( _arg1 instanceof cError ) return _arg1;
case "+": return new cNumber( _arg0.getValue() - _arg1.getValue() );
var _arg0 = arg0.tocNumber(), }
_arg1 = arg1.tocNumber(); else if ( what == "+" ) {
if ( _arg0 instanceof cError ) return _arg0; var _arg0 = arg0.tocNumber(),
if ( _arg1 instanceof cError ) return _arg1; _arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() + _arg1.getValue() ); if ( _arg0 instanceof cError ) return _arg0;
case "/": if ( _arg1 instanceof cError ) return _arg1;
var _arg0 = arg0.tocNumber(), return new cNumber( _arg0.getValue() + _arg1.getValue() );
_arg1 = arg1.tocNumber(); }
if ( _arg0 instanceof cError ) return _arg0; else if ( what == "/" ) {
if ( _arg1 instanceof cError ) return _arg1; var _arg0 = arg0.tocNumber(),
if ( _arg1.getValue() != 0 ) _arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() / _arg1.getValue() ); if ( _arg0 instanceof cError ) return _arg0;
return new cError( cErrorType.division_by_zero ); if ( _arg1 instanceof cError ) return _arg1;
case "*": if ( _arg1.getValue() != 0 )
var _arg0 = arg0.tocNumber(), return new cNumber( _arg0.getValue() / _arg1.getValue() );
_arg1 = arg1.tocNumber(); return new cError( cErrorType.division_by_zero );
if ( _arg0 instanceof cError ) return _arg0; }
if ( _arg1 instanceof cError ) return _arg1; else if ( what == "*" ) {
return new cNumber( _arg0.getValue() * _arg1.getValue() ); var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg0 instanceof cError ) return _arg0;
if ( _arg1 instanceof cError ) return _arg1;
return new cNumber( _arg0.getValue() * _arg1.getValue() );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
...@@ -373,134 +400,152 @@ _func[cElementType.string][cElementType.error] = function ( arg0, arg1, what ) { ...@@ -373,134 +400,152 @@ _func[cElementType.string][cElementType.error] = function ( arg0, arg1, what ) {
}; };
_func[cElementType.string][cElementType.empty] = function ( arg0, arg1, what ) { _func[cElementType.string][cElementType.empty] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" ) {
case ">": return new cBool( arg0.getValue().length != 0 );
return new cBool( arg0.getValue().length != 0 ); }
case ">=": else if ( what == ">=" ) {
return new cBool( arg0.getValue().length >= 0 ); return new cBool( arg0.getValue().length >= 0 );
case "<": }
return new cBool( false ); else if ( what == "<" ) {
case "<=": return new cBool( false );
return new cBool( arg0.getValue().length <= 0 ); }
case "=": else if ( what == "<=" ) {
return new cBool( arg0.getValue().length === 0 ); return new cBool( arg0.getValue().length <= 0 );
case "<>": }
return new cBool( arg0.getValue().length != 0 ); else if ( what == "=" ) {
case "-": return new cBool( arg0.getValue().length === 0 );
case "+": }
case "/": else if ( what == "<>" ) {
case "*": return new cBool( arg0.getValue().length != 0 );
return new cError( cErrorType.wrong_value_type ); }
else if ( what == "-" || what == "+" || what == "/" || what == "*" ) {
return new cError( cErrorType.wrong_value_type );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.bool][cElementType.number] = function ( arg0, arg1, what ) { _func[cElementType.bool][cElementType.number] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" || what == ">=" ) {
case ">": return new cBool( true );
case ">=": }
return new cBool( true ); else if ( what == "<" || what == "<=" ) {
case "<": return new cBool( false );
case "<=": }
return new cBool( false ); else if ( what == "=" ) {
case "=": return new cBool( true );
return new cBool( true ); }
case "<>": else if ( what == "<>" ) {
return new cBool( false ); return new cBool( false );
case "-": }
var _arg = arg0.tocNumber(); else if ( what == "-" ) {
if ( _arg instanceof cError ) return _arg; var _arg = arg0.tocNumber();
return new cNumber( _arg.getValue() - arg1.getValue() ); if ( _arg instanceof cError ) return _arg;
case "+": return new cNumber( _arg.getValue() - arg1.getValue() );
var _arg = arg1.tocNumber(); }
if ( _arg instanceof cError ) return _arg; else if ( what == "+" ) {
return new cNumber( _arg.getValue() + arg1.getValue() ); var _arg = arg1.tocNumber();
case "/": if ( _arg instanceof cError ) return _arg;
var _arg = arg1.tocNumber(); return new cNumber( _arg.getValue() + arg1.getValue() );
if ( _arg instanceof cError ) return _arg; }
if ( arg1.getValue() != 0 ) else if ( what == "/" ) {
return new cNumber( _arg.getValue() / arg1.getValue() ); var _arg = arg1.tocNumber();
else if ( _arg instanceof cError ) return _arg;
return new cError( cErrorType.division_by_zero ); if ( arg1.getValue() != 0 )
case "*": return new cNumber( _arg.getValue() / arg1.getValue() );
var _arg = arg1.tocNumber(); else
if ( _arg instanceof cError ) return _arg; return new cError( cErrorType.division_by_zero );
return new cNumber( _arg.getValue() * arg1.getValue() ); }
else if ( what == "*" ) {
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
return new cNumber( _arg.getValue() * arg1.getValue() );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.bool][cElementType.string] = function ( arg0, arg1, what ) { _func[cElementType.bool][cElementType.string] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" || what == ">=" ) {
case ">": return new cBool( true );
case ">=": }
return new cBool( true ); else if ( what == "<" || what == "<=" ) {
case "<": return new cBool( false );
case "<=": }
return new cBool( false ); else if ( what == "=" ) {
case "=": return new cBool( true );
return new cBool( true ); }
case "<>": else if ( what == "<>" ) {
return new cBool( true ); return new cBool( true );
case "-": }
var _arg0 = arg0.tocNumber(), else if ( what == "-" ) {
_arg1 = arg1.tocNumber(); var _arg0 = arg0.tocNumber(),
if ( _arg1 instanceof cError ) return _arg1; _arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() - _arg1.getValue() ); if ( _arg1 instanceof cError ) return _arg1;
case "+": return new cNumber( _arg0.getValue() - _arg1.getValue() );
var _arg0 = arg0.tocNumber(), }
_arg1 = arg1.tocNumber(); else if ( what == "+" ) {
if ( _arg1 instanceof cError ) return _arg1; var _arg0 = arg0.tocNumber(),
return new cNumber( _arg0.getValue() + _arg1.getValue() ); _arg1 = arg1.tocNumber();
case "/": if ( _arg1 instanceof cError ) return _arg1;
var _arg0 = arg0.tocNumber(), return new cNumber( _arg0.getValue() + _arg1.getValue() );
_arg1 = arg1.tocNumber(); }
if ( _arg1 instanceof cError ) return _arg1; else if ( what == "/" ) {
if ( _arg1.getValue() != 0 ) var _arg0 = arg0.tocNumber(),
return new cNumber( _arg0.getValue() / _arg1.getValue() ); _arg1 = arg1.tocNumber();
return new cError( cErrorType.division_by_zero ); if ( _arg1 instanceof cError ) return _arg1;
case "*": if ( _arg1.getValue() != 0 )
var _arg0 = arg0.tocNumber(), return new cNumber( _arg0.getValue() / _arg1.getValue() );
_arg1 = arg1.tocNumber(); return new cError( cErrorType.division_by_zero );
if ( _arg1 instanceof cError ) return _arg1; }
return new cNumber( _arg0.getValue() * _arg1.getValue() ); else if ( what == "*" ) {
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg1 instanceof cError ) return _arg1;
return new cNumber( _arg0.getValue() * _arg1.getValue() );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.bool][cElementType.bool] = function ( arg0, arg1, what ) { _func[cElementType.bool][cElementType.bool] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" ) {
case ">": return new cBool( arg0.value > arg1.value );
return new cBool( arg0.value > arg1.value ); }
case ">=": else if ( what == ">=" ) {
return new cBool( arg0.value >= arg1.value ); return new cBool( arg0.value >= arg1.value );
case "<": }
return new cBool( arg0.value < arg1.value ); else if ( what == "<" ) {
case "<=": return new cBool( arg0.value < arg1.value );
return new cBool( arg0.value <= arg1.value ); }
case "=": else if ( what == "<=" ) {
return new cBool( arg0.value === arg1.value ); return new cBool( arg0.value <= arg1.value );
case "<>": }
return new cBool( arg0.value !== arg1.value ); else if ( what == "=" ) {
case "-": return new cBool( arg0.value === arg1.value );
var _arg0 = arg0.tocNumber(), }
_arg1 = arg1.tocNumber(); else if ( what == "<>" ) {
return new cNumber( _arg0.getValue() - _arg1.getValue() ); return new cBool( arg0.value !== arg1.value );
case "+": }
var _arg0 = arg0.tocNumber(), else if ( what == "-" ) {
_arg1 = arg1.tocNumber(); var _arg0 = arg0.tocNumber(),
return new cNumber( _arg0.getValue() + _arg1.getValue() ); _arg1 = arg1.tocNumber();
case "/": return new cNumber( _arg0.getValue() - _arg1.getValue() );
if ( !arg1.value ) }
return new cError( cErrorType.division_by_zero ); else if ( what == "+" ) {
var _arg0 = arg0.tocNumber(), var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber(); _arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() / _arg1.getValue() ); return new cNumber( _arg0.getValue() + _arg1.getValue() );
case "*": }
var _arg0 = arg0.tocNumber(), else if ( what == "/" ) {
_arg1 = arg1.tocNumber(); if ( !arg1.value )
return new cNumber( _arg0.getValue() * _arg1.getValue() ); return new cError( cErrorType.division_by_zero );
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() / _arg1.getValue() );
}
else if ( what == "*" ) {
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() * _arg1.getValue() );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
...@@ -510,27 +555,35 @@ _func[cElementType.bool][cElementType.error] = function ( arg0, arg1, what ) { ...@@ -510,27 +555,35 @@ _func[cElementType.bool][cElementType.error] = function ( arg0, arg1, what ) {
}; };
_func[cElementType.bool][cElementType.empty] = function ( arg0, arg1, what ) { _func[cElementType.bool][cElementType.empty] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" ) {
case ">": return new cBool( arg0.value > false );
return new cBool( arg0.value > false ); }
case ">=": else if ( what == ">=" ) {
return new cBool( arg0.value >= false ); return new cBool( arg0.value >= false );
case "<": }
return new cBool( arg0.value < false ); else if ( what == "<" ) {
case "<=": return new cBool( arg0.value < false );
return new cBool( arg0.value <= false ); }
case "=": else if ( what == "<=" ) {
return new cBool( arg0.value === false ); return new cBool( arg0.value <= false );
case "<>": }
return new cBool( arg0.value !== false ); else if ( what == "=" ) {
case "-": return new cBool( arg0.value === false );
return new cNumber( arg0.value ? 1.0 : 0.0 - 0 ); }
case "+": else if ( what == "<>" ) {
return new cNumber( arg0.value ? 1.0 : 0.0 + 0 ); return new cBool( arg0.value !== false );
case "/": }
return new cError( cErrorType.division_by_zero ); else if ( what == "-" ) {
case "*": return new cNumber( arg0.value ? 1.0 : 0.0 - 0 );
return new cNumber( 0 ); }
else if ( what == "+" ) {
return new cNumber( arg0.value ? 1.0 : 0.0 + 0 );
}
else if ( what == "/" ) {
return new cError( cErrorType.division_by_zero );
}
else if ( what == "*" ) {
return new cNumber( 0 );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
...@@ -544,80 +597,98 @@ _func[cElementType.error][cElementType.number] = _func[cElementType.error][cElem ...@@ -544,80 +597,98 @@ _func[cElementType.error][cElementType.number] = _func[cElementType.error][cElem
_func[cElementType.empty][cElementType.number] = function ( arg0, arg1, what ) { _func[cElementType.empty][cElementType.number] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" ) {
case ">": return new cBool( 0 > arg1.getValue() );
return new cBool( 0 > arg1.getValue() ); }
case ">=": else if ( what == ">=" ) {
return new cBool( 0 >= arg1.getValue() ); return new cBool( 0 >= arg1.getValue() );
case "<": }
return new cBool( 0 < arg1.getValue() ); else if ( what == "<" ) {
case "<=": return new cBool( 0 < arg1.getValue() );
return new cBool( 0 <= arg1.getValue() ); }
case "=": else if ( what == "<=" ) {
return new cBool( 0 == arg1.getValue() ); return new cBool( 0 <= arg1.getValue() );
case "<>": }
return new cBool( 0 != arg1.getValue() ); else if ( what == "=" ) {
case "-": return new cBool( 0 == arg1.getValue() );
return new cNumber( 0 - arg1.getValue() ); }
case "+": else if ( what == "<>" ) {
return new cNumber( 0 + arg1.getValue() ); return new cBool( 0 != arg1.getValue() );
case "/": }
if ( arg1.getValue() == 0 ) else if ( what == "-" ) {
return new cError( cErrorType.not_numeric ); return new cNumber( 0 - arg1.getValue() );
return new cNumber( 0 ); }
case "*": else if ( what == "+" ) {
return new cNumber( 0 ); return new cNumber( 0 + arg1.getValue() );
}
else if ( what == "/" ) {
if ( arg1.getValue() == 0 )
return new cError( cErrorType.not_numeric );
return new cNumber( 0 );
}
else if ( what == "*" ) {
return new cNumber( 0 );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.empty][cElementType.string] = function ( arg0, arg1, what ) { _func[cElementType.empty][cElementType.string] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" ) {
case ">": return new cBool( 0 > arg1.getValue().length );
return new cBool( 0 > arg1.getValue().length ); }
case ">=": else if ( what == ">=" ) {
return new cBool( 0 >= arg1.getValue().length ); return new cBool( 0 >= arg1.getValue().length );
case "<": }
return new cBool( 0 < arg1.getValue().length ); else if ( what == "<" ) {
case "<=": return new cBool( 0 < arg1.getValue().length );
return new cBool( 0 <= arg1.getValue().length ); }
case "=": else if ( what == "<=" ) {
return new cBool( 0 === arg1.getValue().length ); return new cBool( 0 <= arg1.getValue().length );
case "<>": }
return new cBool( 0 != arg1.getValue().length ); else if ( what == "=" ) {
case "-": return new cBool( 0 === arg1.getValue().length );
case "+": }
case "/": else if ( what == "<>" ) {
case "*": return new cBool( 0 != arg1.getValue().length );
return new cError( cErrorType.wrong_value_type ); }
else if ( what == "-" || what == "+" || what == "/" || what == "*" ) {
return new cError( cErrorType.wrong_value_type );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
_func[cElementType.empty][cElementType.bool] = function ( arg0, arg1, what ) { _func[cElementType.empty][cElementType.bool] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" ) {
case ">": return new cBool( false > arg1.value );
return new cBool( false > arg1.value ); }
case ">=": else if ( what == ">=" ) {
return new cBool( false >= arg1.value ); return new cBool( false >= arg1.value );
case "<": }
return new cBool( false < arg1.value ); else if ( what == "<" ) {
case "<=": return new cBool( false < arg1.value );
return new cBool( false <= arg1.value ); }
case "=": else if ( what == "<=" ) {
return new cBool( arg1.value === false ); return new cBool( false <= arg1.value );
case "<>": }
return new cBool( arg1.value !== false ); else if ( what == "=" ) {
case "-": return new cBool( arg1.value === false );
return new cNumber( 0 - arg1.value ? 1.0 : 0.0 ); }
case "+": else if ( what == "<>" ) {
return new cNumber( arg1.value ? 1.0 : 0.0 ); return new cBool( arg1.value !== false );
case "/": }
if ( arg1.value ) else if ( what == "-" ) {
return new cNumber( 0 ); return new cNumber( 0 - arg1.value ? 1.0 : 0.0 );
return new cError( cErrorType.not_numeric ); }
case "*": else if ( what == "+" ) {
return new cNumber( arg1.value ? 1.0 : 0.0 );
}
else if ( what == "/" ) {
if ( arg1.value )
return new cNumber( 0 ); return new cNumber( 0 );
return new cError( cErrorType.not_numeric );
}
else if ( what == "*" ) {
return new cNumber( 0 );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
...@@ -627,22 +698,20 @@ _func[cElementType.empty][cElementType.error] = function ( arg0, arg1, what ) { ...@@ -627,22 +698,20 @@ _func[cElementType.empty][cElementType.error] = function ( arg0, arg1, what ) {
}; };
_func[cElementType.empty][cElementType.empty] = function ( arg0, arg1, what ) { _func[cElementType.empty][cElementType.empty] = function ( arg0, arg1, what ) {
switch ( what ) { if ( what == ">" || what == "<" || what == "<>" ) {
case ">": return new cBool( false );
case "<": }
case "<>": else if ( what == ">=" || what == "<=" || what == "=" ) {
return new cBool( false ); return new cBool( true );
case ">=": }
case "<=": else if ( what == "-" || what == "+" ) {
case "=": return new cNumber( 0 );
return new cBool( true ); }
case "-": else if ( what == "/" ) {
case "+": return new cError( cErrorType.not_numeric );
return new cNumber( 0 ); }
case "/": else if ( what == "*" ) {
return new cError( cErrorType.not_numeric ); return new cNumber( 0 );
case "*":
return new cNumber( 0 );
} }
return new cError( cErrorType.wrong_value_type ); return new cError( cErrorType.wrong_value_type );
}; };
...@@ -780,11 +849,20 @@ function checkTypeCell( val ) { ...@@ -780,11 +849,20 @@ function checkTypeCell( val ) {
/*Base classes for operators & functions */ /*Base classes for operators & functions */
/** @constructor */ /** @constructor */
function cBaseOperator( name, priority, argumentCount ) { function cBaseOperator( name, priority, argumentCount ) {
this.name = name ? name : ""; if( name )
this.priority = priority !== undefined ? priority : 10; this.name = name;
else
this.name = "";
if( priority !== undefined )
this.priority = priority;
else
this.priority = 10;
this.type = cElementType.operator; this.type = cElementType.operator;
this.isRightAssociative = false; this.isRightAssociative = false;
this.argumentsCurrent = argumentCount !== undefined ? argumentCount : 2; if( argumentCount !== undefined )
this.argumentsCurrent = argumentCount;
else
this.argumentsCurrent = 2;
this.value = null; this.value = null;
this.formatType = { this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу. def:-1, //подразумевается формат первой ячейки входящей в формулу.
...@@ -904,39 +982,253 @@ cBaseType.prototype = { ...@@ -904,39 +982,253 @@ cBaseType.prototype = {
setNode:function(node){this.node = node;} setNode:function(node){this.node = node;}
} }
function parentLeft() {
this.name = "(";
this.type = cElementType.operator;
this.argumentsCurrent = 1
};
parentLeft.prototype.constructor = parentLeft;
parentLeft.prototype.DecrementArguments = function () {
--this.argumentsCurrent;
}
parentLeft.prototype.IncrementArguments = function () {
++this.argumentsCurrent;
}
parentLeft.prototype.toString = function () {
return this.name;
}
parentLeft.prototype.getArguments = function () {
return this.argumentsCurrent;
}
parentLeft.prototype.Assemble = function ( arg ) {
return new cString( "(" + arg + ")" );
}
function parentRight() {
this.name = ")";
this.type = cElementType.operator;
};
parentRight.prototype.constructor = parentRight;
parentRight.prototype.toString = function () {
return this.name;
}
function cUnarMinusOperator(){
cBaseOperator.apply(this, ['un_minus'/**name operator*/, 50/**priority of operator*/, 1/**count arguments*/]);
this.isRightAssociative = true;
}
cUnarMinusOperator.prototype = Object.create(cBaseOperator.prototype);
cUnarMinusOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
if ( arg0 instanceof cArea ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cArray ) {
arg0.foreach(
function ( arrElem, r, c ) {
arrElem = arrElem.tocNumber();
arg0.array[r][c] = arrElem instanceof cError ? arrElem : new cNumber( -arrElem.getValue() );
}
)
return this.value = arg0;
}
arg0 = arg0.tocNumber();
return this.value = arg0 instanceof cError ? arg0 : new cNumber( -arg0.getValue() )
}
cUnarMinusOperator.prototype.toString = function () { // toString function
return '-';
}
cUnarMinusOperator.prototype.Assemble = function ( arg ) {
return new cString( "-" + arg[0] );
}
function cUnarPlusOperator(){
cBaseOperator.apply(this, ['un_plus', 50, 1]);
this.isRightAssociative = true;
}
cUnarPlusOperator.prototype = Object.create(cBaseOperator.prototype);
cUnarPlusOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
if ( arg0 instanceof cArea ) {
arg0 = arg0.cross( arguments[1].first );
}
arg0 = arg[0].tryConvert();
return this.value = arg0;
}
cUnarPlusOperator.prototype.toString = function () {
return '+';
}
cUnarPlusOperator.prototype.Assemble = function ( arg ) {
return new cString( "+" + arg[0] );
}
function cPlusOperator(){
cBaseOperator.apply(this, ['+', 20]);
}
cPlusOperator.prototype = Object.create(cBaseOperator.prototype);
cPlusOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "+", arguments[1].first );
}
function cMinusOperator(){
cBaseOperator.apply(this, ['-', 20]);
}
cMinusOperator.prototype = Object.create(cBaseOperator.prototype);
cMinusOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "-", arguments[1].first );
}
function cPercentOperator(){
cBaseOperator.apply(this, ['%', 45, 1]);
this.isRightAssociative = true;
}
cPercentOperator.prototype = Object.create(cBaseOperator.prototype);
cPercentOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
if ( arg0 instanceof cArea ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cArray ) {
arg0.foreach(
function ( arrElem, r, c ) {
arrElem = arrElem.tocNumber();
arg0.array[r][c] = arrElem instanceof cError ? arrElem : new cNumber( arrElem.getValue() / 100 );
}
)
return this.value = arg0;
}
arg0 = arg0.tocNumber();
this.value = arg0 instanceof cError ? arg0 : new cNumber( arg0.getValue() / 100 );
this.value.numFormat = 9;
return this.value;
}
cPercentOperator.prototype.Assemble = function ( arg ) {
return new cString( arg[0] + this.name );
}
function cPowOperator(){
cBaseOperator.apply(this, ['^', 40]);
}
cPowOperator.prototype = Object.create(cBaseOperator.prototype);
cPowOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof cArea ) {
arg0 = arg0.cross( arguments[1].first );
}
arg0 = arg0.tocNumber();
if ( arg1 instanceof cArea ) {
arg1 = arg1.cross( arguments[1].first );
}
arg1 = arg1.tocNumber();
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
var _v = Math.pow( arg0.getValue(), arg1.getValue() );
if ( isNaN( _v ) )
return this.value = new cError( cErrorType.not_numeric );
else if ( _v === Number.POSITIVE_INFINITY )
return this.value = new cError( cErrorType.division_by_zero );
return this.value = new cNumber( _v );
}
function cMultOperator(){
cBaseOperator.apply(this, ['*', 30]);
}
cMultOperator.prototype = Object.create(cBaseOperator.prototype);
cMultOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "*", arguments[1].first );
}
function cDivOperator(){
cBaseOperator.apply(this, ['/', 30]);
}
cDivOperator.prototype = Object.create(cBaseOperator.prototype);
cDivOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "/", arguments[1].first );
}
function cConcatSTROperator(){
cBaseOperator.apply(this, ['&', 15]);
}
cConcatSTROperator.prototype = Object.create(cBaseOperator.prototype);
cConcatSTROperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof cArea ) {
arg0 = arg0.cross( arguments[1].first );
}
arg0 = arg0.tocString();
if ( arg1 instanceof cArea ) {
arg1 = arg1.cross( arguments[1].first );
}
arg1 = arg1.tocString();
return this.value = arg0 instanceof cError ? arg0 :
arg1 instanceof cError ? arg1 :
new cString( arg0.toString().concat( arg1.toString() ) )
}
function cEqualsOperator(){
cBaseOperator.apply(this, ['=', 10]);
}
cEqualsOperator.prototype = Object.create(cBaseOperator.prototype);
cEqualsOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "=", arguments[1].first );
}
function cNotEqualsOperator(){
cBaseOperator.apply(this, ['<>', 10]);
}
cNotEqualsOperator.prototype = Object.create(cBaseOperator.prototype);
cNotEqualsOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "<>", arguments[1].first );
}
function cLessOperator(){
cBaseOperator.apply(this, ['<', 10]);
}
cLessOperator.prototype = Object.create(cBaseOperator.prototype);
cLessOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "<", arguments[1].first );
}
function cLessOrEqualOperator(){
cBaseOperator.apply(this, ['<=', 10]);
}
cLessOrEqualOperator.prototype = Object.create(cBaseOperator.prototype);
cLessOrEqualOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "<=", arguments[1].first );
}
function cGreaterOperator(){
cBaseOperator.apply(this, ['>', 10]);
}
cGreaterOperator.prototype = Object.create(cBaseOperator.prototype);
cGreaterOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, ">", arguments[1].first );
}
function cGreaterOrEqualOperator(){
cBaseOperator.apply(this, ['>=', 10]);
}
cGreaterOrEqualOperator.prototype = Object.create(cBaseOperator.prototype);
cGreaterOrEqualOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, ">=", arguments[1].first );
}
/* cFormulaOperators is container for holding all ECMA-376 operators, see chapter $18.17.2.2 in "ECMA-376, Second Edition, Part 1 - Fundamentals And Markup Language Reference" */ /* cFormulaOperators is container for holding all ECMA-376 operators, see chapter $18.17.2.2 in "ECMA-376, Second Edition, Part 1 - Fundamentals And Markup Language Reference" */
var cFormulaOperators = { var cFormulaOperators = {
'(':function () { '(':parentLeft,
var r = {}; ')':parentRight,
r.name = "(";
r.type = cElementType.operator;
r.argumentsCurrent = 1;
r.DecrementArguments = function () {
--this.argumentsCurrent;
}
r.IncrementArguments = function () {
++this.argumentsCurrent;
}
r.toString = function () {
return this.name;
}
r.getArguments = function () {
return this.argumentsCurrent;
}
r.Assemble = function ( arg ) {
return new cString( "(" + arg + ")" );
}
return r;
},
')':function () {
var r = {};
r.name = ')';
r.type = cElementType.operator;
r.toString = function () {
return ')';
}
return r;
},
'{':function () { '{':function () {
var r = {}; var r = {};
r.name = '{'; r.name = '{';
...@@ -954,203 +1246,23 @@ var cFormulaOperators = { ...@@ -954,203 +1246,23 @@ var cFormulaOperators = {
return r; return r;
}, },
/* 50 is highest priority */ /* 50 is highest priority */
'un_minus':function () { 'un_minus':cUnarMinusOperator,
var r = new cBaseOperator( 'un_minus'/**name operator*/, 50/**priority of operator*/, 1/**count arguments*/ ); 'un_plus':cUnarPlusOperator,
r.Calculate = function ( arg ) { //calculate operator '%':cPercentOperator,
var arg0 = arg[0]; '^':cPowOperator,
if ( arg0 instanceof cArea ) { '*':cMultOperator,
arg0 = arg0.cross( arguments[1].first ); '/':cDivOperator,
} '+':cPlusOperator,
else if ( arg0 instanceof cArray ) { '-':cMinusOperator,
arg0.foreach( '&'://concat str
function ( arrElem, r, c ) { cConcatSTROperator,
arrElem = arrElem.tocNumber(); '=':// equals
arg0.array[r][c] = arrElem instanceof cError ? arrElem : new cNumber( -arrElem.getValue() ); cEqualsOperator,
} '<>':cNotEqualsOperator,
) '<':cLessOperator,
return this.value = arg0; '<=':cLessOrEqualOperator,
} '>':cGreaterOperator,
arg0 = arg0.tocNumber(); '>=':cGreaterOrEqualOperator
return this.value = arg0 instanceof cError ? arg0 : new cNumber( -arg0.getValue() )
},
r.toString = function () { // toString function
return '-';
}
r.Assemble = function ( arg ) {
return new cString( "-" + arg[0] );
}
r.isRightAssociative = true;
return r;
},
'un_plus':function () {
var r = new cBaseOperator( 'un_plus', 50, 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if ( arg0 instanceof cArea ) {
arg0 = arg0.cross( arguments[1].first );
}
arg0 = arg[0].tryConvert();
return this.value = arg0;
}
r.toString = function () {
return '+';
}
r.isRightAssociative = true;
r.Assemble = function ( arg ) {
return new cString( "+" + arg[0] );
}
return r;
},
'%':function () {
var r = new cBaseOperator( '%', 45, 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if ( arg0 instanceof cArea ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cArray ) {
arg0.foreach(
function ( arrElem, r, c ) {
arrElem = arrElem.tocNumber();
arg0.array[r][c] = arrElem instanceof cError ? arrElem : new cNumber( arrElem.getValue() / 100 );
}
)
return this.value = arg0;
}
arg0 = arg0.tocNumber();
this.value = arg0 instanceof cError ? arg0 : new cNumber( arg0.getValue() / 100 );
this.value.numFormat = 9;
return this.value;
}
r.isRightAssociative = true;
r.Assemble = function ( arg ) {
return new cString( arg[0] + this.name );
}
return r;
},
'^':function () {
var r = new cBaseOperator( '^', 40 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof cArea ) {
arg0 = arg0.cross( arguments[1].first );
}
arg0 = arg0.tocNumber();
if ( arg1 instanceof cArea ) {
arg1 = arg1.cross( arguments[1].first );
}
arg1 = arg1.tocNumber();
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
var _v = Math.pow( arg0.getValue(), arg1.getValue() );
if ( isNaN( _v ) )
return this.value = new cError( cErrorType.not_numeric );
else if ( _v === Number.POSITIVE_INFINITY )
return this.value = new cError( cErrorType.division_by_zero );
return this.value = new cNumber( _v );
}
return r;
},
'*':function () {
var r = new cBaseOperator( '*', 30 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "*", arguments[1].first );
}
return r;
},
'/':function () {
var r = new cBaseOperator( '/', 30 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "/", arguments[1].first );
}
return r;
},
'+':function () {
var r = new cBaseOperator( '+', 20 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "+", arguments[1].first );
}
return r;
},
'-':function () {
var r = new cBaseOperator( '-', 20 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "-", arguments[1].first );
}
return r;
},
'&':function () {//concat str
var r = new cBaseOperator( '&', 15 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof cArea ) {
arg0 = arg0.cross( arguments[1].first );
}
arg0 = arg0.tocString();
if ( arg1 instanceof cArea ) {
arg1 = arg1.cross( arguments[1].first );
}
arg1 = arg1.tocString();
return this.value = arg0 instanceof cError ? arg0 :
arg1 instanceof cError ? arg1 :
new cString( arg0.toString().concat( arg1.toString() ) )
}
return r;
},
'=':function () {// equals
var r = new cBaseOperator( '=', 10 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "=", arguments[1].first );
}
return r;
},
'<>':function () {
var r = new cBaseOperator( '<>', 10 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "<>", arguments[1].first );
}
return r;
},
'<':function () {
var r = new cBaseOperator( '<', 10 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "<", arguments[1].first );
}
return r;
},
'<=':function () {
var r = new cBaseOperator( '<=', 10 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, "<=", arguments[1].first );
};
return r;
},
'>':function () {
var r = new cBaseOperator( '>', 10 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, ">", arguments[1].first );
};
return r;
},
'>=':function () {
var r = new cBaseOperator( '>=', 10 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
return this.value = _func[arg0.type][arg1.type]( arg0, arg1, ">=", arguments[1].first );
};
return r;
}
/* 10 is lowest priopity */ /* 10 is lowest priopity */
}; };
...@@ -1183,7 +1295,7 @@ function getFormulasInfo() { ...@@ -1183,7 +1295,7 @@ function getFormulasInfo() {
/*Basic types of an elements used into formulas*/ /*Basic types of an elements used into formulas*/
/** @constructor */ /** @constructor */
function cNumber( val ) { function cNumber( val ) {
cNumber.superclass.constructor.call( this, val ); cBaseType.apply( this, arguments );
this.type = cElementType.number; this.type = cElementType.number;
this.value = parseFloat( val ); this.value = parseFloat( val );
if( !isNaN( this.value ) && Math.abs(this.value)!=Infinity ) if( !isNaN( this.value ) && Math.abs(this.value)!=Infinity )
...@@ -1191,7 +1303,7 @@ function cNumber( val ) { ...@@ -1191,7 +1303,7 @@ function cNumber( val ) {
else else
return new cError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
} }
extend( cNumber, cBaseType ); cNumber.prototype = Object.create(cBaseType.prototype);
cNumber.prototype.getValue = function () { cNumber.prototype.getValue = function () {
return this.value//.toFixed( cExcelSignificantDigits ) - 0; return this.value//.toFixed( cExcelSignificantDigits ) - 0;
}; };
...@@ -1207,10 +1319,10 @@ cNumber.prototype.tocBool = function () { ...@@ -1207,10 +1319,10 @@ cNumber.prototype.tocBool = function () {
/** @constructor */ /** @constructor */
function cString( val ) { function cString( val ) {
cString.superclass.constructor.call( this, val ); cBaseType.apply( this, arguments );
this.type = cElementType.string; this.type = cElementType.string;
} }
extend( cString, cBaseType ); cString.prototype = Object.create(cBaseType.prototype);
cString.prototype.tocNumber = function () { cString.prototype.tocNumber = function () {
if ( this.value == "" ) if ( this.value == "" )
return new cEmpty(); return new cEmpty();
...@@ -1249,19 +1361,15 @@ cString.prototype.tryConvert = function () { ...@@ -1249,19 +1361,15 @@ cString.prototype.tryConvert = function () {
/** @constructor */ /** @constructor */
function cBool( val ) { function cBool( val ) {
cBool.superclass.constructor.call( this, val ); cBaseType.apply( this, arguments );
this.type = cElementType.bool; this.type = cElementType.bool;
var that = this; var v = val.toString().toUpperCase();
switch ( val.toString().toUpperCase() ) { if( v == "TRUE" )
case "TRUE": this.value = true;
this.value = true; else
break; this.value = false;
case "FALSE":
this.value = false;
break;
}
} }
extend( cBool, cBaseType ); cBool.prototype = Object.create(cBaseType.prototype);
cBool.prototype.toString = function () { cBool.prototype.toString = function () {
return this.value.toString().toUpperCase(); return this.value.toString().toUpperCase();
}; };
...@@ -1283,89 +1391,69 @@ cBool.prototype.toBool = function () { ...@@ -1283,89 +1391,69 @@ cBool.prototype.toBool = function () {
/** @constructor */ /** @constructor */
function cError( val ) { function cError( val ) {
cError.superclass.constructor.call( this, val ); cBaseType.apply( this, arguments );
this.type = cElementType.error; this.type = cElementType.error;
this.errorType = -1; this.errorType = -1;
if ( isNaN( parseInt( val ) ) ) { if ( isNaN( parseInt( val ) ) ) {
switch ( val ) { if( val == "#VALUE!" ){
case "#VALUE!": this.errorType = cErrorType.wrong_value_type;
this.errorType = cErrorType.wrong_value_type; }else if( val == "#NULL!" ){
break; this.errorType = cErrorType.null_value;
case "#NULL!": }else if( val == "#DIV/0!" ){
this.errorType = cErrorType.null_value; this.errorType = cErrorType.division_by_zero;
break; }else if( val == "#REF!" ){
case "#DIV/0!": this.errorType = cErrorType.bad_reference;
this.errorType = cErrorType.division_by_zero; }else if( val == "#NAME?" ){
break; this.errorType = cErrorType.wrong_name;
case "#REF!": }else if( val == "#NUM!" ){
this.errorType = cErrorType.bad_reference; this.errorType = cErrorType.not_numeric;
break; }else if( val == "#N/A" ){
case "#NAME?": this.errorType = cErrorType.not_available;
this.errorType = cErrorType.wrong_name; }else if( val == "#UNSUPPORTED_FUNCTION!" ){
break; this.errorType = cErrorType.unsupported_function;
case "#NUM!": }else if( val == "#GETTING_DATA" ){
this.errorType = cErrorType.not_numeric; this.errorType = cErrorType.getting_data;
break; }
case "#N/A":
this.errorType = cErrorType.not_available;
break;
case "#UNSUPPORTED_FUNCTION!":
this.errorType = cErrorType.unsupported_function;
break;
case "#GETTING_DATA":
this.errorType = cErrorType.getting_data;
break;
}
return this; return this;
} }
switch ( val ) { if( val == cErrorType.null_value ){
case cErrorType.null_value: this.value = "#NULL!";
this.value = "#NULL!"; this.errorType = cErrorType.null_value;
this.errorType = cErrorType.null_value; }else if( val == cErrorType.division_by_zero ){
break; this.value = "#DIV/0!";
case cErrorType.division_by_zero: this.errorType = cErrorType.division_by_zero;
this.value = "#DIV/0!"; }else if( val == cErrorType.wrong_value_type ){
this.errorType = cErrorType.division_by_zero; this.value = "#VALUE!";
break; this.errorType = cErrorType.wrong_value_type;
case cErrorType.wrong_value_type: }else if( val == cErrorType.bad_reference ){
this.value = "#VALUE!"; this.value = "#REF!";
this.errorType = cErrorType.wrong_value_type; this.errorType = cErrorType.bad_reference;
break; }else if( val == cErrorType.wrong_name ){
case cErrorType.bad_reference: this.value = "#NAME?";
this.value = "#REF!"; this.errorType = cErrorType.wrong_name;
this.errorType = cErrorType.bad_reference; }else if( val == cErrorType.not_numeric ){
break; this.value = "#NUM!";
case cErrorType.wrong_name: this.errorType = cErrorType.not_numeric;
this.value = "#NAME?"; }else if( val == cErrorType.not_available ){
this.errorType = cErrorType.wrong_name; this.value = "#N/A";
break; this.errorType = cErrorType.not_available;
case cErrorType.not_numeric: }else if( val == cErrorType.unsupported_function ){
this.value = "#NUM!"; this.value = "#UNSUPPORTED_FUNCTION!";
this.errorType = cErrorType.not_numeric; this.errorType = cErrorType.unsupported_function;
break; }else if( val == cErrorType.getting_data ){
case cErrorType.not_available: this.value = "#GETTING_DATA";
this.value = "#N/A"; this.errorType = cErrorType.getting_data;
this.errorType = cErrorType.not_available;
break;
case cErrorType.unsupported_function:
this.value = "#UNSUPPORTED_FUNCTION!";
this.errorType = cErrorType.unsupported_function;
break;
case cErrorType.getting_data:
this.value = "#GETTING_DATA";
this.errorType = cErrorType.getting_data;
break;
} }
} }
extend( cError, cBaseType ); cError.prototype = Object.create(cBaseType.prototype);
cError.prototype.tocNumber = cError.prototype.tocString = cError.prototype.tocBool = cError.prototype.tocEmpty = function () { cError.prototype.tocNumber = cError.prototype.tocString = cError.prototype.tocBool = cError.prototype.tocEmpty = function () {
return this; return this;
}; };
/** @constructor */ /** @constructor */
function cArea( val, _ws ) {/*Area means "A1:E5" for example*/ function cArea( val, _ws ) {/*Area means "A1:E5" for example*/
cArea.superclass.constructor.call( this, val ); cBaseType.apply( this, arguments );
this.ws = _ws; this.ws = _ws;
this.wb = _ws.workbook; this.wb = _ws.workbook;
this._cells = val; this._cells = val;
...@@ -1374,7 +1462,7 @@ function cArea( val, _ws ) {/*Area means "A1:E5" for example*/ ...@@ -1374,7 +1462,7 @@ function cArea( val, _ws ) {/*Area means "A1:E5" for example*/
// this.range = this.wb.getWorksheetById(this.ws).getRange2(val); // this.range = this.wb.getWorksheetById(this.ws).getRange2(val);
// this._valid = this.range ? true : false; // this._valid = this.range ? true : false;
} }
extend( cArea, cBaseType ); cArea.prototype = Object.create(cBaseType.prototype);
cArea.prototype.getWsId = function () { cArea.prototype.getWsId = function () {
return this.ws.Id; return this.ws.Id;
}; };
...@@ -1383,29 +1471,31 @@ cArea.prototype.getValue = function () { ...@@ -1383,29 +1471,31 @@ cArea.prototype.getValue = function () {
if ( !r ) { if ( !r ) {
_val.push( new cError( cErrorType.bad_reference ) ) _val.push( new cError( cErrorType.bad_reference ) )
} }
else else {
r._foreachNoEmpty( function ( _cell ) { r._foreachNoEmpty( function ( _cell ) {
switch ( _cell.getType() ) { var cellType = _cell.getType();
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) ) _cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
break; }
case CellValueType.Bool: else if ( cellType == CellValueType.Bool ) {
_val.push( new cBool( _cell.getValueWithoutFormat() ) ); _val.push( new cBool( _cell.getValueWithoutFormat() ) );
break; }
case CellValueType.Error: else if ( cellType == CellValueType.Error ) {
_val.push( new cError( _cell.getValueWithoutFormat() ) ); _val.push( new cError( _cell.getValueWithoutFormat() ) );
break; }
case CellValueType.String: else if ( cellType == CellValueType.String ) {
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
}
else {
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else {
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) ); _val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
break; }
default:
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
} }
} ); } );
}
return _val; return _val;
}; };
cArea.prototype.getValue2 = function ( cell ) { cArea.prototype.getValue2 = function ( cell ) {
...@@ -1413,30 +1503,32 @@ cArea.prototype.getValue2 = function ( cell ) { ...@@ -1413,30 +1503,32 @@ cArea.prototype.getValue2 = function ( cell ) {
if ( !r ) { if ( !r ) {
_val.push( new cError( cErrorType.bad_reference ) ) _val.push( new cError( cErrorType.bad_reference ) )
} }
else else {
r._foreachNoEmpty( function ( _cell ) { r._foreachNoEmpty( function ( _cell ) {
if ( cell.getID() == _cell.getName() ) if ( cell.getID() == _cell.getName() ) {
switch ( _cell.getType() ) { var cellType = _cell.getType();
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) ) _cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
break; }
case CellValueType.Bool: else if ( cellType == CellValueType.Bool ) {
_val.push( new cBool( _cell.getValueWithoutFormat() ) ); _val.push( new cBool( _cell.getValueWithoutFormat() ) );
break; }
case CellValueType.Error: else if ( cellType == CellValueType.Error ) {
_val.push( new cError( _cell.getValueWithoutFormat() ) ); _val.push( new cError( _cell.getValueWithoutFormat() ) );
break; }
case CellValueType.String: else if ( cellType == CellValueType.String ) {
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
}
else {
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) ); _val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
break;
default:
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
} }
}
} ); } );
}
if( _val[0] == undefined || _val[0] == null ) if( _val[0] == undefined || _val[0] == null )
return new cEmpty(); return new cEmpty();
...@@ -1513,29 +1605,30 @@ cArea.prototype.foreach2 = function ( action ) { ...@@ -1513,29 +1605,30 @@ cArea.prototype.foreach2 = function ( action ) {
r._foreach2( function ( _cell ) { r._foreach2( function ( _cell ) {
var val; var val;
if ( _cell ) { if ( _cell ) {
switch ( _cell.getType() ) { var cellType=_cell.getType();
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? val = new cEmpty() : val = new cNumber( _cell.getValueWithoutFormat() ) _cell.getValueWithoutFormat() == "" ? val = new cEmpty() : val = new cNumber( _cell.getValueWithoutFormat() )
break; }
case CellValueType.Bool: else if ( cellType == CellValueType.Bool ) {
val = new cBool( _cell.getValueWithoutFormat() ); val = new cBool( _cell.getValueWithoutFormat() );
break; }
case CellValueType.Error: else if ( cellType == CellValueType.Error ) {
val = new cError( _cell.getValueWithoutFormat() ); val = new cError( _cell.getValueWithoutFormat() );
break; }
case CellValueType.String: else if ( cellType == CellValueType.String ) {
val = new cString( _cell.getValueWithoutFormat() ); val = new cString( _cell.getValueWithoutFormat() );
break; }
default: else {
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) { if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
val = new cNumber( _cell.getValueWithoutFormat() ) val = new cNumber( _cell.getValueWithoutFormat() )
} }
else else
val = checkTypeCell( "" + _cell.getValueWithoutFormat() ); val = checkTypeCell( "" + _cell.getValueWithoutFormat() );
} }
} }
else else{
val = new cEmpty() val = new cEmpty();
}
action(val); action(val);
} ); } );
} }
...@@ -1547,25 +1640,25 @@ cArea.prototype.getMatrix = function () { ...@@ -1547,25 +1640,25 @@ cArea.prototype.getMatrix = function () {
if ( !arr[i - r1] ) if ( !arr[i - r1] )
arr[i - r1] = []; arr[i - r1] = [];
if ( cell ) { if ( cell ) {
switch ( cell.getType() ) { var cellType = cell.getType();
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
arr[i - r1][j - c1] = cell.isEmptyTextString() ? new cEmpty() : new cNumber( cell.getValueWithoutFormat() ) arr[i - r1][j - c1] = cell.isEmptyTextString() ? new cEmpty() : new cNumber( cell.getValueWithoutFormat() )
break; }
case CellValueType.Bool: else if ( cellType == CellValueType.Bool ) {
arr[i - r1][j - c1] = new cBool( cell.getValueWithoutFormat() ); arr[i - r1][j - c1] = new cBool( cell.getValueWithoutFormat() );
break; }
case CellValueType.Error: else if ( cellType == CellValueType.Error ) {
arr[i - r1][j - c1] = new cError( cell.getValueWithoutFormat() ); arr[i - r1][j - c1] = new cError( cell.getValueWithoutFormat() );
break; }
case CellValueType.String: else if ( cellType == CellValueType.String ) {
arr[i - r1][j - c1] = new cString( cell.getValueWithoutFormat() ); arr[i - r1][j - c1] = new cString( cell.getValueWithoutFormat() );
break; }
default: else {
if ( !cell.isEmptyTextString()) { if ( !cell.isEmptyTextString() ) {
arr[i - r1][j - c1] = new cNumber( cell.getValueWithoutFormat() ) arr[i - r1][j - c1] = new cNumber( cell.getValueWithoutFormat() )
} }
else else
arr[i - r1][j - c1] = checkTypeCell( "" + cell.getValueWithoutFormat() ); arr[i - r1][j - c1] = checkTypeCell( "" + cell.getValueWithoutFormat() );
} }
} }
else else
...@@ -1576,16 +1669,16 @@ cArea.prototype.getMatrix = function () { ...@@ -1576,16 +1669,16 @@ cArea.prototype.getMatrix = function () {
/** @constructor */ /** @constructor */
function cRef( val, _ws ) {/*Ref means A1 for example*/ function cRef( val, _ws ) {/*Ref means A1 for example*/
cRef.superclass.constructor.call( this, val ); cBaseType.apply( this, arguments );
this._cells = val; this._cells = val;
this.ws = _ws; this.ws = _ws;
this.wb = _ws.workbook; this.wb = _ws.workbook;
this.isAbsolute = false; this.isAbsolute = false;
this.type = cElementType.cell; this.type = cElementType.cell;
this.range = _ws.getRange2( val ); this.range = _ws.getRange2( val );
this._valid = new CellAddress( val.replace( /\$/g, "" ) ).isValid(); this._valid = new CellAddress( val.replace( rx_space_g, "" ) ).isValid();
} }
extend( cRef, cBaseType ); cRef.prototype = Object.create(cBaseType.prototype);
cRef.prototype.getWsId = function () { cRef.prototype.getWsId = function () {
return this.ws.Id; return this.ws.Id;
}; };
...@@ -1593,21 +1686,22 @@ cRef.prototype.getValue = function () { ...@@ -1593,21 +1686,22 @@ cRef.prototype.getValue = function () {
if ( !this._valid ) { if ( !this._valid ) {
return new cError( cErrorType.bad_reference ) return new cError( cErrorType.bad_reference )
} }
switch ( this.range.getType() ) { var cellType = this.range.getType()
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
{ var v = this.range.getValueWithoutFormat();
var v = this.range.getValueWithoutFormat(); if ( v == "" )
if ( v == "" ) return new cEmpty()
return new cEmpty() else
else return new cNumber( "" + v );
return new cNumber( "" + v ); }
} else if ( cellType == CellValueType.Bool ) {
case CellValueType.Bool: return new cBool( "" + this.range.getValueWithoutFormat() )
return new cBool( "" + this.range.getValueWithoutFormat() ) }
case CellValueType.Error: else if ( cellType == CellValueType.Error ) {
return new cError( "" + this.range.getValueWithoutFormat() ) return new cError( "" + this.range.getValueWithoutFormat() )
default: }
return checkTypeCell( "" + this.range.getValueWithoutFormat() ) else {
return checkTypeCell( "" + this.range.getValueWithoutFormat() )
} }
}; };
cRef.prototype.tocNumber = function () { cRef.prototype.tocNumber = function () {
...@@ -1638,7 +1732,7 @@ cRef.prototype.isValid = function () { ...@@ -1638,7 +1732,7 @@ cRef.prototype.isValid = function () {
/** @constructor */ /** @constructor */
function cArea3D( val, _wsFrom, _wsTo, wb ) {/*Area3D means "Sheat1!A1:E5" for example*/ function cArea3D( val, _wsFrom, _wsTo, wb ) {/*Area3D means "Sheat1!A1:E5" for example*/
cArea3D.superclass.constructor.call( this, val ); cBaseType.apply( this, arguments );
this._wb = wb; this._wb = wb;
this._cells = val; this._cells = val;
this.isAbsolute = false; this.isAbsolute = false;
...@@ -1646,7 +1740,7 @@ function cArea3D( val, _wsFrom, _wsTo, wb ) {/*Area3D means "Sheat1!A1:E5" for e ...@@ -1646,7 +1740,7 @@ function cArea3D( val, _wsFrom, _wsTo, wb ) {/*Area3D means "Sheat1!A1:E5" for e
this.wsFrom = this._wb.getWorksheetByName( _wsFrom ).getId(); this.wsFrom = this._wb.getWorksheetByName( _wsFrom ).getId();
this.wsTo = this._wb.getWorksheetByName( _wsTo ).getId(); this.wsTo = this._wb.getWorksheetByName( _wsTo ).getId();
} }
extend( cArea3D, cBaseType ); cArea3D.prototype = Object.create(cBaseType.prototype);
cArea3D.prototype.wsRange = function () { cArea3D.prototype.wsRange = function () {
var r = []; var r = [];
if ( !this.wsTo ) this.wsTo = this.wsFrom; if ( !this.wsTo ) this.wsTo = this.wsFrom;
...@@ -1691,25 +1785,25 @@ cArea3D.prototype.getValue = function () { ...@@ -1691,25 +1785,25 @@ cArea3D.prototype.getValue = function () {
return _val; return _val;
} }
_r[i]._foreachNoEmpty( function ( _cell ) { _r[i]._foreachNoEmpty( function ( _cell ) {
switch ( _cell.getType() ) { var cellType = _cell.getType()
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) ) _cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
break; }
case CellValueType.Bool: else if ( cellType == CellValueType.Bool ) {
_val.push( new cBool( _cell.getValueWithoutFormat() ) ); _val.push( new cBool( _cell.getValueWithoutFormat() ) );
break; }
case CellValueType.Error: else if ( cellType == CellValueType.Error ) {
_val.push( new cError( _cell.getValueWithoutFormat() ) ); _val.push( new cError( _cell.getValueWithoutFormat() ) );
break; }
case CellValueType.String: else if ( cellType == CellValueType.String ) {
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
}
else {
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) ); _val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
break;
default:
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
} }
} ) } )
} }
...@@ -1736,26 +1830,26 @@ cArea3D.prototype.getValue2 = function ( cell ) { ...@@ -1736,26 +1830,26 @@ cArea3D.prototype.getValue2 = function ( cell ) {
} }
_r[0]._foreachNoEmpty( function ( _cell ) { _r[0]._foreachNoEmpty( function ( _cell ) {
if ( cell.getID() == _cell.getName() ) if ( cell.getID() == _cell.getName() )
switch ( _cell.getType() ) { var cellType = _cell.getType();
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) ) _cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
break; }
case CellValueType.Bool: else if ( cellType == CellValueType.Bool ) {
_val.push( new cBool( _cell.getValueWithoutFormat() ) ); _val.push( new cBool( _cell.getValueWithoutFormat() ) );
break; }
case CellValueType.Error: else if ( cellType == CellValueType.Error ) {
_val.push( new cError( _cell.getValueWithoutFormat() ) ); _val.push( new cError( _cell.getValueWithoutFormat() ) );
break; }
case CellValueType.String: else if ( cellType == CellValueType.String ) {
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) ); _val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
break; }
default: else {
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) { if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) ) _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
} }
else
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
}
} ) } )
if( _val[0] == undefined || _val[0] == null ) if( _val[0] == undefined || _val[0] == null )
...@@ -1890,25 +1984,25 @@ cArea3D.prototype.getMatrix = function () { ...@@ -1890,25 +1984,25 @@ cArea3D.prototype.getMatrix = function () {
if ( !arr[k][i - r1] ) if ( !arr[k][i - r1] )
arr[k][i - r1] = []; arr[k][i - r1] = [];
if ( cell ) { if ( cell ) {
switch ( cell.getType() ) { var cellType = cell.getType();
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
arr[k][i - r1][j - c1] = cell.getValueWithoutFormat() == "" ? new cEmpty() : new cNumber( cell.getValueWithoutFormat() ) arr[k][i - r1][j - c1] = cell.isEmptyTextString() ? new cEmpty() : new cNumber( cell.getValueWithoutFormat() )
break; }
case CellValueType.Bool: else if ( cellType == CellValueType.Bool ) {
arr[k][i - r1][j - c1] = new cBool( cell.getValueWithoutFormat() ); arr[k][i - r1][j - c1] = new cBool( cell.getValueWithoutFormat() );
break; }
case CellValueType.Error: else if ( cellType == CellValueType.Error ) {
arr[k][i - r1][j - c1] = new cError( cell.getValueWithoutFormat() ); arr[k][i - r1][j - c1] = new cError( cell.getValueWithoutFormat() );
break; }
case CellValueType.String: else if ( cellType == CellValueType.String ) {
arr[k][i - r1][j - c1] = new cString( cell.getValueWithoutFormat() ); arr[k][i - r1][j - c1] = new cString( cell.getValueWithoutFormat() );
break; }
default: else {
if ( cell.getValueWithoutFormat() && cell.getValueWithoutFormat() != "" ) { if ( cell.isEmptyTextString() ) {
arr[k][i - r1][j - c1] = new cNumber( cell.getValueWithoutFormat() ) arr[k][i - r1][j - c1] = new cNumber( cell.getValueWithoutFormat() )
} }
else else
arr[k][i - r1][j - c1] = checkTypeCell( "" + cell.getValueWithoutFormat() ); arr[k][i - r1][j - c1] = checkTypeCell( "" + cell.getValueWithoutFormat() );
} }
} }
else else
...@@ -1926,25 +2020,25 @@ cArea3D.prototype.foreach2 = function ( action ) { ...@@ -1926,25 +2020,25 @@ cArea3D.prototype.foreach2 = function ( action ) {
_r[i]._foreach2( function ( _cell ) { _r[i]._foreach2( function ( _cell ) {
var val; var val;
if(_cell){ if(_cell){
switch ( _cell.getType() ) { var cellType =_cell.getType();
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? val = new cEmpty() : val = new cNumber( _cell.getValueWithoutFormat() ) _cell.getValueWithoutFormat() == "" ? val = new cEmpty() : val = new cNumber( _cell.getValueWithoutFormat() )
break; }
case CellValueType.Bool: else if ( cellType == CellValueType.Bool ) {
val = new cBool( _cell.getValueWithoutFormat() ); val = new cBool( _cell.getValueWithoutFormat() );
break; }
case CellValueType.Error: else if ( cellType == CellValueType.Error ) {
val = new cError( _cell.getValueWithoutFormat() ); val = new cError( _cell.getValueWithoutFormat() );
break; }
case CellValueType.String: else if ( cellType == CellValueType.String ) {
val = new cString( _cell.getValueWithoutFormat() ); val = new cString( _cell.getValueWithoutFormat() );
break; }
default: else {
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) { if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
val = new cNumber( _cell.getValueWithoutFormat() ) val = new cNumber( _cell.getValueWithoutFormat() )
} }
else else
val = checkTypeCell( "" + _cell.getValueWithoutFormat() ); val = checkTypeCell( "" + _cell.getValueWithoutFormat() );
} }
} }
else else
...@@ -1957,14 +2051,14 @@ cArea3D.prototype.foreach2 = function ( action ) { ...@@ -1957,14 +2051,14 @@ cArea3D.prototype.foreach2 = function ( action ) {
/** @constructor */ /** @constructor */
function cRef3D( val, _wsFrom, wb ) {/*Ref means Sheat1!A1 for example*/ function cRef3D( val, _wsFrom, wb ) {/*Ref means Sheat1!A1 for example*/
cRef3D.superclass.constructor.call( this, val ); cBaseType.apply( this, arguments );
this._wb = wb; this._wb = wb;
this._cells = val; this._cells = val;
this.isAbsolute = false; this.isAbsolute = false;
this.type = cElementType.cell; this.type = cElementType.cell;
this.ws = this._wb.getWorksheetByName( _wsFrom ); this.ws = this._wb.getWorksheetByName( _wsFrom );
} }
extend( cRef3D, cBaseType ); cRef3D.prototype = Object.create(cBaseType.prototype);
cRef3D.prototype.getWsId = function () { cRef3D.prototype.getWsId = function () {
return this.ws.Id; return this.ws.Id;
}; };
...@@ -1984,23 +2078,25 @@ cRef3D.prototype.getValue = function () { ...@@ -1984,23 +2078,25 @@ cRef3D.prototype.getValue = function () {
if ( !_r ) { if ( !_r ) {
return new cError( cErrorType.bad_reference ); return new cError( cErrorType.bad_reference );
} }
switch ( _r.getType() ) { var cellType = _r.getType();
case CellValueType.Number: if ( cellType == CellValueType.Number ) {
{ var v = _r.getValueWithoutFormat();
var v = _r.getValueWithoutFormat(); if ( v == "" )
if ( v == "" ) return new cEmpty();
return new cEmpty( "" + v ); else
else return new cNumber( "" + v );
return new cNumber( "" + v ); }
} else if ( cellType == CellValueType.String ) {
case CellValueType.String: return new cString( "" + _r.getValueWithoutFormat() );
return new cString( "" + _r.getValueWithoutFormat() ); }
case CellValueType.Bool: else if ( cellType == CellValueType.Bool ) {
return new cBool( "" + _r.getValueWithoutFormat() ) return new cBool( "" + _r.getValueWithoutFormat() )
case CellValueType.Error: }
return new cError( "" + _r.getValueWithoutFormat() ) else if ( cellType == CellValueType.Error ) {
default: return new cError( "" + _r.getValueWithoutFormat() )
return checkTypeCell( "" + _r.getValueWithoutFormat() ) }
else {
return checkTypeCell( "" + _r.getValueWithoutFormat() )
} }
}; };
cRef3D.prototype.tocBool = function () { cRef3D.prototype.tocBool = function () {
...@@ -2035,10 +2131,10 @@ cRef3D.prototype.getWS = function () { ...@@ -2035,10 +2131,10 @@ cRef3D.prototype.getWS = function () {
/** @constructor */ /** @constructor */
function cEmpty() { function cEmpty() {
cEmpty.superclass.constructor.call( this, "" ); cBaseType.apply( this, [""] );
this.type = cElementType.empty; this.type = cElementType.empty;
} }
extend( cEmpty, cBaseType ); cEmpty.prototype = Object.create(cBaseType.prototype);
cEmpty.prototype.tocNumber = function () { cEmpty.prototype.tocNumber = function () {
return new cNumber( 0 ); return new cNumber( 0 );
}; };
...@@ -2054,11 +2150,11 @@ cEmpty.prototype.toString = function () { ...@@ -2054,11 +2150,11 @@ cEmpty.prototype.toString = function () {
/** @constructor */ /** @constructor */
function cName( val, wb ) { function cName( val, wb ) {
cName.superclass.constructor.call( this, val ); cBaseType.apply( this, arguments );
this.wb = wb; this.wb = wb;
this.type = cElementType.name; this.type = cElementType.name;
} }
extend( cName, cBaseType ); cName.prototype = Object.create(cBaseType.prototype);
cName.prototype.toRef = function ( wsID ) { cName.prototype.toRef = function ( wsID ) {
var _3DRefTmp, var _3DRefTmp,
ref = this.wb.getDefinesNames( this.value, wsID ).Ref; ref = this.wb.getDefinesNames( this.value, wsID ).Ref;
...@@ -2081,14 +2177,14 @@ cName.prototype.toRef = function ( wsID ) { ...@@ -2081,14 +2177,14 @@ cName.prototype.toRef = function ( wsID ) {
/** @constructor */ /** @constructor */
function cArray() { function cArray() {
cArray.superclass.constructor.call( this ); cBaseType.apply( this, arguments );
this.array = []; this.array = [];
this.rowCount = 0; this.rowCount = 0;
this.countElementInRow = []; this.countElementInRow = [];
this.countElement = 0; this.countElement = 0;
this.type = cElementType.array; this.type = cElementType.array;
} }
extend( cArray, cBaseType ); cArray.prototype = Object.create(cBaseType.prototype);
cArray.prototype.addRow = function () { cArray.prototype.addRow = function () {
this.array[this.array.length] = []; this.array[this.array.length] = [];
this.countElementInRow[this.rowCount++] = 0; this.countElementInRow[this.rowCount++] = 0;
...@@ -2279,11 +2375,11 @@ parserFormula.prototype = { ...@@ -2279,11 +2375,11 @@ parserFormula.prototype = {
if ( operand_expected ) { if ( operand_expected ) {
if ( this.operand_str == "-" ) { if ( this.operand_str == "-" ) {
operand_expected = true; operand_expected = true;
found_operator = cFormulaOperators['un_minus'](); found_operator = new cFormulaOperators['un_minus']();
} }
else if ( this.operand_str == "+" ) { else if ( this.operand_str == "+" ) {
operand_expected = true; operand_expected = true;
found_operator = cFormulaOperators['un_plus'](); found_operator = new cFormulaOperators['un_plus']();
} }
else { else {
this.error.push( c_oAscError.ID.FrmlWrongOperator ); this.error.push( c_oAscError.ID.FrmlWrongOperator );
...@@ -2295,19 +2391,19 @@ parserFormula.prototype = { ...@@ -2295,19 +2391,19 @@ parserFormula.prototype = {
else if ( !operand_expected ) { else if ( !operand_expected ) {
if ( this.operand_str == "-" ) { if ( this.operand_str == "-" ) {
operand_expected = true; operand_expected = true;
found_operator = cFormulaOperators['-'](); found_operator = new cFormulaOperators['-']();
} }
else if ( this.operand_str == "+" ) { else if ( this.operand_str == "+" ) {
operand_expected = true; operand_expected = true;
found_operator = cFormulaOperators['+'](); found_operator = new cFormulaOperators['+']();
} }
else if ( this.operand_str == "%" ) { else if ( this.operand_str == "%" ) {
operand_expected = false; operand_expected = false;
found_operator = cFormulaOperators['%'](); found_operator = new cFormulaOperators['%']();
} }
else { else {
if ( this.operand_str in cFormulaOperators ) { if ( this.operand_str in cFormulaOperators ) {
found_operator = cFormulaOperators[this.operand_str](); found_operator = new cFormulaOperators[this.operand_str]();
operand_expected = true; operand_expected = true;
} }
else { else {
...@@ -2339,7 +2435,7 @@ parserFormula.prototype = { ...@@ -2339,7 +2435,7 @@ parserFormula.prototype = {
/* Left & Right Parentheses */ /* Left & Right Parentheses */
else if ( parserHelp.isLeftParentheses.call( this, this.Formula, this.pCurrPos ) ) { else if ( parserHelp.isLeftParentheses.call( this, this.Formula, this.pCurrPos ) ) {
operand_expected = true; operand_expected = true;
this.elemArr.push( cFormulaOperators[this.operand_str]() ); this.elemArr.push( new cFormulaOperators[this.operand_str]() );
} }
else if ( parserHelp.isRightParentheses.call( this, this.Formula, this.pCurrPos ) ) { else if ( parserHelp.isRightParentheses.call( this, this.Formula, this.pCurrPos ) ) {
...@@ -2692,7 +2788,7 @@ parserFormula.prototype = { ...@@ -2692,7 +2788,7 @@ parserFormula.prototype = {
return this.value; return this.value;
}, },
/* Метод возвращает все ссылки на ячейки которые учавствуют в формуле*/ /* Метод возвращает все ссылки на ячейки которые участвуют в формуле*/
getRef:function () { getRef:function () {
var aOutRef = []; var aOutRef = [];
for ( var i = 0; i < this.outStack.length; i++ ) { for ( var i = 0; i < this.outStack.length; i++ ) {
...@@ -3161,7 +3257,7 @@ function searchRegExp(str, flags){ ...@@ -3161,7 +3257,7 @@ function searchRegExp(str, flags){
return $1 ? $0 : '(.*)'; return $1 ? $0 : '(.*)';
} ) } )
.replace( /(~)?\?/g, function ( $0, $1 ) { .replace( /(~)?\?/g, function ( $0, $1 ) {
return $1 ? $0 : '.'; return $1 ? $0 : '.{1}';
} ) } )
.replace( /(~\*)/g, "\\*" ).replace( /(~\?)/g, "\\?" ); .replace( /(~\*)/g, "\\*" ).replace( /(~\?)/g, "\\?" );
...@@ -3325,8 +3421,7 @@ function lcl_Erfc0600( x ) { ...@@ -3325,8 +3421,7 @@ function lcl_Erfc0600( x ) {
return fVal = Math.exp( -1.0 * x * x ) * fPSum / fQSum; return fVal = Math.exp( -1.0 * x * x ) * fPSum / fQSum;
} }
/** Approximation algorithm for erfc for 6.0 < x < 26.54 (but used for all /** Approximation algorithm for erfc for 6.0 < x < 26.54 (but used for all x > 6.0). */
x > 6.0). */
function lcl_Erfc2654( x ) { function lcl_Erfc2654( x ) {
var pn = [ var pn = [
5.64189583547756078E-1, 5.64189583547756078E-1,
......
...@@ -38,127 +38,115 @@ function consolelog(text){ ...@@ -38,127 +38,115 @@ function consolelog(text){
} }
/** @constructor */ /** @constructor */
function DependencyGraph(wb) { function DependencyGraph( wb ) {
this.wb = wb; this.wb = wb;
this.nodesId = null; this.nodesId = null;
this.nodesCell = null; this.nodesCell = null;
this.nodesArea = null; this.nodesArea = null;
this.nodeslength = null; this.nodeslength = null;
this.bSetRefError = false; this.bSetRefError = false;
this.clear(); this.clear();
} }
DependencyGraph.prototype = { DependencyGraph.prototype = {
clear : function(){ clear:function () {
this.nodesId = {}; this.nodesId = {};
this.nodesCell = {}; this.nodesCell = {};
this.nodesArea = {}; this.nodesArea = {};
this.nodeslength = 0; this.nodeslength = 0;
this.bSetRefError = false; this.bSetRefError = false;
}, },
nodeExist : function(node){ nodeExist:function ( node ) {
return this.nodeExist2(node.sheetId, node.cellId); return this.nodeExist2( node.sheetId, node.cellId );
}, },
nodeExist2 : function(sheetId, cellId){ nodeExist2:function ( sheetId, cellId ) {
return null != this.getNode(sheetId, cellId); return null != this.getNode( sheetId, cellId );
}, },
nodeExistWithArea : function(sheetId, cellId){ nodeExistWithArea:function ( sheetId, cellId ) {
var bRes = this.nodeExist2(sheetId, cellId); var bRes = this.nodeExist2( sheetId, cellId );
if(!bRes) if ( !bRes ) {
{ var nodesSheetArea = this.nodesArea[sheetId];
var nodesSheetArea = this.nodesArea[sheetId]; if ( null != nodesSheetArea ) {
if(null != nodesSheetArea) var bbox = Asc.g_oRangeCache.getAscRange( cellId );
{ bRes = nodesSheetArea.get( bbox ).all.length > 0;
var bbox = Asc.g_oRangeCache.getAscRange(cellId); }
bRes = nodesSheetArea.get(bbox).all.length > 0; }
} return bRes;
} },
return bRes; getNode2:function ( node ) {
}, return this.nodesId[node.nodeId];
getNode2 : function(node){ },
return this.nodesId[node.nodeId]; getNode:function ( sheetId, cellId ) {
}, return this.nodesId[getVertexId( sheetId, cellId )];
getNode : function(sheetId, cellId){ },
return this.nodesId[getVertexId(sheetId, cellId)]; addNode2:function ( node ) {
}, return this.addNode( node.sheetId, node.cellId );
addNode2 : function(node){ },
return this.addNode(node.sheetId, node.cellId); addNode:function ( sheetId, cellId ) {
},
addNode : function(sheetId, cellId){
var _this = this; var _this = this;
var nodeId = getVertexId(sheetId, cellId) var nodeId = getVertexId( sheetId, cellId )
var oRes = this.nodesId[nodeId]; var oRes = this.nodesId[nodeId];
if(null == oRes) if ( null == oRes ) {
{ var node = new Vertex( sheetId, cellId, this.wb )
var node = new Vertex(sheetId, cellId, this.wb) var oBBoxNode = node.getBBox();
var oBBoxNode = node.getBBox(); if ( node.isArea ) {
if(node.isArea) var nodesSheetArea = this.nodesArea[node.sheetId];
{ if ( null == nodesSheetArea ) {
var nodesSheetArea = this.nodesArea[node.sheetId];
if(null == nodesSheetArea)
{
nodesSheetArea = new RangeDataManager(function(data, from, to){_this._changeNode(data, from, to);}); nodesSheetArea = new RangeDataManager(function(data, from, to){_this._changeNode(data, from, to);});
this.nodesArea[node.sheetId] = nodesSheetArea; this.nodesArea[node.sheetId] = nodesSheetArea;
} }
nodesSheetArea.add(oBBoxNode, node); nodesSheetArea.add( oBBoxNode, node );
} }
else else {
{ var nodesSheetCell = this.nodesCell[node.sheetId];
var nodesSheetCell = this.nodesCell[node.sheetId]; if ( null == nodesSheetCell ) {
if(null == nodesSheetCell)
{
nodesSheetCell = new CellArea(function(data, from, to){_this._changeNode(data, from, to);}); nodesSheetCell = new CellArea(function(data, from, to){_this._changeNode(data, from, to);});
this.nodesCell[node.sheetId] = nodesSheetCell; this.nodesCell[node.sheetId] = nodesSheetCell;
} }
nodesSheetCell.add(oBBoxNode.r1, oBBoxNode.c1, node); nodesSheetCell.add( oBBoxNode.r1, oBBoxNode.c1, node );
} }
oRes = node; oRes = node;
} }
return oRes; return oRes;
}, },
addEdge2 : function(nodeFrom, nodeTo){ addEdge2:function ( nodeFrom, nodeTo ) {
nodeFrom.addMasterEdge(nodeTo); nodeFrom.addMasterEdge( nodeTo );
nodeTo.addSlaveEdge(nodeFrom); nodeTo.addSlaveEdge( nodeFrom );
}, },
addEdge : function(sheetIdFrom, cellIdFrom, sheetIdTo, cellIdTo){ addEdge:function ( sheetIdFrom, cellIdFrom, sheetIdTo, cellIdTo ) {
var n1 = this.addNode(sheetIdFrom, cellIdFrom), var n1 = this.addNode( sheetIdFrom, cellIdFrom ),
n2 = this.addNode(sheetIdTo, cellIdTo); n2 = this.addNode( sheetIdTo, cellIdTo );
this.addEdge2(n1, n2); this.addEdge2( n1, n2 );
}, },
getNodeBySheetId : function(sheetId){ getNodeBySheetId:function ( sheetId ) {
var arr = []; var arr = [];
var nodesSheetCell = this.nodesCell[sheetId]; var nodesSheetCell = this.nodesCell[sheetId];
if(nodesSheetCell) if ( nodesSheetCell ) {
{ var aNodes = nodesSheetCell.getAll();
var aNodes = nodesSheetCell.getAll(); for ( var i = 0, length = aNodes.length; i < length; i++ ) {
for(var i = 0, length = aNodes.length; i < length; i++) var node = aNodes[i].data;
{ var n = node.getSlaveEdges();
var node = aNodes[i].data; if ( n ) {
var n = node.getSlaveEdges(); arr.push( node );
if(n) for ( var id2 in n ) {
{ n[id2].weightNode++;
arr.push(node); // arr.push(n[id2]);
for(var id2 in n){ }
n[id2].weightNode++; }
// arr.push(n[id2]); }
} }
} return arr;
} },
}
return arr;
},
deleteNode : function(node){ deleteNode : function(node){
if(node.isArea) if ( node.isArea ) {
{
var nodesSheetArea = this.nodesArea[node.sheetId]; var nodesSheetArea = this.nodesArea[node.sheetId];
if(nodesSheetArea) if(nodesSheetArea)
nodesSheetArea.removeElement(new RangeDataManagerElem(node.getBBox(), node)); nodesSheetArea.removeElement(new RangeDataManagerElem(node.getBBox(), node));
} }
else else {
{
var nodesSheetCell = this.nodesCell[node.sheetId]; var nodesSheetCell = this.nodesCell[node.sheetId];
if(nodesSheetCell) if(nodesSheetCell)
nodesSheetCell.removeElement(new RangeDataManagerElem(node.getBBox(), node)); nodesSheetCell.removeElement(new RangeDataManagerElem(node.getBBox(), node));
} }
}, },
deleteNodes : function(sheetId, bbox){ deleteNodes : function(sheetId, bbox){
var bSetRefErrorOld = this.bSetRefError; var bSetRefErrorOld = this.bSetRefError;
...@@ -170,7 +158,7 @@ DependencyGraph.prototype = { ...@@ -170,7 +158,7 @@ DependencyGraph.prototype = {
oGetRes = nodesSheetArea.get(bbox); oGetRes = nodesSheetArea.get(bbox);
for(var i = 0, length = oGetRes.inner.length; i < length; ++i) for(var i = 0, length = oGetRes.inner.length; i < length; ++i)
nodesSheetArea.removeElement(oGetRes.inner[i]); nodesSheetArea.removeElement(oGetRes.inner[i]);
} }
var nodesSheetCell = this.nodesCell[sheetId]; var nodesSheetCell = this.nodesCell[sheetId];
if(nodesSheetCell) if(nodesSheetCell)
{ {
...@@ -179,58 +167,57 @@ DependencyGraph.prototype = { ...@@ -179,58 +167,57 @@ DependencyGraph.prototype = {
nodesSheetCell.removeElement(oGetRes[i]); nodesSheetCell.removeElement(oGetRes[i]);
} }
this.bSetRefError = bSetRefErrorOld; this.bSetRefError = bSetRefErrorOld;
}, },
deleteMasterNodes : function(sheetId, cellId){ deleteMasterNodes:function ( sheetId, cellId ) {
var node = this.getNode(sheetId, cellId); var node = this.getNode( sheetId, cellId );
if(node) if ( node ) {
{ var arr = node.deleteAllMasterEdges();
var arr = node.deleteAllMasterEdges(); for ( var i in arr ) {
for(var i in arr){ var nodeMaster = arr[i];
var nodeMaster = arr[i]; if ( nodeMaster.refCount <= 0 )
if( nodeMaster.refCount <= 0 ) this.deleteNode( nodeMaster );
this.deleteNode(nodeMaster); }
} }
}
return node; return node;
}, },
deleteMasterNodes2 : function(sheetId, cellId){ deleteMasterNodes2 : function(sheetId, cellId){
var node = this.deleteMasterNodes(sheetId, cellId); var node = this.deleteMasterNodes(sheetId, cellId);
if(node && node.refCount <= 0) if(node && node.refCount <= 0)
this.deleteNode(node); this.deleteNode(node);
return node; return node;
}, },
getSlaveNodes : function(sheetId, cellId){ getSlaveNodes:function ( sheetId, cellId ) {
//todo //todo
return null; return null;
}, },
getMasterNodes : function(sheetId, cellId){ getMasterNodes:function ( sheetId, cellId ) {
//todo //todo
return null; return null;
}, },
getNodesLength : function(){ getNodesLength:function () {
return this.nodeslength; return this.nodeslength;
}, },
checkOffset : function(BBox, offset, wsId, noDelete){ checkOffset:function ( BBox, offset, wsId, noDelete ) {
var _this = this; var _this = this;
var bHor = 0 != offset.offsetCol; var bHor = 0 != offset.offsetCol;
var toDelete = offset.offsetCol < 0 || offset.offsetRow < 0; var toDelete = offset.offsetCol < 0 || offset.offsetRow < 0;
var bSetRefErrorOld = this.bSetRefError; var bSetRefErrorOld = this.bSetRefError;
this.bSetRefError = true; this.bSetRefError = true;
var oShiftGetBBox = shiftGetBBox(BBox, bHor); var oShiftGetBBox = shiftGetBBox(BBox, bHor);
var sShiftGetBBoxName = oShiftGetBBox.getName(); var sShiftGetBBoxName = oShiftGetBBox.getName();
this.wb.needRecalc.nodes[getVertexId(wsId, sShiftGetBBoxName)] = [wsId, sShiftGetBBoxName]; this.wb.needRecalc.nodes[getVertexId(wsId, sShiftGetBBoxName)] = [wsId, sShiftGetBBoxName];
this.wb.needRecalc.length++; this.wb.needRecalc.length++;
var nodesSheetArea = this.nodesArea[wsId]; var nodesSheetArea = this.nodesArea[wsId];
if(nodesSheetArea) if(nodesSheetArea)
nodesSheetArea.shift(BBox, !toDelete, bHor); nodesSheetArea.shift(BBox, !toDelete, bHor);
var nodesSheetCell = this.nodesCell[wsId]; var nodesSheetCell = this.nodesCell[wsId];
if(nodesSheetCell) if(nodesSheetCell)
nodesSheetCell.shift(BBox, !toDelete, bHor); nodesSheetCell.shift( BBox, !toDelete, bHor );
this.bSetRefError = bSetRefErrorOld; this.bSetRefError = bSetRefErrorOld;
}, },
_changeNode : function(node, from, to) _changeNode : function(node, from, to)
{ {
var toDelete = null == to; var toDelete = null == to;
var toAdd = null == from; var toAdd = null == from;
var wsId = node.sheetId; var wsId = node.sheetId;
if(toAdd) if(toAdd)
...@@ -254,61 +241,57 @@ DependencyGraph.prototype = { ...@@ -254,61 +241,57 @@ DependencyGraph.prototype = {
delete this.nodesId[node.nodeId]; delete this.nodesId[node.nodeId];
this.nodeslength--; this.nodeslength--;
} }
else else {
{ var sOldnodeId = node.nodeId;
var sOldnodeId = node.nodeId; var sOldCellId = node.cellId;
var sOldCellId = node.cellId;
if((from.r1 == to.r1 && from.c1 == to.c1) || (from.r2 == to.r2 && from.c2 == to.c2)) if((from.r1 == to.r1 && from.c1 == to.c1) || (from.r2 == to.r2 && from.c2 == to.c2))
node.moveStretch(to); node.moveStretch(to);
else else
node.move({offsetCol: to.c1 - from.c1, offsetRow: to.r1 - from.r1}, wsId, toDelete); node.move({offsetCol: to.c1 - from.c1, offsetRow: to.r1 - from.r1}, wsId, toDelete);
delete this.nodesId[sOldnodeId]; delete this.nodesId[sOldnodeId];
this.nodesId[node.nodeId] = node; this.nodesId[node.nodeId] = node;
} }
//важно что ячейки уже сдвинулись, поэтому до вызова returnCell нужно сделать node.move //важно что ячейки уже сдвинулись, поэтому до вызова returnCell нужно сделать node.move
if(!node.isArea) if(!node.isArea)
{ {
var cwf = this.wb.cwf[wsId]; var cwf = this.wb.cwf[wsId];
if(cwf) if(cwf)
{ {
var cell = node.returnCell(); var cell = node.returnCell();
if( cell && cell.formulaParsed ) if ( cell && cell.formulaParsed ) {
{
if(!toAdd) if(!toAdd)
delete cwf.cells[sOldCellId]; delete cwf.cells[sOldCellId];
if(!toDelete) if ( !toDelete )
cwf.cells[node.cellId] = node.cellId; cwf.cells[node.cellId] = node.cellId;
} }
} }
} }
}, },
getCellInRange : function(sheetId, bbox){ getCellInRange : function(sheetId, bbox){
var res = [], oGetRes, nodesSheetCell = this.nodesCell[sheetId]; var res = [], oGetRes, nodesSheetCell = this.nodesCell[sheetId];
if(nodesSheetCell) if ( nodesSheetCell ) {
{
oGetRes = nodesSheetCell.get(bbox); oGetRes = nodesSheetCell.get(bbox);
for(var i = 0, length = oGetRes.length; i < length; i++) for ( var i = 0, length = oGetRes.length; i < length; i++ ) {
{ elem = oGetRes[i];
elem = oGetRes[i];
res.push(elem.data); res.push(elem.data);
} }
} }
return res; return res;
}, },
getAreaInRange : function(sheetId, bbox){ getAreaInRange : function(sheetId, bbox){
var res = [], oGetRes, nodesSheetArea = this.nodesArea[sheetId]; var res = [], oGetRes, nodesSheetArea = this.nodesArea[sheetId];
if(nodesSheetArea) if(nodesSheetArea)
{ {
oGetRes = nodesSheetArea.get(bbox); oGetRes = nodesSheetArea.get(bbox);
for(var i = 0, length = oGetRes.all.length; i < length; i++) for(var i = 0, length = oGetRes.all.length; i < length; i++)
{ {
elem = oGetRes.all[i]; elem = oGetRes.all[i];
res.push(elem.data); res.push(elem.data);
} }
} }
return res; return res;
}, },
getInRange : function(sheetId, bbox){ getInRange : function(sheetId, bbox){
return this.getCellInRange(sheetId, bbox).concat(this.getAreaInRange(sheetId, bbox)); return this.getCellInRange(sheetId, bbox).concat(this.getAreaInRange(sheetId, bbox));
}, },
...@@ -321,312 +304,293 @@ DependencyGraph.prototype = { ...@@ -321,312 +304,293 @@ DependencyGraph.prototype = {
if(nodesSheetArea) if(nodesSheetArea)
oGetRes = nodesSheetArea.move(BBoxFrom, oBBoxTo); oGetRes = nodesSheetArea.move(BBoxFrom, oBBoxTo);
}, },
drawDep : function(cellId,se){ drawDep:function ( cellId, se ) {
// ToDo неиспользуемая функция, реализовать после выпуска // ToDo неиспользуемая функция, реализовать после выпуска
if( !cellId ) if ( !cellId )
return; return;
var _wsV = this.wb.oApi.wb.getWorksheet(), var _wsV = this.wb.oApi.wb.getWorksheet(),
_getCellMetrics = _wsV.cellCommentator.getCellMetrics, _getCellMetrics = _wsV.cellCommentator.getCellMetrics,
_cc = _wsV.cellCommentator, _cc = _wsV.cellCommentator,
ctx = _wsV.overlayCtx, ctx = _wsV.overlayCtx,
_wsVM = _wsV.model, _wsVM = _wsV.model,
nodeId = getVertexId(_wsVM.getId(), cellId), nodeId = getVertexId( _wsVM.getId(), cellId ),
node = this.getNode(_wsVM.getId(), cellId), node = this.getNode( _wsVM.getId(), cellId ),
cell; cell;
function gCM(_this,col,row){
var metrics = { top: 0, left: 0, width: 0, height: 0, result: false }; // px
var fvr = _this.getFirstVisibleRow(); function gCM( _this, col, row ) {
var fvc = _this.getFirstVisibleCol(); var metrics = { top:0, left:0, width:0, height:0, result:false }; // px
var mergedRange = _wsVM.getMergedByCell(row, col);
if (mergedRange && (fvc < mergedRange.c2) && (fvr < mergedRange.r2)) { var fvr = _this.getFirstVisibleRow();
var fvc = _this.getFirstVisibleCol();
var mergedRange = _wsVM.getMergedByCell( row, col );
var startCol = (mergedRange.c1 > fvc) ? mergedRange.c1 : fvc; if ( mergedRange && (fvc < mergedRange.c2) && (fvr < mergedRange.r2) ) {
var startRow = (mergedRange.r1 > fvr) ? mergedRange.r1 : fvr;
metrics.top = _this.getCellTop(startRow, 0) - _this.getCellTop(fvr, 0) + _this.getCellTop(0, 0); var startCol = (mergedRange.c1 > fvc) ? mergedRange.c1 : fvc;
metrics.left = _this.getCellLeft(startCol, 0) - _this.getCellLeft(fvc, 0) + _this.getCellLeft(0, 0); var startRow = (mergedRange.r1 > fvr) ? mergedRange.r1 : fvr;
for (var i = startCol; i <= mergedRange.c2; i++) { metrics.top = _this.getCellTop( startRow, 0 ) - _this.getCellTop( fvr, 0 ) + _this.getCellTop( 0, 0 );
metrics.width += _this.getColumnWidth(i, 0) metrics.left = _this.getCellLeft( startCol, 0 ) - _this.getCellLeft( fvc, 0 ) + _this.getCellLeft( 0, 0 );
}
for (var i = startRow; i <= mergedRange.r2; i++) {
metrics.height += _this.getRowHeight(i, 0)
}
metrics.result = true;
}
else{
metrics.top = _this.getCellTop(row, 0) - _this.getCellTop(fvr, 0) + _this.getCellTop(0, 0); for ( var i = startCol; i <= mergedRange.c2; i++ ) {
metrics.left = _this.getCellLeft(col, 0) - _this.getCellLeft(fvc, 0) + _this.getCellLeft(0, 0); metrics.width += _this.getColumnWidth( i, 0 )
metrics.width = _this.getColumnWidth(col, 0); }
metrics.height = _this.getRowHeight(row, 0); for ( var i = startRow; i <= mergedRange.r2; i++ ) {
metrics.result = true; metrics.height += _this.getRowHeight( i, 0 )
} }
metrics.result = true;
return metrics; }
} else {
if( !node )
return;
cell = node.returnCell();
if( !cell )
return;
var m = [cell.getCellAddress().getRow0(),cell.getCellAddress().getCol0()],
rc = [], me = se?node.getSlaveEdges():node.getMasterEdges();
for( var id in me ){
if( me[id].sheetId != node.sheetId )
return;
if( !me[id].isArea ){
var _t1 = gCM(_wsV,me[id].returnCell().getCellAddress().getCol0(),me[id].returnCell().getCellAddress().getRow0())
rc.push({ t: _t1.top, l: _t1.left, w: _t1.width, h: _t1.height, apt: _t1.top+_t1.height/2, apl: _t1.left+_t1.width/4});
}
else{
var _t1 = gCM(_wsV,me[id].getBBox().c1,me[id].getBBox().r1),
_t2 = gCM(_wsV,me[id].getBBox().c2,me[id].getBBox().r2);
rc.push({ t: _t1.top, l: _t1.left, w: _t2.left+_t2.width-_t1.left, h: _t2.top+_t2.height-_t1.top, apt: _t1.top+_t1.height/2, apl:_t1.left+_t1.width/4 });
}
}
if( rc.length == 0 )
return;
var color = new CColor(0, 0, 255); metrics.top = _this.getCellTop( row, 0 ) - _this.getCellTop( fvr, 0 ) + _this.getCellTop( 0, 0 );
metrics.left = _this.getCellLeft( col, 0 ) - _this.getCellLeft( fvc, 0 ) + _this.getCellLeft( 0, 0 );
function draw_arrow(context, fromx, fromy, tox, toy) { metrics.width = _this.getColumnWidth( col, 0 );
var headlen = 9; metrics.height = _this.getRowHeight( row, 0 );
var dx = tox - fromx; metrics.result = true;
var dy = toy - fromy; }
var angle = Math.atan2(dy, dx), _a = Math.PI / 18;
// ToDo посмотреть на четкость moveTo, lineTo
context.save()
.setLineWidth(1)
.beginPath()
.moveTo(_cc.pxToPt(fromx), _cc.pxToPt(fromy))
.lineTo(_cc.pxToPt(tox), _cc.pxToPt(toy));
// .dashLine(_cc.pxToPt(fromx-.5), _cc.pxToPt(fromy-.5), _cc.pxToPt(tox-.5), _cc.pxToPt(toy-.5), 15, 5)
context
.moveTo(
_cc.pxToPt(tox - headlen * Math.cos(angle - _a)),
_cc.pxToPt(toy - headlen * Math.sin(angle - _a)))
.lineTo(_cc.pxToPt(tox), _cc.pxToPt(toy))
.lineTo(
_cc.pxToPt(tox - headlen * Math.cos(angle + _a)),
_cc.pxToPt(toy - headlen * Math.sin(angle + _a)))
.lineTo(
_cc.pxToPt(tox - headlen * Math.cos(angle - _a)),
_cc.pxToPt(toy - headlen * Math.sin(angle - _a)))
.setStrokeStyle(color)
.setFillStyle(color)
.stroke()
.fill()
.closePath()
.restore();
}
function h(m,rc){
var m = gCM(_wsV,m[1],m[0]);
var arrowPointTop = 10, arrowPointLeft = 10;
for(var i = 0; i<rc.length;i++){
var m2 = rc[i],
x1 = Math.floor(m2.apl),
y1 = Math.floor(m2.apt),
x2 = Math.floor(m.left+m.width/4),
y2 = Math.floor(m.top+m.height/2);
if( x1<0 && x2<0 || y1<0 && y2<0)
continue;
// ToDo посмотреть на четкость rect return metrics;
if( m2.apl > 0 && m2.apt >0) }
ctx.save()
.setLineWidth(1)
.setStrokeStyle(color)
.rect( _cc.pxToPt(m2.l),_cc.pxToPt(m2.t),_cc.pxToPt(m2.w-1),_cc.pxToPt(m2.h-1) )
.stroke()
.restore();
if(y1<0 && x1 != x2)
x1 = x1-Math.floor(Math.sqrt(((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))*y1*y1/((y2-y1)*(y2-y1)))/2)
if(x1<0 && y1 != y2)
y1 = y1-Math.floor(Math.sqrt(((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2))*x1*x1/((x2-x1)*(x2-x1)))/2)
draw_arrow(ctx, x1<0?_wsV.getCellLeft(0, 0):x1, y1<0?_wsV.getCellTop(0, 0):y1, x2, y2);
if( m2.apl > 0 && m2.apt >0)
ctx.save()
.beginPath()
.arc(_cc.pxToPt(Math.floor(m2.apl)),
_cc.pxToPt(Math.floor(m2.apt)),
3,0, 2 * Math.PI, false,-0.5,-0.5)
.setFillStyle(color)
.fill()
.closePath()
.restore();
}
}
ctx.clear();
_wsV._drawSelection();
if( se ){ if ( !node )
for( var i = 0; i < rc.length; i++ ) return;
h(rc[i],[m]);
} cell = node.returnCell();
else
h(m,rc); if ( !cell )
}, return;
removeNodeBySheetId : function(sheetId){
var arr = false; var m = [cell.getCellAddress().getRow0(), cell.getCellAddress().getCol0()],
rc = [], me = se ? node.getSlaveEdges() : node.getMasterEdges();
for ( var id in me ) {
if ( me[id].sheetId != node.sheetId )
return;
if ( !me[id].isArea ) {
var _t1 = gCM( _wsV, me[id].returnCell().getCellAddress().getCol0(), me[id].returnCell().getCellAddress().getRow0() )
rc.push( { t:_t1.top, l:_t1.left, w:_t1.width, h:_t1.height, apt:_t1.top + _t1.height / 2, apl:_t1.left + _t1.width / 4} );
}
else {
var _t1 = gCM( _wsV, me[id].getBBox().c1, me[id].getBBox().r1 ),
_t2 = gCM( _wsV, me[id].getBBox().c2, me[id].getBBox().r2 );
rc.push( { t:_t1.top, l:_t1.left, w:_t2.left + _t2.width - _t1.left, h:_t2.top + _t2.height - _t1.top, apt:_t1.top + _t1.height / 2, apl:_t1.left + _t1.width / 4 } );
}
}
if ( rc.length == 0 )
return;
var color = new CColor( 0, 0, 255 );
function draw_arrow( context, fromx, fromy, tox, toy ) {
var headlen = 9;
var dx = tox - fromx;
var dy = toy - fromy;
var angle = Math.atan2( dy, dx ), _a = Math.PI / 18;
// ToDo посмотреть на четкость moveTo, lineTo
context.save()
.setLineWidth( 1 )
.beginPath()
.moveTo( _cc.pxToPt( fromx ), _cc.pxToPt( fromy ) )
.lineTo( _cc.pxToPt( tox ), _cc.pxToPt( toy ) );
// .dashLine(_cc.pxToPt(fromx-.5), _cc.pxToPt(fromy-.5), _cc.pxToPt(tox-.5), _cc.pxToPt(toy-.5), 15, 5)
context
.moveTo(
_cc.pxToPt( tox - headlen * Math.cos( angle - _a ) ),
_cc.pxToPt( toy - headlen * Math.sin( angle - _a ) ) )
.lineTo( _cc.pxToPt( tox ), _cc.pxToPt( toy ) )
.lineTo(
_cc.pxToPt( tox - headlen * Math.cos( angle + _a ) ),
_cc.pxToPt( toy - headlen * Math.sin( angle + _a ) ) )
.lineTo(
_cc.pxToPt( tox - headlen * Math.cos( angle - _a ) ),
_cc.pxToPt( toy - headlen * Math.sin( angle - _a ) ) )
.setStrokeStyle( color )
.setFillStyle( color )
.stroke()
.fill()
.closePath()
.restore();
}
function h( m, rc ) {
var m = gCM( _wsV, m[1], m[0] );
var arrowPointTop = 10, arrowPointLeft = 10;
for ( var i = 0; i < rc.length; i++ ) {
var m2 = rc[i],
x1 = Math.floor( m2.apl ),
y1 = Math.floor( m2.apt ),
x2 = Math.floor( m.left + m.width / 4 ),
y2 = Math.floor( m.top + m.height / 2 );
if ( x1 < 0 && x2 < 0 || y1 < 0 && y2 < 0 )
continue;
// ToDo посмотреть на четкость rect
if ( m2.apl > 0 && m2.apt > 0 )
ctx.save()
.setLineWidth( 1 )
.setStrokeStyle( color )
.rect( _cc.pxToPt( m2.l ), _cc.pxToPt( m2.t ), _cc.pxToPt( m2.w - 1 ), _cc.pxToPt( m2.h - 1 ) )
.stroke()
.restore();
if ( y1 < 0 && x1 != x2 )
x1 = x1 - Math.floor( Math.sqrt( ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) * y1 * y1 / ((y2 - y1) * (y2 - y1)) ) / 2 )
if ( x1 < 0 && y1 != y2 )
y1 = y1 - Math.floor( Math.sqrt( ((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2)) * x1 * x1 / ((x2 - x1) * (x2 - x1)) ) / 2 )
draw_arrow( ctx, x1 < 0 ? _wsV.getCellLeft( 0, 0 ) : x1, y1 < 0 ? _wsV.getCellTop( 0, 0 ) : y1, x2, y2 );
if ( m2.apl > 0 && m2.apt > 0 )
ctx.save()
.beginPath()
.arc( _cc.pxToPt( Math.floor( m2.apl ) ),
_cc.pxToPt( Math.floor( m2.apt ) ),
3, 0, 2 * Math.PI, false, -0.5, -0.5 )
.setFillStyle( color )
.fill()
.closePath()
.restore();
}
}
ctx.clear();
_wsV._drawSelection();
if ( se ) {
for ( var i = 0; i < rc.length; i++ )
h( rc[i], [m] );
}
else
h( m, rc );
},
removeNodeBySheetId:function ( sheetId ) {
var arr = false;
// this.wb.needRecalc = []; // this.wb.needRecalc = [];
// this.wb.needRecalc.length = 0; // this.wb.needRecalc.length = 0;
var nodesSheet = nodes[sheetId]; var nodesSheet = nodes[sheetId];
if(nodesSheet){ if ( nodesSheet ) {
var aNodes = nodesSheet.getAll(); var aNodes = nodesSheet.getAll();
for(var i = 0, length = aNodes.length; i < length; i++) for ( var i = 0, length = aNodes.length; i < length; i++ ) {
{ var node = aNodes[i].data;
var node = aNodes[i].data; var se = node.getSlaveEdges();
var se = node.getSlaveEdges(); for ( var id2 in se ) {
for(var id2 in se){ if ( se[id2].sheetId != sheetId ) {
if(se[id2].sheetId != sheetId){ if ( !arr ) arr = true;
if(!arr) arr = true;
// this.wb.needRecalc[id2] = [se[id2].sheetId,se[id2].cellId]; // this.wb.needRecalc[id2] = [se[id2].sheetId,se[id2].cellId];
// this.wb.needRecalc.length++; // this.wb.needRecalc.length++;
// arr.push(se[id2]); // arr.push(se[id2]);
} }
} }
node.deleteAllMasterEdges(); node.deleteAllMasterEdges();
node.deleteAllSlaveEdges(); node.deleteAllSlaveEdges();
delete nodesId[node.nodeId]; delete nodesId[node.nodeId];
this.nodeslength--; this.nodeslength--;
} }
nodesSheet.removeAll(); nodesSheet.removeAll();
} }
return arr; return arr;
}, },
getNodeDependence : function(aElems) getNodeDependence:function ( aElems ) {
{ var oRes = {oMasterNodes:{}, oMasterAreaNodes:{}, oWeightMap:{}};
var oRes = {oMasterNodes: {}, oMasterAreaNodes: {}, oWeightMap: {}}; var aWeightMapMasters = [];
var aWeightMapMasters = []; var aWeightMapMastersNodes = [];
var aWeightMapMastersNodes = []; var node;
var node; var elem;
var elem; var oSheetRanges = {};
var oSheetRanges = {}; var bInArea = false;
var bInArea = false; while ( null != aElems ) {
while(null != aElems) for ( var i in aElems ) {
{ elem = aElems[i];
for(var i in aElems) var sheetId = elem[0];
{
elem = aElems[i];
var sheetId = elem[0];
var cellId = elem[1]; var cellId = elem[1];
//нужно обавлять в oSheetRanges даже несушествующие node, чтобы поддержать именении ячеек в SUM(A1:B2) //нужно обавлять в oSheetRanges даже несушествующие node, чтобы поддержать именении ячеек в SUM(A1:B2)
this._getNodeDependenceNodeToRange(sheetId, Asc.g_oRangeCache.getAscRange(cellId), oSheetRanges); this._getNodeDependenceNodeToRange(sheetId, Asc.g_oRangeCache.getAscRange(cellId), oSheetRanges);
node = this.getNode(sheetId, cellId); node = this.getNode(sheetId, cellId);
if(node && null == oRes.oWeightMap[node.nodeId]) if ( node && null == oRes.oWeightMap[node.nodeId] ) {
{ //все node из aElems записываем в master
//все node из aElems записываем в master var oWeightMapElem = {cur:0, max:0, gray:false, bad:false, master:true, area:bInArea};
var oWeightMapElem = {cur: 0, max: 0, gray: false, bad: false, master: true, area: bInArea}; aWeightMapMasters.push( oWeightMapElem );
aWeightMapMasters.push(oWeightMapElem); aWeightMapMastersNodes.push( node );
aWeightMapMastersNodes.push(node); oRes.oWeightMap[node.nodeId] = oWeightMapElem;
oRes.oWeightMap[node.nodeId] = oWeightMapElem; this._getNodeDependence( oRes, oSheetRanges, node );
this._getNodeDependence(oRes, oSheetRanges, node); }
} }
} aElems = null;
aElems = null; bInArea = true;
bInArea = true; //расширяем за счет area nodes
//расширяем за счет area nodes for ( var i in oSheetRanges ) {
for(var i in oSheetRanges) var oSheetRange = oSheetRanges[i];
{ if ( oSheetRange.changed ) {
var oSheetRange = oSheetRanges[i]; oSheetRange.changed = false;
if(oSheetRange.changed) var nodesSheetArea = this.nodesArea[i];
{ if ( null != nodesSheetArea ) {
oSheetRange.changed = false; var aAllOuter = null;
var nodesSheetArea = this.nodesArea[i]; if ( null == oSheetRange.prevRange ) {
if(null != nodesSheetArea) var oGetRes = nodesSheetArea.get( oSheetRange.range );
{ if ( oGetRes.all.length > 0 )
var aAllOuter = null; aAllOuter = oGetRes.all;
if(null == oSheetRange.prevRange) }
{ else {
var oGetRes = nodesSheetArea.get(oSheetRange.range); var aEdgeBBox = [];
if(oGetRes.all.length > 0) if ( oSheetRange.range.c1 < oSheetRange.prevRange.c1 )
aAllOuter = oGetRes.all; aEdgeBBox.push( new Asc.Range( oSheetRange.range.c1, oSheetRange.range.r1, oSheetRange.prevRange.c1 - 1, oSheetRange.range.r2 ) );
} if ( oSheetRange.range.c2 > oSheetRange.prevRange.c2 )
else aEdgeBBox.push( new Asc.Range( oSheetRange.range.c2, oSheetRange.range.r1, oSheetRange.prevRange.c2 + 1, oSheetRange.range.r2 ) );
{ if ( oSheetRange.range.r1 < oSheetRange.prevRange.r1 )
var aEdgeBBox = []; aEdgeBBox.push( new Asc.Range( oSheetRange.range.c1 + 1, oSheetRange.range.r1, oSheetRange.range.c2 - 1, oSheetRange.prevRange.r1 - 1 ) );
if(oSheetRange.range.c1 < oSheetRange.prevRange.c1) if ( oSheetRange.range.r2 > oSheetRange.prevRange.r2 )
aEdgeBBox.push(new Asc.Range(oSheetRange.range.c1, oSheetRange.range.r1, oSheetRange.prevRange.c1 - 1, oSheetRange.range.r2)); aEdgeBBox.push( new Asc.Range( oSheetRange.range.c1 + 1, oSheetRange.range.r2, oSheetRange.range.c2 - 1, oSheetRange.prevRange.r2 + 1 ) );
if(oSheetRange.range.c2 > oSheetRange.prevRange.c2) aAllOuter = [];
aEdgeBBox.push(new Asc.Range(oSheetRange.range.c2, oSheetRange.range.r1, oSheetRange.prevRange.c2 + 1, oSheetRange.range.r2)); for ( var j = 0, length = aEdgeBBox.length; j < length; j++ ) {
if(oSheetRange.range.r1 < oSheetRange.prevRange.r1) var bbox = aEdgeBBox[j];
aEdgeBBox.push(new Asc.Range(oSheetRange.range.c1 + 1, oSheetRange.range.r1, oSheetRange.range.c2 - 1, oSheetRange.prevRange.r1 - 1)); var oGetRes = nodesSheetArea.get( bbox );
if(oSheetRange.range.r2 > oSheetRange.prevRange.r2) if ( oGetRes.all.length > 0 )
aEdgeBBox.push(new Asc.Range(oSheetRange.range.c1 + 1, oSheetRange.range.r2, oSheetRange.range.c2 - 1, oSheetRange.prevRange.r2 + 1)); aAllOuter = aAllOuter.concat( oGetRes.all );
aAllOuter = []; }
for(var j = 0, length = aEdgeBBox.length; j < length; j++) }
{ if ( aAllOuter && aAllOuter.length > 0 ) {
var bbox = aEdgeBBox[j]; if ( null == aElems )
var oGetRes = nodesSheetArea.get(bbox); aElems = [];
if(oGetRes.all.length > 0) for ( var j in aAllOuter ) {
aAllOuter = aAllOuter.concat(oGetRes.all); var node = aAllOuter[j].data;
}
}
if(aAllOuter && aAllOuter.length > 0)
{
if(null == aElems)
aElems = [];
for(var j in aAllOuter)
{
var node = aAllOuter[j].data;
aElems[node.nodeId] = [node.sheetId, node.cellId]; aElems[node.nodeId] = [node.sheetId, node.cellId];
} }
} }
} }
} }
} }
} }
for(var i = 0, length = aWeightMapMasters.length; i < length; i++) for ( var i = 0, length = aWeightMapMasters.length; i < length; i++ ) {
{ var oWeightMapElem = aWeightMapMasters[i];
var oWeightMapElem = aWeightMapMasters[i]; //возвращаем только настощие master
//возвращаем только настощие master if ( oWeightMapElem.master ) {
if(oWeightMapElem.master) node = aWeightMapMastersNodes[i];
{ if ( oWeightMapElem.area )
node = aWeightMapMastersNodes[i]; oRes.oMasterAreaNodes[node.nodeId] = node;
if(oWeightMapElem.area) else
oRes.oMasterAreaNodes[node.nodeId] = node; oRes.oMasterNodes[node.nodeId] = node;
else }
oRes.oMasterNodes[node.nodeId] = node; }
} return oRes;
} },
return oRes; _getNodeDependence:function ( oRes, oSheetRanges, node ) {
}, var bBad = false;
_getNodeDependence : function(oRes, oSheetRanges, node) var oWeightMapElem = oRes.oWeightMap[node.nodeId];
{ if ( null == oWeightMapElem ) {
var bBad = false; oWeightMapElem = {cur:0, max:1, gray:false, bad:false, master:false, area:false};
var oWeightMapElem = oRes.oWeightMap[node.nodeId]; oRes.oWeightMap[node.nodeId] = oWeightMapElem;
if(null == oWeightMapElem) }
{ else {
oWeightMapElem = {cur: 0, max: 1, gray: false, bad: false, master: false, area: false}; oWeightMapElem.max++;
oRes.oWeightMap[node.nodeId] = oWeightMapElem; //если пришли в gray node, то это цикл
} if ( oWeightMapElem.gray )
else bBad = oWeightMapElem.bad = true;
{ else {
oWeightMapElem.max++; if ( oWeightMapElem.master && oWeightMapElem.max > 1 )
//если пришли в gray node, то это цикл
if(oWeightMapElem.gray)
bBad = oWeightMapElem.bad = true;
else
{
if(oWeightMapElem.master && oWeightMapElem.max > 1)
{ {
//если повторно пришли в master node, то не считаем ее master //если повторно пришли в master node, то не считаем ее master
oWeightMapElem.master = false; oWeightMapElem.master = false;
...@@ -634,45 +598,40 @@ DependencyGraph.prototype = { ...@@ -634,45 +598,40 @@ DependencyGraph.prototype = {
} }
} }
} }
if(1 == oWeightMapElem.max) if ( 1 == oWeightMapElem.max )
this._getNodeDependenceNodeToRange(node.sheetId, node.getBBox(), oSheetRanges); this._getNodeDependenceNodeToRange( node.sheetId, node.getBBox(), oSheetRanges );
if(!bBad && oWeightMapElem.max <= 1) if ( !bBad && oWeightMapElem.max <= 1 ) {
{ oWeightMapElem.gray = true;
oWeightMapElem.gray = true; var aNext = node.getSlaveEdges();
var aNext = node.getSlaveEdges(); for ( var i in aNext ) {
for(var i in aNext) if ( this._getNodeDependence( oRes, oSheetRanges, aNext[i] ) )
{ bBad = true;
if(this._getNodeDependence(oRes, oSheetRanges, aNext[i])) }
bBad = true; oWeightMapElem.gray = false;
} oWeightMapElem.bad = bBad;
oWeightMapElem.gray = false; }
oWeightMapElem.bad = bBad; return bBad;
} },
return bBad; _getNodeDependenceNodeToRange:function ( sheetId, bbox, oSheetRanges ) {
}, var oSheetRange = oSheetRanges[sheetId];
_getNodeDependenceNodeToRange : function(sheetId, bbox, oSheetRanges){ if ( null == oSheetRange ) {
var oSheetRange = oSheetRanges[sheetId]; oSheetRange = {range:null, changed:false, prevRange:null};
if(null == oSheetRange) oSheetRanges[sheetId] = oSheetRange;
{ }
oSheetRange = {range: null, changed: false, prevRange: null}; if ( null == oSheetRange.range || !oSheetRange.range.containsRange( bbox ) ) {
oSheetRanges[sheetId] = oSheetRange; if ( null == oSheetRange.range )
} oSheetRange.range = bbox.clone();
if(null == oSheetRange.range || !oSheetRange.range.containsRange(bbox)) else {
{ if ( !oSheetRange.changed )
if(null == oSheetRange.range) oSheetRange.prevRange = oSheetRange.range.clone();
oSheetRange.range = bbox.clone(); oSheetRange.range.union2( bbox );
else }
{ oSheetRange.changed = true;
if(!oSheetRange.changed) }
oSheetRange.prevRange = oSheetRange.range.clone(); },
oSheetRange.range.union2(bbox); getAll:function () {
} return this.nodesId;
oSheetRange.changed = true; }
}
},
getAll : function(){
return this.nodesId;
}
}; };
/** @constructor */ /** @constructor */
...@@ -684,9 +643,9 @@ function Vertex(sheetId, cellId, wb){ ...@@ -684,9 +643,9 @@ function Vertex(sheetId, cellId, wb){
this.isArea = !this.bbox.isOneCell(); this.isArea = !this.bbox.isOneCell();
this.valid = true; this.valid = true;
this.nodeId = getVertexId(this.sheetId, this.cellId); this.nodeId = getVertexId(this.sheetId, this.cellId);
this.wb = wb; this.wb = wb;
this.cell = null; this.cell = null;
//вершина которую мы прошли и поставили в очередь обхода //вершина которую мы прошли и поставили в очередь обхода
this.isBlack = false; this.isBlack = false;
...@@ -718,10 +677,10 @@ Vertex.prototype = { ...@@ -718,10 +677,10 @@ Vertex.prototype = {
{ {
var cell = this.returnCell(); var cell = this.returnCell();
if( cell && cell.formulaParsed ) if( cell && cell.formulaParsed )
{ {
this.wb.dependencyFormulas.deleteMasterNodes2( wsId, cellId ); this.wb.dependencyFormulas.deleteMasterNodes2( wsId, cellId );
cell.formulaParsed.setRefError(wsId, cellId); cell.formulaParsed.setRefError(wsId, cellId);
cell.setFormula(cell.formulaParsed.assemble(), true); cell.setFormula(cell.formulaParsed.assemble(), true);
addToArrRecalc(this.wb, wsId, cellId); addToArrRecalc(this.wb, wsId, cellId);
this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId ]; this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId ];
this.wb.needRecalc.length++; this.wb.needRecalc.length++;
...@@ -742,10 +701,10 @@ Vertex.prototype = { ...@@ -742,10 +701,10 @@ Vertex.prototype = {
var slave = _sn[_id] var slave = _sn[_id]
cell = slave.returnCell(); cell = slave.returnCell();
if( cell && cell.formulaParsed ) if( cell && cell.formulaParsed )
{ {
this.wb.dependencyFormulas.deleteMasterNodes2( slave.sheetId, slave.cellId ); this.wb.dependencyFormulas.deleteMasterNodes2( slave.sheetId, slave.cellId );
cell.formulaParsed.shiftCells( offset, null, this, slave.sheetId, toDelete); cell.formulaParsed.shiftCells( offset, null, this, slave.sheetId, toDelete);
cell.setFormula(cell.formulaParsed.assemble(), true); cell.setFormula(cell.formulaParsed.assemble(), true);
addToArrRecalc(this.wb, slave.sheetId, slave.cellId); addToArrRecalc(this.wb, slave.sheetId, slave.cellId);
this.wb.needRecalc.nodes[slave.nodeId] = [slave.sheetId, slave.cellId ]; this.wb.needRecalc.nodes[slave.nodeId] = [slave.sheetId, slave.cellId ];
this.wb.needRecalc.length++; this.wb.needRecalc.length++;
...@@ -764,10 +723,10 @@ Vertex.prototype = { ...@@ -764,10 +723,10 @@ Vertex.prototype = {
for( var _id in _sn ){ for( var _id in _sn ){
var slave = _sn[_id]; var slave = _sn[_id];
var cell = slave.returnCell(); var cell = slave.returnCell();
if( cell && cell.formulaParsed ){ if( cell && cell.formulaParsed ){
this.wb.dependencyFormulas.deleteMasterNodes2( slave.sheetId, slave.cellId ); this.wb.dependencyFormulas.deleteMasterNodes2( slave.sheetId, slave.cellId );
cell.formulaParsed.stretchArea( this, sNewName ); cell.formulaParsed.stretchArea( this, sNewName );
cell.setFormula(cell.formulaParsed.assemble(), true); cell.setFormula(cell.formulaParsed.assemble(), true);
addToArrRecalc(this.wb, slave.sheetId, slave.cellId); addToArrRecalc(this.wb, slave.sheetId, slave.cellId);
this.wb.needRecalc.nodes[slave.nodeId] = [slave.sheetId, slave.cellId ]; this.wb.needRecalc.nodes[slave.nodeId] = [slave.sheetId, slave.cellId ];
this.wb.needRecalc.length++; this.wb.needRecalc.length++;
...@@ -891,14 +850,14 @@ function unLockDraw(wb){ ...@@ -891,14 +850,14 @@ function unLockDraw(wb){
} }
} }
function addToArrRecalc(wb, sheetId, cellId){ function addToArrRecalc(wb, sheetId, cellId){
var temp = arrRecalc[sheetId]; var temp = arrRecalc[sheetId];
if( !temp ) if( !temp )
{ {
temp = {}; temp = {};
arrRecalc[sheetId] = temp; arrRecalc[sheetId] = temp;
}
temp[cellId] = cellId;
} }
temp[cellId] = cellId;
}
function buildRecalc(_wb,notrec){ function buildRecalc(_wb,notrec){
var ws; var ws;
if( lc > 1 ) return; if( lc > 1 ) return;
...@@ -911,152 +870,71 @@ function buildRecalc(_wb,notrec){ ...@@ -911,152 +870,71 @@ function buildRecalc(_wb,notrec){
if(!notrec) if(!notrec)
sortDependency(_wb) sortDependency(_wb)
} }
function searchCleenCacheArea(o1,o2){
var o3 = {};
for (var _item in o2){
if (o1 && o1.hasOwnProperty(_item)){
if(o1[_item].min.getRow() > o2[_item].min.getRow()) o1[_item].min = new CellAddress(o2[_item].min.getRow(),o1[_item].min.getCol());
if(o1[_item].min.getCol() > o2[_item].min.getCol()) o1[_item].min = new CellAddress(o1[_item].min.getRow(),o2[_item].min.getCol());
if(o1[_item].max.getRow() < o2[_item].max.getRow()) o1[_item].max = new CellAddress(o2[_item].max.getRow(),o1[_item].max.getCol());
if(o1[_item].max.getCol() < o2[_item].max.getCol()) o1[_item].max = new CellAddress(o1[_item].max.getRow(),o2[_item].max.getCol());
o3[_item] = o1[_item];
}
else{
o3[_item] = o2[_item];
}
}
for (var _item in o1){
if (o3 && o3.hasOwnProperty(_item)){
if(o1[_item].min.getRow() > o3[_item].min.getRow()) o1[_item].min = new CellAddress(o3[_item].min.getRow(),o1[_item].min.getCol());
if(o1[_item].min.getCol() > o3[_item].min.getCol()) o1[_item].min = new CellAddress(o1[_item].min.getRow(),o3[_item].min.getCol());
if(o1[_item].max.getRow() < o3[_item].max.getRow()) o1[_item].max = new CellAddress(o3[_item].max.getRow(),o1[_item].max.getCol());
if(o1[_item].max.getCol() < o3[_item].max.getCol()) o1[_item].max = new CellAddress(o1[_item].max.getRow(),o3[_item].max.getCol());
o3[_item] = o1[_item];
}
else{
o3[_item] = o1[_item];
}
}
return o3;
}
function helpRecalc(dep1, nR, calculatedCells, wb){
var sr1, sr2;
for(var i = 0; i < dep1.badF.length; i++){
for(var j = 0; j < dep1.depF.length; j++){
if(dep1.badF[i] == dep1.depF[j])
dep1.depF.splice(j,1);
}
}
for(var j = 0; j < dep1.depF.length; j++){
if( dep1.depF[j].nodeId in nR){
nR[dep1.depF[j].nodeId] = undefined;
delete nR[dep1.depF[j].nodeId]
nR.length--;
}
}
for(var j = 0; j < dep1.badF.length; j++){
if( dep1.badF[j].nodeId in nR){
nR[dep1.badF[j].nodeId] = undefined;
delete nR[dep1.badF[j].nodeId]
nR.length--;
}
}
sr1 = wb.recalcDependency(dep1.badF,true);
for(var k = 0; k < dep1.depF.length; k++){
if(dep1.depF[k].nodeId in calculatedCells){
dep1.depF.splice(k,1);
k--;
}
}
sr2 = wb.recalcDependency(dep1.depF,false);
for(var k = 0; k < dep1.depF.length; k++){
calculatedCells[dep1.depF[k].nodeId] = dep1.depF[k].nodeId
}
return searchCleenCacheArea(sr1,sr2);
}
function sortDependency(wb){ function sortDependency( wb ) {
if ( wb.isNeedCacheClean ){ if ( wb.isNeedCacheClean ){
buildRecalc(wb, true); buildRecalc(wb, true);
arrRecalc = {}; arrRecalc = {};
} }
var nR = wb.needRecalc; var nR = wb.needRecalc;
if(nR && (nR.length > 0)) if(nR && (nR.length > 0))
{ {
var oCleanCellCacheArea = {}; var oCleanCellCacheArea = {};
var oNodeDependence = wb.dependencyFormulas.getNodeDependence(nR.nodes); var oNodeDependence = wb.dependencyFormulas.getNodeDependence(nR.nodes);
for(var i in oNodeDependence.oMasterNodes) for ( var i in oNodeDependence.oMasterNodes ) {
{ var node = oNodeDependence.oMasterNodes[i];
var node = oNodeDependence.oMasterNodes[i]; _sortDependency( wb, node, oNodeDependence.oWeightMap, false, oCleanCellCacheArea );
_sortDependency(wb, node, oNodeDependence.oWeightMap, false, oCleanCellCacheArea); }
} for ( var i in oNodeDependence.oMasterAreaNodes ) {
for(var i in oNodeDependence.oMasterAreaNodes) var node = oNodeDependence.oMasterAreaNodes[i];
{ _sortDependency( wb, node, oNodeDependence.oWeightMap, false, oCleanCellCacheArea );
var node = oNodeDependence.oMasterAreaNodes[i]; }
_sortDependency(wb, node, oNodeDependence.oWeightMap, false, oCleanCellCacheArea); for ( var sheetId in oCleanCellCacheArea ) {
} var sheetArea = oCleanCellCacheArea[sheetId];
for(var sheetId in oCleanCellCacheArea) for ( var rowId in sheetArea ) {
{ var nRow = rowId - 0;
var sheetArea = oCleanCellCacheArea[sheetId]; wb.handlers.trigger( "cleanCellCache", sheetId, new Asc.Range( 0, nRow, gc_nMaxCol0, nRow ), c_oAscCanChangeColWidth.numbers );
for(var rowId in sheetArea) }
{ }
var nRow = rowId - 0; }
wb.handlers.trigger("cleanCellCache", sheetId, new Asc.Range(0, nRow, gc_nMaxCol0, nRow), c_oAscCanChangeColWidth.numbers);
}
}
}
wb.needRecalc = {nodes: {}, length:0}; wb.needRecalc = {nodes: {}, length:0};
} }
function _sortDependency(wb, node, oWeightMap, bBad, oCleanCellCacheArea){ function _sortDependency( wb, node, oWeightMap, bBad, oCleanCellCacheArea ) {
if(node) if ( node ) {
{ var oWeightMapElem = oWeightMap[node.nodeId];
var oWeightMapElem = oWeightMap[node.nodeId]; if ( oWeightMapElem ) {
if(oWeightMapElem) oWeightMapElem.cur++;
{ if ( (!oWeightMapElem.bad && oWeightMapElem.cur >= oWeightMapElem.max) || (oWeightMapElem.bad && !oWeightMapElem.gray) ) {
oWeightMapElem.cur++; bBad = oWeightMapElem.bad;
if((!oWeightMapElem.bad && oWeightMapElem.cur >= oWeightMapElem.max) || (oWeightMapElem.bad && !oWeightMapElem.gray)) //пересчитываем функцию
{ var ws = wb.getWorksheetById( node.sheetId );
bBad = oWeightMapElem.bad; ws._RecalculatedFunctions( node.cellId, bBad );
//пересчитываем функцию //запоминаем области для удаления cache
var ws = wb.getWorksheetById(node.sheetId); var sheetArea = oCleanCellCacheArea[node.sheetId];
ws._RecalculatedFunctions( node.cellId, bBad ); if ( null == sheetArea ) {
//запоминаем области для удаления cache sheetArea = {};
var sheetArea = oCleanCellCacheArea[node.sheetId]; oCleanCellCacheArea[node.sheetId] = sheetArea;
if(null == sheetArea) }
{ var range = Asc.g_oRangeCache.getAscRange( node.cellId );
sheetArea = {}; if ( range ) {
oCleanCellCacheArea[node.sheetId] = sheetArea; for ( var i = range.r1; i <= range.r2; i++ )
} sheetArea[i] = 1;
var range = Asc.g_oRangeCache.getAscRange(node.cellId); }
if(range) //обрабатываем child
{ oWeightMapElem.gray = true;
for(var i = range.r1; i <= range.r2; i++) var oSlaveNodes = node.getSlaveEdges();
sheetArea[i] = 1; if ( oSlaveNodes ) {
} for ( var i in oSlaveNodes )
//обрабатываем child _sortDependency( wb, oSlaveNodes[i], oWeightMap, bBad, oCleanCellCacheArea );
oWeightMapElem.gray = true; }
var oSlaveNodes = node.getSlaveEdges(); if ( oWeightMapElem.area ) {
if(oSlaveNodes) for ( var i = 0, length = oWeightMapElem.area.length; i < length; i++ )
{ _sortDependency( wb, oWeightMapElem.area[i].data, oWeightMap, bBad, oCleanCellCacheArea );
for(var i in oSlaveNodes) }
_sortDependency(wb, oSlaveNodes[i], oWeightMap, bBad, oCleanCellCacheArea); oWeightMapElem.gray = false;
} }
if(oWeightMapElem.area) }
{ }
for(var i = 0, length = oWeightMapElem.area.length; i < length; i++)
_sortDependency(wb, oWeightMapElem.area[i].data, oWeightMap, bBad, oCleanCellCacheArea);
}
oWeightMapElem.gray = false;
}
}
}
} }
function angleFormatToInterface(val) function angleFormatToInterface(val)
...@@ -1553,13 +1431,13 @@ Workbook.prototype._generateFontMap=function(){ ...@@ -1553,13 +1431,13 @@ Workbook.prototype._generateFontMap=function(){
"Arial" : 1 "Arial" : 1
}; };
if (null != g_oDefaultFont.fn) if(null != g_oDefaultFont.fn)
oFontMap[g_oDefaultFont.fn] = 1; oFontMap[g_oDefaultFont.fn] = 1;
for (var i = 0, length = this.aWorksheets.length; i < length; ++i) for(var i = 0, length = this.aWorksheets.length; i < length; ++i)
this.aWorksheets[i].generateFontMap(oFontMap); this.aWorksheets[i].generateFontMap(oFontMap);
this.CellStyles.generateFontMap(oFontMap); this.CellStyles.generateFontMap(oFontMap);
return oFontMap; return oFontMap;
}; };
Workbook.prototype.generateFontMap=function(){ Workbook.prototype.generateFontMap=function(){
...@@ -1591,11 +1469,11 @@ Workbook.prototype.recalcWB = function(is3D){ ...@@ -1591,11 +1469,11 @@ Workbook.prototype.recalcWB = function(is3D){
{ {
nR[node.nodeId] = [node.sheetId, node.cellId]; nR[node.nodeId] = [node.sheetId, node.cellId];
nR.length++; nR.length++;
}
}
sortDependency(this);
} }
} }
sortDependency(this);
}
}
Workbook.prototype.isDefinedNamesExists = function(name, sheetId){ Workbook.prototype.isDefinedNamesExists = function(name, sheetId){
if(null != sheetId) if(null != sheetId)
{ {
...@@ -1649,28 +1527,32 @@ Workbook.prototype.recalcDependency = function(f,bad,notRecalc){ ...@@ -1649,28 +1527,32 @@ Workbook.prototype.recalcDependency = function(f,bad,notRecalc){
var sr = {}; var sr = {};
for(var i = 0; i < f.length; i++){ for(var i = 0; i < f.length; i++){
if( f[i].cellId.indexOf(":") > -1 ) continue; var sheetID = f[i].sheetId, cellID = f[i].cellId, selectedSheet;
if( cellID.indexOf(":") > -1 ) continue;
var l = new CellAddress(f[i].cellId); var l = new CellAddress(cellID);
var lRow = l.getRow(), lCol = l.getCol();
if( !(f[i].sheetId in sr) ){ if( !(sheetID in sr) ){
sr[f[i].sheetId] = {max:new CellAddress(f[i].cellId),min:new CellAddress(f[i].cellId)} sr[sheetID] = {max:new CellAddress(cellID),min:new CellAddress(cellID)}
} }
if ( sr[f[i].sheetId].min.getRow() > l.getRow() ) selectedSheet = sr[sheetID];
sr[f[i].sheetId].min = new CellAddress( l.getRow(), sr[f[i].sheetId].min.getCol() );
if ( selectedSheet.min.getRow() > lRow )
selectedSheet.min = new CellAddress( lRow, selectedSheet.min.getCol() );
if ( sr[f[i].sheetId].min.getCol() > l.getCol() ) if ( selectedSheet.min.getCol() > lCol )
sr[f[i].sheetId].min = new CellAddress( sr[f[i].sheetId].min.getRow(), l.getCol() ); selectedSheet.min = new CellAddress( selectedSheet.min.getRow(), lCol );
if ( sr[f[i].sheetId].max.getRow() < l.getRow() ) if ( selectedSheet.max.getRow() < lRow )
sr[f[i].sheetId].max = new CellAddress( l.getRow(), sr[f[i].sheetId].max.getCol() ); selectedSheet.max = new CellAddress( lRow, selectedSheet.max.getCol() );
if ( sr[f[i].sheetId].max.getCol() < l.getCol() ) if ( selectedSheet.max.getCol() < lCol )
sr[f[i].sheetId].max = new CellAddress( sr[f[i].sheetId].max.getRow(), l.getCol() ); selectedSheet.max = new CellAddress( selectedSheet.max.getRow(), lCol );
if( !notRecalc ) if( !notRecalc )
this.getWorksheetById( f[i].sheetId )._RecalculatedFunctions( f[i].cellId, bad ); this.getWorksheetById( sheetID )._RecalculatedFunctions( cellID, bad );
} }
return sr; return sr;
...@@ -2873,7 +2755,7 @@ Woorksheet.prototype.getRange=function(cellAdd1, cellAdd2){ ...@@ -2873,7 +2755,7 @@ Woorksheet.prototype.getRange=function(cellAdd1, cellAdd2){
Woorksheet.prototype.getRange2=function(sRange){ Woorksheet.prototype.getRange2=function(sRange){
var bbox = Asc.g_oRangeCache.getAscRange(sRange); var bbox = Asc.g_oRangeCache.getAscRange(sRange);
if(null != bbox) if(null != bbox)
return this.getRange3(bbox.r1, bbox.c1, bbox.r2, bbox.c2); return this.getRange3(bbox.r1, bbox.c1, bbox.r2, bbox.c2);
return null; return null;
}; };
Woorksheet.prototype.getRange3=function(r1, c1, r2, c2){ Woorksheet.prototype.getRange3=function(r1, c1, r2, c2){
...@@ -2915,7 +2797,7 @@ Woorksheet.prototype._removeCell=function(nRow, nCol, cell){ ...@@ -2915,7 +2797,7 @@ Woorksheet.prototype._removeCell=function(nRow, nCol, cell){
if(null != cell.xfs) if(null != cell.xfs)
oUndoRedoData_CellData.style = cell.xfs.clone(); oUndoRedoData_CellData.style = cell.xfs.clone();
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveCell, this.getId(), new Asc.Range(0, nRow, gc_nMaxCol0, nRow), new UndoRedoData_CellSimpleData(nRow, nCol, oUndoRedoData_CellData, null)); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveCell, this.getId(), new Asc.Range(0, nRow, gc_nMaxCol0, nRow), new UndoRedoData_CellSimpleData(nRow, nCol, oUndoRedoData_CellData, null));
} }
if(cell.formulaParsed) if(cell.formulaParsed)
this.wb.dependencyFormulas.deleteMasterNodes2( this.getId(), cell.getName() ); this.wb.dependencyFormulas.deleteMasterNodes2( this.getId(), cell.getName() );
...@@ -3224,7 +3106,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3224,7 +3106,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
} }
} }
} }
History.TurnOn(); History.TurnOn();
if(false == this.workbook.bUndoChanges && false == this.workbook.bRedoChanges) if(false == this.workbook.bUndoChanges && false == this.workbook.bRedoChanges)
{ {
...@@ -3269,7 +3151,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3269,7 +3151,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
/* /*
Если необходим пересчет, то по списку пересчитываемых ячеек сортируем граф зависимостей и пересчиываем в получившемся порядке. Плохим ячейкам с цикличискими ссылками выставляем ошибку "#REF!". Если необходим пересчет, то по списку пересчитываемых ячеек сортируем граф зависимостей и пересчиываем в получившемся порядке. Плохим ячейкам с цикличискими ссылками выставляем ошибку "#REF!".
*/ */
sortDependency(this.workbook); sortDependency(this.workbook);
} }
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange, History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange,
this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0), this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0),
...@@ -3458,41 +3340,35 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){ ...@@ -3458,41 +3340,35 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){
if( c && c.sFormula ){ if( c && c.sFormula ){
c.formulaParsed = new parserFormula( c.sFormula, c.oId.getID(), this ); c.formulaParsed = new parserFormula( c.sFormula, c.oId.getID(), this );
c.formulaParsed.parse(); c.formulaParsed.parse();
c.formulaParsed.buildDependencies(); c.formulaParsed.buildDependencies();
} }
} }
} }
Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
var thas = this; function adjustCellFormat( c ) {
function adjustCellFormat(c, ftext) { // ищет в формуле первый рэндж и устанавливает формат ячейки как формат первой ячейки в рэндже
// ищет в формуле первый рэндж и устанавливает формат ячейки как формат первой ячейки в рэндже var elem = null;
var elem = null; if ( c.formulaParsed && c.formulaParsed.outStack ) {
if(c.formulaParsed && c.formulaParsed.outStack) for ( var i = 0, length = c.formulaParsed.outStack.length; i < length; i++ ) {
{ elem = c.formulaParsed.outStack[i];
for(var i = 0, length = c.formulaParsed.outStack.length; i < length; i++) if ( elem instanceof cRef || elem instanceof cRef3D || elem instanceof cArea || elem instanceof cArea3D ) {
{ var r = elem.getRange();
elem = c.formulaParsed.outStack[i]; if ( elem instanceof cArea3D && r.length > 0 )
if(elem instanceof cRef || elem instanceof cRef3D || elem instanceof cArea || elem instanceof cArea3D) r = r[0];
{ if ( r && r.getNumFormatStr ) {
var r = elem.getRange(); var sCurFormat = c.getNumFormatStr();
if(elem instanceof cArea3D && r.length > 0) if ( g_oDefaultNum.f == sCurFormat ) {
r = r[0]; var sNewFormat = r.getNumFormatStr();
if(r && r.getNumFormatStr) if ( sCurFormat != sNewFormat )
{ c.setNumFormat( sNewFormat );
var sCurFormat = c.getNumFormatStr(); }
if( g_oDefaultNum.f == sCurFormat) }
{ break;
var sNewFormat = r.getNumFormatStr(); }
if(sCurFormat != sNewFormat) }
c.setNumFormat(sNewFormat); }
} }
}
break;
}
}
}
}
if( cell.indexOf(":")>-1 ) return; if( cell.indexOf(":")>-1 ) return;
...@@ -3577,7 +3453,7 @@ Woorksheet.prototype._ReBuildFormulas=function(cellRange){ ...@@ -3577,7 +3453,7 @@ Woorksheet.prototype._ReBuildFormulas=function(cellRange){
} }
Woorksheet.prototype.renameDependencyNodes = function(offset, oBBox, rec, noDelete){ Woorksheet.prototype.renameDependencyNodes = function(offset, oBBox, rec, noDelete){
this.workbook.dependencyFormulas.checkOffset(oBBox, offset, this.Id, noDelete); this.workbook.dependencyFormulas.checkOffset(oBBox, offset, this.Id, noDelete);
} }
Woorksheet.prototype.helperRebuildFormulas = function(cell,lastName){ Woorksheet.prototype.helperRebuildFormulas = function(cell,lastName){
if( cell.sFormula ){ if( cell.sFormula ){
this.workbook.cwf[this.Id].cells[lastName] = null; this.workbook.cwf[this.Id].cells[lastName] = null;
...@@ -3799,13 +3675,13 @@ Cell.prototype.setValue=function(val,callback){ ...@@ -3799,13 +3675,13 @@ Cell.prototype.setValue=function(val,callback){
delete wb.cwf[ws.Id].cells[this.oId.getID()]; delete wb.cwf[ws.Id].cells[this.oId.getID()];
} }
} }
} }
else{ else{
wb.cwf[ws.Id].cells[this.oId.getID()] = this.oId.getID(); wb.cwf[ws.Id].cells[this.oId.getID()] = this.oId.getID();
addToArrRecalc(this.ws.workbook, this.ws.getId(), this.oId.getID()); addToArrRecalc(this.ws.workbook, this.ws.getId(), this.oId.getID());
} }
wb.needRecalc.nodes[getVertexId(sheetId,this.oId.getID())] = [sheetId, this.oId.getID()]; wb.needRecalc.nodes[getVertexId(sheetId,this.oId.getID())] = [sheetId, this.oId.getID()];
wb.needRecalc.length++; wb.needRecalc.length++;
this.sFormula = null; this.sFormula = null;
this.setFormulaCA(false); this.setFormulaCA(false);
...@@ -3857,8 +3733,8 @@ Cell.prototype.setValue2=function(array){ ...@@ -3857,8 +3733,8 @@ Cell.prototype.setValue2=function(array){
this.oValue.setValue2(array); this.oValue.setValue2(array);
wb.needRecalc.nodes[getVertexId(sheetId,this.oId.getID())] = [sheetId, this.oId.getID()]; wb.needRecalc.nodes[getVertexId(sheetId,this.oId.getID())] = [sheetId, this.oId.getID()];
wb.needRecalc.length++; wb.needRecalc.length++;
sortDependency(this.ws.workbook); sortDependency(this.ws.workbook);
var DataNew = null; var DataNew = null;
if(History.Is_On()) if(History.Is_On())
DataNew = this.getValueData(); DataNew = this.getValueData();
...@@ -6875,7 +6751,7 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){ ...@@ -6875,7 +6751,7 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){
this.worksheet.workbook.needRecalc.nodes[ getVertexId(this.worksheet.getId(),sNewName) ] = [ this.worksheet.getId(),sNewName ]; this.worksheet.workbook.needRecalc.nodes[ getVertexId(this.worksheet.getId(),sNewName) ] = [ this.worksheet.getId(),sNewName ];
this.worksheet.workbook.needRecalc.length++; this.worksheet.workbook.needRecalc.length++;
} }
} }
else else
{ {
if(null != rowTo.c[i]) if(null != rowTo.c[i])
...@@ -7286,12 +7162,12 @@ Range.prototype.promote=function(bCtrl, bVertical, nIndex){ ...@@ -7286,12 +7162,12 @@ Range.prototype.promote=function(bCtrl, bVertical, nIndex){
oCopyCell.setFormula(assemb); oCopyCell.setFormula(assemb);
addToArrRecalc(this.worksheet.workbook, this.worksheet.getId(), sCopyCellName); addToArrRecalc(this.worksheet.workbook, this.worksheet.getId(), sCopyCellName);
this.worksheet.workbook.needRecalc.nodes[ getVertexId(this.worksheet.getId(),sCopyCellName) ] = [ this.worksheet.getId(),sCopyCellName ]; this.worksheet.workbook.needRecalc.nodes[ getVertexId(this.worksheet.getId(),sCopyCellName) ] = [ this.worksheet.getId(),sCopyCellName ];
this.worksheet.workbook.needRecalc.length++; this.worksheet.workbook.needRecalc.length++;
}
} }
} }
} }
} }
}
} }
//добавляем замерженые области //добавляем замерженые области
var nShiftHorizontal = 0; var nShiftHorizontal = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment