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

git-svn-id:...

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