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();
\ No newline at end of file
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
......
......@@ -859,7 +859,7 @@
oParser = new parserFormula( "SUMIF(A12:A17,\"\",C12:C17)", "A22", ws );
ok( oParser.parse() );
notEqual( oParser.calculate().getValue(), 400 );
strictEqual( oParser.calculate().getValue(), 400 );
} )
......
......@@ -136,6 +136,7 @@ Math.binomCoeff = function ( n, k ) {
Math.permut = function ( n, k ) {
return Math.floor( this.fact( n ) / this.fact( n - k ) + .5 );
}
var _func = [];//для велосипеда а-ля перегрузка функций.
_func[cElementType.number] = [];
_func[cElementType.string] = [];
......@@ -147,86 +148,96 @@ _func[cElementType.array] = [];
_func[cElementType.number][cElementType.number] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
return new cBool( arg0.getValue() > arg1.getValue() );
case ">=":
return new cBool( arg0.getValue() >= arg1.getValue() );
case "<":
return new cBool( arg0.getValue() < arg1.getValue() );
case "<=":
return new cBool( arg0.getValue() <= arg1.getValue() );
case "=":
return new cBool( arg0.getValue() == arg1.getValue() );
case "<>":
return new cBool( arg0.getValue() != arg1.getValue() );
case "-":
return new cNumber( arg0.getValue() - arg1.getValue() );
case "+":
return new cNumber( arg0.getValue() + arg1.getValue() );
case "/":
if ( arg1.getValue() != 0 )
return new cNumber( arg0.getValue() / arg1.getValue() );
else
return new cError( cErrorType.division_by_zero );
case "*":
return new cNumber( arg0.getValue() * arg1.getValue() );
if ( what == ">" ) {
return new cBool( arg0.getValue() > arg1.getValue() );
}
else if ( what == ">=" ) {
return new cBool( arg0.getValue() >= arg1.getValue() );
}
else if ( what == "<" ) {
return new cBool( arg0.getValue() < arg1.getValue() );
}
else if ( what == "<=" ) {
return new cBool( arg0.getValue() <= arg1.getValue() );
}
else if ( what == "=" ) {
return new cBool( arg0.getValue() == arg1.getValue() );
}
else if ( what == "<>" ) {
return new cBool( arg0.getValue() != arg1.getValue() );
}
else if ( what == "-" ) {
return new cNumber( arg0.getValue() - arg1.getValue() );
}
else if ( what == "+" ) {
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 );
};
_func[cElementType.number][cElementType.string] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
case ">=":
return new cBool( false );
case "<":
case "<=":
return new cBool( true );
case "=":
return new cBool( false );
case "<>":
return new cBool( true );
case "-":
case "+":
case "/":
case "*":
return new cError( cErrorType.wrong_value_type );
if ( what == ">" || what == ">=" ) {
return new cBool( false );
}
else if ( what == "<" || what == "<=" ) {
return new cBool( true );
}
else if ( what == "=" ) {
return new cBool( false );
}
else if ( what == "<>" ) {
return new cBool( true );
}
else if ( what == "-" || what == "+" || what == "/" || what == "*" ) {
return new cError( cErrorType.wrong_value_type );
}
return new cError( cErrorType.wrong_value_type );
};
_func[cElementType.number][cElementType.bool] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
case ">=":
return new cBool( false );
case "<":
case "<=":
return new cBool( true );
case "=":
return new cBool( false );
case "<>":
return new cBool( true );
case "-":
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
return new cNumber( arg0.getValue() - _arg.getValue() );
case "+":
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
return new cNumber( arg0.getValue() + _arg.getValue() );
case "/":
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
if ( _arg.getValue() != 0 )
return new cNumber( arg0.getValue() / _arg.getValue() );
else
return new cError( cErrorType.division_by_zero );
case "*":
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
return new cNumber( arg0.getValue() * _arg.getValue() );
if ( what == ">" || what == ">=" ) {
return new cBool( false );
}
else if ( what == "<" || what == "<=" ) {
return new cBool( true );
}
else if ( what == "=" ) {
return new cBool( false );
}
else if ( what == "<>" ) {
return new cBool( true );
}
else if ( what == "-" ) {
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
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() );
}
else if ( what == "/" ) {
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
if ( _arg.getValue() != 0 )
return new cNumber( arg0.getValue() / _arg.getValue() );
else
return new cError( cErrorType.division_by_zero );
}
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 );
};
......@@ -236,134 +247,150 @@ _func[cElementType.number][cElementType.error] = function ( arg0, arg1, what ) {
};
_func[cElementType.number][cElementType.empty] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
return new cBool( arg0.getValue() > 0 );
case ">=":
return new cBool( arg0.getValue() >= 0 );
case "<":
return new cBool( arg0.getValue() < 0 );
case "<=":
return new cBool( arg0.getValue() <= 0 );
case "=":
return new cBool( arg0.getValue() == 0 );
case "<>":
return new cBool( arg0.getValue() != 0 );
case "-":
return new cNumber( arg0.getValue() - 0 );
case "+":
return new cNumber( arg0.getValue() + 0 );
case "/":
return new cError( cErrorType.division_by_zero );
case "*":
return new cNumber( 0 );
if ( what == ">" ) {
return new cBool( arg0.getValue() > 0 );
}
else if ( what == ">=" ) {
return new cBool( arg0.getValue() >= 0 );
}
else if ( what == "<" ) {
return new cBool( arg0.getValue() < 0 );
}
else if ( what == "<=" ) {
return new cBool( arg0.getValue() <= 0 );
}
else if ( what == "=" ) {
return new cBool( arg0.getValue() == 0 );
}
else if ( what == "<>" ) {
return new cBool( arg0.getValue() != 0 );
}
else if ( what == "-" ) {
return new cNumber( arg0.getValue() - 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 );
};
_func[cElementType.string][cElementType.number] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
case ">=":
return new cBool( true );
case "<":
case "<=":
case "=":
return new cBool( false );
case "<>":
return new cBool( true );
case "-":
case "+":
case "/":
case "*":
return new cError( cErrorType.wrong_value_type );
if ( what == ">" || what == ">=" ) {
return new cBool( true );
}
else if ( what == "<" || what == "<=" || what == "=" ) {
return new cBool( false );
}
else if ( what == "<>" ) {
return new cBool( true );
}
else if ( what == "-" || what == "+" || what == "/" || what == "*" ) {
return new cError( cErrorType.wrong_value_type );
}
return new cError( cErrorType.wrong_value_type );
};
_func[cElementType.string][cElementType.string] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
return new cBool( arg0.getValue() > arg1.getValue() );
case ">=":
return new cBool( arg0.getValue() >= arg1.getValue() );
case "<":
return new cBool( arg0.getValue() < arg1.getValue() );
case "<=":
return new cBool( arg0.getValue() <= arg1.getValue() );
case "=":
return new cBool( arg0.getValue() === arg1.getValue() );
case "<>":
return new cBool( arg0.getValue() !== arg1.getValue() );
case "-":
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() );
case "+":
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() );
case "/":
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg0 instanceof cError ) return _arg0;
if ( _arg1 instanceof cError ) return _arg1;
if ( _arg1.getValue() != 0 )
return new cNumber( _arg0.getValue() / _arg1.getValue() );
return new cError( cErrorType.division_by_zero );
case "*":
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() );
if ( what == ">" ) {
return new cBool( arg0.getValue() > arg1.getValue() );
}
else if ( what == ">=" ) {
return new cBool( arg0.getValue() >= arg1.getValue() );
}
else if ( what == "<" ) {
return new cBool( arg0.getValue() < arg1.getValue() );
}
else if ( what == "<=" ) {
return new cBool( arg0.getValue() <= arg1.getValue() );
}
else if ( what == "=" ) {
return new cBool( arg0.getValue() === arg1.getValue() );
}
else if ( what == "<>" ) {
return new cBool( arg0.getValue() !== arg1.getValue() );
}
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() );
}
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() );
}
else if ( what == "/" ) {
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg0 instanceof cError ) return _arg0;
if ( _arg1 instanceof cError ) return _arg1;
if ( _arg1.getValue() != 0 )
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 );
};
_func[cElementType.string][cElementType.bool] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
case ">=":
return new cBool( false );
case "<":
case "<=":
return new cBool( true );
case "=":
return new cBool( false );
case "<>":
return new cBool( false );
case "-":
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() );
case "+":
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() );
case "/":
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg0 instanceof cError ) return _arg0;
if ( _arg1 instanceof cError ) return _arg1;
if ( _arg1.getValue() != 0 )
return new cNumber( _arg0.getValue() / _arg1.getValue() );
return new cError( cErrorType.division_by_zero );
case "*":
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() );
if ( what == ">" || what == ">=" ) {
return new cBool( false );
}
else if ( what == "<" || what == "<=" ) {
return new cBool( true );
}
else if ( what == "=" ) {
return new cBool( false );
}
else if ( what == "<>" ) {
return new cBool( false );
}
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() );
}
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() );
}
else if ( what == "/" ) {
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg0 instanceof cError ) return _arg0;
if ( _arg1 instanceof cError ) return _arg1;
if ( _arg1.getValue() != 0 )
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 );
};
......@@ -373,134 +400,152 @@ _func[cElementType.string][cElementType.error] = function ( arg0, arg1, what ) {
};
_func[cElementType.string][cElementType.empty] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
return new cBool( arg0.getValue().length != 0 );
case ">=":
return new cBool( arg0.getValue().length >= 0 );
case "<":
return new cBool( false );
case "<=":
return new cBool( arg0.getValue().length <= 0 );
case "=":
return new cBool( arg0.getValue().length === 0 );
case "<>":
return new cBool( arg0.getValue().length != 0 );
case "-":
case "+":
case "/":
case "*":
return new cError( cErrorType.wrong_value_type );
if ( what == ">" ) {
return new cBool( arg0.getValue().length != 0 );
}
else if ( what == ">=" ) {
return new cBool( arg0.getValue().length >= 0 );
}
else if ( what == "<" ) {
return new cBool( false );
}
else if ( what == "<=" ) {
return new cBool( arg0.getValue().length <= 0 );
}
else if ( what == "=" ) {
return new cBool( arg0.getValue().length === 0 );
}
else if ( what == "<>" ) {
return new cBool( arg0.getValue().length != 0 );
}
else if ( what == "-" || what == "+" || what == "/" || what == "*" ) {
return new cError( cErrorType.wrong_value_type );
}
return new cError( cErrorType.wrong_value_type );
};
_func[cElementType.bool][cElementType.number] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
case ">=":
return new cBool( true );
case "<":
case "<=":
return new cBool( false );
case "=":
return new cBool( true );
case "<>":
return new cBool( false );
case "-":
var _arg = arg0.tocNumber();
if ( _arg instanceof cError ) return _arg;
return new cNumber( _arg.getValue() - arg1.getValue() );
case "+":
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
return new cNumber( _arg.getValue() + arg1.getValue() );
case "/":
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
if ( arg1.getValue() != 0 )
return new cNumber( _arg.getValue() / arg1.getValue() );
else
return new cError( cErrorType.division_by_zero );
case "*":
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
return new cNumber( _arg.getValue() * arg1.getValue() );
if ( what == ">" || what == ">=" ) {
return new cBool( true );
}
else if ( what == "<" || what == "<=" ) {
return new cBool( false );
}
else if ( what == "=" ) {
return new cBool( true );
}
else if ( what == "<>" ) {
return new cBool( false );
}
else if ( what == "-" ) {
var _arg = arg0.tocNumber();
if ( _arg instanceof cError ) return _arg;
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() );
}
else if ( what == "/" ) {
var _arg = arg1.tocNumber();
if ( _arg instanceof cError ) return _arg;
if ( arg1.getValue() != 0 )
return new cNumber( _arg.getValue() / arg1.getValue() );
else
return new cError( cErrorType.division_by_zero );
}
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 );
};
_func[cElementType.bool][cElementType.string] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
case ">=":
return new cBool( true );
case "<":
case "<=":
return new cBool( false );
case "=":
return new cBool( true );
case "<>":
return new cBool( true );
case "-":
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg1 instanceof cError ) return _arg1;
return new cNumber( _arg0.getValue() - _arg1.getValue() );
case "+":
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg1 instanceof cError ) return _arg1;
return new cNumber( _arg0.getValue() + _arg1.getValue() );
case "/":
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg1 instanceof cError ) return _arg1;
if ( _arg1.getValue() != 0 )
return new cNumber( _arg0.getValue() / _arg1.getValue() );
return new cError( cErrorType.division_by_zero );
case "*":
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg1 instanceof cError ) return _arg1;
return new cNumber( _arg0.getValue() * _arg1.getValue() );
if ( what == ">" || what == ">=" ) {
return new cBool( true );
}
else if ( what == "<" || what == "<=" ) {
return new cBool( false );
}
else if ( what == "=" ) {
return new cBool( true );
}
else if ( what == "<>" ) {
return new cBool( true );
}
else if ( what == "-" ) {
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
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() );
}
else if ( what == "/" ) {
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
if ( _arg1 instanceof cError ) return _arg1;
if ( _arg1.getValue() != 0 )
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 ( _arg1 instanceof cError ) return _arg1;
return new cNumber( _arg0.getValue() * _arg1.getValue() );
}
return new cError( cErrorType.wrong_value_type );
};
_func[cElementType.bool][cElementType.bool] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
return new cBool( arg0.value > arg1.value );
case ">=":
return new cBool( arg0.value >= arg1.value );
case "<":
return new cBool( arg0.value < arg1.value );
case "<=":
return new cBool( arg0.value <= arg1.value );
case "=":
return new cBool( arg0.value === arg1.value );
case "<>":
return new cBool( arg0.value !== arg1.value );
case "-":
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() - _arg1.getValue() );
case "+":
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() + _arg1.getValue() );
case "/":
if ( !arg1.value )
return new cError( cErrorType.division_by_zero );
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() / _arg1.getValue() );
case "*":
var _arg0 = arg0.tocNumber(),
_arg1 = arg1.tocNumber();
return new cNumber( _arg0.getValue() * _arg1.getValue() );
if ( what == ">" ) {
return new cBool( arg0.value > arg1.value );
}
else if ( what == ">=" ) {
return new cBool( arg0.value >= arg1.value );
}
else if ( what == "<" ) {
return new cBool( arg0.value < arg1.value );
}
else if ( what == "<=" ) {
return new cBool( arg0.value <= arg1.value );
}
else if ( what == "=" ) {
return new cBool( arg0.value === arg1.value );
}
else if ( what == "<>" ) {
return new cBool( arg0.value !== arg1.value );
}
else if ( what == "-" ) {
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() );
}
else if ( what == "/" ) {
if ( !arg1.value )
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 );
};
......@@ -510,27 +555,35 @@ _func[cElementType.bool][cElementType.error] = function ( arg0, arg1, what ) {
};
_func[cElementType.bool][cElementType.empty] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
return new cBool( arg0.value > false );
case ">=":
return new cBool( arg0.value >= false );
case "<":
return new cBool( arg0.value < false );
case "<=":
return new cBool( arg0.value <= false );
case "=":
return new cBool( arg0.value === false );
case "<>":
return new cBool( arg0.value !== false );
case "-":
return new cNumber( arg0.value ? 1.0 : 0.0 - 0 );
case "+":
return new cNumber( arg0.value ? 1.0 : 0.0 + 0 );
case "/":
return new cError( cErrorType.division_by_zero );
case "*":
return new cNumber( 0 );
if ( what == ">" ) {
return new cBool( arg0.value > false );
}
else if ( what == ">=" ) {
return new cBool( arg0.value >= false );
}
else if ( what == "<" ) {
return new cBool( arg0.value < false );
}
else if ( what == "<=" ) {
return new cBool( arg0.value <= false );
}
else if ( what == "=" ) {
return new cBool( arg0.value === false );
}
else if ( what == "<>" ) {
return new cBool( arg0.value !== false );
}
else if ( what == "-" ) {
return new cNumber( arg0.value ? 1.0 : 0.0 - 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 );
};
......@@ -544,80 +597,98 @@ _func[cElementType.error][cElementType.number] = _func[cElementType.error][cElem
_func[cElementType.empty][cElementType.number] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
return new cBool( 0 > arg1.getValue() );
case ">=":
return new cBool( 0 >= arg1.getValue() );
case "<":
return new cBool( 0 < arg1.getValue() );
case "<=":
return new cBool( 0 <= arg1.getValue() );
case "=":
return new cBool( 0 == arg1.getValue() );
case "<>":
return new cBool( 0 != arg1.getValue() );
case "-":
return new cNumber( 0 - arg1.getValue() );
case "+":
return new cNumber( 0 + arg1.getValue() );
case "/":
if ( arg1.getValue() == 0 )
return new cError( cErrorType.not_numeric );
return new cNumber( 0 );
case "*":
return new cNumber( 0 );
if ( what == ">" ) {
return new cBool( 0 > arg1.getValue() );
}
else if ( what == ">=" ) {
return new cBool( 0 >= arg1.getValue() );
}
else if ( what == "<" ) {
return new cBool( 0 < arg1.getValue() );
}
else if ( what == "<=" ) {
return new cBool( 0 <= arg1.getValue() );
}
else if ( what == "=" ) {
return new cBool( 0 == arg1.getValue() );
}
else if ( what == "<>" ) {
return new cBool( 0 != arg1.getValue() );
}
else if ( what == "-" ) {
return new cNumber( 0 - arg1.getValue() );
}
else if ( what == "+" ) {
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 );
};
_func[cElementType.empty][cElementType.string] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
return new cBool( 0 > arg1.getValue().length );
case ">=":
return new cBool( 0 >= arg1.getValue().length );
case "<":
return new cBool( 0 < arg1.getValue().length );
case "<=":
return new cBool( 0 <= arg1.getValue().length );
case "=":
return new cBool( 0 === arg1.getValue().length );
case "<>":
return new cBool( 0 != arg1.getValue().length );
case "-":
case "+":
case "/":
case "*":
return new cError( cErrorType.wrong_value_type );
if ( what == ">" ) {
return new cBool( 0 > arg1.getValue().length );
}
else if ( what == ">=" ) {
return new cBool( 0 >= arg1.getValue().length );
}
else if ( what == "<" ) {
return new cBool( 0 < arg1.getValue().length );
}
else if ( what == "<=" ) {
return new cBool( 0 <= arg1.getValue().length );
}
else if ( what == "=" ) {
return new cBool( 0 === arg1.getValue().length );
}
else if ( what == "<>" ) {
return new cBool( 0 != arg1.getValue().length );
}
else if ( what == "-" || what == "+" || what == "/" || what == "*" ) {
return new cError( cErrorType.wrong_value_type );
}
return new cError( cErrorType.wrong_value_type );
};
_func[cElementType.empty][cElementType.bool] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
return new cBool( false > arg1.value );
case ">=":
return new cBool( false >= arg1.value );
case "<":
return new cBool( false < arg1.value );
case "<=":
return new cBool( false <= arg1.value );
case "=":
return new cBool( arg1.value === false );
case "<>":
return new cBool( arg1.value !== false );
case "-":
return new cNumber( 0 - arg1.value ? 1.0 : 0.0 );
case "+":
return new cNumber( arg1.value ? 1.0 : 0.0 );
case "/":
if ( arg1.value )
return new cNumber( 0 );
return new cError( cErrorType.not_numeric );
case "*":
if ( what == ">" ) {
return new cBool( false > arg1.value );
}
else if ( what == ">=" ) {
return new cBool( false >= arg1.value );
}
else if ( what == "<" ) {
return new cBool( false < arg1.value );
}
else if ( what == "<=" ) {
return new cBool( false <= arg1.value );
}
else if ( what == "=" ) {
return new cBool( arg1.value === false );
}
else if ( what == "<>" ) {
return new cBool( arg1.value !== false );
}
else if ( what == "-" ) {
return new cNumber( 0 - arg1.value ? 1.0 : 0.0 );
}
else if ( what == "+" ) {
return new cNumber( arg1.value ? 1.0 : 0.0 );
}
else if ( what == "/" ) {
if ( arg1.value )
return new cNumber( 0 );
return new cError( cErrorType.not_numeric );
}
else if ( what == "*" ) {
return new cNumber( 0 );
}
return new cError( cErrorType.wrong_value_type );
};
......@@ -627,22 +698,20 @@ _func[cElementType.empty][cElementType.error] = function ( arg0, arg1, what ) {
};
_func[cElementType.empty][cElementType.empty] = function ( arg0, arg1, what ) {
switch ( what ) {
case ">":
case "<":
case "<>":
return new cBool( false );
case ">=":
case "<=":
case "=":
return new cBool( true );
case "-":
case "+":
return new cNumber( 0 );
case "/":
return new cError( cErrorType.not_numeric );
case "*":
return new cNumber( 0 );
if ( what == ">" || what == "<" || what == "<>" ) {
return new cBool( false );
}
else if ( what == ">=" || what == "<=" || what == "=" ) {
return new cBool( true );
}
else if ( what == "-" || what == "+" ) {
return new cNumber( 0 );
}
else if ( what == "/" ) {
return new cError( cErrorType.not_numeric );
}
else if ( what == "*" ) {
return new cNumber( 0 );
}
return new cError( cErrorType.wrong_value_type );
};
......@@ -780,11 +849,20 @@ function checkTypeCell( val ) {
/*Base classes for operators & functions */
/** @constructor */
function cBaseOperator( name, priority, argumentCount ) {
this.name = name ? name : "";
this.priority = priority !== undefined ? priority : 10;
if( name )
this.name = name;
else
this.name = "";
if( priority !== undefined )
this.priority = priority;
else
this.priority = 10;
this.type = cElementType.operator;
this.isRightAssociative = false;
this.argumentsCurrent = argumentCount !== undefined ? argumentCount : 2;
if( argumentCount !== undefined )
this.argumentsCurrent = argumentCount;
else
this.argumentsCurrent = 2;
this.value = null;
this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу.
......@@ -904,39 +982,253 @@ cBaseType.prototype = {
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" */
var cFormulaOperators = {
'(':function () {
var r = {};
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;
},
'(':parentLeft,
')':parentRight,
'{':function () {
var r = {};
r.name = '{';
......@@ -954,203 +1246,23 @@ var cFormulaOperators = {
return r;
},
/* 50 is highest priority */
'un_minus':function () {
var r = new cBaseOperator( 'un_minus'/**name operator*/, 50/**priority of operator*/, 1/**count arguments*/ );
r.Calculate = function ( arg ) { //calculate operator
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() )
},
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;
}
'un_minus':cUnarMinusOperator,
'un_plus':cUnarPlusOperator,
'%':cPercentOperator,
'^':cPowOperator,
'*':cMultOperator,
'/':cDivOperator,
'+':cPlusOperator,
'-':cMinusOperator,
'&'://concat str
cConcatSTROperator,
'=':// equals
cEqualsOperator,
'<>':cNotEqualsOperator,
'<':cLessOperator,
'<=':cLessOrEqualOperator,
'>':cGreaterOperator,
'>=':cGreaterOrEqualOperator
/* 10 is lowest priopity */
};
......@@ -1183,7 +1295,7 @@ function getFormulasInfo() {
/*Basic types of an elements used into formulas*/
/** @constructor */
function cNumber( val ) {
cNumber.superclass.constructor.call( this, val );
cBaseType.apply( this, arguments );
this.type = cElementType.number;
this.value = parseFloat( val );
if( !isNaN( this.value ) && Math.abs(this.value)!=Infinity )
......@@ -1191,7 +1303,7 @@ function cNumber( val ) {
else
return new cError( cErrorType.not_numeric );
}
extend( cNumber, cBaseType );
cNumber.prototype = Object.create(cBaseType.prototype);
cNumber.prototype.getValue = function () {
return this.value//.toFixed( cExcelSignificantDigits ) - 0;
};
......@@ -1207,10 +1319,10 @@ cNumber.prototype.tocBool = function () {
/** @constructor */
function cString( val ) {
cString.superclass.constructor.call( this, val );
cBaseType.apply( this, arguments );
this.type = cElementType.string;
}
extend( cString, cBaseType );
cString.prototype = Object.create(cBaseType.prototype);
cString.prototype.tocNumber = function () {
if ( this.value == "" )
return new cEmpty();
......@@ -1249,19 +1361,15 @@ cString.prototype.tryConvert = function () {
/** @constructor */
function cBool( val ) {
cBool.superclass.constructor.call( this, val );
cBaseType.apply( this, arguments );
this.type = cElementType.bool;
var that = this;
switch ( val.toString().toUpperCase() ) {
case "TRUE":
this.value = true;
break;
case "FALSE":
this.value = false;
break;
}
var v = val.toString().toUpperCase();
if( v == "TRUE" )
this.value = true;
else
this.value = false;
}
extend( cBool, cBaseType );
cBool.prototype = Object.create(cBaseType.prototype);
cBool.prototype.toString = function () {
return this.value.toString().toUpperCase();
};
......@@ -1283,89 +1391,69 @@ cBool.prototype.toBool = function () {
/** @constructor */
function cError( val ) {
cError.superclass.constructor.call( this, val );
cBaseType.apply( this, arguments );
this.type = cElementType.error;
this.errorType = -1;
if ( isNaN( parseInt( val ) ) ) {
switch ( val ) {
case "#VALUE!":
this.errorType = cErrorType.wrong_value_type;
break;
case "#NULL!":
this.errorType = cErrorType.null_value;
break;
case "#DIV/0!":
this.errorType = cErrorType.division_by_zero;
break;
case "#REF!":
this.errorType = cErrorType.bad_reference;
break;
case "#NAME?":
this.errorType = cErrorType.wrong_name;
break;
case "#NUM!":
this.errorType = cErrorType.not_numeric;
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;
}
if( val == "#VALUE!" ){
this.errorType = cErrorType.wrong_value_type;
}else if( val == "#NULL!" ){
this.errorType = cErrorType.null_value;
}else if( val == "#DIV/0!" ){
this.errorType = cErrorType.division_by_zero;
}else if( val == "#REF!" ){
this.errorType = cErrorType.bad_reference;
}else if( val == "#NAME?" ){
this.errorType = cErrorType.wrong_name;
}else if( val == "#NUM!" ){
this.errorType = cErrorType.not_numeric;
}else if( val == "#N/A" ){
this.errorType = cErrorType.not_available;
}else if( val == "#UNSUPPORTED_FUNCTION!" ){
this.errorType = cErrorType.unsupported_function;
}else if( val == "#GETTING_DATA" ){
this.errorType = cErrorType.getting_data;
}
return this;
}
switch ( val ) {
case cErrorType.null_value:
this.value = "#NULL!";
this.errorType = cErrorType.null_value;
break;
case cErrorType.division_by_zero:
this.value = "#DIV/0!";
this.errorType = cErrorType.division_by_zero;
break;
case cErrorType.wrong_value_type:
this.value = "#VALUE!";
this.errorType = cErrorType.wrong_value_type;
break;
case cErrorType.bad_reference:
this.value = "#REF!";
this.errorType = cErrorType.bad_reference;
break;
case cErrorType.wrong_name:
this.value = "#NAME?";
this.errorType = cErrorType.wrong_name;
break;
case cErrorType.not_numeric:
this.value = "#NUM!";
this.errorType = cErrorType.not_numeric;
break;
case cErrorType.not_available:
this.value = "#N/A";
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;
if( val == cErrorType.null_value ){
this.value = "#NULL!";
this.errorType = cErrorType.null_value;
}else if( val == cErrorType.division_by_zero ){
this.value = "#DIV/0!";
this.errorType = cErrorType.division_by_zero;
}else if( val == cErrorType.wrong_value_type ){
this.value = "#VALUE!";
this.errorType = cErrorType.wrong_value_type;
}else if( val == cErrorType.bad_reference ){
this.value = "#REF!";
this.errorType = cErrorType.bad_reference;
}else if( val == cErrorType.wrong_name ){
this.value = "#NAME?";
this.errorType = cErrorType.wrong_name;
}else if( val == cErrorType.not_numeric ){
this.value = "#NUM!";
this.errorType = cErrorType.not_numeric;
}else if( val == cErrorType.not_available ){
this.value = "#N/A";
this.errorType = cErrorType.not_available;
}else if( val == cErrorType.unsupported_function ){
this.value = "#UNSUPPORTED_FUNCTION!";
this.errorType = cErrorType.unsupported_function;
}else if( val == cErrorType.getting_data ){
this.value = "#GETTING_DATA";
this.errorType = cErrorType.getting_data;
}
}
extend( cError, cBaseType );
cError.prototype = Object.create(cBaseType.prototype);
cError.prototype.tocNumber = cError.prototype.tocString = cError.prototype.tocBool = cError.prototype.tocEmpty = function () {
return this;
};
/** @constructor */
function cArea( val, _ws ) {/*Area means "A1:E5" for example*/
cArea.superclass.constructor.call( this, val );
cBaseType.apply( this, arguments );
this.ws = _ws;
this.wb = _ws.workbook;
this._cells = val;
......@@ -1374,7 +1462,7 @@ function cArea( val, _ws ) {/*Area means "A1:E5" for example*/
// this.range = this.wb.getWorksheetById(this.ws).getRange2(val);
// this._valid = this.range ? true : false;
}
extend( cArea, cBaseType );
cArea.prototype = Object.create(cBaseType.prototype);
cArea.prototype.getWsId = function () {
return this.ws.Id;
};
......@@ -1383,29 +1471,31 @@ cArea.prototype.getValue = function () {
if ( !r ) {
_val.push( new cError( cErrorType.bad_reference ) )
}
else
else {
r._foreachNoEmpty( function ( _cell ) {
switch ( _cell.getType() ) {
case CellValueType.Number:
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
break;
case CellValueType.Bool:
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.Error:
_val.push( new cError( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.String:
var cellType = _cell.getType();
if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else if ( cellType == CellValueType.Bool ) {
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
}
else if ( cellType == CellValueType.Error ) {
_val.push( new cError( _cell.getValueWithoutFormat() ) );
}
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() ) );
break;
default:
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
}
}
} );
}
return _val;
};
cArea.prototype.getValue2 = function ( cell ) {
......@@ -1413,30 +1503,32 @@ cArea.prototype.getValue2 = function ( cell ) {
if ( !r ) {
_val.push( new cError( cErrorType.bad_reference ) )
}
else
else {
r._foreachNoEmpty( function ( _cell ) {
if ( cell.getID() == _cell.getName() )
switch ( _cell.getType() ) {
case CellValueType.Number:
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
break;
case CellValueType.Bool:
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.Error:
_val.push( new cError( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.String:
if ( cell.getID() == _cell.getName() ) {
var cellType = _cell.getType();
if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else if ( cellType == CellValueType.Bool ) {
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
}
else if ( cellType == CellValueType.Error ) {
_val.push( new cError( _cell.getValueWithoutFormat() ) );
}
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() ) );
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 )
return new cEmpty();
......@@ -1513,29 +1605,30 @@ cArea.prototype.foreach2 = function ( action ) {
r._foreach2( function ( _cell ) {
var val;
if ( _cell ) {
switch ( _cell.getType() ) {
case CellValueType.Number:
_cell.getValueWithoutFormat() == "" ? val = new cEmpty() : val = new cNumber( _cell.getValueWithoutFormat() )
break;
case CellValueType.Bool:
val = new cBool( _cell.getValueWithoutFormat() );
break;
case CellValueType.Error:
val = new cError( _cell.getValueWithoutFormat() );
break;
case CellValueType.String:
val = new cString( _cell.getValueWithoutFormat() );
break;
default:
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
val = new cNumber( _cell.getValueWithoutFormat() )
}
else
val = checkTypeCell( "" + _cell.getValueWithoutFormat() );
var cellType=_cell.getType();
if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? val = new cEmpty() : val = new cNumber( _cell.getValueWithoutFormat() )
}
else if ( cellType == CellValueType.Bool ) {
val = new cBool( _cell.getValueWithoutFormat() );
}
else if ( cellType == CellValueType.Error ) {
val = new cError( _cell.getValueWithoutFormat() );
}
else if ( cellType == CellValueType.String ) {
val = new cString( _cell.getValueWithoutFormat() );
}
else {
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
val = new cNumber( _cell.getValueWithoutFormat() )
}
else
val = checkTypeCell( "" + _cell.getValueWithoutFormat() );
}
}
else
val = new cEmpty()
else{
val = new cEmpty();
}
action(val);
} );
}
......@@ -1547,25 +1640,25 @@ cArea.prototype.getMatrix = function () {
if ( !arr[i - r1] )
arr[i - r1] = [];
if ( cell ) {
switch ( cell.getType() ) {
case CellValueType.Number:
arr[i - r1][j - c1] = cell.isEmptyTextString() ? new cEmpty() : new cNumber( cell.getValueWithoutFormat() )
break;
case CellValueType.Bool:
arr[i - r1][j - c1] = new cBool( cell.getValueWithoutFormat() );
break;
case CellValueType.Error:
arr[i - r1][j - c1] = new cError( cell.getValueWithoutFormat() );
break;
case CellValueType.String:
arr[i - r1][j - c1] = new cString( cell.getValueWithoutFormat() );
break;
default:
if ( !cell.isEmptyTextString()) {
arr[i - r1][j - c1] = new cNumber( cell.getValueWithoutFormat() )
}
else
arr[i - r1][j - c1] = checkTypeCell( "" + cell.getValueWithoutFormat() );
var cellType = cell.getType();
if ( cellType == CellValueType.Number ) {
arr[i - r1][j - c1] = cell.isEmptyTextString() ? new cEmpty() : new cNumber( cell.getValueWithoutFormat() )
}
else if ( cellType == CellValueType.Bool ) {
arr[i - r1][j - c1] = new cBool( cell.getValueWithoutFormat() );
}
else if ( cellType == CellValueType.Error ) {
arr[i - r1][j - c1] = new cError( cell.getValueWithoutFormat() );
}
else if ( cellType == CellValueType.String ) {
arr[i - r1][j - c1] = new cString( cell.getValueWithoutFormat() );
}
else {
if ( !cell.isEmptyTextString() ) {
arr[i - r1][j - c1] = new cNumber( cell.getValueWithoutFormat() )
}
else
arr[i - r1][j - c1] = checkTypeCell( "" + cell.getValueWithoutFormat() );
}
}
else
......@@ -1576,16 +1669,16 @@ cArea.prototype.getMatrix = function () {
/** @constructor */
function cRef( val, _ws ) {/*Ref means A1 for example*/
cRef.superclass.constructor.call( this, val );
cBaseType.apply( this, arguments );
this._cells = val;
this.ws = _ws;
this.wb = _ws.workbook;
this.isAbsolute = false;
this.type = cElementType.cell;
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 () {
return this.ws.Id;
};
......@@ -1593,21 +1686,22 @@ cRef.prototype.getValue = function () {
if ( !this._valid ) {
return new cError( cErrorType.bad_reference )
}
switch ( this.range.getType() ) {
case CellValueType.Number:
{
var v = this.range.getValueWithoutFormat();
if ( v == "" )
return new cEmpty()
else
return new cNumber( "" + v );
}
case CellValueType.Bool:
return new cBool( "" + this.range.getValueWithoutFormat() )
case CellValueType.Error:
return new cError( "" + this.range.getValueWithoutFormat() )
default:
return checkTypeCell( "" + this.range.getValueWithoutFormat() )
var cellType = this.range.getType()
if ( cellType == CellValueType.Number ) {
var v = this.range.getValueWithoutFormat();
if ( v == "" )
return new cEmpty()
else
return new cNumber( "" + v );
}
else if ( cellType == CellValueType.Bool ) {
return new cBool( "" + this.range.getValueWithoutFormat() )
}
else if ( cellType == CellValueType.Error ) {
return new cError( "" + this.range.getValueWithoutFormat() )
}
else {
return checkTypeCell( "" + this.range.getValueWithoutFormat() )
}
};
cRef.prototype.tocNumber = function () {
......@@ -1638,7 +1732,7 @@ cRef.prototype.isValid = function () {
/** @constructor */
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._cells = val;
this.isAbsolute = false;
......@@ -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.wsTo = this._wb.getWorksheetByName( _wsTo ).getId();
}
extend( cArea3D, cBaseType );
cArea3D.prototype = Object.create(cBaseType.prototype);
cArea3D.prototype.wsRange = function () {
var r = [];
if ( !this.wsTo ) this.wsTo = this.wsFrom;
......@@ -1691,25 +1785,25 @@ cArea3D.prototype.getValue = function () {
return _val;
}
_r[i]._foreachNoEmpty( function ( _cell ) {
switch ( _cell.getType() ) {
case CellValueType.Number:
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
break;
case CellValueType.Bool:
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.Error:
_val.push( new cError( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.String:
var cellType = _cell.getType()
if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else if ( cellType == CellValueType.Bool ) {
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
}
else if ( cellType == CellValueType.Error ) {
_val.push( new cError( _cell.getValueWithoutFormat() ) );
}
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() ) );
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 ) {
}
_r[0]._foreachNoEmpty( function ( _cell ) {
if ( cell.getID() == _cell.getName() )
switch ( _cell.getType() ) {
case CellValueType.Number:
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
break;
case CellValueType.Bool:
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.Error:
_val.push( new cError( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.String:
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
break;
default:
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
var cellType = _cell.getType();
if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? _val.push( new cEmpty() ) : _val.push( new cNumber( _cell.getValueWithoutFormat() ) )
}
else if ( cellType == CellValueType.Bool ) {
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
}
else if ( cellType == CellValueType.Error ) {
_val.push( new cError( _cell.getValueWithoutFormat() ) );
}
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() ) );
}
} )
if( _val[0] == undefined || _val[0] == null )
......@@ -1890,25 +1984,25 @@ cArea3D.prototype.getMatrix = function () {
if ( !arr[k][i - r1] )
arr[k][i - r1] = [];
if ( cell ) {
switch ( cell.getType() ) {
case CellValueType.Number:
arr[k][i - r1][j - c1] = cell.getValueWithoutFormat() == "" ? new cEmpty() : new cNumber( cell.getValueWithoutFormat() )
break;
case CellValueType.Bool:
arr[k][i - r1][j - c1] = new cBool( cell.getValueWithoutFormat() );
break;
case CellValueType.Error:
arr[k][i - r1][j - c1] = new cError( cell.getValueWithoutFormat() );
break;
case CellValueType.String:
arr[k][i - r1][j - c1] = new cString( cell.getValueWithoutFormat() );
break;
default:
if ( cell.getValueWithoutFormat() && cell.getValueWithoutFormat() != "" ) {
arr[k][i - r1][j - c1] = new cNumber( cell.getValueWithoutFormat() )
}
else
arr[k][i - r1][j - c1] = checkTypeCell( "" + cell.getValueWithoutFormat() );
var cellType = cell.getType();
if ( cellType == CellValueType.Number ) {
arr[k][i - r1][j - c1] = cell.isEmptyTextString() ? new cEmpty() : new cNumber( cell.getValueWithoutFormat() )
}
else if ( cellType == CellValueType.Bool ) {
arr[k][i - r1][j - c1] = new cBool( cell.getValueWithoutFormat() );
}
else if ( cellType == CellValueType.Error ) {
arr[k][i - r1][j - c1] = new cError( cell.getValueWithoutFormat() );
}
else if ( cellType == CellValueType.String ) {
arr[k][i - r1][j - c1] = new cString( cell.getValueWithoutFormat() );
}
else {
if ( cell.isEmptyTextString() ) {
arr[k][i - r1][j - c1] = new cNumber( cell.getValueWithoutFormat() )
}
else
arr[k][i - r1][j - c1] = checkTypeCell( "" + cell.getValueWithoutFormat() );
}
}
else
......@@ -1926,25 +2020,25 @@ cArea3D.prototype.foreach2 = function ( action ) {
_r[i]._foreach2( function ( _cell ) {
var val;
if(_cell){
switch ( _cell.getType() ) {
case CellValueType.Number:
_cell.getValueWithoutFormat() == "" ? val = new cEmpty() : val = new cNumber( _cell.getValueWithoutFormat() )
break;
case CellValueType.Bool:
val = new cBool( _cell.getValueWithoutFormat() );
break;
case CellValueType.Error:
val = new cError( _cell.getValueWithoutFormat() );
break;
case CellValueType.String:
val = new cString( _cell.getValueWithoutFormat() );
break;
default:
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
val = new cNumber( _cell.getValueWithoutFormat() )
}
else
val = checkTypeCell( "" + _cell.getValueWithoutFormat() );
var cellType =_cell.getType();
if ( cellType == CellValueType.Number ) {
_cell.getValueWithoutFormat() == "" ? val = new cEmpty() : val = new cNumber( _cell.getValueWithoutFormat() )
}
else if ( cellType == CellValueType.Bool ) {
val = new cBool( _cell.getValueWithoutFormat() );
}
else if ( cellType == CellValueType.Error ) {
val = new cError( _cell.getValueWithoutFormat() );
}
else if ( cellType == CellValueType.String ) {
val = new cString( _cell.getValueWithoutFormat() );
}
else {
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() != "" ) {
val = new cNumber( _cell.getValueWithoutFormat() )
}
else
val = checkTypeCell( "" + _cell.getValueWithoutFormat() );
}
}
else
......@@ -1957,14 +2051,14 @@ cArea3D.prototype.foreach2 = function ( action ) {
/** @constructor */
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._cells = val;
this.isAbsolute = false;
this.type = cElementType.cell;
this.ws = this._wb.getWorksheetByName( _wsFrom );
}
extend( cRef3D, cBaseType );
cRef3D.prototype = Object.create(cBaseType.prototype);
cRef3D.prototype.getWsId = function () {
return this.ws.Id;
};
......@@ -1984,23 +2078,25 @@ cRef3D.prototype.getValue = function () {
if ( !_r ) {
return new cError( cErrorType.bad_reference );
}
switch ( _r.getType() ) {
case CellValueType.Number:
{
var v = _r.getValueWithoutFormat();
if ( v == "" )
return new cEmpty( "" + v );
else
return new cNumber( "" + v );
}
case CellValueType.String:
return new cString( "" + _r.getValueWithoutFormat() );
case CellValueType.Bool:
return new cBool( "" + _r.getValueWithoutFormat() )
case CellValueType.Error:
return new cError( "" + _r.getValueWithoutFormat() )
default:
return checkTypeCell( "" + _r.getValueWithoutFormat() )
var cellType = _r.getType();
if ( cellType == CellValueType.Number ) {
var v = _r.getValueWithoutFormat();
if ( v == "" )
return new cEmpty();
else
return new cNumber( "" + v );
}
else if ( cellType == CellValueType.String ) {
return new cString( "" + _r.getValueWithoutFormat() );
}
else if ( cellType == CellValueType.Bool ) {
return new cBool( "" + _r.getValueWithoutFormat() )
}
else if ( cellType == CellValueType.Error ) {
return new cError( "" + _r.getValueWithoutFormat() )
}
else {
return checkTypeCell( "" + _r.getValueWithoutFormat() )
}
};
cRef3D.prototype.tocBool = function () {
......@@ -2035,10 +2131,10 @@ cRef3D.prototype.getWS = function () {
/** @constructor */
function cEmpty() {
cEmpty.superclass.constructor.call( this, "" );
cBaseType.apply( this, [""] );
this.type = cElementType.empty;
}
extend( cEmpty, cBaseType );
cEmpty.prototype = Object.create(cBaseType.prototype);
cEmpty.prototype.tocNumber = function () {
return new cNumber( 0 );
};
......@@ -2054,11 +2150,11 @@ cEmpty.prototype.toString = function () {
/** @constructor */
function cName( val, wb ) {
cName.superclass.constructor.call( this, val );
cBaseType.apply( this, arguments );
this.wb = wb;
this.type = cElementType.name;
}
extend( cName, cBaseType );
cName.prototype = Object.create(cBaseType.prototype);
cName.prototype.toRef = function ( wsID ) {
var _3DRefTmp,
ref = this.wb.getDefinesNames( this.value, wsID ).Ref;
......@@ -2081,14 +2177,14 @@ cName.prototype.toRef = function ( wsID ) {
/** @constructor */
function cArray() {
cArray.superclass.constructor.call( this );
cBaseType.apply( this, arguments );
this.array = [];
this.rowCount = 0;
this.countElementInRow = [];
this.countElement = 0;
this.type = cElementType.array;
}
extend( cArray, cBaseType );
cArray.prototype = Object.create(cBaseType.prototype);
cArray.prototype.addRow = function () {
this.array[this.array.length] = [];
this.countElementInRow[this.rowCount++] = 0;
......@@ -2279,11 +2375,11 @@ parserFormula.prototype = {
if ( operand_expected ) {
if ( this.operand_str == "-" ) {
operand_expected = true;
found_operator = cFormulaOperators['un_minus']();
found_operator = new cFormulaOperators['un_minus']();
}
else if ( this.operand_str == "+" ) {
operand_expected = true;
found_operator = cFormulaOperators['un_plus']();
found_operator = new cFormulaOperators['un_plus']();
}
else {
this.error.push( c_oAscError.ID.FrmlWrongOperator );
......@@ -2295,19 +2391,19 @@ parserFormula.prototype = {
else if ( !operand_expected ) {
if ( this.operand_str == "-" ) {
operand_expected = true;
found_operator = cFormulaOperators['-']();
found_operator = new cFormulaOperators['-']();
}
else if ( this.operand_str == "+" ) {
operand_expected = true;
found_operator = cFormulaOperators['+']();
found_operator = new cFormulaOperators['+']();
}
else if ( this.operand_str == "%" ) {
operand_expected = false;
found_operator = cFormulaOperators['%']();
found_operator = new cFormulaOperators['%']();
}
else {
if ( this.operand_str in cFormulaOperators ) {
found_operator = cFormulaOperators[this.operand_str]();
found_operator = new cFormulaOperators[this.operand_str]();
operand_expected = true;
}
else {
......@@ -2339,7 +2435,7 @@ parserFormula.prototype = {
/* Left & Right Parentheses */
else if ( parserHelp.isLeftParentheses.call( this, this.Formula, this.pCurrPos ) ) {
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 ) ) {
......@@ -2692,7 +2788,7 @@ parserFormula.prototype = {
return this.value;
},
/* Метод возвращает все ссылки на ячейки которые учавствуют в формуле*/
/* Метод возвращает все ссылки на ячейки которые участвуют в формуле*/
getRef:function () {
var aOutRef = [];
for ( var i = 0; i < this.outStack.length; i++ ) {
......@@ -3161,7 +3257,7 @@ function searchRegExp(str, flags){
return $1 ? $0 : '(.*)';
} )
.replace( /(~)?\?/g, function ( $0, $1 ) {
return $1 ? $0 : '.';
return $1 ? $0 : '.{1}';
} )
.replace( /(~\*)/g, "\\*" ).replace( /(~\?)/g, "\\?" );
......@@ -3325,8 +3421,7 @@ function lcl_Erfc0600( x ) {
return fVal = Math.exp( -1.0 * x * x ) * fPSum / fQSum;
}
/** Approximation algorithm for erfc for 6.0 < x < 26.54 (but used for all
x > 6.0). */
/** Approximation algorithm for erfc for 6.0 < x < 26.54 (but used for all x > 6.0). */
function lcl_Erfc2654( x ) {
var pn = [
5.64189583547756078E-1,
......
......@@ -38,127 +38,115 @@ function consolelog(text){
}
/** @constructor */
function DependencyGraph(wb) {
this.wb = wb;
this.nodesId = null;
this.nodesCell = null;
this.nodesArea = null;
this.nodeslength = null;
function DependencyGraph( wb ) {
this.wb = wb;
this.nodesId = null;
this.nodesCell = null;
this.nodesArea = null;
this.nodeslength = null;
this.bSetRefError = false;
this.clear();
this.clear();
}
DependencyGraph.prototype = {
clear : function(){
this.nodesId = {};
this.nodesCell = {};
this.nodesArea = {};
this.nodeslength = 0;
clear:function () {
this.nodesId = {};
this.nodesCell = {};
this.nodesArea = {};
this.nodeslength = 0;
this.bSetRefError = false;
},
nodeExist : function(node){
return this.nodeExist2(node.sheetId, node.cellId);
},
nodeExist2 : function(sheetId, cellId){
return null != this.getNode(sheetId, cellId);
},
nodeExistWithArea : function(sheetId, cellId){
var bRes = this.nodeExist2(sheetId, cellId);
if(!bRes)
{
var nodesSheetArea = this.nodesArea[sheetId];
if(null != nodesSheetArea)
{
var bbox = Asc.g_oRangeCache.getAscRange(cellId);
bRes = nodesSheetArea.get(bbox).all.length > 0;
}
}
return bRes;
},
getNode2 : function(node){
return this.nodesId[node.nodeId];
},
getNode : function(sheetId, cellId){
return this.nodesId[getVertexId(sheetId, cellId)];
},
addNode2 : function(node){
return this.addNode(node.sheetId, node.cellId);
},
addNode : function(sheetId, cellId){
},
nodeExist:function ( node ) {
return this.nodeExist2( node.sheetId, node.cellId );
},
nodeExist2:function ( sheetId, cellId ) {
return null != this.getNode( sheetId, cellId );
},
nodeExistWithArea:function ( sheetId, cellId ) {
var bRes = this.nodeExist2( sheetId, cellId );
if ( !bRes ) {
var nodesSheetArea = this.nodesArea[sheetId];
if ( null != nodesSheetArea ) {
var bbox = Asc.g_oRangeCache.getAscRange( cellId );
bRes = nodesSheetArea.get( bbox ).all.length > 0;
}
}
return bRes;
},
getNode2:function ( node ) {
return this.nodesId[node.nodeId];
},
getNode:function ( sheetId, cellId ) {
return this.nodesId[getVertexId( sheetId, cellId )];
},
addNode2:function ( node ) {
return this.addNode( node.sheetId, node.cellId );
},
addNode:function ( sheetId, cellId ) {
var _this = this;
var nodeId = getVertexId(sheetId, cellId)
var oRes = this.nodesId[nodeId];
if(null == oRes)
{
var node = new Vertex(sheetId, cellId, this.wb)
var oBBoxNode = node.getBBox();
if(node.isArea)
{
var nodesSheetArea = this.nodesArea[node.sheetId];
if(null == nodesSheetArea)
{
var nodeId = getVertexId( sheetId, cellId )
var oRes = this.nodesId[nodeId];
if ( null == oRes ) {
var node = new Vertex( sheetId, cellId, this.wb )
var oBBoxNode = node.getBBox();
if ( node.isArea ) {
var nodesSheetArea = this.nodesArea[node.sheetId];
if ( null == nodesSheetArea ) {
nodesSheetArea = new RangeDataManager(function(data, from, to){_this._changeNode(data, from, to);});
this.nodesArea[node.sheetId] = nodesSheetArea;
}
nodesSheetArea.add(oBBoxNode, node);
}
else
{
var nodesSheetCell = this.nodesCell[node.sheetId];
if(null == nodesSheetCell)
{
this.nodesArea[node.sheetId] = nodesSheetArea;
}
nodesSheetArea.add( oBBoxNode, node );
}
else {
var nodesSheetCell = this.nodesCell[node.sheetId];
if ( null == nodesSheetCell ) {
nodesSheetCell = new CellArea(function(data, from, to){_this._changeNode(data, from, to);});
this.nodesCell[node.sheetId] = nodesSheetCell;
}
nodesSheetCell.add(oBBoxNode.r1, oBBoxNode.c1, node);
}
oRes = node;
}
return oRes;
},
addEdge2 : function(nodeFrom, nodeTo){
nodeFrom.addMasterEdge(nodeTo);
nodeTo.addSlaveEdge(nodeFrom);
},
addEdge : function(sheetIdFrom, cellIdFrom, sheetIdTo, cellIdTo){
var n1 = this.addNode(sheetIdFrom, cellIdFrom),
n2 = this.addNode(sheetIdTo, cellIdTo);
this.addEdge2(n1, n2);
},
getNodeBySheetId : function(sheetId){
var arr = [];
var nodesSheetCell = this.nodesCell[sheetId];
if(nodesSheetCell)
{
var aNodes = nodesSheetCell.getAll();
for(var i = 0, length = aNodes.length; i < length; i++)
{
var node = aNodes[i].data;
var n = node.getSlaveEdges();
if(n)
{
arr.push(node);
for(var id2 in n){
n[id2].weightNode++;
// arr.push(n[id2]);
}
}
}
}
return arr;
},
this.nodesCell[node.sheetId] = nodesSheetCell;
}
nodesSheetCell.add( oBBoxNode.r1, oBBoxNode.c1, node );
}
oRes = node;
}
return oRes;
},
addEdge2:function ( nodeFrom, nodeTo ) {
nodeFrom.addMasterEdge( nodeTo );
nodeTo.addSlaveEdge( nodeFrom );
},
addEdge:function ( sheetIdFrom, cellIdFrom, sheetIdTo, cellIdTo ) {
var n1 = this.addNode( sheetIdFrom, cellIdFrom ),
n2 = this.addNode( sheetIdTo, cellIdTo );
this.addEdge2( n1, n2 );
},
getNodeBySheetId:function ( sheetId ) {
var arr = [];
var nodesSheetCell = this.nodesCell[sheetId];
if ( nodesSheetCell ) {
var aNodes = nodesSheetCell.getAll();
for ( var i = 0, length = aNodes.length; i < length; i++ ) {
var node = aNodes[i].data;
var n = node.getSlaveEdges();
if ( n ) {
arr.push( node );
for ( var id2 in n ) {
n[id2].weightNode++;
// arr.push(n[id2]);
}
}
}
}
return arr;
},
deleteNode : function(node){
if(node.isArea)
{
if ( node.isArea ) {
var nodesSheetArea = this.nodesArea[node.sheetId];
if(nodesSheetArea)
nodesSheetArea.removeElement(new RangeDataManagerElem(node.getBBox(), node));
}
else
{
else {
var nodesSheetCell = this.nodesCell[node.sheetId];
if(nodesSheetCell)
nodesSheetCell.removeElement(new RangeDataManagerElem(node.getBBox(), node));
}
if(nodesSheetCell)
nodesSheetCell.removeElement(new RangeDataManagerElem(node.getBBox(), node));
}
},
deleteNodes : function(sheetId, bbox){
var bSetRefErrorOld = this.bSetRefError;
......@@ -170,7 +158,7 @@ DependencyGraph.prototype = {
oGetRes = nodesSheetArea.get(bbox);
for(var i = 0, length = oGetRes.inner.length; i < length; ++i)
nodesSheetArea.removeElement(oGetRes.inner[i]);
}
}
var nodesSheetCell = this.nodesCell[sheetId];
if(nodesSheetCell)
{
......@@ -179,58 +167,57 @@ DependencyGraph.prototype = {
nodesSheetCell.removeElement(oGetRes[i]);
}
this.bSetRefError = bSetRefErrorOld;
},
deleteMasterNodes : function(sheetId, cellId){
var node = this.getNode(sheetId, cellId);
if(node)
{
var arr = node.deleteAllMasterEdges();
for(var i in arr){
var nodeMaster = arr[i];
if( nodeMaster.refCount <= 0 )
this.deleteNode(nodeMaster);
}
}
},
deleteMasterNodes:function ( sheetId, cellId ) {
var node = this.getNode( sheetId, cellId );
if ( node ) {
var arr = node.deleteAllMasterEdges();
for ( var i in arr ) {
var nodeMaster = arr[i];
if ( nodeMaster.refCount <= 0 )
this.deleteNode( nodeMaster );
}
}
return node;
},
},
deleteMasterNodes2 : function(sheetId, cellId){
var node = this.deleteMasterNodes(sheetId, cellId);
if(node && node.refCount <= 0)
this.deleteNode(node);
return node;
},
getSlaveNodes : function(sheetId, cellId){
//todo
return null;
},
getMasterNodes : function(sheetId, cellId){
//todo
return null;
},
getNodesLength : function(){
return this.nodeslength;
},
checkOffset : function(BBox, offset, wsId, noDelete){
var _this = this;
var bHor = 0 != offset.offsetCol;
var toDelete = offset.offsetCol < 0 || offset.offsetRow < 0;
getSlaveNodes:function ( sheetId, cellId ) {
//todo
return null;
},
getMasterNodes:function ( sheetId, cellId ) {
//todo
return null;
},
getNodesLength:function () {
return this.nodeslength;
},
checkOffset:function ( BBox, offset, wsId, noDelete ) {
var _this = this;
var bHor = 0 != offset.offsetCol;
var toDelete = offset.offsetCol < 0 || offset.offsetRow < 0;
var bSetRefErrorOld = this.bSetRefError;
this.bSetRefError = true;
var oShiftGetBBox = shiftGetBBox(BBox, bHor);
var sShiftGetBBoxName = oShiftGetBBox.getName();
this.wb.needRecalc.nodes[getVertexId(wsId, sShiftGetBBoxName)] = [wsId, sShiftGetBBoxName];
this.wb.needRecalc.length++;
var nodesSheetArea = this.nodesArea[wsId];
var nodesSheetArea = this.nodesArea[wsId];
if(nodesSheetArea)
nodesSheetArea.shift(BBox, !toDelete, bHor);
var nodesSheetCell = this.nodesCell[wsId];
var nodesSheetCell = this.nodesCell[wsId];
if(nodesSheetCell)
nodesSheetCell.shift(BBox, !toDelete, bHor);
nodesSheetCell.shift( BBox, !toDelete, bHor );
this.bSetRefError = bSetRefErrorOld;
},
},
_changeNode : function(node, from, to)
{
var toDelete = null == to;
var toDelete = null == to;
var toAdd = null == from;
var wsId = node.sheetId;
if(toAdd)
......@@ -254,61 +241,57 @@ DependencyGraph.prototype = {
delete this.nodesId[node.nodeId];
this.nodeslength--;
}
else
{
var sOldnodeId = node.nodeId;
var sOldCellId = node.cellId;
else {
var sOldnodeId = node.nodeId;
var sOldCellId = node.cellId;
if((from.r1 == to.r1 && from.c1 == to.c1) || (from.r2 == to.r2 && from.c2 == to.c2))
node.moveStretch(to);
else
else
node.move({offsetCol: to.c1 - from.c1, offsetRow: to.r1 - from.r1}, wsId, toDelete);
delete this.nodesId[sOldnodeId];
this.nodesId[node.nodeId] = node;
delete this.nodesId[sOldnodeId];
this.nodesId[node.nodeId] = node;
}
//важно что ячейки уже сдвинулись, поэтому до вызова returnCell нужно сделать node.move
if(!node.isArea)
{
var cwf = this.wb.cwf[wsId];
var cwf = this.wb.cwf[wsId];
if(cwf)
{
var cell = node.returnCell();
if( cell && cell.formulaParsed )
{
var cell = node.returnCell();
if ( cell && cell.formulaParsed ) {
if(!toAdd)
delete cwf.cells[sOldCellId];
if(!toDelete)
cwf.cells[node.cellId] = node.cellId;
}
}
}
},
if ( !toDelete )
cwf.cells[node.cellId] = node.cellId;
}
}
}
},
getCellInRange : function(sheetId, bbox){
var res = [], oGetRes, nodesSheetCell = this.nodesCell[sheetId];
if(nodesSheetCell)
{
if ( nodesSheetCell ) {
oGetRes = nodesSheetCell.get(bbox);
for(var i = 0, length = oGetRes.length; i < length; i++)
{
elem = oGetRes[i];
for ( var i = 0, length = oGetRes.length; i < length; i++ ) {
elem = oGetRes[i];
res.push(elem.data);
}
}
return res;
},
getAreaInRange : function(sheetId, bbox){
var res = [], oGetRes, nodesSheetArea = this.nodesArea[sheetId];
if(nodesSheetArea)
{
oGetRes = nodesSheetArea.get(bbox);
for(var i = 0, length = oGetRes.all.length; i < length; i++)
{
}
}
return res;
},
getAreaInRange : function(sheetId, bbox){
var res = [], oGetRes, nodesSheetArea = this.nodesArea[sheetId];
if(nodesSheetArea)
{
oGetRes = nodesSheetArea.get(bbox);
for(var i = 0, length = oGetRes.all.length; i < length; i++)
{
elem = oGetRes.all[i];
res.push(elem.data);
}
}
return res;
},
}
}
return res;
},
getInRange : function(sheetId, bbox){
return this.getCellInRange(sheetId, bbox).concat(this.getAreaInRange(sheetId, bbox));
},
......@@ -321,312 +304,293 @@ DependencyGraph.prototype = {
if(nodesSheetArea)
oGetRes = nodesSheetArea.move(BBoxFrom, oBBoxTo);
},
drawDep : function(cellId,se){
// ToDo неиспользуемая функция, реализовать после выпуска
if( !cellId )
return;
var _wsV = this.wb.oApi.wb.getWorksheet(),
_getCellMetrics = _wsV.cellCommentator.getCellMetrics,
_cc = _wsV.cellCommentator,
ctx = _wsV.overlayCtx,
_wsVM = _wsV.model,
nodeId = getVertexId(_wsVM.getId(), cellId),
node = this.getNode(_wsVM.getId(), cellId),
cell;
function gCM(_this,col,row){
var metrics = { top: 0, left: 0, width: 0, height: 0, result: false }; // px
drawDep:function ( cellId, se ) {
// ToDo неиспользуемая функция, реализовать после выпуска
if ( !cellId )
return;
var _wsV = this.wb.oApi.wb.getWorksheet(),
_getCellMetrics = _wsV.cellCommentator.getCellMetrics,
_cc = _wsV.cellCommentator,
ctx = _wsV.overlayCtx,
_wsVM = _wsV.model,
nodeId = getVertexId( _wsVM.getId(), cellId ),
node = this.getNode( _wsVM.getId(), cellId ),
cell;
var fvr = _this.getFirstVisibleRow();
var fvc = _this.getFirstVisibleCol();
var mergedRange = _wsVM.getMergedByCell(row, col);
function gCM( _this, col, row ) {
var metrics = { top:0, left:0, width:0, height:0, result:false }; // px
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;
var startRow = (mergedRange.r1 > fvr) ? mergedRange.r1 : fvr;
if ( mergedRange && (fvc < mergedRange.c2) && (fvr < mergedRange.r2) ) {
metrics.top = _this.getCellTop(startRow, 0) - _this.getCellTop(fvr, 0) + _this.getCellTop(0, 0);
metrics.left = _this.getCellLeft(startCol, 0) - _this.getCellLeft(fvc, 0) + _this.getCellLeft(0, 0);
var startCol = (mergedRange.c1 > fvc) ? mergedRange.c1 : fvc;
var startRow = (mergedRange.r1 > fvr) ? mergedRange.r1 : fvr;
for (var i = startCol; i <= mergedRange.c2; i++) {
metrics.width += _this.getColumnWidth(i, 0)
}
for (var i = startRow; i <= mergedRange.r2; i++) {
metrics.height += _this.getRowHeight(i, 0)
}
metrics.result = true;
}
else{
metrics.top = _this.getCellTop( startRow, 0 ) - _this.getCellTop( fvr, 0 ) + _this.getCellTop( 0, 0 );
metrics.left = _this.getCellLeft( startCol, 0 ) - _this.getCellLeft( fvc, 0 ) + _this.getCellLeft( 0, 0 );
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);
metrics.width = _this.getColumnWidth(col, 0);
metrics.height = _this.getRowHeight(row, 0);
metrics.result = true;
}
return metrics;
}
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;
for ( var i = startCol; i <= mergedRange.c2; i++ ) {
metrics.width += _this.getColumnWidth( i, 0 )
}
for ( var i = startRow; i <= mergedRange.r2; i++ ) {
metrics.height += _this.getRowHeight( i, 0 )
}
metrics.result = true;
}
else {
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;
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 );
metrics.width = _this.getColumnWidth( col, 0 );
metrics.height = _this.getRowHeight( row, 0 );
metrics.result = true;
}
// 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();
return metrics;
}
if( se ){
for( var i = 0; i < rc.length; i++ )
h(rc[i],[m]);
}
else
h(m,rc);
},
removeNodeBySheetId : function(sheetId){
var arr = false;
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 );
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.length = 0;
var nodesSheet = nodes[sheetId];
if(nodesSheet){
var aNodes = nodesSheet.getAll();
for(var i = 0, length = aNodes.length; i < length; i++)
{
var node = aNodes[i].data;
var se = node.getSlaveEdges();
for(var id2 in se){
if(se[id2].sheetId != sheetId){
if(!arr) arr = true;
var nodesSheet = nodes[sheetId];
if ( nodesSheet ) {
var aNodes = nodesSheet.getAll();
for ( var i = 0, length = aNodes.length; i < length; i++ ) {
var node = aNodes[i].data;
var se = node.getSlaveEdges();
for ( var id2 in se ) {
if ( se[id2].sheetId != sheetId ) {
if ( !arr ) arr = true;
// this.wb.needRecalc[id2] = [se[id2].sheetId,se[id2].cellId];
// this.wb.needRecalc.length++;
// arr.push(se[id2]);
}
}
node.deleteAllMasterEdges();
node.deleteAllSlaveEdges();
delete nodesId[node.nodeId];
this.nodeslength--;
}
nodesSheet.removeAll();
}
return arr;
},
getNodeDependence : function(aElems)
{
var oRes = {oMasterNodes: {}, oMasterAreaNodes: {}, oWeightMap: {}};
var aWeightMapMasters = [];
var aWeightMapMastersNodes = [];
var node;
var elem;
var oSheetRanges = {};
var bInArea = false;
while(null != aElems)
{
for(var i in aElems)
{
elem = aElems[i];
var sheetId = elem[0];
// arr.push(se[id2]);
}
}
node.deleteAllMasterEdges();
node.deleteAllSlaveEdges();
delete nodesId[node.nodeId];
this.nodeslength--;
}
nodesSheet.removeAll();
}
return arr;
},
getNodeDependence:function ( aElems ) {
var oRes = {oMasterNodes:{}, oMasterAreaNodes:{}, oWeightMap:{}};
var aWeightMapMasters = [];
var aWeightMapMastersNodes = [];
var node;
var elem;
var oSheetRanges = {};
var bInArea = false;
while ( null != aElems ) {
for ( var i in aElems ) {
elem = aElems[i];
var sheetId = elem[0];
var cellId = elem[1];
//нужно обавлять в oSheetRanges даже несушествующие node, чтобы поддержать именении ячеек в SUM(A1:B2)
this._getNodeDependenceNodeToRange(sheetId, Asc.g_oRangeCache.getAscRange(cellId), oSheetRanges);
node = this.getNode(sheetId, cellId);
if(node && null == oRes.oWeightMap[node.nodeId])
{
//все node из aElems записываем в master
var oWeightMapElem = {cur: 0, max: 0, gray: false, bad: false, master: true, area: bInArea};
aWeightMapMasters.push(oWeightMapElem);
aWeightMapMastersNodes.push(node);
oRes.oWeightMap[node.nodeId] = oWeightMapElem;
this._getNodeDependence(oRes, oSheetRanges, node);
}
}
aElems = null;
bInArea = true;
//расширяем за счет area nodes
for(var i in oSheetRanges)
{
var oSheetRange = oSheetRanges[i];
if(oSheetRange.changed)
{
oSheetRange.changed = false;
var nodesSheetArea = this.nodesArea[i];
if(null != nodesSheetArea)
{
var aAllOuter = null;
if(null == oSheetRange.prevRange)
{
var oGetRes = nodesSheetArea.get(oSheetRange.range);
if(oGetRes.all.length > 0)
aAllOuter = oGetRes.all;
}
else
{
var aEdgeBBox = [];
if(oSheetRange.range.c1 < oSheetRange.prevRange.c1)
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)
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)
aEdgeBBox.push(new Asc.Range(oSheetRange.range.c1 + 1, oSheetRange.range.r1, oSheetRange.range.c2 - 1, oSheetRange.prevRange.r1 - 1));
if(oSheetRange.range.r2 > oSheetRange.prevRange.r2)
aEdgeBBox.push(new Asc.Range(oSheetRange.range.c1 + 1, oSheetRange.range.r2, oSheetRange.range.c2 - 1, oSheetRange.prevRange.r2 + 1));
aAllOuter = [];
for(var j = 0, length = aEdgeBBox.length; j < length; j++)
{
var bbox = aEdgeBBox[j];
var oGetRes = nodesSheetArea.get(bbox);
if(oGetRes.all.length > 0)
aAllOuter = aAllOuter.concat(oGetRes.all);
}
}
if(aAllOuter && aAllOuter.length > 0)
{
if(null == aElems)
aElems = [];
for(var j in aAllOuter)
{
var node = aAllOuter[j].data;
if ( node && null == oRes.oWeightMap[node.nodeId] ) {
//все node из aElems записываем в master
var oWeightMapElem = {cur:0, max:0, gray:false, bad:false, master:true, area:bInArea};
aWeightMapMasters.push( oWeightMapElem );
aWeightMapMastersNodes.push( node );
oRes.oWeightMap[node.nodeId] = oWeightMapElem;
this._getNodeDependence( oRes, oSheetRanges, node );
}
}
aElems = null;
bInArea = true;
//расширяем за счет area nodes
for ( var i in oSheetRanges ) {
var oSheetRange = oSheetRanges[i];
if ( oSheetRange.changed ) {
oSheetRange.changed = false;
var nodesSheetArea = this.nodesArea[i];
if ( null != nodesSheetArea ) {
var aAllOuter = null;
if ( null == oSheetRange.prevRange ) {
var oGetRes = nodesSheetArea.get( oSheetRange.range );
if ( oGetRes.all.length > 0 )
aAllOuter = oGetRes.all;
}
else {
var aEdgeBBox = [];
if ( oSheetRange.range.c1 < oSheetRange.prevRange.c1 )
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 )
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 )
aEdgeBBox.push( new Asc.Range( oSheetRange.range.c1 + 1, oSheetRange.range.r1, oSheetRange.range.c2 - 1, oSheetRange.prevRange.r1 - 1 ) );
if ( oSheetRange.range.r2 > oSheetRange.prevRange.r2 )
aEdgeBBox.push( new Asc.Range( oSheetRange.range.c1 + 1, oSheetRange.range.r2, oSheetRange.range.c2 - 1, oSheetRange.prevRange.r2 + 1 ) );
aAllOuter = [];
for ( var j = 0, length = aEdgeBBox.length; j < length; j++ ) {
var bbox = aEdgeBBox[j];
var oGetRes = nodesSheetArea.get( bbox );
if ( oGetRes.all.length > 0 )
aAllOuter = aAllOuter.concat( oGetRes.all );
}
}
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];
}
}
}
}
}
}
for(var i = 0, length = aWeightMapMasters.length; i < length; i++)
{
var oWeightMapElem = aWeightMapMasters[i];
//возвращаем только настощие master
if(oWeightMapElem.master)
{
node = aWeightMapMastersNodes[i];
if(oWeightMapElem.area)
oRes.oMasterAreaNodes[node.nodeId] = node;
else
oRes.oMasterNodes[node.nodeId] = node;
}
}
return oRes;
},
_getNodeDependence : function(oRes, oSheetRanges, node)
{
var bBad = false;
var oWeightMapElem = oRes.oWeightMap[node.nodeId];
if(null == oWeightMapElem)
{
oWeightMapElem = {cur: 0, max: 1, gray: false, bad: false, master: false, area: false};
oRes.oWeightMap[node.nodeId] = oWeightMapElem;
}
else
{
oWeightMapElem.max++;
//если пришли в gray node, то это цикл
if(oWeightMapElem.gray)
bBad = oWeightMapElem.bad = true;
else
{
if(oWeightMapElem.master && oWeightMapElem.max > 1)
}
}
}
}
}
}
for ( var i = 0, length = aWeightMapMasters.length; i < length; i++ ) {
var oWeightMapElem = aWeightMapMasters[i];
//возвращаем только настощие master
if ( oWeightMapElem.master ) {
node = aWeightMapMastersNodes[i];
if ( oWeightMapElem.area )
oRes.oMasterAreaNodes[node.nodeId] = node;
else
oRes.oMasterNodes[node.nodeId] = node;
}
}
return oRes;
},
_getNodeDependence:function ( oRes, oSheetRanges, node ) {
var bBad = false;
var oWeightMapElem = oRes.oWeightMap[node.nodeId];
if ( null == oWeightMapElem ) {
oWeightMapElem = {cur:0, max:1, gray:false, bad:false, master:false, area:false};
oRes.oWeightMap[node.nodeId] = oWeightMapElem;
}
else {
oWeightMapElem.max++;
//если пришли в gray node, то это цикл
if ( oWeightMapElem.gray )
bBad = oWeightMapElem.bad = true;
else {
if ( oWeightMapElem.master && oWeightMapElem.max > 1 )
{
//если повторно пришли в master node, то не считаем ее master
oWeightMapElem.master = false;
......@@ -634,45 +598,40 @@ DependencyGraph.prototype = {
}
}
}
if(1 == oWeightMapElem.max)
this._getNodeDependenceNodeToRange(node.sheetId, node.getBBox(), oSheetRanges);
if(!bBad && oWeightMapElem.max <= 1)
{
oWeightMapElem.gray = true;
var aNext = node.getSlaveEdges();
for(var i in aNext)
{
if(this._getNodeDependence(oRes, oSheetRanges, aNext[i]))
bBad = true;
}
oWeightMapElem.gray = false;
oWeightMapElem.bad = bBad;
}
return bBad;
},
_getNodeDependenceNodeToRange : function(sheetId, bbox, oSheetRanges){
var oSheetRange = oSheetRanges[sheetId];
if(null == oSheetRange)
{
oSheetRange = {range: null, changed: false, prevRange: null};
oSheetRanges[sheetId] = oSheetRange;
}
if(null == oSheetRange.range || !oSheetRange.range.containsRange(bbox))
{
if(null == oSheetRange.range)
oSheetRange.range = bbox.clone();
else
{
if(!oSheetRange.changed)
oSheetRange.prevRange = oSheetRange.range.clone();
oSheetRange.range.union2(bbox);
}
oSheetRange.changed = true;
}
},
getAll : function(){
return this.nodesId;
}
if ( 1 == oWeightMapElem.max )
this._getNodeDependenceNodeToRange( node.sheetId, node.getBBox(), oSheetRanges );
if ( !bBad && oWeightMapElem.max <= 1 ) {
oWeightMapElem.gray = true;
var aNext = node.getSlaveEdges();
for ( var i in aNext ) {
if ( this._getNodeDependence( oRes, oSheetRanges, aNext[i] ) )
bBad = true;
}
oWeightMapElem.gray = false;
oWeightMapElem.bad = bBad;
}
return bBad;
},
_getNodeDependenceNodeToRange:function ( sheetId, bbox, oSheetRanges ) {
var oSheetRange = oSheetRanges[sheetId];
if ( null == oSheetRange ) {
oSheetRange = {range:null, changed:false, prevRange:null};
oSheetRanges[sheetId] = oSheetRange;
}
if ( null == oSheetRange.range || !oSheetRange.range.containsRange( bbox ) ) {
if ( null == oSheetRange.range )
oSheetRange.range = bbox.clone();
else {
if ( !oSheetRange.changed )
oSheetRange.prevRange = oSheetRange.range.clone();
oSheetRange.range.union2( bbox );
}
oSheetRange.changed = true;
}
},
getAll:function () {
return this.nodesId;
}
};
/** @constructor */
......@@ -684,9 +643,9 @@ function Vertex(sheetId, cellId, wb){
this.isArea = !this.bbox.isOneCell();
this.valid = true;
this.nodeId = getVertexId(this.sheetId, this.cellId);
this.wb = wb;
this.wb = wb;
this.cell = null;
//вершина которую мы прошли и поставили в очередь обхода
this.isBlack = false;
......@@ -718,10 +677,10 @@ Vertex.prototype = {
{
var cell = this.returnCell();
if( cell && cell.formulaParsed )
{
{
this.wb.dependencyFormulas.deleteMasterNodes2( wsId, cellId );
cell.formulaParsed.setRefError(wsId, cellId);
cell.setFormula(cell.formulaParsed.assemble(), true);
cell.setFormula(cell.formulaParsed.assemble(), true);
addToArrRecalc(this.wb, wsId, cellId);
this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId ];
this.wb.needRecalc.length++;
......@@ -742,10 +701,10 @@ Vertex.prototype = {
var slave = _sn[_id]
cell = slave.returnCell();
if( cell && cell.formulaParsed )
{
{
this.wb.dependencyFormulas.deleteMasterNodes2( slave.sheetId, slave.cellId );
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);
this.wb.needRecalc.nodes[slave.nodeId] = [slave.sheetId, slave.cellId ];
this.wb.needRecalc.length++;
......@@ -764,10 +723,10 @@ Vertex.prototype = {
for( var _id in _sn ){
var slave = _sn[_id];
var cell = slave.returnCell();
if( cell && cell.formulaParsed ){
if( cell && cell.formulaParsed ){
this.wb.dependencyFormulas.deleteMasterNodes2( slave.sheetId, slave.cellId );
cell.formulaParsed.stretchArea( this, sNewName );
cell.setFormula(cell.formulaParsed.assemble(), true);
cell.setFormula(cell.formulaParsed.assemble(), true);
addToArrRecalc(this.wb, slave.sheetId, slave.cellId);
this.wb.needRecalc.nodes[slave.nodeId] = [slave.sheetId, slave.cellId ];
this.wb.needRecalc.length++;
......@@ -891,14 +850,14 @@ function unLockDraw(wb){
}
}
function addToArrRecalc(wb, sheetId, cellId){
var temp = arrRecalc[sheetId];
if( !temp )
{
temp = {};
arrRecalc[sheetId] = temp;
var temp = arrRecalc[sheetId];
if( !temp )
{
temp = {};
arrRecalc[sheetId] = temp;
}
temp[cellId] = cellId;
}
temp[cellId] = cellId;
}
function buildRecalc(_wb,notrec){
var ws;
if( lc > 1 ) return;
......@@ -911,152 +870,71 @@ function buildRecalc(_wb,notrec){
if(!notrec)
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 ){
buildRecalc(wb, true);
arrRecalc = {};
}
var nR = wb.needRecalc;
var nR = wb.needRecalc;
if(nR && (nR.length > 0))
{
var oCleanCellCacheArea = {};
var oCleanCellCacheArea = {};
var oNodeDependence = wb.dependencyFormulas.getNodeDependence(nR.nodes);
for(var i in oNodeDependence.oMasterNodes)
{
var node = oNodeDependence.oMasterNodes[i];
_sortDependency(wb, node, oNodeDependence.oWeightMap, false, oCleanCellCacheArea);
}
for(var i in oNodeDependence.oMasterAreaNodes)
{
var node = oNodeDependence.oMasterAreaNodes[i];
_sortDependency(wb, node, oNodeDependence.oWeightMap, false, oCleanCellCacheArea);
}
for(var sheetId in oCleanCellCacheArea)
{
var sheetArea = oCleanCellCacheArea[sheetId];
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);
}
}
}
for ( var i in oNodeDependence.oMasterNodes ) {
var node = oNodeDependence.oMasterNodes[i];
_sortDependency( wb, node, oNodeDependence.oWeightMap, false, oCleanCellCacheArea );
}
for ( var i in oNodeDependence.oMasterAreaNodes ) {
var node = oNodeDependence.oMasterAreaNodes[i];
_sortDependency( wb, node, oNodeDependence.oWeightMap, false, oCleanCellCacheArea );
}
for ( var sheetId in oCleanCellCacheArea ) {
var sheetArea = oCleanCellCacheArea[sheetId];
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};
}
function _sortDependency(wb, node, oWeightMap, bBad, oCleanCellCacheArea){
if(node)
{
var oWeightMapElem = oWeightMap[node.nodeId];
if(oWeightMapElem)
{
oWeightMapElem.cur++;
if((!oWeightMapElem.bad && oWeightMapElem.cur >= oWeightMapElem.max) || (oWeightMapElem.bad && !oWeightMapElem.gray))
{
bBad = oWeightMapElem.bad;
//пересчитываем функцию
var ws = wb.getWorksheetById(node.sheetId);
ws._RecalculatedFunctions( node.cellId, bBad );
//запоминаем области для удаления cache
var sheetArea = oCleanCellCacheArea[node.sheetId];
if(null == sheetArea)
{
sheetArea = {};
oCleanCellCacheArea[node.sheetId] = sheetArea;
}
var range = Asc.g_oRangeCache.getAscRange(node.cellId);
if(range)
{
for(var i = range.r1; i <= range.r2; i++)
sheetArea[i] = 1;
}
//обрабатываем child
oWeightMapElem.gray = true;
var oSlaveNodes = node.getSlaveEdges();
if(oSlaveNodes)
{
for(var i in oSlaveNodes)
_sortDependency(wb, oSlaveNodes[i], oWeightMap, bBad, oCleanCellCacheArea);
}
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 _sortDependency( wb, node, oWeightMap, bBad, oCleanCellCacheArea ) {
if ( node ) {
var oWeightMapElem = oWeightMap[node.nodeId];
if ( oWeightMapElem ) {
oWeightMapElem.cur++;
if ( (!oWeightMapElem.bad && oWeightMapElem.cur >= oWeightMapElem.max) || (oWeightMapElem.bad && !oWeightMapElem.gray) ) {
bBad = oWeightMapElem.bad;
//пересчитываем функцию
var ws = wb.getWorksheetById( node.sheetId );
ws._RecalculatedFunctions( node.cellId, bBad );
//запоминаем области для удаления cache
var sheetArea = oCleanCellCacheArea[node.sheetId];
if ( null == sheetArea ) {
sheetArea = {};
oCleanCellCacheArea[node.sheetId] = sheetArea;
}
var range = Asc.g_oRangeCache.getAscRange( node.cellId );
if ( range ) {
for ( var i = range.r1; i <= range.r2; i++ )
sheetArea[i] = 1;
}
//обрабатываем child
oWeightMapElem.gray = true;
var oSlaveNodes = node.getSlaveEdges();
if ( oSlaveNodes ) {
for ( var i in oSlaveNodes )
_sortDependency( wb, oSlaveNodes[i], oWeightMap, bBad, oCleanCellCacheArea );
}
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)
......@@ -1553,13 +1431,13 @@ Workbook.prototype._generateFontMap=function(){
"Arial" : 1
};
if (null != g_oDefaultFont.fn)
if(null != g_oDefaultFont.fn)
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.CellStyles.generateFontMap(oFontMap);
return oFontMap;
};
Workbook.prototype.generateFontMap=function(){
......@@ -1591,11 +1469,11 @@ Workbook.prototype.recalcWB = function(is3D){
{
nR[node.nodeId] = [node.sheetId, node.cellId];
nR.length++;
}
}
sortDependency(this);
}
}
sortDependency(this);
}
}
Workbook.prototype.isDefinedNamesExists = function(name, sheetId){
if(null != sheetId)
{
......@@ -1649,28 +1527,32 @@ Workbook.prototype.recalcDependency = function(f,bad,notRecalc){
var sr = {};
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) ){
sr[f[i].sheetId] = {max:new CellAddress(f[i].cellId),min:new CellAddress(f[i].cellId)}
if( !(sheetID in sr) ){
sr[sheetID] = {max:new CellAddress(cellID),min:new CellAddress(cellID)}
}
if ( sr[f[i].sheetId].min.getRow() > l.getRow() )
sr[f[i].sheetId].min = new CellAddress( l.getRow(), sr[f[i].sheetId].min.getCol() );
selectedSheet = sr[sheetID];
if ( selectedSheet.min.getRow() > lRow )
selectedSheet.min = new CellAddress( lRow, selectedSheet.min.getCol() );
if ( sr[f[i].sheetId].min.getCol() > l.getCol() )
sr[f[i].sheetId].min = new CellAddress( sr[f[i].sheetId].min.getRow(), l.getCol() );
if ( selectedSheet.min.getCol() > lCol )
selectedSheet.min = new CellAddress( selectedSheet.min.getRow(), lCol );
if ( sr[f[i].sheetId].max.getRow() < l.getRow() )
sr[f[i].sheetId].max = new CellAddress( l.getRow(), sr[f[i].sheetId].max.getCol() );
if ( selectedSheet.max.getRow() < lRow )
selectedSheet.max = new CellAddress( lRow, selectedSheet.max.getCol() );
if ( sr[f[i].sheetId].max.getCol() < l.getCol() )
sr[f[i].sheetId].max = new CellAddress( sr[f[i].sheetId].max.getRow(), l.getCol() );
if ( selectedSheet.max.getCol() < lCol )
selectedSheet.max = new CellAddress( selectedSheet.max.getRow(), lCol );
if( !notRecalc )
this.getWorksheetById( f[i].sheetId )._RecalculatedFunctions( f[i].cellId, bad );
this.getWorksheetById( sheetID )._RecalculatedFunctions( cellID, bad );
}
return sr;
......@@ -2873,7 +2755,7 @@ Woorksheet.prototype.getRange=function(cellAdd1, cellAdd2){
Woorksheet.prototype.getRange2=function(sRange){
var bbox = Asc.g_oRangeCache.getAscRange(sRange);
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;
};
Woorksheet.prototype.getRange3=function(r1, c1, r2, c2){
......@@ -2915,7 +2797,7 @@ Woorksheet.prototype._removeCell=function(nRow, nCol, cell){
if(null != cell.xfs)
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));
}
}
if(cell.formulaParsed)
this.wb.dependencyFormulas.deleteMasterNodes2( this.getId(), cell.getName() );
......@@ -3224,7 +3106,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
}
}
}
History.TurnOn();
if(false == this.workbook.bUndoChanges && false == this.workbook.bRedoChanges)
{
......@@ -3269,7 +3151,7 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
/*
Если необходим пересчет, то по списку пересчитываемых ячеек сортируем граф зависимостей и пересчиываем в получившемся порядке. Плохим ячейкам с цикличискими ссылками выставляем ошибку "#REF!".
*/
sortDependency(this.workbook);
sortDependency(this.workbook);
}
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange,
this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0),
......@@ -3458,41 +3340,35 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){
if( c && c.sFormula ){
c.formulaParsed = new parserFormula( c.sFormula, c.oId.getID(), this );
c.formulaParsed.parse();
c.formulaParsed.parse();
c.formulaParsed.buildDependencies();
}
}
}
Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
var thas = this;
function adjustCellFormat(c, ftext) {
// ищет в формуле первый рэндж и устанавливает формат ячейки как формат первой ячейки в рэндже
var elem = null;
if(c.formulaParsed && c.formulaParsed.outStack)
{
for(var i = 0, length = c.formulaParsed.outStack.length; i < length; i++)
{
elem = c.formulaParsed.outStack[i];
if(elem instanceof cRef || elem instanceof cRef3D || elem instanceof cArea || elem instanceof cArea3D)
{
var r = elem.getRange();
if(elem instanceof cArea3D && r.length > 0)
r = r[0];
if(r && r.getNumFormatStr)
{
var sCurFormat = c.getNumFormatStr();
if( g_oDefaultNum.f == sCurFormat)
{
var sNewFormat = r.getNumFormatStr();
if(sCurFormat != sNewFormat)
c.setNumFormat(sNewFormat);
}
}
break;
}
}
}
}
function adjustCellFormat( c ) {
// ищет в формуле первый рэндж и устанавливает формат ячейки как формат первой ячейки в рэндже
var elem = null;
if ( c.formulaParsed && c.formulaParsed.outStack ) {
for ( var i = 0, length = c.formulaParsed.outStack.length; i < length; i++ ) {
elem = c.formulaParsed.outStack[i];
if ( elem instanceof cRef || elem instanceof cRef3D || elem instanceof cArea || elem instanceof cArea3D ) {
var r = elem.getRange();
if ( elem instanceof cArea3D && r.length > 0 )
r = r[0];
if ( r && r.getNumFormatStr ) {
var sCurFormat = c.getNumFormatStr();
if ( g_oDefaultNum.f == sCurFormat ) {
var sNewFormat = r.getNumFormatStr();
if ( sCurFormat != sNewFormat )
c.setNumFormat( sNewFormat );
}
}
break;
}
}
}
}
if( cell.indexOf(":")>-1 ) return;
......@@ -3577,7 +3453,7 @@ Woorksheet.prototype._ReBuildFormulas=function(cellRange){
}
Woorksheet.prototype.renameDependencyNodes = function(offset, oBBox, rec, noDelete){
this.workbook.dependencyFormulas.checkOffset(oBBox, offset, this.Id, noDelete);
}
}
Woorksheet.prototype.helperRebuildFormulas = function(cell,lastName){
if( cell.sFormula ){
this.workbook.cwf[this.Id].cells[lastName] = null;
......@@ -3799,13 +3675,13 @@ Cell.prototype.setValue=function(val,callback){
delete wb.cwf[ws.Id].cells[this.oId.getID()];
}
}
}
}
else{
wb.cwf[ws.Id].cells[this.oId.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.length++;
wb.needRecalc.length++;
this.sFormula = null;
this.setFormulaCA(false);
......@@ -3857,8 +3733,8 @@ Cell.prototype.setValue2=function(array){
this.oValue.setValue2(array);
wb.needRecalc.nodes[getVertexId(sheetId,this.oId.getID())] = [sheetId, this.oId.getID()];
wb.needRecalc.length++;
sortDependency(this.ws.workbook);
wb.needRecalc.length++;
sortDependency(this.ws.workbook);
var DataNew = null;
if(History.Is_On())
DataNew = this.getValueData();
......@@ -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.length++;
}
}
}
else
{
if(null != rowTo.c[i])
......@@ -7286,12 +7162,12 @@ Range.prototype.promote=function(bCtrl, bVertical, nIndex){
oCopyCell.setFormula(assemb);
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.length++;
}
this.worksheet.workbook.needRecalc.length++;
}
}
}
}
}
}
//добавляем замерженые области
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