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

добавлены функции

NPER, ACOSH,  ASINH, ATANH, COMBIN, COSH, FACT, FACTDOUBLE, LCM,  MDETERM, MINVERSE, MMULT, MULTINOMIAL, QUOTIENT, RANDBETWEEN, ROMAN, SINH, SUMSQ, TANH, TRUNC
поправлены функции SUMIF, COUNTIF, SEARCH

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@48405 954022d7-b5bf-4e40-9824-e11837661b57
parent 05a4e071
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<link rel="stylesheet" href="qunit/qunit-1.11.0.css" type="text/css" media="screen" /> <link rel="stylesheet" href="qunit/qunit-1.11.0.css" type="text/css" media="screen" />
<script type="text/javascript" src="qunit/qunit-1.11.0.js"></script> <script type="text/javascript" src="qunit/qunit-1.11.0.js"></script>
<script type="text/javascript" src="../../Common/3rdparty/XRegExp/xregexp-all.js"></script> <script type="text/javascript" src="../../../Common/3rdparty/XRegExp/xregexp-all.js"></script>
<script src="../../Common/downloaderfiles.js"></script> <script src="../../Common/downloaderfiles.js"></script>
<script type="text/javascript" src="../../Common/3rdparty/Underscore/underscore-min.js"></script> <script type="text/javascript" src="../../Common/3rdparty/Underscore/underscore-min.js"></script>
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
<script type="text/javascript" src="../../Common/Charts/DrawingObjects.js"></script> <script type="text/javascript" src="../../Common/Charts/DrawingObjects.js"></script>
<script type="text/javascript" src="../../Common/Charts/charts.js"></script> <script type="text/javascript" src="../../Common/Charts/charts.js"></script>
<script type="text/javascript" src="../../Common/commonDefines.js"></script> <script type="text/javascript" src="../../Common/commonDefines.js"></script>
<script type="text/javascript" src="../../Common/editorscommon.js"></script>
<script type="text/javascript" src="../../Common/FontsFreeType/font_engine.js"></script> <script type="text/javascript" src="../../Common/FontsFreeType/font_engine.js"></script>
<script type="text/javascript" src="../../Common/FontsFreeType/FontFile.js"></script> <script type="text/javascript" src="../../Common/FontsFreeType/FontFile.js"></script>
...@@ -27,7 +28,6 @@ ...@@ -27,7 +28,6 @@
<script type="text/javascript" src="../../Word/Drawing/Externals.js"></script> <script type="text/javascript" src="../../Word/Drawing/Externals.js"></script>
<script type="text/javascript" src="../../Word/Drawing/Metafile.js"></script> <script type="text/javascript" src="../../Word/Drawing/Metafile.js"></script>
<script type="text/javascript" src="../../Word/Drawing/AllFonts.js"></script> <script type="text/javascript" src="../../Word/Drawing/AllFonts.js"></script>
<script type="text/javascript" src="../../Word/Drawing/GlobalLoaders.js"></script>
<script type="text/javascript" src="../utils/utils.js"></script> <script type="text/javascript" src="../utils/utils.js"></script>
<script type="text/javascript" src="../model/clipboard.js"></script> <script type="text/javascript" src="../model/clipboard.js"></script>
...@@ -36,10 +36,12 @@ ...@@ -36,10 +36,12 @@
<script type="text/javascript" src="../graphics/DrawingContext.js"></script> <script type="text/javascript" src="../graphics/DrawingContext.js"></script>
<script type="text/javascript" src="../graphics/pdfprinter.js"></script> <script type="text/javascript" src="../graphics/pdfprinter.js"></script>
<!--TODO: remove test data-->
<!-- <script type="text/javascript" src="../offlinedocs/test-workbook9/Editor.js"></script> --> <!-- <script type="text/javascript" src="../offlinedocs/test-workbook9/Editor.js"></script> -->
<script type="text/javascript" src="../offlinedocs/test-workbook2.js"></script> <script type="text/javascript" src="../offlinedocs/test-workbook2.js"></script>
<script type="text/javascript" src="../model/CollaborativeEditing.js"></script> <script type="text/javascript" src="../model/CollaborativeEditing.js"></script>
<script type="text/javascript" src="../model/ConditionalFormatting.js"></script>
<script type="text/javascript" src="../model/parserFormula.js"></script> <script type="text/javascript" src="../model/parserFormula.js"></script>
<script type="text/javascript" src="../model/dateandtimeFunctions.js"></script> <script type="text/javascript" src="../model/dateandtimeFunctions.js"></script>
<script type="text/javascript" src="../model/engineeringFunctions.js"></script> <script type="text/javascript" src="../model/engineeringFunctions.js"></script>
...@@ -75,14 +77,20 @@ ...@@ -75,14 +77,20 @@
<script type="text/javascript" src="../api.js"></script> <script type="text/javascript" src="../api.js"></script>
<!--for presentation--> <!--for presentation-->
<script type="text/javascript" src="../Common/PresentationSerializeAdapter.js"></script> <script type="text/javascript" src="../../Common/PresentationSerializeAdapter.js"></script>
<!--for theme--> <!--for theme-->
<script type="text/javascript" src="../../Common/Shapes/EditorSettings.js"></script> <script type="text/javascript" src="../../Common/Shapes/EditorSettings.js"></script>
<script type="text/javascript" src="../../Common/Shapes/Serialize.js"></script> <script type="text/javascript" src="../../Common/Shapes/Serialize.js"></script>
<script type="text/javascript" src="../../Common/Shapes/SerializeWriter.js"></script> <script type="text/javascript" src="../../Common/Shapes/SerializeWriter.js"></script>
<script type="text/javascript" src="../../Word/Editor/SerializeCommon.js"></script> <script type="text/javascript" src="../../Word/Editor/SerializeCommon.js"></script>
<script type="text/javascript" src="../../Word/Editor/GraphicObjects/ObjectTypes/Format.js"></script> <script type="text/javascript" src="../model/DrawingObjects/Format/Format.js"></script>
<script type="text/javascript" src="../../Word/Editor/GraphicObjects/ObjectTypes/CreateGeometry.js"></script>
<script type="text/javascript" src="../model/DrawingObjects/Format/Geometry.js"></script>
<script type="text/javascript" src="../model/DrawingObjects/Format/Path.js"></script>
<script type="text/javascript" src="../../Word/Editor/GraphicObjects/Math.js"></script>
<script type="text/javascript" src="../../Word/Drawing/ArcTo.js"></script>
<script type="text/javascript" src="../../Word/Drawing/ColorArray.js"></script>
<script type="text/javascript" src="../../Word/apiCommon.js"></script> <script type="text/javascript" src="../../Word/apiCommon.js"></script>
<!--for chart--> <!--for chart-->
...@@ -120,17 +128,34 @@ ...@@ -120,17 +128,34 @@
<script src="../../Common/Charts/libraries/rgbcolor.js"></script> <script src="../../Common/Charts/libraries/rgbcolor.js"></script>
<!--for shapes--> <!--for shapes-->
<script src="../../Word/Drawing/Graphics.js"></script> <script src="../model/DrawingObjects/Graphics.js"></script>
<script src="../model/DrawingObjects/Overlay.js"></script>
<script src="../model/DrawingObjects/Controls.js"></script>
<script src="../model/DrawingObjects/DrawingObjectsController.js"></script> <script src="../model/DrawingObjects/DrawingObjectsController.js"></script>
<script src="../model/DrawingObjects/DrawingDocument.js"></script>
<script src="../model/DrawingObjects/States.js"></script> <script src="../model/DrawingObjects/States.js"></script>
<script src="../model/DrawingObjects/GlobalLoaders.js"></script>
<script src="../model/DrawingObjects/GlobalCounters.js"></script>
<script src="../model/DrawingObjects/ShapeDrawer.js"></script>
<script src="../model/DrawingObjects/Format/GroupShape.js"></script> <script src="../model/DrawingObjects/Format/GroupShape.js"></script>
<script src="../model/DrawingObjects/Format/Image.js"></script> <script src="../model/DrawingObjects/Format/Image.js"></script>
<script src="../model/DrawingObjects/Format/Shape.js"></script> <script src="../model/DrawingObjects/Format/Shape.js"></script>
<script src="../model/DrawingObjects/Format/TextBody.js"></script>
<script src="../model/DrawingObjects/Format/Styles.js"></script>
<script src="../model/DrawingObjects/Format/Numbering.js"></script>
<script src="../model/DrawingObjects/Format/ParagraphContent.js"></script>
<script src="../model/DrawingObjects/Format/Paragraph.js"></script>
<script src="../model/DrawingObjects/Format/DocumentContent.js"></script>
<script src="../model/DrawingObjects/Format/FontClassification.js"></script>
<script src="../model/DrawingObjects/Tracks/AdjustmentTracks.js"></script>
<script src="../model/DrawingObjects/Tracks/ResizeTracks.js"></script> <script src="../model/DrawingObjects/Tracks/ResizeTracks.js"></script>
<script src="../model/DrawingObjects/Tracks/RotateTracks.js"></script> <script src="../model/DrawingObjects/Tracks/RotateTracks.js"></script>
<script src="../model/DrawingObjects/Tracks/NewShapeTracks.js"></script> <script src="../model/DrawingObjects/Tracks/NewShapeTracks.js"></script>
<script src="../model/DrawingObjects/Tracks/PolyLine.js"></script>
<script src="../model/DrawingObjects/Tracks/Spline.js"></script>
<script src="../model/DrawingObjects/Tracks/MoveTracks.js"></script>
<script src="../model/DrawingObjects/Hit.js"></script> <script src="../model/DrawingObjects/Hit.js"></script>
<script type="text/javascript" src="FormulaTests.js"></script> <script type="text/javascript" src="FormulaTests.js"></script>
......
$(function () { $( function () {
var ver = 2; var ver = 2;
var oParser, wb, ws, date1, date2, dif = 1e-9, var oParser, wb, ws, date1, date2, dif = 1e-9,
data = getTestWorkbook(), data = getTestWorkbook(),
sData = data + ""; sData = data + "";
if( c_oSerFormat.Signature === sData.substring(0, c_oSerFormat.Signature.length)) if ( c_oSerFormat.Signature === sData.substring( 0, c_oSerFormat.Signature.length ) ) {
{
var sUrlPath = "offlinedocs/"; var sUrlPath = "offlinedocs/";
var wb = new Workbook(sUrlPath, new Asc.asc_CHandlersList(),null); var wb = new Workbook( sUrlPath, new Asc.asc_CHandlersList(), null );
wb.initGlobalObjects(); wb.initGlobalObjects();
var oBinaryFileReader = new BinaryFileReader(sUrlPath); var oBinaryFileReader = new BinaryFileReader( sUrlPath );
oBinaryFileReader.Read(sData, wb); oBinaryFileReader.Read( sData, wb );
} }
ws = wb.getWorksheet(wb.getActive()); ws = wb.getWorksheet( wb.getActive() );
QUnit.log(function( details ) { QUnit.log( function ( details ) {
console.log( "Log: " + details.name + ", result - " + details.result ); console.log( "Log: " + details.name + ", result - " + details.result );
}); } );
module("Formula"); module( "Formula" );
test("Test: \"Absolute reference\"",function(){ test( "Test: \"Absolute reference\"", function () {
ws.getRange2("A7").setValue("1"); ws.getRange2( "A7" ).setValue( "1" );
ws.getRange2("A8").setValue("2"); ws.getRange2( "A8" ).setValue( "2" );
ws.getRange2("A9").setValue("3"); ws.getRange2( "A9" ).setValue( "3" );
oParser = new parserFormula('A$7+A8',"A1",ws); oParser = new parserFormula( 'A$7+A8', "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual(oParser.calculate().getValue(),3); strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula('A$7+A$8',"A1",ws); oParser = new parserFormula( 'A$7+A$8', "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual(oParser.calculate().getValue(),3); strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula('$A$7+$A$8',"A1",ws); oParser = new parserFormula( '$A$7+$A$8', "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual(oParser.calculate().getValue(),3); strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula('SUM($A$7:$A$9)',"A1",ws); oParser = new parserFormula( 'SUM($A$7:$A$9)', "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual(oParser.calculate().getValue(),6); strictEqual( oParser.calculate().getValue(), 6 );
}) } )
test( "Test: \"1+3\"", function () {
test("Test: \"1+3\"",function(){ oParser = new parserFormula( '1+3', "A1", ws );
oParser = new parserFormula('1+3',"A1",ws); ok( oParser.parse() );
ok(oParser.parse()); strictEqual( oParser.calculate().getValue(), 4 );
strictEqual(oParser.calculate().getValue(),4); } )
})
test( "Test: \"(1+2)*4+3\"", function () {
test("Test: \"(1+2)*4+3\"",function(){ oParser = new parserFormula( '(1+2)*4+3', "A1", ws );
oParser = new parserFormula('(1+2)*4+3',"A1",ws); ok( oParser.parse() );
ok(oParser.parse()); strictEqual( oParser.calculate().getValue(), (1 + 2) * 4 + 3 );
strictEqual(oParser.calculate().getValue(), (1+2)*4+3); } )
})
test( "Test: \"2^52\"", function () {
test("Test: \"2^52\"",function(){ oParser = new parserFormula( '2^52', "A1", ws );
oParser = new parserFormula('2^52',"A1",ws); ok( oParser.parse() );
ok(oParser.parse()); strictEqual( oParser.calculate().getValue(), Math.pow( 2, 52 ) );
strictEqual( oParser.calculate().getValue(), Math.pow(2,52) ); } )
})
test( "Test: \"-10\"", function () {
test("Test: \"-10\"",function(){ oParser = new parserFormula( '-10', "A1", ws );
oParser = new parserFormula('-10',"A1",ws); ok( oParser.parse() );
ok(oParser.parse()); strictEqual( oParser.calculate().getValue(), -10 );
strictEqual( oParser.calculate().getValue(), -10); } )
})
test( "Test: \"-10*2\"", function () {
test("Test: \"-10*2\"",function (){ oParser = new parserFormula( '-10*2', "A1", ws );
oParser = new parserFormula('-10*2',"A1",ws); ok( oParser.parse() );
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), -20 ); strictEqual( oParser.calculate().getValue(), -20 );
}) } )
test("Test: \"-10+10\"",function(){ test( "Test: \"-10+10\"", function () {
oParser = new parserFormula('-10+10',"A1",ws); oParser = new parserFormula( '-10+10', "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 ); strictEqual( oParser.calculate().getValue(), 0 );
}) } )
test("Test: \"12%\"",function(){ test( "Test: \"12%\"", function () {
oParser = new parserFormula('12%',"A1",ws); oParser = new parserFormula( '12%', "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0.12 ); strictEqual( oParser.calculate().getValue(), 0.12 );
}) } )
test("Test: \"SIN have wrong arguments count\"",function(){ test( "Test: \"SIN have wrong arguments count\"", function () {
oParser = new parserFormula('SIN(3.1415926,3.1415926*2)',"A1",ws); oParser = new parserFormula( 'SIN(3.1415926,3.1415926*2)', "A1", ws );
ok(!oParser.parse()); ok( !oParser.parse() );
}) } )
test("Test: \"sin(3.1415926)\"",function(){ test( "Test: \"sin(3.1415926)\"", function () {
oParser = new parserFormula('SIN(3.1415926)',"A1",ws); oParser = new parserFormula( 'SIN(3.1415926)', "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), parseFloat(Math.sin(3.1415926).toFixed(15)) ); strictEqual( oParser.calculate().getValue(), parseFloat( Math.sin( 3.1415926 ).toFixed( 15 ) ) );
}) } )
test("Test: \"COS(PI()/2)\"",function(){ test( "Test: \"COS(PI()/2)\"", function () {
oParser = new parserFormula('COS(PI()/2)',"A1",ws); oParser = new parserFormula( 'COS(PI()/2)', "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), parseFloat(Math.cos(Math.PI/2).toFixed(15)) ); strictEqual( oParser.calculate().getValue(), parseFloat( Math.cos( Math.PI / 2 ).toFixed( 15 ) ) );
}) } )
test("Test: \"SUM(1,2,3)\"",function(){ test( "Test: \"SUM(1,2,3)\"", function () {
oParser = new parserFormula('SUM(1,2,3)',"A1",ws); oParser = new parserFormula( 'SUM(1,2,3)', "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1+2+3); strictEqual( oParser.calculate().getValue(), 1 + 2 + 3 );
}) } )
test("Test: \"-\"12\"+2\"",function(){ test( "Test: \"-\"12\"+2\"", function () {
oParser = new parserFormula("-\"12\"+2","A1",ws); oParser = new parserFormula( "-\"12\"+2", "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -10); strictEqual( oParser.calculate().getValue(), -10 );
}) } )
test("Test: \"-TRUE\"",function(){ test( "Test: \"-TRUE\"", function () {
oParser = new parserFormula("-TRUE","A1",ws); oParser = new parserFormula( "-TRUE", "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1); strictEqual( oParser.calculate().getValue(), -1 );
}) } )
test("Test: \"\"s\"&5\"",function(){ test( "Test: \"\"s\"&5\"", function () {
oParser = new parserFormula("\"s\"&5","A1",ws); oParser = new parserFormula( "\"s\"&5", "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "s5"); strictEqual( oParser.calculate().getValue(), "s5" );
}) } )
test("Test: \"2<>\"3\"\"", function(){ test( "Test: \"2<>\"3\"\"", function () {
oParser = new parserFormula("2<>\"3\"","A1",ws); oParser = new parserFormula( "2<>\"3\"", "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual(oParser.calculate().getValue(),"TRUE","2<>\"3\"") strictEqual( oParser.calculate().getValue(), "TRUE", "2<>\"3\"" )
}) } )
test("Test: \"2=\"3\"\" & \"2>\"3\"\"",function(){ test( "Test: \"2=\"3\"\" & \"2>\"3\"\"", function () {
oParser = new parserFormula("2=\"3\"","A1",ws); oParser = new parserFormula( "2=\"3\"", "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "FALSE", "2=\"3\"" ); strictEqual( oParser.calculate().getValue(), "FALSE", "2=\"3\"" );
oParser = new parserFormula("2>\"3\"","A1",ws); oParser = new parserFormula( "2>\"3\"", "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "FALSE", "2>\"3\""); strictEqual( oParser.calculate().getValue(), "FALSE", "2>\"3\"" );
}) } )
test("Test: \"\"f\">\"3\"\" & \"\"f\">\"3\"\"",function(){ test( "Test: \"\"f\">\"3\"\" & \"\"f\">\"3\"\"", function () {
oParser = new parserFormula("\"f\">\"3\"","A1",ws); oParser = new parserFormula( "\"f\">\"3\"", "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "TRUE" ); strictEqual( oParser.calculate().getValue(), "TRUE" );
oParser = new parserFormula("\"f\"<\"3\"","A1",ws); oParser = new parserFormula( "\"f\"<\"3\"", "A1", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( "FALSE", oParser.calculate().getValue(), "FALSE"); strictEqual( "FALSE", oParser.calculate().getValue(), "FALSE" );
}) } )
test("Test: \"FALSE>=FALSE\"",function(){
oParser = new parserFormula("FALSE>=FALSE","A1",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), "TRUE" );
})
test("Test: \"\"TRUE\"&\"TRUE\"\"",function(){
oParser = new parserFormula("\"TRUE\"&\"TRUE\"","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "TRUETRUE");
})
test("Test: \"10*\"\"\"",function(){
oParser = new parserFormula("10*\"\"","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
})
test("Test: \"POWER(2,8)\"",function(){
oParser = new parserFormula("POWER(2,8)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), Math.pow(2,8));
})
test("Test: \"POWER(0,-3)\"",function(){
oParser = new parserFormula("POWER(0,-3)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "#DIV/0!");
})
test("Test: \"ISNA(A1)\"",function(){
var r = ws.getRange2("K1");
ws.getRange2("A1").setValue("#N/A");
r.setValue("=ISNA(A1)");
strictEqual( ws.getCell2("K1").getCells()[0].getValue(), "TRUE");
})
test("Test: \"ROUNDUP(31415.92654;-2)\"",function(){
oParser = new parserFormula("ROUNDUP(31415.92654;-2)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 31500);
})
test("Test: \"ROUNDUP(3.2;0)\"",function(){
oParser = new parserFormula("ROUNDUP(3.2;0)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 4);
})
test("Test: \"ROUNDUP(-3.14159;1)\"",function(){
oParser = new parserFormula("ROUNDUP(-3.14159;1)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), -3.2);
})
test("Test: \"ROUNDUP(3.14159;3)\"",function(){
oParser = new parserFormula("ROUNDUP(3.14159;3)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 3.142);
})
test("Test: \"ROUNDDOWN(31415.92654;-2)\"",function(){
oParser = new parserFormula("ROUNDDOWN(31415.92654;-2)","A1",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), 31400);
})
test("Test: \"ROUNDDOWN(-3.14159;1)\"",function(){
oParser = new parserFormula("ROUNDDOWN(-3.14159;1)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), -3.1);
})
test("Test: \"ROUNDDOWN(3.14159;3)\"",function(){
oParser = new parserFormula("ROUNDDOWN(3.14159;3)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 3.141);
})
test("Test: \"ROUNDDOWN(3.2;0)\"",function(){
oParser = new parserFormula("ROUNDDOWN(3.2;0)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 3);
})
test("Test: \"MROUND(10;3)\"",function(){
oParser = new parserFormula("MROUND(10;3)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 9);
})
test("Test: \"MROUND(-10;-3)\"",function(){
oParser = new parserFormula("MROUND(-10;-3)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(),-9);
})
test("Test: \"MROUND(1.3;0.2)\"",function(){
oParser = new parserFormula("MROUND(1.3;0.2)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1.4);
})
test("Test: \"T(\"HELLO\")\"",function(){
oParser = new parserFormula("T(\"HELLO\")","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "HELLO");
})
test("Test: \"T(123)\"",function(){
oParser = new parserFormula("T(123)","A1",ws);
ok(oParser.parse());
ok( !oParser.calculate().getValue(), "123");
})
test("Test: YEAR",function(){
oParser = new parserFormula("YEAR(2013)","A1",ws);
ok(oParser.parse());
if( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 1909);
else
strictEqual( oParser.calculate().getValue(), 1905);
})
test("Test: DAY",function(){
oParser = new parserFormula("DAY(2013)","A1",ws);
ok(oParser.parse());
if( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 6);
else
strictEqual( oParser.calculate().getValue(), 5);
})
test("Test: DAY 2",function(){
oParser = new parserFormula("DAY(\"20 may 2045\")","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 20);
})
test("Test: MONTH",function(){
oParser = new parserFormula("MONTH(2013)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 7);
})
test("Test: \"10-3\"",function(){
oParser = new parserFormula("10-3","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 7);
})
test("Test: \"SUM\"",function(){
oParser = new parserFormula("SUM(S5:T5)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 0);
})
test("Test: \"MAX\"",function(){
oParser = new parserFormula("MAX(S5:T5)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 0);
})
test("Test: \"MAXA\"",function(){
oParser = new parserFormula("MAXA(S5:T5)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 0);
})
test("Test: \"MIN\"",function(){
oParser = new parserFormula("MIN(S5:T5)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 0);
})
test("Test: \"MINA\"",function(){
oParser = new parserFormula("MINA(S5:T5)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 0);
})
test("Test: SUM(S7:S9,{1,2,3})",function(){
ws.getRange2("S7").setValue("1");
ws.getRange2("S8").setValue("2");
ws.getRange2("S9").setValue("3");
ws.getRange2("S10").setValue("=SUM(S7:S9,{1,2,3})");
strictEqual( ws.getCell2("S10").getCells()[0].getValue(), "12");
})
test("Test: ISREF",function(){
oParser = new parserFormula("ISREF(G0)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "FALSE");
})
test("Test: MOD",function(){
oParser = new parserFormula("MOD(7,3)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
})
test("Test: rename sheet #1",function(){
oParser = new parserFormula("Лист2!A2","A1",ws);
ok(oParser.parse() === true);
// strictEqual( oParser.parse(), true)
strictEqual( oParser.changeSheet("Лист2","Лист3").assemble(), "Лист3!A2");
})
test("Test: rename sheet #2",function(){
oParser = new parserFormula("Лист2:Лист3!A2","A1",ws);
ok(oParser.parse());
strictEqual( oParser.changeSheet("Лист2","Лист1").assemble(), "Лист1:Лист3!A2");
})
test("Test: rename sheet #3",function(){
oParser = new parserFormula("Лист2!A2:A5","A1",ws);
ok(oParser.parse());
strictEqual( oParser.changeSheet("Лист2","Лист3").assemble(), "Лист3!A2:A5");
})
test("Test: rename sheet #4",function(){
ws = wb.getWorksheetById(1);
ws.getRange2("S95").setValue("2");
ws = wb.getWorksheetById(2);
ws.getRange2("S100").setValue("="+wb.getWorksheetById(1).getName()+"!S95");
strictEqual( ws.getCell2("S100").getCells()[0].getValue(), "2");
wb.getWorksheetById(1).setName("ЛистTEMP");
strictEqual( ws.getCell2("S100").getCells()[0].getFormula(), wb.getWorksheetById(1).getName()+"!S95", ws.getCell2("S100").getCells()[0].getFormula() + " " + wb.getWorksheetById(1).getName()+"!S95");
})
test("Test: wrong ref",function(){
oParser = new parserFormula("1+XXX1","A1",ws);
ok(oParser.parse());
notStrictEqual( oParser.calculate().getValue(), "1");
})
test("Test: \"CODE\"",function(){
oParser = new parserFormula("CODE(\"abc\")","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 97);
})
test("Test: \"CHAR\"",function(){
oParser = new parserFormula("CHAR(97)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "a");
})
test("Test: \"CHAR(CODE())\"",function(){
oParser = new parserFormula("CHAR(CODE(\"A\"))","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "A");
})
test("Test: \"PROPER\"",function(){
oParser = new parserFormula("PROPER(\"2-cent's worth\")","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "2-Cent'S Worth");
oParser = new parserFormula("PROPER(\"76BudGet\")","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "76Budget");
oParser = new parserFormula("PROPER(\"this is a TITLE\")","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "This Is A Title");
})
test("Test: \"GCD\"",function(){
oParser = new parserFormula("GCD(10,100,50)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 10);
oParser = new parserFormula("GCD(24.6,36.2)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 12);
oParser = new parserFormula("GCD(-1,39,52)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "#NUM!");
})
test("Test: \"FIXED\"",function(){
oParser = new parserFormula("FIXED(1234567,-3)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "1,235,000");
oParser = new parserFormula("FIXED(.555555,10)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "0.5555550000");
oParser = new parserFormula("FIXED(1234567.555555,4,TRUE)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "1234567.5556");
oParser = new parserFormula("FIXED(1234567)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "1,234,567");
})
test("Test: \"COUNTIF\"",function(){
ws.getRange2("A7").setValue("3");
ws.getRange2("B7").setValue("10");
ws.getRange2("C7").setValue("7");
ws.getRange2("D7").setValue("10");
ws.getRange2("A8").setValue("apples");
ws.getRange2("B8").setValue("oranges");
ws.getRange2("C8").setValue("grapes");
ws.getRange2("D8").setValue("melons");
oParser = new parserFormula("COUNTIF(A7:D7,\"=10\")","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
oParser = new parserFormula("COUNTIF(A7:D7,\">5\")","B1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 3);
oParser = new parserFormula("COUNTIF(A7:D7,\"<>10\")","C1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
oParser = new parserFormula("COUNTIF(A8:D8,\"*es\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 3);
oParser = new parserFormula("COUNTIF(A8:D8,\"??a*\")","B2",ws); test( "Test: \"FALSE>=FALSE\"", function () {
ok(oParser.parse()); oParser = new parserFormula( "FALSE>=FALSE", "A1", ws );
strictEqual( oParser.calculate().getValue(), 2); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "TRUE" );
oParser = new parserFormula("COUNTIF(A8:D8,\"*l*\")","C2",ws); } )
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
})
test("Test: \"REPLACE\"",function(){
oParser = new parserFormula("REPLACE(\"abcdefghijk\",3,4,\"XY\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "abXYghijk");
oParser = new parserFormula("REPLACE(\"abcdefghijk\",3,1,\"12345\")","B2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "ab12345defghijk");
oParser = new parserFormula("REPLACE(\"abcdefghijk\",15,4,\"XY\")","C2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "abcdefghijkXY");
}) test( "Test: \"\"TRUE\"&\"TRUE\"\"", function () {
oParser = new parserFormula( "\"TRUE\"&\"TRUE\"", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "TRUETRUE" );
} )
test("Test: \"SEARCH\"",function(){ test( "Test: \"10*\"\"\"", function () {
oParser = new parserFormula( "10*\"\"", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
} )
test( "Test: \"POWER(2,8)\"", function () {
oParser = new parserFormula( "POWER(2,8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), Math.pow( 2, 8 ) );
} )
test( "Test: \"POWER(0,-3)\"", function () {
oParser = new parserFormula( "POWER(0,-3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
} )
test( "Test: \"ISNA(A1)\"", function () {
var r = ws.getRange2( "K1" );
ws.getRange2( "A1" ).setValue( "#N/A" );
r.setValue( "=ISNA(A1)" );
strictEqual( ws.getCell2( "K1" ).getCells()[0].getValue(), "TRUE" );
} )
test( "Test: \"ROUNDUP(31415.92654;-2)\"", function () {
oParser = new parserFormula( "ROUNDUP(31415.92654;-2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 31500 );
} )
test( "Test: \"ROUNDUP(3.2;0)\"", function () {
oParser = new parserFormula( "ROUNDUP(3.2;0)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
} )
test( "Test: \"ROUNDUP(-3.14159;1)\"", function () {
oParser = new parserFormula( "ROUNDUP(-3.14159;1)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -3.2 );
} )
test( "Test: \"ROUNDUP(3.14159;3)\"", function () {
oParser = new parserFormula( "ROUNDUP(3.14159;3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3.142 );
} )
test( "Test: \"ROUNDDOWN(31415.92654;-2)\"", function () {
oParser = new parserFormula( "ROUNDDOWN(31415.92654;-2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 31400 );
} )
test( "Test: \"ROUNDDOWN(-3.14159;1)\"", function () {
oParser = new parserFormula( "ROUNDDOWN(-3.14159;1)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -3.1 );
} )
test( "Test: \"ROUNDDOWN(3.14159;3)\"", function () {
oParser = new parserFormula( "ROUNDDOWN(3.14159;3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3.141 );
} )
test( "Test: \"ROUNDDOWN(3.2;0)\"", function () {
oParser = new parserFormula( "ROUNDDOWN(3.2;0)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
} )
test( "Test: \"MROUND(10;3)\"", function () {
oParser = new parserFormula( "MROUND(10;3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 9 );
} )
test( "Test: \"MROUND(-10;-3)\"", function () {
oParser = new parserFormula( "MROUND(-10;-3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -9 );
} )
test( "Test: \"MROUND(1.3;0.2)\"", function () {
oParser = new parserFormula( "MROUND(1.3;0.2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1.4 );
} )
test( "Test: \"T(\"HELLO\")\"", function () {
oParser = new parserFormula( "T(\"HELLO\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "HELLO" );
} )
test( "Test: \"T(123)\"", function () {
oParser = new parserFormula( "T(123)", "A1", ws );
ok( oParser.parse() );
ok( !oParser.calculate().getValue(), "123" );
} )
test( "Test: YEAR", function () {
oParser = new parserFormula( "YEAR(2013)", "A1", ws );
ok( oParser.parse() );
if ( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 1909 );
else
strictEqual( oParser.calculate().getValue(), 1905 );
} )
test( "Test: DAY", function () {
oParser = new parserFormula( "DAY(2013)", "A1", ws );
ok( oParser.parse() );
if ( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 6 );
else
strictEqual( oParser.calculate().getValue(), 5 );
} )
test( "Test: DAY 2", function () {
oParser = new parserFormula( "DAY(\"20 may 2045\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 20 );
} )
test( "Test: MONTH", function () {
oParser = new parserFormula( "MONTH(2013)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 7 );
} )
test( "Test: \"10-3\"", function () {
oParser = new parserFormula( "10-3", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 7 );
} )
test( "Test: \"SUM\"", function () {
oParser = new parserFormula( "SUM(S5:T5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
} )
oParser = new parserFormula("SEARCH(\"de\",\"abcdEF\")","A2",ws); test( "Test: \"MAX\"", function () {
ok(oParser.parse()); oParser = new parserFormula( "MAX(S5:T5)", "A1", ws );
strictEqual( oParser.calculate().getValue(), 4); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
} )
oParser = new parserFormula("SEARCH(\"?c*e\",\"abcdEF\")","B2",ws); test( "Test: \"MAXA\"", function () {
ok(oParser.parse()); oParser = new parserFormula( "MAXA(S5:T5)", "A1", ws );
strictEqual( oParser.calculate().getValue(), 2); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
} )
oParser = new parserFormula("SEARCH(\"de\",\"dEFabcdEF\",3)","C2",ws); test( "Test: \"MIN\"", function () {
ok(oParser.parse()); oParser = new parserFormula( "MIN(S5:T5)", "A1", ws );
strictEqual( oParser.calculate().getValue(), 7); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
} )
oParser = new parserFormula("SEARCH(\"de\",\"dEFabcdEF\",30)","C2",ws); test( "Test: \"MINA\"", function () {
ok(oParser.parse()); oParser = new parserFormula( "MINA(S5:T5)", "A1", ws );
strictEqual( oParser.calculate().getValue(), "#VALUE!"); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
} )
test( "Test: SUM(S7:S9,{1,2,3})", function () {
ws.getRange2( "S7" ).setValue( "1" );
ws.getRange2( "S8" ).setValue( "2" );
ws.getRange2( "S9" ).setValue( "3" );
ws.getRange2( "S10" ).setValue( "=SUM(S7:S9,{1,2,3})" );
strictEqual( ws.getCell2( "S10" ).getCells()[0].getValue(), "12" );
} )
test( "Test: ISREF", function () {
oParser = new parserFormula( "ISREF(G0)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "FALSE" );
} )
test( "Test: MOD", function () {
oParser = new parserFormula( "MOD(7,3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
} )
test( "Test: rename sheet #1", function () {
oParser = new parserFormula( "Лист2!A2", "A1", ws );
ok( oParser.parse() === true );
// strictEqual( oParser.parse(), true)
strictEqual( oParser.changeSheet( "Лист2", "Лист3" ).assemble(), "Лист3!A2" );
} )
test( "Test: rename sheet #2", function () {
oParser = new parserFormula( "Лист2:Лист3!A2", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.changeSheet( "Лист2", "Лист1" ).assemble(), "Лист1:Лист3!A2" );
} )
test( "Test: rename sheet #3", function () {
oParser = new parserFormula( "Лист2!A2:A5", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.changeSheet( "Лист2", "Лист3" ).assemble(), "Лист3!A2:A5" );
} )
test( "Test: rename sheet #4", function () {
ws = wb.getWorksheetById( 1 );
ws.getRange2( "S95" ).setValue( "2" );
ws = wb.getWorksheetById( 2 );
ws.getRange2( "S100" ).setValue( "=" + wb.getWorksheetById( 1 ).getName() + "!S95" );
strictEqual( ws.getCell2( "S100" ).getCells()[0].getValue(), "2" );
wb.getWorksheetById( 1 ).setName( "ЛистTEMP" );
strictEqual( ws.getCell2( "S100" ).getCells()[0].getFormula(), wb.getWorksheetById( 1 ).getName() + "!S95", ws.getCell2( "S100" ).getCells()[0].getFormula() + " " + wb.getWorksheetById( 1 ).getName() + "!S95" );
} )
test( "Test: wrong ref", function () {
oParser = new parserFormula( "1+XXX1", "A1", ws );
ok( oParser.parse() );
notStrictEqual( oParser.calculate().getValue(), "1" );
} )
test( "Test: \"CODE\"", function () {
oParser = new parserFormula( "CODE(\"abc\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 97 );
} )
test( "Test: \"CHAR\"", function () {
oParser = new parserFormula( "CHAR(97)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "a" );
} )
test( "Test: \"CHAR(CODE())\"", function () {
oParser = new parserFormula( "CHAR(CODE(\"A\"))", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "A" );
} )
test( "Test: \"PROPER\"", function () {
oParser = new parserFormula( "PROPER(\"2-cent's worth\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "2-Cent'S Worth" );
oParser = new parserFormula( "PROPER(\"76BudGet\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "76Budget" );
oParser = new parserFormula( "PROPER(\"this is a TITLE\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "This Is A Title" );
} )
test( "Test: \"GCD\"", function () {
oParser = new parserFormula( "GCD(10,100,50)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 10 );
oParser = new parserFormula( "GCD(24.6,36.2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 12 );
oParser = new parserFormula( "GCD(-1,39,52)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
} )
test( "Test: \"FIXED\"", function () {
oParser = new parserFormula( "FIXED(1234567,-3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "1,235,000" );
oParser = new parserFormula( "FIXED(.555555,10)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "0.5555550000" );
oParser = new parserFormula( "FIXED(1234567.555555,4,TRUE)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "1234567.5556" );
oParser = new parserFormula( "FIXED(1234567)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "1,234,567" );
} )
test( "Test: \"COUNTIF\"", function () {
ws.getRange2( "A7" ).setValue( "3" );
ws.getRange2( "B7" ).setValue( "10" );
ws.getRange2( "C7" ).setValue( "7" );
ws.getRange2( "D7" ).setValue( "10" );
ws.getRange2( "A8" ).setValue( "apples" );
ws.getRange2( "B8" ).setValue( "oranges" );
ws.getRange2( "C8" ).setValue( "grapes" );
ws.getRange2( "D8" ).setValue( "melons" );
oParser = new parserFormula( "COUNTIF(A7:D7,\"=10\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "COUNTIF(A7:D7,\">5\")", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( "COUNTIF(A7:D7,\"<>10\")", "C1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "COUNTIF(A8:D8,\"*es\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( "COUNTIF(A8:D8,\"??a*\")", "B2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "COUNTIF(A8:D8,\"*l*\")", "C2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
} )
test( "Test: \"REPLACE\"", function () {
oParser = new parserFormula( "REPLACE(\"abcdefghijk\",3,4,\"XY\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "abXYghijk" );
oParser = new parserFormula( "REPLACE(\"abcdefghijk\",3,1,\"12345\")", "B2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "ab12345defghijk" );
oParser = new parserFormula( "REPLACE(\"abcdefghijk\",15,4,\"XY\")", "C2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "abcdefghijkXY" );
} )
test( "Test: \"SEARCH\"", function () {
oParser = new parserFormula( "SEARCH(\"~*\",\"abc*dEF\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
oParser = new parserFormula( "SEARCH(\"~\",\"abc~dEF\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
oParser = new parserFormula( "SEARCH(\"de\",\"abcdEF\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
oParser = new parserFormula( "SEARCH(\"?c*e\",\"abcdEF\")", "B2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "SEARCH(\"de\",\"dEFabcdEF\",3)", "C2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 7 );
oParser = new parserFormula( "SEARCH(\"de\",\"dEFabcdEF\",30)", "C2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
}) } )
test("Test: \"SUBSTITUTE\"",function(){ test( "Test: \"SUBSTITUTE\"", function () {
oParser = new parserFormula("SUBSTITUTE(\"abcaAabca\",\"a\",\"xx\")","A2",ws); oParser = new parserFormula( "SUBSTITUTE(\"abcaAabca\",\"a\",\"xx\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "xxbcxxAxxbcxx"); strictEqual( oParser.calculate().getValue(), "xxbcxxAxxbcxx" );
oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\")","B2",ws); oParser = new parserFormula( "SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\")", "B2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "xxbcxxxxxxbcxx"); strictEqual( oParser.calculate().getValue(), "xxbcxxxxxxbcxx" );
oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"\",10)","C2",ws); oParser = new parserFormula( "SUBSTITUTE(\"abcaaabca\",\"a\",\"\",10)", "C2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "bcbc"); strictEqual( oParser.calculate().getValue(), "bcbc" );
oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\",3)","C2",ws); oParser = new parserFormula( "SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\",3)", "C2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "abcaxxabca"); strictEqual( oParser.calculate().getValue(), "abcaxxabca" );
}) } )
test("Test: \"TRIM\"",function(){ test( "Test: \"TRIM\"", function () {
oParser = new parserFormula("TRIM(\" abc def \")","A2",ws); oParser = new parserFormula( "TRIM(\" abc def \")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "abc def"); strictEqual( oParser.calculate().getValue(), "abc def" );
}) } )
test("Test: \"DOLLAR\"",function(){ test( "Test: \"DOLLAR\"", function () {
oParser = new parserFormula("DOLLAR(1234.567)","A2",ws); oParser = new parserFormula( "DOLLAR(1234.567)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "$1,234.57"); strictEqual( oParser.calculate().getValue(), "$1,234.57" );
oParser = new parserFormula("DOLLAR(1234.567,-2)","A2",ws); oParser = new parserFormula( "DOLLAR(1234.567,-2)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "$1,200"); strictEqual( oParser.calculate().getValue(), "$1,200" );
oParser = new parserFormula("DOLLAR(-1234.567,4)","A2",ws); oParser = new parserFormula( "DOLLAR(-1234.567,4)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "$-1,234.5670"); strictEqual( oParser.calculate().getValue(), "$-1,234.5670" );
}) } )
test("Test: \"VALUE\"",function(){ test( "Test: \"VALUE\"", function () {
oParser = new parserFormula("VALUE(\"123.456\")","A2",ws); oParser = new parserFormula( "VALUE(\"123.456\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 123.456); strictEqual( oParser.calculate().getValue(), 123.456 );
oParser = new parserFormula("VALUE(\"$1,000\")","A2",ws); oParser = new parserFormula( "VALUE(\"$1,000\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!"); strictEqual( oParser.calculate().getValue(), "#VALUE!" );
oParser = new parserFormula("VALUE(\"23-Mar-2002\")","A2",ws); oParser = new parserFormula( "VALUE(\"23-Mar-2002\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37338); strictEqual( oParser.calculate().getValue(), 37338 );
oParser = new parserFormula("VALUE(\"03-26-2006\")","A2",ws); oParser = new parserFormula( "VALUE(\"03-26-2006\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
if( g_bDate1904 ) if ( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 37340); strictEqual( oParser.calculate().getValue(), 37340 );
else else
strictEqual( oParser.calculate().getValue(), 38802); strictEqual( oParser.calculate().getValue(), 38802 );
oParser = new parserFormula("VALUE(\"16:48:00\")-VALUE(\"12:17:12\")","A2",ws); oParser = new parserFormula( "VALUE(\"16:48:00\")-VALUE(\"12:17:12\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0.188055555555556); strictEqual( oParser.calculate().getValue(), 0.188055555555556 );
}) } )
test("Test: \"DATEVALUE\"",function(){ test( "Test: \"DATEVALUE\"", function () {
oParser = new parserFormula("DATEVALUE(\"10-10-2010 10:26\")","A2",ws); oParser = new parserFormula( "DATEVALUE(\"10-10-2010 10:26\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 40461); strictEqual( oParser.calculate().getValue(), 40461 );
oParser = new parserFormula("DATEVALUE(\"10-10-2010 10:26\")","A2",ws); oParser = new parserFormula( "DATEVALUE(\"10-10-2010 10:26\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 40461); strictEqual( oParser.calculate().getValue(), 40461 );
ws.getRange2("A7").setValue("3-Mar"); ws.getRange2( "A7" ).setValue( "3-Mar" );
oParser = new parserFormula("DATEVALUE(A7)","A2",ws); oParser = new parserFormula( "DATEVALUE(A7)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 41336); strictEqual( oParser.calculate().getValue(), 41336 );
oParser = new parserFormula("DATEVALUE(\"$1,000\")","A2",ws); oParser = new parserFormula( "DATEVALUE(\"$1,000\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!"); strictEqual( oParser.calculate().getValue(), "#VALUE!" );
oParser = new parserFormula("DATEVALUE(\"23-Mar-2002\")","A2",ws); oParser = new parserFormula( "DATEVALUE(\"23-Mar-2002\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37338); strictEqual( oParser.calculate().getValue(), 37338 );
oParser = new parserFormula("DATEVALUE(\"03-26-2006\")","A2",ws); oParser = new parserFormula( "DATEVALUE(\"03-26-2006\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
if( g_bDate1904 ) if ( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 37340); strictEqual( oParser.calculate().getValue(), 37340 );
else else
strictEqual( oParser.calculate().getValue(), 38802); strictEqual( oParser.calculate().getValue(), 38802 );
}) } )
test("Test: \"EDATE\"",function(){ test( "Test: \"EDATE\"", function () {
if( !g_bDate1904 ){ if ( !g_bDate1904 ) {
oParser = new parserFormula("EDATE(DATE(2006,1,31),5)","A2",ws); oParser = new parserFormula( "EDATE(DATE(2006,1,31),5)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38898); strictEqual( oParser.calculate().getValue(), 38898 );
oParser = new parserFormula("EDATE(DATE(2004,2,29),12)","A2",ws); oParser = new parserFormula( "EDATE(DATE(2004,2,29),12)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38411); strictEqual( oParser.calculate().getValue(), 38411 );
ws.getRange2("A7").setValue("02-28-2004"); ws.getRange2( "A7" ).setValue( "02-28-2004" );
oParser = new parserFormula("EDATE(A7,12)","A2",ws); oParser = new parserFormula( "EDATE(A7,12)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38411); strictEqual( oParser.calculate().getValue(), 38411 );
oParser = new parserFormula("EDATE(DATE(2004,1,15),-23)","A2",ws); oParser = new parserFormula( "EDATE(DATE(2004,1,15),-23)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37302); strictEqual( oParser.calculate().getValue(), 37302 );
} }
else{ else {
oParser = new parserFormula("EDATE(DATE(2006,1,31),5)","A2",ws); oParser = new parserFormula( "EDATE(DATE(2006,1,31),5)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37436); strictEqual( oParser.calculate().getValue(), 37436 );
oParser = new parserFormula("EDATE(DATE(2004,2,29),12)","A2",ws); oParser = new parserFormula( "EDATE(DATE(2004,2,29),12)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 36949); strictEqual( oParser.calculate().getValue(), 36949 );
ws.getRange2("A7").setValue("02-28-2004"); ws.getRange2( "A7" ).setValue( "02-28-2004" );
oParser = new parserFormula("EDATE(A7,12)","A2",ws); oParser = new parserFormula( "EDATE(A7,12)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 36949); strictEqual( oParser.calculate().getValue(), 36949 );
oParser = new parserFormula("EDATE(DATE(2004,1,15),-23)","A2",ws); oParser = new parserFormula( "EDATE(DATE(2004,1,15),-23)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 35840); strictEqual( oParser.calculate().getValue(), 35840 );
} }
}) } )
test("Test: \"EOMONTH\"",function(){ test( "Test: \"EOMONTH\"", function () {
if( !g_bDate1904 ){ if ( !g_bDate1904 ) {
oParser = new parserFormula("EOMONTH(DATE(2006,1,31),5)","A2",ws); oParser = new parserFormula( "EOMONTH(DATE(2006,1,31),5)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38898); strictEqual( oParser.calculate().getValue(), 38898 );
oParser = new parserFormula("EOMONTH(DATE(2004,2,29),12)","A2",ws); oParser = new parserFormula( "EOMONTH(DATE(2004,2,29),12)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38411); strictEqual( oParser.calculate().getValue(), 38411 );
ws.getRange2("A7").setValue("02-28-2004"); ws.getRange2( "A7" ).setValue( "02-28-2004" );
oParser = new parserFormula("EOMONTH(A7,12)","A2",ws); oParser = new parserFormula( "EOMONTH(A7,12)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38411); strictEqual( oParser.calculate().getValue(), 38411 );
oParser = new parserFormula("EOMONTH(DATE(2004,1,15),-23)","A2",ws); oParser = new parserFormula( "EOMONTH(DATE(2004,1,15),-23)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37315); strictEqual( oParser.calculate().getValue(), 37315 );
} }
else{ else {
oParser = new parserFormula("EOMONTH(DATE(2006,1,31),5)","A2",ws); oParser = new parserFormula( "EOMONTH(DATE(2006,1,31),5)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37436); strictEqual( oParser.calculate().getValue(), 37436 );
oParser = new parserFormula("EOMONTH(DATE(2004,2,29),12)","A2",ws); oParser = new parserFormula( "EOMONTH(DATE(2004,2,29),12)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 36949); strictEqual( oParser.calculate().getValue(), 36949 );
ws.getRange2("A7").setValue("02-28-2004"); ws.getRange2( "A7" ).setValue( "02-28-2004" );
oParser = new parserFormula("EOMONTH(A7,12)","A2",ws); oParser = new parserFormula( "EOMONTH(A7,12)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 36949); strictEqual( oParser.calculate().getValue(), 36949 );
oParser = new parserFormula("EOMONTH(DATE(2004,1,15),-23)","A2",ws); oParser = new parserFormula( "EOMONTH(DATE(2004,1,15),-23)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 35853); strictEqual( oParser.calculate().getValue(), 35853 );
} }
}) } )
test("Test: \"NETWORKDAYS\"",function(){ test( "Test: \"NETWORKDAYS\"", function () {
oParser = new parserFormula("NETWORKDAYS(DATE(2006,1,1),DATE(2006,1,31))","A2",ws); oParser = new parserFormula( "NETWORKDAYS(DATE(2006,1,1),DATE(2006,1,31))", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 22); strictEqual( oParser.calculate().getValue(), 22 );
oParser = new parserFormula("NETWORKDAYS(DATE(2006,1,31),DATE(2006,1,1))","A2",ws); oParser = new parserFormula( "NETWORKDAYS(DATE(2006,1,31),DATE(2006,1,1))", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -22); strictEqual( oParser.calculate().getValue(), -22 );
oParser = new parserFormula("NETWORKDAYS(DATE(2006,1,1),DATE(2006,2,1),{\"01-02-2006\",\"01-16-2006\"})","A2",ws); oParser = new parserFormula( "NETWORKDAYS(DATE(2006,1,1),DATE(2006,2,1),{\"01-02-2006\",\"01-16-2006\"})", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 21); strictEqual( oParser.calculate().getValue(), 21 );
}) } )
test("Test: \"PV\"",function(){ test( "Test: \"PV\"", function () {
oParser = new parserFormula("PV(0.08/12,12*20,500,,0)","A2",ws); oParser = new parserFormula( "PV(0.08/12,12*20,500,,0)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -59777.14585118638 ); strictEqual( oParser.calculate().getValue(), -59777.14585118638 );
oParser = new parserFormula("PV(0,12*20,500,,0)","A2",ws); oParser = new parserFormula( "PV(0,12*20,500,,0)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -120000 ); strictEqual( oParser.calculate().getValue(), -120000 );
}) } )
test("Test: \"NPV\"",function(){ test( "Test: \"NPV\"", function () {
oParser = new parserFormula("NPV(0.1,-10000,3000,4200,6800)","A2",ws); oParser = new parserFormula( "NPV(0.1,-10000,3000,4200,6800)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1188.4434123352216 ); strictEqual( oParser.calculate().getValue(), 1188.4434123352216 );
}) } )
test("Test: \"SUMIF\"",function(){ test( "Test: \"SUMIF\"", function () {
ws.getRange2("A2").setValue("100000"); ws.getRange2( "A2" ).setValue( "100000" );
ws.getRange2("A3").setValue("200000"); ws.getRange2( "A3" ).setValue( "200000" );
ws.getRange2("A4").setValue("300000"); ws.getRange2( "A4" ).setValue( "300000" );
ws.getRange2("A5").setValue("400000"); ws.getRange2( "A5" ).setValue( "400000" );
ws.getRange2("B2").setValue("7000"); ws.getRange2( "B2" ).setValue( "7000" );
ws.getRange2("B3").setValue("14000"); ws.getRange2( "B3" ).setValue( "14000" );
ws.getRange2("B4").setValue("21000"); ws.getRange2( "B4" ).setValue( "21000" );
ws.getRange2("B5").setValue("28000"); ws.getRange2( "B5" ).setValue( "28000" );
ws.getRange2("C2").setValue("250000"); ws.getRange2( "C2" ).setValue( "250000" );
oParser = new parserFormula("SUMIF(A2:A5,\">160000\",B2:B5)","A7",ws); oParser = new parserFormula( "SUMIF(A2:A5,\">160000\",B2:B5)", "A7", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 63000 ); strictEqual( oParser.calculate().getValue(), 63000 );
oParser = new parserFormula("SUMIF(A2:A5,\">160000\")","A8",ws); oParser = new parserFormula( "SUMIF(A2:A5,\">160000\")", "A8", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 900000 ); strictEqual( oParser.calculate().getValue(), 900000 );
oParser = new parserFormula("SUMIF(A2:A5,300000,B2:B5)","A9",ws); oParser = new parserFormula( "SUMIF(A2:A5,300000,B2:B5)", "A9", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 21000 ); strictEqual( oParser.calculate().getValue(), 21000 );
oParser = new parserFormula("SUMIF(A2:A5,\">\" & C2,B2:B5)","A10",ws); oParser = new parserFormula( "SUMIF(A2:A5,\">\" & C2,B2:B5)", "A10", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 49000 ); strictEqual( oParser.calculate().getValue(), 49000 );
ws.getRange2("A12").setValue("Vegetables"); ws.getRange2( "A12" ).setValue( "Vegetables" );
ws.getRange2("A13").setValue("Vegetables"); ws.getRange2( "A13" ).setValue( "Vegetables" );
ws.getRange2("A14").setValue("Fruits"); ws.getRange2( "A14" ).setValue( "Fruits" );
ws.getRange2("A15").setValue(""); ws.getRange2( "A15" ).setValue( "" );
ws.getRange2("A16").setValue("Vegetables"); ws.getRange2( "A16" ).setValue( "Vegetables" );
ws.getRange2("A17").setValue("Fruits"); ws.getRange2( "A17" ).setValue( "Fruits" );
ws.getRange2("B12").setValue("Tomatoes"); ws.getRange2( "B12" ).setValue( "Tomatoes" );
ws.getRange2("B13").setValue("Celery"); ws.getRange2( "B13" ).setValue( "Celery" );
ws.getRange2("B14").setValue("Oranges"); ws.getRange2( "B14" ).setValue( "Oranges" );
ws.getRange2("B15").setValue("Butter"); ws.getRange2( "B15" ).setValue( "Butter" );
ws.getRange2("B16").setValue("Carrots"); ws.getRange2( "B16" ).setValue( "Carrots" );
ws.getRange2("B17").setValue("Apples"); ws.getRange2( "B17" ).setValue( "Apples" );
ws.getRange2("C12").setValue("2300"); ws.getRange2( "C12" ).setValue( "2300" );
ws.getRange2("C13").setValue("5500"); ws.getRange2( "C13" ).setValue( "5500" );
ws.getRange2("C14").setValue("800"); ws.getRange2( "C14" ).setValue( "800" );
ws.getRange2("C15").setValue("400"); ws.getRange2( "C15" ).setValue( "400" );
ws.getRange2("C16").setValue("4200"); ws.getRange2( "C16" ).setValue( "4200" );
ws.getRange2("C17").setValue("1200"); ws.getRange2( "C17" ).setValue( "1200" );
oParser = new parserFormula("SUMIF(A12:A17,\"Fruits\",C12:C17)","A19",ws); oParser = new parserFormula( "SUMIF(A12:A17,\"Fruits\",C12:C17)", "A19", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2000 ); strictEqual( oParser.calculate().getValue(), 2000 );
oParser = new parserFormula("SUMIF(A12:A17,\"Vegetables\",C12:C17)","A20",ws); oParser = new parserFormula( "SUMIF(A12:A17,\"Vegetables\",C12:C17)", "A20", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 12000 ); strictEqual( oParser.calculate().getValue(), 12000 );
oParser = new parserFormula("SUMIF(B12:B17,\"*es\",C12:C17)","A21",ws); oParser = new parserFormula( "SUMIF(B12:B17,\"*es\",C12:C17)", "A21", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4300 ); strictEqual( oParser.calculate().getValue(), 4300 );
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 ); notEqual( oParser.calculate().getValue(), 400 );
}) } )
test("Test: \"TEXT\"",function(){ test( "Test: \"TEXT\"", function () {
wb.dependencyFormulas = new DependencyGraph(wb); wb.dependencyFormulas = new DependencyGraph( wb );
oParser = new parserFormula("TEXT(1234.567,\"$0.00\")","A2",ws); oParser = new parserFormula( "TEXT(1234.567,\"$0.00\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "$1234.57" ); strictEqual( oParser.calculate().getValue(), "$1234.57" );
oParser = new parserFormula("TEXT(0.125,\"0.0%\")","A2",ws); oParser = new parserFormula( "TEXT(0.125,\"0.0%\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "12.5%" ); strictEqual( oParser.calculate().getValue(), "12.5%" );
}) } )
test("Test: \"WORKDAY\"",function(){ test( "Test: \"WORKDAY\"", function () {
wb.dependencyFormulas = new DependencyGraph(wb); wb.dependencyFormulas = new DependencyGraph( wb );
oParser = new parserFormula("WORKDAY(DATE(2006,1,1),0)","A2",ws); oParser = new parserFormula( "WORKDAY(DATE(2006,1,1),0)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38718 ); strictEqual( oParser.calculate().getValue(), 38718 );
oParser = new parserFormula("WORKDAY(DATE(2006,1,1),10)","A2",ws); oParser = new parserFormula( "WORKDAY(DATE(2006,1,1),10)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38730 ); strictEqual( oParser.calculate().getValue(), 38730 );
oParser = new parserFormula("WORKDAY(DATE(2006,1,1),-10)","A2",ws); oParser = new parserFormula( "WORKDAY(DATE(2006,1,1),-10)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38705 ); strictEqual( oParser.calculate().getValue(), 38705 );
oParser = new parserFormula("WORKDAY(DATE(2006,1,1),20,{\"1-2-2006\",\"1-16-2006\"})","A2",ws); oParser = new parserFormula( "WORKDAY(DATE(2006,1,1),20,{\"1-2-2006\",\"1-16-2006\"})", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38748 ); strictEqual( oParser.calculate().getValue(), 38748 );
}) } )
test("Test: \"FV\"",function(){ test( "Test: \"FV\"", function () {
function fv( rate, nper, pmt, pv, type ){ function fv( rate, nper, pmt, pv, type ) {
var res; var res;
if( type === undefined || type === null ) if ( type === undefined || type === null )
type = 0; type = 0;
if( pv === undefined || pv === null ) if ( pv === undefined || pv === null )
pv = 0; pv = 0;
if( rate != 0 ){ if ( rate != 0 ) {
res = -1 * ( pv * Math.pow( 1 + rate, nper ) + pmt * ( 1 + rate * type ) * ( Math.pow( 1 + rate ,nper ) - 1) / rate ); res = -1 * ( pv * Math.pow( 1 + rate, nper ) + pmt * ( 1 + rate * type ) * ( Math.pow( 1 + rate, nper ) - 1) / rate );
} }
else{ else {
res = -1 * ( pv + pmt * nper ); res = -1 * ( pv + pmt * nper );
} }
return res; return res;
} }
oParser = new parserFormula("FV(0.06/12,10,-200,-500,1)","A2",ws); oParser = new parserFormula( "FV(0.06/12,10,-200,-500,1)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), fv(0.06/12,10,-200,-500,1) ); strictEqual( oParser.calculate().getValue(), fv( 0.06 / 12, 10, -200, -500, 1 ) );
oParser = new parserFormula("FV(0.12/12,12,-1000)","A2",ws); oParser = new parserFormula( "FV(0.12/12,12,-1000)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), fv(0.12/12,12,-1000) ); strictEqual( oParser.calculate().getValue(), fv( 0.12 / 12, 12, -1000 ) );
oParser = new parserFormula("FV(0.11/12,35,-2000,,1)","A2",ws); oParser = new parserFormula( "FV(0.11/12,35,-2000,,1)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
ok( Math.abs(oParser.calculate().getValue() - fv(0.11/12,35,-2000,null,1)) < dif ); ok( Math.abs( oParser.calculate().getValue() - fv( 0.11 / 12, 35, -2000, null, 1 ) ) < dif );
oParser = new parserFormula("FV(0.06/12,12,-100,-1000,1)","A2",ws); oParser = new parserFormula( "FV(0.06/12,12,-100,-1000,1)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
ok( Math.abs(oParser.calculate().getValue() - fv(0.06/12,12,-100,-1000,1)) < dif ); ok( Math.abs( oParser.calculate().getValue() - fv( 0.06 / 12, 12, -100, -1000, 1 ) ) < dif );
}) } )
test("Test: \"STDEV\"",function(){ test( "Test: \"STDEV\"", function () {
function stdev(){ function stdev() {
var average = 0, sum = 0, res = 0; var average = 0, sum = 0, res = 0;
for( var i = 0; i < arguments.length; i++){ for ( var i = 0; i < arguments.length; i++ ) {
average += arguments[i] / arguments.length; average += arguments[i] / arguments.length;
} }
for( var i = 0; i < arguments.length; i++){ for ( var i = 0; i < arguments.length; i++ ) {
res += (arguments[i] - average)*(arguments[i] - average); res += (arguments[i] - average) * (arguments[i] - average);
} }
return Math.sqrt(res / (arguments.length - 1)); return Math.sqrt( res / (arguments.length - 1) );
} }
oParser = new parserFormula("STDEV(123,134,143,173,112,109)","A2",ws); oParser = new parserFormula( "STDEV(123,134,143,173,112,109)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
ok( Math.abs(oParser.calculate().getValue() - stdev(123,134,143,173,112,109)) < dif ); ok( Math.abs( oParser.calculate().getValue() - stdev( 123, 134, 143, 173, 112, 109 ) ) < dif );
}) } )
test("Test: \"PMT\"",function(){ test( "Test: \"PMT\"", function () {
function pmt( rate, nper, pv, fv, type ){ function pmt( rate, nper, pv, fv, type ) {
var res; var res;
if( type === undefined || type === null ) if ( type === undefined || type === null )
type = 0; type = 0;
if( fv === undefined || fv === null ) if ( fv === undefined || fv === null )
fv = 0; fv = 0;
if( rate != 0 ){ if ( rate != 0 ) {
res = -1*( pv * Math.pow( 1 + rate, nper ) + fv ) / res = -1 * ( pv * Math.pow( 1 + rate, nper ) + fv ) /
( ( 1 + rate * type ) * ( Math.pow( 1 + rate, nper ) - 1 ) / rate ); ( ( 1 + rate * type ) * ( Math.pow( 1 + rate, nper ) - 1 ) / rate );
} }
else{ else {
res = -1*( pv + fv )/ nper; res = -1 * ( pv + fv ) / nper;
} }
return res; return res;
} }
oParser = new parserFormula("PMT(0.08/12,10,10000)","A2",ws); oParser = new parserFormula( "PMT(0.08/12,10,10000)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
ok( Math.abs(oParser.calculate().getValue() - pmt(0.08/12,10,10000)) < dif ); ok( Math.abs( oParser.calculate().getValue() - pmt( 0.08 / 12, 10, 10000 ) ) < dif );
oParser = new parserFormula("PMT(0.08/12,10,10000,0,1)","A2",ws); oParser = new parserFormula( "PMT(0.08/12,10,10000,0,1)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
ok( Math.abs(oParser.calculate().getValue() - pmt(0.08/12,10,10000,0,1)) < dif ); ok( Math.abs( oParser.calculate().getValue() - pmt( 0.08 / 12, 10, 10000, 0, 1 ) ) < dif );
}) } )
test("Test: \"TIMEVALUE\"",function(){ test( "Test: \"TIMEVALUE\"", function () {
oParser = new parserFormula("timevalue(\"10:02:34\")","A2",ws); oParser = new parserFormula( "timevalue(\"10:02:34\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
ok( Math.abs(oParser.calculate().getValue() - 0.4184490740740740) < dif ); ok( Math.abs( oParser.calculate().getValue() - 0.4184490740740740 ) < dif );
oParser = new parserFormula("timevalue(\"02-01-2006 10:15:29 AM\")","A2",ws); oParser = new parserFormula( "timevalue(\"02-01-2006 10:15:29 AM\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
ok( Math.abs(oParser.calculate().getValue() - 0.4274189814823330) < dif ); ok( Math.abs( oParser.calculate().getValue() - 0.4274189814823330 ) < dif );
oParser = new parserFormula("timevalue(\"22:02\")","A2",ws); oParser = new parserFormula( "timevalue(\"22:02\")", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
ok( Math.abs(oParser.calculate().getValue() - 0.9180555555555560) < dif ); ok( Math.abs( oParser.calculate().getValue() - 0.9180555555555560 ) < dif );
}) } )
test("Test: \"DAYS360\"",function(){ test( "Test: \"DAYS360\"", function () {
oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31))","A2",ws); oParser = new parserFormula( "DAYS360(DATE(2002,2,3),DATE(2005,5,31))", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual(oParser.calculate().getValue(), 1198); strictEqual( oParser.calculate().getValue(), 1198 );
oParser = new parserFormula("DAYS360(DATE(2005,5,31),DATE(2002,2,3))","A2",ws); oParser = new parserFormula( "DAYS360(DATE(2005,5,31),DATE(2002,2,3))", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual(oParser.calculate().getValue(), -1197); strictEqual( oParser.calculate().getValue(), -1197 );
oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31),FALSE)","A2",ws); oParser = new parserFormula( "DAYS360(DATE(2002,2,3),DATE(2005,5,31),FALSE)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual(oParser.calculate().getValue(), 1198); strictEqual( oParser.calculate().getValue(), 1198 );
oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31),TRUE)","A2",ws); oParser = new parserFormula( "DAYS360(DATE(2002,2,3),DATE(2005,5,31),TRUE)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual(oParser.calculate().getValue(), 1197); strictEqual( oParser.calculate().getValue(), 1197 );
}) } )
test("Test: \"WEEKNUM\"",function(){ test( "Test: \"WEEKNUM\"", function () {
oParser = new parserFormula("WEEKNUM(DATE(2006,1,1))","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2006,1,1))", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2006,1,1),17)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2006,1,1),17)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2006,1,1),1)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2006,1,1),1)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2006,1,1),21)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2006,1,1),21)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 52); strictEqual( oParser.calculate().getValue(), 52 );
oParser = new parserFormula("WEEKNUM(DATE(2006,2,1),1)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2006,2,1),1)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5); strictEqual( oParser.calculate().getValue(), 5 );
oParser = new parserFormula("WEEKNUM(DATE(2006,2,1),2)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2006,2,1),2)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6); strictEqual( oParser.calculate().getValue(), 6 );
oParser = new parserFormula("WEEKNUM(DATE(2006,2,1),11)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2006,2,1),11)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6); strictEqual( oParser.calculate().getValue(), 6 );
oParser = new parserFormula("WEEKNUM(DATE(2007,1,1),15)","A2",ws);//понед oParser = new parserFormula( "WEEKNUM(DATE(2007,1,1),15)", "A2", ws );//понед
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,1),15)","A2",ws);//втор oParser = new parserFormula( "WEEKNUM(DATE(2008,1,1),15)", "A2", ws );//втор
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2003,1,1),15)","A2",ws);//сред oParser = new parserFormula( "WEEKNUM(DATE(2003,1,1),15)", "A2", ws );//сред
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2009,1,1),15)","A2",ws);//чет oParser = new parserFormula( "WEEKNUM(DATE(2009,1,1),15)", "A2", ws );//чет
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2010,1,1),15)","A2",ws);//пят oParser = new parserFormula( "WEEKNUM(DATE(2010,1,1),15)", "A2", ws );//пят
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2011,1,1),15)","A2",ws);//суб oParser = new parserFormula( "WEEKNUM(DATE(2011,1,1),15)", "A2", ws );//суб
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2012,1,1),11)","A2",ws);//вск oParser = new parserFormula( "WEEKNUM(DATE(2012,1,1),11)", "A2", ws );//вск
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,4),11)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2008,1,4),11)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,10),11)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2008,1,10),11)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2); strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,11),11)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2008,1,11),11)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2); strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,17),11)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2008,1,17),11)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3); strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,18),11)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2008,1,18),11)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3); strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,24),11)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2008,1,24),11)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4); strictEqual( oParser.calculate().getValue(), 4 );
oParser = new parserFormula("WEEKNUM(DATE(2013,1,1),21)","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2013,1,1),21)", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1); strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2013,1,7))","A2",ws); oParser = new parserFormula( "WEEKNUM(DATE(2013,1,7))", "A2", ws );
ok(oParser.parse()); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2); strictEqual( oParser.calculate().getValue(), 2 );
}) } )
test("Test: \"YEARFRAC\"",function(){ test( "Test: \"YEARFRAC\"", function () {
function okWrapper(a,b){ function okWrapper( a, b ) {
ok( Math.abs(a - b) < dif ); ok( Math.abs( a - b ) < dif );
} }
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,3,26))","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,3,26))", "A2", ws );
okWrapper( oParser.calculate().getValue(), 0.236111111); ok( oParser.parse() );
okWrapper( oParser.calculate().getValue(), 0.236111111 );
oParser = new parserFormula("YEARFRAC(DATE(2006,3,26),DATE(2006,1,1))","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2006,3,26),DATE(2006,1,1))", "A2", ws );
okWrapper( oParser.calculate().getValue(), 0.236111111); ok( oParser.parse() );
okWrapper( oParser.calculate().getValue(), 0.236111111 );
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1))","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1))", "A2", ws );
okWrapper( oParser.calculate().getValue(), 0.5); ok( oParser.parse() );
okWrapper( oParser.calculate().getValue(), 0.5 );
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2007,9,1))","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2007,9,1))", "A2", ws );
okWrapper( oParser.calculate().getValue(), 1.666666667); ok( oParser.parse() );
okWrapper( oParser.calculate().getValue(), 1.666666667 );
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),0)","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),0)", "A2", ws );
okWrapper( oParser.calculate().getValue(), 0.5); ok( oParser.parse() );
okWrapper( oParser.calculate().getValue(), 0.5 );
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),1)","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),1)", "A2", ws );
okWrapper( oParser.calculate().getValue(), 0.495890411); ok( oParser.parse() );
okWrapper( oParser.calculate().getValue(), 0.495890411 );
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),2)","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),2)", "A2", ws );
okWrapper( oParser.calculate().getValue(), 0.502777778); ok( oParser.parse() );
okWrapper( oParser.calculate().getValue(), 0.502777778 );
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),3)","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),3)", "A2", ws );
okWrapper( oParser.calculate().getValue(), 0.495890411); ok( oParser.parse() );
okWrapper( oParser.calculate().getValue(), 0.495890411 );
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),4)","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),4)", "A2", ws );
okWrapper( oParser.calculate().getValue(), 0.5); ok( oParser.parse() );
okWrapper( oParser.calculate().getValue(), 0.5 );
oParser = new parserFormula("YEARFRAC(DATE(2004,3,1),DATE(2006,3,1),1)","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "YEARFRAC(DATE(2004,3,1),DATE(2006,3,1),1)", "A2", ws );
okWrapper( oParser.calculate().getValue(), 1.998175182481752); ok( oParser.parse() );
}) okWrapper( oParser.calculate().getValue(), 1.998175182481752 );
} )
test("Test: \"DATEDIF\"",function(){
test( "Test: \"DATEDIF\"", function () {
oParser = new parserFormula("DATEDIF(DATE(2001,1,1),DATE(2003,1,1),\"Y\")","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "DATEDIF(DATE(2001,1,1),DATE(2003,1,1),\"Y\")", "A2", ws );
strictEqual( oParser.calculate().getValue(), 2); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"D\")","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"D\")", "A2", ws );
strictEqual( oParser.calculate().getValue(), 440); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 440 );
oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"YD\")","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"YD\")", "A2", ws );
strictEqual( oParser.calculate().getValue(), 75); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 75 );
oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"MD\")","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"MD\")", "A2", ws );
strictEqual( oParser.calculate().getValue(), 14); ok( oParser.parse() );
}) strictEqual( oParser.calculate().getValue(), 14 );
} )
test("Test: \"SUMPRODUCT\"",function(){
test( "Test: \"SUMPRODUCT\"", function () {
oParser = new parserFormula("SUMPRODUCT({2,3})","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "SUMPRODUCT({2,3})", "A2", ws );
strictEqual( oParser.calculate().getValue(), 5); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5 );
oParser = new parserFormula("SUMPRODUCT({2,3},{4,5})","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "SUMPRODUCT({2,3},{4,5})", "A2", ws );
strictEqual( oParser.calculate().getValue(), 23); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 23 );
oParser = new parserFormula("SUMPRODUCT({2,3},{4,5},{2,2})","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "SUMPRODUCT({2,3},{4,5},{2,2})", "A2", ws );
strictEqual( oParser.calculate().getValue(), 46); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 46 );
oParser = new parserFormula("SUMPRODUCT({2,3;4,5},{2,2;3,4})","A2",ws);
ok(oParser.parse()); oParser = new parserFormula( "SUMPRODUCT({2,3;4,5},{2,2;3,4})", "A2", ws );
strictEqual( oParser.calculate().getValue(), 42); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 42 );
ws.getRange2("N44").setValue("1");
ws.getRange2("N45").setValue("2"); ws.getRange2( "N44" ).setValue( "1" );
ws.getRange2("N46").setValue("3"); ws.getRange2( "N45" ).setValue( "2" );
ws.getRange2("N47").setValue("4"); ws.getRange2( "N46" ).setValue( "3" );
ws.getRange2( "N47" ).setValue( "4" );
ws.getRange2("O44").setValue("5");
ws.getRange2("O45").setValue("6"); ws.getRange2( "O44" ).setValue( "5" );
ws.getRange2("O46").setValue("7"); ws.getRange2( "O45" ).setValue( "6" );
ws.getRange2("O47").setValue("8"); ws.getRange2( "O46" ).setValue( "7" );
ws.getRange2( "O47" ).setValue( "8" );
ws.getRange2("P44").setValue("9");
ws.getRange2("P45").setValue("10"); ws.getRange2( "P44" ).setValue( "9" );
ws.getRange2("P46").setValue("11"); ws.getRange2( "P45" ).setValue( "10" );
ws.getRange2("P47").setValue("12"); ws.getRange2( "P46" ).setValue( "11" );
oParser = new parserFormula("SUMPRODUCT(N44:N47,O44:O47,P44:P47)","A2",ws); ws.getRange2( "P47" ).setValue( "12" );
ok(oParser.parse()); oParser = new parserFormula( "SUMPRODUCT(N44:N47,O44:O47,P44:P47)", "A2", ws );
strictEqual( oParser.calculate().getValue(), 780); ok( oParser.parse() );
}) strictEqual( oParser.calculate().getValue(), 780 );
} )
});
test( "Test: \"SINH\"", function () {
oParser = new parserFormula( "SINH(0)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "SINH(1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), ((Math.E - 1 / Math.E) / 2).toFixed( cExcelSignificantDigits ) - 0 );
} )
test( "Test: \"COSH\"", function () {
oParser = new parserFormula( "COSH(0)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "COSH(1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), ((Math.E + 1 / Math.E) / 2).toFixed( cExcelSignificantDigits ) - 0 );
} )
test( "Test: \"TANH\"", function () {
oParser = new parserFormula( "TANH(0)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "TANH(1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), ((Math.E * Math.E - 1) / (Math.E * Math.E + 1)).toFixed( cExcelSignificantDigits ) - 0 );
} )
test( "Test: \"COMBIN\"", function () {
oParser = new parserFormula( "COMBIN(8,2)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 28 );
oParser = new parserFormula( "COMBIN(10,4)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 210 );
oParser = new parserFormula( "COMBIN(6,5)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6 );
oParser = new parserFormula( "COMBIN(-6,5)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
oParser = new parserFormula( "COMBIN(3,5)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
oParser = new parserFormula( "COMBIN(6,-5)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
} )
test( "Test: \"FACTDOUBLE\"", function () {
oParser = new parserFormula( "FACTDOUBLE(8)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 * 4 * 6 * 8 );
oParser = new parserFormula( "FACTDOUBLE(9)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 9 * 7 * 5 * 3 );
oParser = new parserFormula( "FACTDOUBLE(6.5)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6 * 4 * 2 );
oParser = new parserFormula( "FACTDOUBLE(-6)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
oParser = new parserFormula( "FACTDOUBLE(600)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
} )
test( "Test: \"GCD\"", function () {
oParser = new parserFormula( "LCM(5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5 );
oParser = new parserFormula( "LCM(24.6,36.2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 72 );
oParser = new parserFormula( "LCM(-1,39,52)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
oParser = new parserFormula( "LCM(0,39,52)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
oParser = new parserFormula( "LCM(24,36,15)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 360 );
} )
test( "Test: \"RANDBETWEEN\"", function () {
var res;
oParser = new parserFormula( "RANDBETWEEN(1,6)", "A1", ws );
ok( oParser.parse() );
res = oParser.calculate().getValue()
ok( res >= 1 && res <= 6 );
oParser = new parserFormula( "RANDBETWEEN(-10,10)", "A1", ws );
ok( oParser.parse() );
res = oParser.calculate().getValue()
ok( res >= -10 && res <= 10 );
oParser = new parserFormula( "RANDBETWEEN(-25,-3)", "A1", ws );
ok( oParser.parse() );
res = oParser.calculate().getValue()
ok( res >= -25 && res <= -3 );
} )
test( "Test: \"QUOTIENT\"", function () {
oParser = new parserFormula( "QUOTIENT(1,6)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "QUOTIENT(-10,3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -3 );
oParser = new parserFormula( "QUOTIENT(5,3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "QUOTIENT(5,0)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
} )
test( "Test: \"TRUNC\"", function () {
oParser = new parserFormula( "TRUNC(PI())", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( "TRUNC(PI(),3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3.141 );
oParser = new parserFormula( "TRUNC(PI(),-2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "TRUNC(-PI(),2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -3.14 );
} )
test( "Test: \"MULTINOMIAL\"", function () {
oParser = new parserFormula( "MULTINOMIAL(2,3,4)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), Math.fact( 2 + 3 + 4 ) / (Math.fact( 2 ) * Math.fact( 3 ) * Math.fact( 4 )) );
oParser = new parserFormula( "MULTINOMIAL(2,3,\"r\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
oParser = new parserFormula( "MULTINOMIAL(150,50)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
} )
test( "Test: \"SUMSQ\"", function () {
oParser = new parserFormula( "SUMSQ(2.5,-3.6,2.4)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2.5 * 2.5 + 3.6 * 3.6 + 2.4 * 2.4 );
oParser = new parserFormula( "SUMSQ(2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
oParser = new parserFormula( "SUMSQ(150,50)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 150 * 150 + 50 * 50 );
oParser = new parserFormula( "SUMSQ(150,\"f\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
} )
test( "Test: \"ROMAN\"", function () {
oParser = new parserFormula( "ROMAN(499,0)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "CDXCIX" );
oParser = new parserFormula( "ROMAN(499,1)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "LDVLIV" );
oParser = new parserFormula( "ROMAN(499,2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "XDIX" );
oParser = new parserFormula( "ROMAN(499,3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "VDIV" );
oParser = new parserFormula( "ROMAN(499,4)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "ID" );
oParser = new parserFormula( "ROMAN(2013,0)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "MMXIII" );
oParser = new parserFormula( "ROMAN(2013,5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
oParser = new parserFormula( "ROMAN(-2013,1)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
oParser = new parserFormula( "ROMAN(2499,1)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "MMLDVLIV" );
} )
} );
...@@ -461,6 +461,8 @@ ...@@ -461,6 +461,8 @@
api.asc_registerCallback("asc_onActiveSheetChanged", onActiveSheetChanged); api.asc_registerCallback("asc_onActiveSheetChanged", onActiveSheetChanged);
// api.asc_registerCallback("asc_onCellTextChanged", function(){console.log(arguments)});
api.asc_registerCallback("asc_onConfirmAction", function(){ api.asc_registerCallback("asc_onConfirmAction", function(){
var arg = arguments; var arg = arguments;
$("#ConfirmMess") $("#ConfirmMess")
...@@ -485,7 +487,7 @@ ...@@ -485,7 +487,7 @@
}); });
api.asc_registerCallback("asc_onEditCell", function (state) { api.asc_registerCallback("asc_onEditCell", function (state) {
console.log("Cell Edit State - " + state); // console.log("Cell Edit State - " + state);
}); });
api.asc_registerCallback("asc_onSelectionRangeChanged", function (val) { api.asc_registerCallback("asc_onSelectionRangeChanged", function (val) {
......
...@@ -6,123 +6,123 @@ ...@@ -6,123 +6,123 @@
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
cFormulaFunction.Financial = { cFormulaFunction.Financial = {
'groupName' : "Financial", 'groupName':"Financial",
'ACCRINT' : function(){ 'ACCRINT':function () {
var r = new cBaseFunction("ACCRINT"); var r = new cBaseFunction( "ACCRINT" );
return r; return r;
}, },
'ACCRINTM' : function(){ 'ACCRINTM':function () {
var r = new cBaseFunction("ACCRINTM"); var r = new cBaseFunction( "ACCRINTM" );
return r; return r;
}, },
'AMORDEGRC' : function(){ 'AMORDEGRC':function () {
var r = new cBaseFunction("AMORDEGRC"); var r = new cBaseFunction( "AMORDEGRC" );
return r; return r;
}, },
'AMORLINC' : function(){ 'AMORLINC':function () {
var r = new cBaseFunction("AMORLINC"); var r = new cBaseFunction( "AMORLINC" );
return r; return r;
}, },
'COUPDAYBS' : function(){ 'COUPDAYBS':function () {
var r = new cBaseFunction("COUPDAYBS"); var r = new cBaseFunction( "COUPDAYBS" );
return r; return r;
}, },
'COUPDAYS' : function(){ 'COUPDAYS':function () {
var r = new cBaseFunction("COUPDAYS"); var r = new cBaseFunction( "COUPDAYS" );
return r; return r;
}, },
'COUPDAYSNC' : function(){ 'COUPDAYSNC':function () {
var r = new cBaseFunction("COUPDAYSNC"); var r = new cBaseFunction( "COUPDAYSNC" );
return r; return r;
}, },
'COUPNCD' : function(){ 'COUPNCD':function () {
var r = new cBaseFunction("COUPNCD"); var r = new cBaseFunction( "COUPNCD" );
return r; return r;
}, },
'COUPNUM' : function(){ 'COUPNUM':function () {
var r = new cBaseFunction("COUPNUM"); var r = new cBaseFunction( "COUPNUM" );
return r; return r;
}, },
'COUPPCD' : function(){ 'COUPPCD':function () {
var r = new cBaseFunction("COUPPCD"); var r = new cBaseFunction( "COUPPCD" );
return r; return r;
}, },
'CUMIPMT' : function(){ 'CUMIPMT':function () {
var r = new cBaseFunction("CUMIPMT"); var r = new cBaseFunction( "CUMIPMT" );
return r; return r;
}, },
'CUMPRINC' : function(){ 'CUMPRINC':function () {
var r = new cBaseFunction("CUMPRINC"); var r = new cBaseFunction( "CUMPRINC" );
return r; return r;
}, },
'DB' : function(){ 'DB':function () {
var r = new cBaseFunction("DB"); var r = new cBaseFunction( "DB" );
return r; return r;
}, },
'DDB' : function(){ 'DDB':function () {
var r = new cBaseFunction("DDB"); var r = new cBaseFunction( "DDB" );
return r; return r;
}, },
'DISC' : function(){ 'DISC':function () {
var r = new cBaseFunction("DISC"); var r = new cBaseFunction( "DISC" );
return r; return r;
}, },
'DOLLARDE' : function(){ 'DOLLARDE':function () {
var r = new cBaseFunction("DOLLARDE"); var r = new cBaseFunction( "DOLLARDE" );
return r; return r;
}, },
'DOLLARFR' : function(){ 'DOLLARFR':function () {
var r = new cBaseFunction("DOLLARFR"); var r = new cBaseFunction( "DOLLARFR" );
return r; return r;
}, },
'DURATION' : function(){ 'DURATION':function () {
var r = new cBaseFunction("DURATION"); var r = new cBaseFunction( "DURATION" );
return r; return r;
}, },
'EFFECT' : function(){ 'EFFECT':function () {
var r = new cBaseFunction("EFFECT"); var r = new cBaseFunction( "EFFECT" );
return r; return r;
}, },
'FV' : function(){ 'FV':function () {
var r = new cBaseFunction("FV"); var r = new cBaseFunction( "FV" );
r.setArgumentsMin(3); r.setArgumentsMin( 3 );
r.setArgumentsMax(5); r.setArgumentsMax( 5 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var rate = arg[0], nper = arg[1], pmt = arg[2], pv = arg[3] ? arg[3] : new cNumber(0), type = arg[4] ? arg[4] : new cNumber(0); var rate = arg[0], nper = arg[1], pmt = arg[2], pv = arg[3] ? arg[3] : new cNumber( 0 ), type = arg[4] ? arg[4] : new cNumber( 0 );
if ( rate instanceof cArea || rate instanceof cArea3D ){ if ( rate instanceof cArea || rate instanceof cArea3D ) {
rate = rate.cross(arguments[1].first); rate = rate.cross( arguments[1].first );
} }
else if( rate instanceof cArray ){ else if ( rate instanceof cArray ) {
rate = rate.getElementRowCol(0,0); rate = rate.getElementRowCol( 0, 0 );
} }
if ( nper instanceof cArea || nper instanceof cArea3D ){ if ( nper instanceof cArea || nper instanceof cArea3D ) {
nper = nper.cross(arguments[1].first); nper = nper.cross( arguments[1].first );
} }
else if( nper instanceof cArray ){ else if ( nper instanceof cArray ) {
nper = nper.getElementRowCol(0,0); nper = nper.getElementRowCol( 0, 0 );
} }
if ( pmt instanceof cArea || pmt instanceof cArea3D ){ if ( pmt instanceof cArea || pmt instanceof cArea3D ) {
pmt = pmt.cross(arguments[1].first); pmt = pmt.cross( arguments[1].first );
} }
else if( pmt instanceof cArray ){ else if ( pmt instanceof cArray ) {
pmt = pmt.getElementRowCol(0,0); pmt = pmt.getElementRowCol( 0, 0 );
} }
if ( pv instanceof cArea || pv instanceof cArea3D ){ if ( pv instanceof cArea || pv instanceof cArea3D ) {
pv = pv.cross(arguments[1].first); pv = pv.cross( arguments[1].first );
} }
else if( pv instanceof cArray ){ else if ( pv instanceof cArray ) {
pv = pv.getElementRowCol(0,0); pv = pv.getElementRowCol( 0, 0 );
} }
if ( type instanceof cArea || type instanceof cArea3D ){ if ( type instanceof cArea || type instanceof cArea3D ) {
type = type.cross(arguments[1].first); type = type.cross( arguments[1].first );
} }
else if( type instanceof cArray ){ else if ( type instanceof cArray ) {
type = type.getElementRowCol(0,0); type = type.getElementRowCol( 0, 0 );
} }
rate = rate.tocNumber(); rate = rate.tocNumber();
...@@ -140,76 +140,147 @@ cFormulaFunction.Financial = { ...@@ -140,76 +140,147 @@ cFormulaFunction.Financial = {
if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric ); if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric );
var res; var res;
if( rate.getValue() != 0 ){ if ( rate.getValue() != 0 ) {
res = -1*( pv.getValue()*Math.pow(1+rate.getValue(),nper.getValue())+pmt.getValue()*( 1 + rate.getValue()*type.getValue() )*(Math.pow((1+rate.getValue()),nper.getValue())-1)/rate.getValue() ); res = -1 * ( pv.getValue() * Math.pow( 1 + rate.getValue(), nper.getValue() ) + pmt.getValue() * ( 1 + rate.getValue() * type.getValue() ) * (Math.pow( (1 + rate.getValue()), nper.getValue() ) - 1) / rate.getValue() );
} }
else{ else {
res = -1*( pv.getValue()+pmt.getValue()*nper.getValue() ); res = -1 * ( pv.getValue() + pmt.getValue() * nper.getValue() );
} }
return this.value = new cNumber(res); return this.value = new cNumber( res );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( rate , nper , pmt [ , [ pv ] [ ,[ type ] ] ] )" args:"( rate , nper , pmt [ , [ pv ] [ ,[ type ] ] ] )"
}; };
} }
r.setFormat(r.formatType.noneFormat); r.setFormat( r.formatType.noneFormat );
return r; return r;
}, },
'FVSCHEDULE' : function(){ 'FVSCHEDULE':function () {
var r = new cBaseFunction("FVSCHEDULE"); var r = new cBaseFunction( "FVSCHEDULE" );
return r; return r;
}, },
'INTRATE' : function(){ 'INTRATE':function () {
var r = new cBaseFunction("INTRATE"); var r = new cBaseFunction( "INTRATE" );
return r; return r;
}, },
'IPMT' : function(){ 'IPMT':function () {
var r = new cBaseFunction("IPMT"); var r = new cBaseFunction( "IPMT" );
return r; return r;
}, },
'IRR' : function(){ 'IRR':function () {
var r = new cBaseFunction("IRR"); var r = new cBaseFunction( "IRR" );
return r; return r;
}, },
'ISPMT' : function(){ 'ISPMT':function () {
var r = new cBaseFunction("ISPMT"); var r = new cBaseFunction( "ISPMT" );
return r; return r;
}, },
'MDURATION' : function(){ 'MDURATION':function () {
var r = new cBaseFunction("MDURATION"); var r = new cBaseFunction( "MDURATION" );
return r; return r;
}, },
'MIRR' : function(){ 'MIRR':function () {
var r = new cBaseFunction("MIRR"); var r = new cBaseFunction( "MIRR" );
return r; return r;
}, },
'NOMINAL' : function(){ 'NOMINAL':function () {
var r = new cBaseFunction("NOMINAL"); var r = new cBaseFunction( "NOMINAL" );
return r; return r;
}, },
'NPER' : function(){ 'NPER':function () {
var r = new cBaseFunction("NPER"); var r = new cBaseFunction( "NPER" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 5 );
r.Calculate = function ( arg ) {
var rate = arg[0], pmt = arg[1], pv = arg[2], fv = arg[3] ? arg[3] : new cNumber( 0 ), type = arg[4] ? arg[4] : new cNumber( 0 );
if ( rate instanceof cArea || rate instanceof cArea3D ) {
rate = rate.cross( arguments[1].first );
}
else if ( rate instanceof cArray ) {
rate = rate.getElementRowCol( 0, 0 );
}
if ( pmt instanceof cArea || pmt instanceof cArea3D ) {
pmt = pmt.cross( arguments[1].first );
}
else if ( pmt instanceof cArray ) {
pmt = pmt.getElementRowCol( 0, 0 );
}
if ( pv instanceof cArea || pv instanceof cArea3D ) {
pv = pv.cross( arguments[1].first );
}
else if ( pv instanceof cArray ) {
pv = pv.getElementRowCol( 0, 0 );
}
if ( fv instanceof cArea || fv instanceof cArea3D ) {
fv = fv.cross( arguments[1].first );
}
else if ( fv instanceof cArray ) {
fv = fv.getElementRowCol( 0, 0 );
}
if ( type instanceof cArea || type instanceof cArea3D ) {
type = type.cross( arguments[1].first );
}
else if ( type instanceof cArray ) {
type = type.getElementRowCol( 0, 0 );
}
rate = rate.tocNumber();
pmt = pmt.tocNumber();
pv = pv.tocNumber();
fv = fv.tocNumber();
type = type.tocNumber();
if ( rate instanceof cError ) return this.value = rate;
if ( pmt instanceof cError ) return this.value = pmt;
if ( pmt instanceof cError ) return this.value = pv;
if ( fv instanceof cError ) return this.value = fv;
if ( type instanceof cError ) return this.value = type;
if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric );
var res;
if ( rate.getValue() != 0 ) {
res = -1 * ( fv.getValue() + pmt.getValue() * (1 + rate.getValue() * type.getValue()) * ( (Math.pow( (1 + rate.getValue()), nper.getValue() ) - 1) / rate.getValue() ) ) / Math.pow( 1 + rate.getValue(), nper.getValue() )
}
else {
res = -1 * ( fv.getValue() + pmt.getValue() * pmt.getValue() );
}
return this.value = new cNumber( res );
}
r.getInfo = function () {
return {
name:this.name,
args:"( rate , pmt , pv [ , [ fv ] [ , [ type ] ] ] )"
};
}
r.setFormat( r.formatType.noneFormat );
return r; return r;
}, },
'NPV' : function(){ 'NPV':function () {
var r = new cBaseFunction("NPV"); var r = new cBaseFunction( "NPV" );
r.setArgumentsMin(2); r.setArgumentsMin( 2 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], iStart = 1, res = 0, rate; var arg0 = arg[0], arg1 = arg[1], iStart = 1, res = 0, rate;
function elemCalc(rate,value,step){ function elemCalc( rate, value, step ) {
return value / Math.pow(1+rate,step); return value / Math.pow( 1 + rate, step );
} }
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
else if( arg0 instanceof cArray ){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
...@@ -219,107 +290,107 @@ cFormulaFunction.Financial = { ...@@ -219,107 +290,107 @@ cFormulaFunction.Financial = {
rate = arg0.getValue(); rate = arg0.getValue();
if( rate == -1) if ( rate == -1 )
return this.value = new cError( cErrorType.division_by_zero ); return this.value = new cError( cErrorType.division_by_zero );
for(var i = 1; i < this.getArguments(); i++){ for ( var i = 1; i < this.getArguments(); i++ ) {
var argI = arg[i]; var argI = arg[i];
if( argI instanceof cArea || argI instanceof cArea3D ){ if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argIArr = argI.getValue(); var argIArr = argI.getValue();
for (var j = 0; j < argIArr.length; j++){ for ( var j = 0; j < argIArr.length; j++ ) {
if( argIArr[j] instanceof cNumber ){ if ( argIArr[j] instanceof cNumber ) {
res += elemCalc( rate, argIArr[j].getValue(), iStart++ ); res += elemCalc( rate, argIArr[j].getValue(), iStart++ );
} }
} }
continue; continue;
} }
else if( argI instanceof cArray ){ else if ( argI instanceof cArray ) {
argI.foreach(function(elem,r,c){ argI.foreach( function ( elem, r, c ) {
if( elem instanceof cNumber ){ if ( elem instanceof cNumber ) {
res += elemCalc( rate, elem.getValue(), iStart++ ); res += elemCalc( rate, elem.getValue(), iStart++ );
} }
}) } )
continue; continue;
} }
argI = argI.tocNumber(); argI = argI.tocNumber();
if( argI instanceof cError ) if ( argI instanceof cError )
continue; continue;
res += elemCalc( rate, argI.getValue(), iStart++ ); res += elemCalc( rate, argI.getValue(), iStart++ );
} }
return this.value = new cNumber(res); return this.value = new cNumber( res );
}; };
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( rate , argument-list )" args:"( rate , argument-list )"
}; };
}; };
r.setFormat(r.formatType.noneFormat); r.setFormat( r.formatType.noneFormat );
return r; return r;
}, },
'ODDFPRICE' : function(){ 'ODDFPRICE':function () {
var r = new cBaseFunction("ODDFPRICE"); var r = new cBaseFunction( "ODDFPRICE" );
return r; return r;
}, },
'ODDFYIELD' : function(){ 'ODDFYIELD':function () {
var r = new cBaseFunction("ODDFYIELD"); var r = new cBaseFunction( "ODDFYIELD" );
return r; return r;
}, },
'ODDLPRICE' : function(){ 'ODDLPRICE':function () {
var r = new cBaseFunction("ODDLPRICE"); var r = new cBaseFunction( "ODDLPRICE" );
return r; return r;
}, },
'ODDLYIELD' : function(){ 'ODDLYIELD':function () {
var r = new cBaseFunction("ODDLYIELD"); var r = new cBaseFunction( "ODDLYIELD" );
return r; return r;
}, },
'PMT' : function(){ 'PMT':function () {
var r = new cBaseFunction("PMT"); var r = new cBaseFunction( "PMT" );
r.setArgumentsMin(3); r.setArgumentsMin( 3 );
r.setArgumentsMax(5); r.setArgumentsMax( 5 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var rate = arg[0], nper = arg[1], pv = arg[2], fv = arg[3] ? arg[3] : new cNumber(0), type = arg[4] ? arg[4] : new cNumber(0); var rate = arg[0], nper = arg[1], pv = arg[2], fv = arg[3] ? arg[3] : new cNumber( 0 ), type = arg[4] ? arg[4] : new cNumber( 0 );
if ( rate instanceof cArea || rate instanceof cArea3D ){ if ( rate instanceof cArea || rate instanceof cArea3D ) {
rate = rate.cross(arguments[1].first); rate = rate.cross( arguments[1].first );
} }
else if( rate instanceof cArray ){ else if ( rate instanceof cArray ) {
rate = rate.getElementRowCol(0,0); rate = rate.getElementRowCol( 0, 0 );
} }
if ( nper instanceof cArea || nper instanceof cArea3D ){ if ( nper instanceof cArea || nper instanceof cArea3D ) {
nper = nper.cross(arguments[1].first); nper = nper.cross( arguments[1].first );
} }
else if( nper instanceof cArray ){ else if ( nper instanceof cArray ) {
nper = nper.getElementRowCol(0,0); nper = nper.getElementRowCol( 0, 0 );
} }
if ( pv instanceof cArea || pv instanceof cArea3D ){ if ( pv instanceof cArea || pv instanceof cArea3D ) {
pv = pv.cross(arguments[1].first); pv = pv.cross( arguments[1].first );
} }
else if( pv instanceof cArray ){ else if ( pv instanceof cArray ) {
pv = pv.getElementRowCol(0,0); pv = pv.getElementRowCol( 0, 0 );
} }
if ( fv instanceof cArea || fv instanceof cArea3D ){ if ( fv instanceof cArea || fv instanceof cArea3D ) {
fv = fv.cross(arguments[1].first); fv = fv.cross( arguments[1].first );
} }
else if( fv instanceof cArray ){ else if ( fv instanceof cArray ) {
fv = fv.getElementRowCol(0,0); fv = fv.getElementRowCol( 0, 0 );
} }
if ( type instanceof cArea || type instanceof cArea3D ){ if ( type instanceof cArea || type instanceof cArea3D ) {
type = type.cross(arguments[1].first); type = type.cross( arguments[1].first );
} }
else if( type instanceof cArray ){ else if ( type instanceof cArray ) {
type = type.getElementRowCol(0,0); type = type.getElementRowCol( 0, 0 );
} }
rate = rate.tocNumber(); rate = rate.tocNumber();
...@@ -340,81 +411,81 @@ cFormulaFunction.Financial = { ...@@ -340,81 +411,81 @@ cFormulaFunction.Financial = {
if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric ); if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric );
var res; var res;
if( rate.getValue() != 0 ){ if ( rate.getValue() != 0 ) {
res = -1*( pv.getValue() * Math.pow( 1 + rate.getValue(), nper.getValue() ) + fv.getValue() ) / res = -1 * ( pv.getValue() * Math.pow( 1 + rate.getValue(), nper.getValue() ) + fv.getValue() ) /
( ( 1 + rate.getValue() * type.getValue() ) * ( Math.pow((1 + rate.getValue()), nper.getValue() ) - 1 ) / rate.getValue() ); ( ( 1 + rate.getValue() * type.getValue() ) * ( Math.pow( (1 + rate.getValue()), nper.getValue() ) - 1 ) / rate.getValue() );
} }
else{ else {
res = -1*( pv.getValue()+fv.getValue() )/ nper.getValue(); res = -1 * ( pv.getValue() + fv.getValue() ) / nper.getValue();
} }
return this.value = new cNumber(res); return this.value = new cNumber( res );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( rate , nper , pv [ , [ fv ] [ ,[ type ] ] ] )" args:"( rate , nper , pv [ , [ fv ] [ ,[ type ] ] ] )"
}; };
} }
r.setFormat(r.formatType.noneFormat); r.setFormat( r.formatType.noneFormat );
return r; return r;
}, },
'PPMT' : function(){ 'PPMT':function () {
var r = new cBaseFunction("PPMT"); var r = new cBaseFunction( "PPMT" );
return r; return r;
}, },
'PRICE' : function(){ 'PRICE':function () {
var r = new cBaseFunction("PRICE"); var r = new cBaseFunction( "PRICE" );
return r; return r;
}, },
'PRICEDISC' : function(){ 'PRICEDISC':function () {
var r = new cBaseFunction("PRICEDISC"); var r = new cBaseFunction( "PRICEDISC" );
return r; return r;
}, },
'PRICEMAT' : function(){ 'PRICEMAT':function () {
var r = new cBaseFunction("PRICEMAT"); var r = new cBaseFunction( "PRICEMAT" );
return r; return r;
}, },
'PV' : function(){ 'PV':function () {
var r = new cBaseFunction("PV"); var r = new cBaseFunction( "PV" );
r.setArgumentsMin(3); r.setArgumentsMin( 3 );
r.setArgumentsMax(5); r.setArgumentsMax( 5 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var rate = arg[0], nper = arg[1], pmt = arg[2], fv = arg[3] ? arg[3] : new cNumber(0), type = arg[4] ? arg[4] : new cNumber(0); var rate = arg[0], nper = arg[1], pmt = arg[2], fv = arg[3] ? arg[3] : new cNumber( 0 ), type = arg[4] ? arg[4] : new cNumber( 0 );
if ( rate instanceof cArea || rate instanceof cArea3D ){ if ( rate instanceof cArea || rate instanceof cArea3D ) {
rate = rate.cross(arguments[1].first); rate = rate.cross( arguments[1].first );
} }
else if( rate instanceof cArray ){ else if ( rate instanceof cArray ) {
rate = rate.getElementRowCol(0,0); rate = rate.getElementRowCol( 0, 0 );
} }
if ( nper instanceof cArea || nper instanceof cArea3D ){ if ( nper instanceof cArea || nper instanceof cArea3D ) {
nper = nper.cross(arguments[1].first); nper = nper.cross( arguments[1].first );
} }
else if( nper instanceof cArray ){ else if ( nper instanceof cArray ) {
nper = nper.getElementRowCol(0,0); nper = nper.getElementRowCol( 0, 0 );
} }
if ( pmt instanceof cArea || pmt instanceof cArea3D ){ if ( pmt instanceof cArea || pmt instanceof cArea3D ) {
pmt = pmt.cross(arguments[1].first); pmt = pmt.cross( arguments[1].first );
} }
else if( pmt instanceof cArray ){ else if ( pmt instanceof cArray ) {
pmt = pmt.getElementRowCol(0,0); pmt = pmt.getElementRowCol( 0, 0 );
} }
if ( fv instanceof cArea || fv instanceof cArea3D ){ if ( fv instanceof cArea || fv instanceof cArea3D ) {
fv = fv.cross(arguments[1].first); fv = fv.cross( arguments[1].first );
} }
else if( fv instanceof cArray ){ else if ( fv instanceof cArray ) {
fv = fv.getElementRowCol(0,0); fv = fv.getElementRowCol( 0, 0 );
} }
if ( type instanceof cArea || type instanceof cArea3D ){ if ( type instanceof cArea || type instanceof cArea3D ) {
type = type.cross(arguments[1].first); type = type.cross( arguments[1].first );
} }
else if( type instanceof cArray ){ else if ( type instanceof cArray ) {
type = type.getElementRowCol(0,0); type = type.getElementRowCol( 0, 0 );
} }
rate = rate.tocNumber(); rate = rate.tocNumber();
...@@ -432,74 +503,74 @@ cFormulaFunction.Financial = { ...@@ -432,74 +503,74 @@ cFormulaFunction.Financial = {
if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric ); if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric );
var res; var res;
if( rate.getValue() != 0 ){ if ( rate.getValue() != 0 ) {
res = -1*( fv.getValue() + pmt.getValue()*(1+rate.getValue()*type.getValue())*( (Math.pow((1+rate.getValue()),nper.getValue())-1)/rate.getValue() ) )/Math.pow(1+rate.getValue(),nper.getValue()) res = -1 * ( fv.getValue() + pmt.getValue() * (1 + rate.getValue() * type.getValue()) * ( (Math.pow( (1 + rate.getValue()), nper.getValue() ) - 1) / rate.getValue() ) ) / Math.pow( 1 + rate.getValue(), nper.getValue() )
} }
else{ else {
res = -1*( fv.getValue()+pmt.getValue()*nper.getValue() ); res = -1 * ( fv.getValue() + pmt.getValue() * nper.getValue() );
} }
return this.value = new cNumber(res); return this.value = new cNumber( res );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( rate , nper , pmt [ , [ fv ] [ ,[ type ] ] ] )" args:"( rate , nper , pmt [ , [ fv ] [ ,[ type ] ] ] )"
}; };
} }
r.setFormat(r.formatType.noneFormat); r.setFormat( r.formatType.noneFormat );
return r; return r;
}, },
'RATE' : function(){ 'RATE':function () {
var r = new cBaseFunction("RATE"); var r = new cBaseFunction( "RATE" );
return r; return r;
}, },
'RECEIVED' : function(){ 'RECEIVED':function () {
var r = new cBaseFunction("RECEIVED"); var r = new cBaseFunction( "RECEIVED" );
return r; return r;
}, },
'SLN' : function(){ 'SLN':function () {
var r = new cBaseFunction("SLN"); var r = new cBaseFunction( "SLN" );
return r; return r;
}, },
'SYD' : function(){ 'SYD':function () {
var r = new cBaseFunction("SYD"); var r = new cBaseFunction( "SYD" );
return r; return r;
}, },
'TBILLEQ' : function(){ 'TBILLEQ':function () {
var r = new cBaseFunction("TBILLEQ"); var r = new cBaseFunction( "TBILLEQ" );
return r; return r;
}, },
'TBILLPRICE' : function(){ 'TBILLPRICE':function () {
var r = new cBaseFunction("TBILLPRICE"); var r = new cBaseFunction( "TBILLPRICE" );
return r; return r;
}, },
'TBILLYIELD' : function(){ 'TBILLYIELD':function () {
var r = new cBaseFunction("TBILLYIELD"); var r = new cBaseFunction( "TBILLYIELD" );
return r; return r;
}, },
'VDB' : function(){ 'VDB':function () {
var r = new cBaseFunction("VDB"); var r = new cBaseFunction( "VDB" );
return r; return r;
}, },
'XIRR' : function(){ 'XIRR':function () {
var r = new cBaseFunction("XIRR"); var r = new cBaseFunction( "XIRR" );
return r; return r;
}, },
'XNPV' : function(){ 'XNPV':function () {
var r = new cBaseFunction("XNPV"); var r = new cBaseFunction( "XNPV" );
return r; return r;
}, },
'YIELD' : function(){ 'YIELD':function () {
var r = new cBaseFunction("YIELD"); var r = new cBaseFunction( "YIELD" );
return r; return r;
}, },
'YIELDDISC' : function(){ 'YIELDDISC':function () {
var r = new cBaseFunction("YIELDDISC"); var r = new cBaseFunction( "YIELDDISC" );
return r; return r;
}, },
'YIELDMAT' : function(){ 'YIELDMAT':function () {
var r = new cBaseFunction("YIELDMAT"); var r = new cBaseFunction( "YIELDMAT" );
return r; return r;
} }
} }
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -6,55 +6,55 @@ ...@@ -6,55 +6,55 @@
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
cFormulaFunction.Statistical = { cFormulaFunction.Statistical = {
'groupName' : "Statistical", 'groupName':"Statistical",
'AVEDEV' : function(){ 'AVEDEV':function () {
var r = new cBaseFunction("AVEDEV"); var r = new cBaseFunction( "AVEDEV" );
return r; return r;
}, },
'AVERAGE' : function(){ 'AVERAGE':function () {
var r = new cBaseFunction("AVERAGE"); var r = new cBaseFunction( "AVERAGE" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var count = 0, sum = new cNumber(0); var count = 0, sum = new cNumber( 0 );
for ( var i = 0; i < arg.length; i++){ for ( var i = 0; i < arg.length; i++ ) {
var _arg = arg[i]; var _arg = arg[i];
if( _arg instanceof cRef || _arg instanceof cRef3D){ if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue(); var _argV = _arg.getValue();
if ( _argV instanceof cNumber ){ if ( _argV instanceof cNumber ) {
sum = _func[sum.type][_argV.type](sum,_argV,"+"); sum = _func[sum.type][_argV.type]( sum, _argV, "+" );
count++; count++;
} }
} }
else if ( _arg instanceof cArea || _arg instanceof cArea3D){ else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue(); var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++){ for ( var j = 0; j < _argAreaValue.length; j++ ) {
var __arg = _argAreaValue[j]; var __arg = _argAreaValue[j];
if ( __arg instanceof cNumber ){ if ( __arg instanceof cNumber ) {
sum = _func[sum.type][__arg.type](sum,__arg,"+"); sum = _func[sum.type][__arg.type]( sum, __arg, "+" );
count++; count++;
} }
} }
} }
else if( _arg instanceof cArray ){ else if ( _arg instanceof cArray ) {
_arg.foreach(function(elem){ _arg.foreach( function ( elem ) {
var e = elem.tocNumber(); var e = elem.tocNumber();
if( e instanceof cNumber ){ if ( e instanceof cNumber ) {
sum = _func[sum.type][e.type](sum,e,"+"); sum = _func[sum.type][e.type]( sum, e, "+" );
count++; count++;
} }
}) } )
} }
else{ else {
if( _arg instanceof cError ) if ( _arg instanceof cError )
continue; continue;
sum = _func[sum.type][_arg.type](sum,_arg,"+"); sum = _func[sum.type][_arg.type]( sum, _arg, "+" );
count++; count++;
} }
} }
return this.value = new cNumber (sum.getValue() / count); return this.value = new cNumber( sum.getValue() / count );
}; };
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(number1, number2, ...)" args:"(number1, number2, ...)"
...@@ -62,153 +62,153 @@ cFormulaFunction.Statistical = { ...@@ -62,153 +62,153 @@ cFormulaFunction.Statistical = {
} }
return r; return r;
}, },
'AVERAGEA' : function(){ 'AVERAGEA':function () {
var r = new cBaseFunction("AVERAGEA"); var r = new cBaseFunction( "AVERAGEA" );
return r; return r;
}, },
'AVERAGEIF' : function(){ 'AVERAGEIF':function () {
var r = new cBaseFunction("AVERAGEIF"); var r = new cBaseFunction( "AVERAGEIF" );
return r; return r;
}, },
'AVERAGEIFS' : function(){ 'AVERAGEIFS':function () {
var r = new cBaseFunction("AVERAGEIFS"); var r = new cBaseFunction( "AVERAGEIFS" );
return r; return r;
}, },
'BETADIST' : function(){ 'BETADIST':function () {
var r = new cBaseFunction("BETADIST"); var r = new cBaseFunction( "BETADIST" );
return r; return r;
}, },
'BETAINV' : function(){ 'BETAINV':function () {
var r = new cBaseFunction("BETAINV"); var r = new cBaseFunction( "BETAINV" );
return r; return r;
}, },
'BINOMDIST' : function(){ 'BINOMDIST':function () {
var r = new cBaseFunction("BINOMDIST"); var r = new cBaseFunction( "BINOMDIST" );
return r; return r;
}, },
'CHIDIST' : function(){ 'CHIDIST':function () {
var r = new cBaseFunction("CHIDIST"); var r = new cBaseFunction( "CHIDIST" );
return r; return r;
}, },
'CHIINV' : function(){ 'CHIINV':function () {
var r = new cBaseFunction("CHIINV"); var r = new cBaseFunction( "CHIINV" );
return r; return r;
}, },
'CHITEST' : function(){ 'CHITEST':function () {
var r = new cBaseFunction("CHITEST"); var r = new cBaseFunction( "CHITEST" );
return r; return r;
}, },
'CONFIDENCE' : function(){ 'CONFIDENCE':function () {
var r = new cBaseFunction("CONFIDENCE"); var r = new cBaseFunction( "CONFIDENCE" );
return r; return r;
}, },
'CORREL' : function(){ 'CORREL':function () {
var r = new cBaseFunction("CORREL"); var r = new cBaseFunction( "CORREL" );
return r; return r;
}, },
'COUNT' : function(){ 'COUNT':function () {
var r = new cBaseFunction("COUNT"); var r = new cBaseFunction( "COUNT" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var count = 0; var count = 0;
for ( var i = 0; i < arg.length; i++){ for ( var i = 0; i < arg.length; i++ ) {
var _arg = arg[i]; var _arg = arg[i];
if( _arg instanceof cRef || _arg instanceof cRef3D){ if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue(); var _argV = _arg.getValue();
if ( _argV instanceof cNumber ){ if ( _argV instanceof cNumber ) {
count++; count++;
} }
} }
else if ( _arg instanceof cArea || _arg instanceof cArea3D){ else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue(); var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++){ for ( var j = 0; j < _argAreaValue.length; j++ ) {
if ( _argAreaValue[j] instanceof cNumber ){ if ( _argAreaValue[j] instanceof cNumber ) {
count++; count++;
} }
} }
} }
else if( _arg instanceof cNumber || _arg instanceof cBool || _arg instanceof cEmpty ){ else if ( _arg instanceof cNumber || _arg instanceof cBool || _arg instanceof cEmpty ) {
count++; count++;
} }
else if( _arg instanceof cString ){ else if ( _arg instanceof cString ) {
if (_arg.tocNumber() instanceof cNumber) if ( _arg.tocNumber() instanceof cNumber )
count++; count++;
} }
else if( _arg instanceof cArray ){ else if ( _arg instanceof cArray ) {
_arg.foreach(function(elem){ _arg.foreach( function ( elem ) {
var e = elem.tocNumber(); var e = elem.tocNumber();
if( e instanceof cNumber ){ if ( e instanceof cNumber ) {
count++; count++;
} }
}) } )
} }
} }
return this.value = new cNumber( count ); return this.value = new cNumber( count );
}; };
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( argument-list )" args:"( argument-list )"
}; };
} }
r.setFormat(r.formatType.noneFormat); r.setFormat( r.formatType.noneFormat );
return r; return r;
}, },
'COUNTA' : function(){ 'COUNTA':function () {
var r = new cBaseFunction("COUNTA"); var r = new cBaseFunction( "COUNTA" );
return r; return r;
}, },
'COUNTBLANK' : function(){ 'COUNTBLANK':function () {
var r = new cBaseFunction("COUNTBLANK"); var r = new cBaseFunction( "COUNTBLANK" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ) if ( arg0 instanceof cArea || arg0 instanceof cArea3D )
return this.value = arg0.countCells(); return this.value = arg0.countCells();
else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){ else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
return this.value = new cNumber( 1 ); return this.value = new cNumber( 1 );
} }
else else
return this.value = new cError( cErrorType.bad_reference ); return this.value = new cError( cErrorType.bad_reference );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( argument-list )" args:"( argument-list )"
}; };
} }
r.setFormat(r.formatType.noneFormat); r.setFormat( r.formatType.noneFormat );
return r; return r;
}, },
'COUNTIF' : function(){ 'COUNTIF':function () {
var r = new cBaseFunction("COUNTIF"); var r = new cBaseFunction( "COUNTIF" );
r.setArgumentsMin(2); r.setArgumentsMin( 2 );
r.setArgumentsMax(2); r.setArgumentsMax( 2 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], _count = 0, valueForSearching, regexpSearch; var arg0 = arg[0], arg1 = arg[1], _count = 0, valueForSearching, regexpSearch;
if( !(arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea || arg0 instanceof cArea3D) ){ if ( !(arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea || arg0 instanceof cArea3D) ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first); arg1 = arg1.cross( arguments[1].first );
} }
else if( arg1 instanceof cArray ){ else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if( !(arg1 instanceof cString) ){ if ( !(arg1 instanceof cString) ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
function matching(x,y,oper){ function matching( x, y, oper ) {
var res = 0; var res = 0;
if( typeof x === typeof y ){ if ( typeof x === typeof y ) {
switch(oper){ switch ( oper ) {
case "<>": case "<>":
res = (x.value != y.value); res = (x.value != y.value);
break; break;
...@@ -235,72 +235,72 @@ cFormulaFunction.Statistical = { ...@@ -235,72 +235,72 @@ cFormulaFunction.Statistical = {
} }
arg1 = arg1.toString(); arg1 = arg1.toString();
var operators = new RegExp("^ *[<=> ]+ *"), searchOperators = new RegExp("^ *[*?]") var operators = new RegExp( "^ *[<=> ]+ *" ), searchOperators = new RegExp( "^ *[*?]" )
var match = arg1.match(operators); var match = arg1.match( operators );
if( match || parseNum(arg1) ){ if ( match || parseNum( arg1 ) ) {
var search, oper, val; var search, oper, val;
if( match ){ if ( match ) {
search = arg1.substr( match[0].length ); search = arg1.substr( match[0].length );
oper = match[0].replace(/\s/g,""); oper = match[0].replace( /\s/g, "" );
} }
else{ else {
search = arg1; search = arg1;
} }
valueForSearching = parseNum( search ) ? new cNumber( search ) : new cString( search ); valueForSearching = parseNum( search ) ? new cNumber( search ) : new cString( search );
if( arg0 instanceof cArea ){ if ( arg0 instanceof cArea ) {
val = arg0.getValue(); val = arg0.getValue();
for( var i = 0; i < val.length; i++ ){ for ( var i = 0; i < val.length; i++ ) {
matching( val[i], valueForSearching, oper); matching( val[i], valueForSearching, oper );
} }
} }
else if( arg0 instanceof cArea3D ){ else if ( arg0 instanceof cArea3D ) {
val = arg0.getValue(); val = arg0.getValue();
for(var i = 0; i < val.length; i++){ for ( var i = 0; i < val.length; i++ ) {
matching( val[i], valueForSearching, oper); matching( val[i], valueForSearching, oper );
} }
} }
else{ else {
val = arg0.getValue(); val = arg0.getValue();
matching( val, valueForSearching, oper); matching( val, valueForSearching, oper );
} }
} }
else{ else {
match = arg1.match(searchOperators) match = arg1.match( searchOperators )
if( match ){ if ( match ) {
valueForSearching = arg1 valueForSearching = arg1
.replace(/(~)?\*/g, function($0, $1){ .replace( /(~)?\*/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]*'; return $1 ? $0 : '[\\w\\W]*';
}) } )
.replace(/(~)?\?/g, function($0, $1){ .replace( /(~)?\?/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]{1,1}'; return $1 ? $0 : '[\\w\\W]{1,1}';
}) } )
.replace(/\~/g, "\\"); .replace( /(~\*)/g, "\\*" ).replace( /(~\?)/g, "\\?" )
regexpSearch = new RegExp(valueForSearching+"$","i"); regexpSearch = new RegExp( valueForSearching + "$", "i" );
if( arg0 instanceof cArea ){ if ( arg0 instanceof cArea ) {
val = arg0.getValue(); val = arg0.getValue();
for( var i = 0; i < val.length; i++ ){ for ( var i = 0; i < val.length; i++ ) {
_count += regexpSearch.test(val[i].value); _count += regexpSearch.test( val[i].value );
} }
} }
else if( arg0 instanceof cArea3D ){ else if ( arg0 instanceof cArea3D ) {
val = arg0.getValue(); val = arg0.getValue();
for(var i in val){ for ( var i in val ) {
for(var j in val[i]){ for ( var j in val[i] ) {
_count += regexpSearch.test(val[i][j].value); _count += regexpSearch.test( val[i][j].value );
} }
} }
} }
else{ else {
val = arg0.getValue(); val = arg0.getValue();
_count += regexpSearch.test(val.value); _count += regexpSearch.test( val.value );
} }
} }
} }
return this.value = new cNumber(_count); return this.value = new cNumber( _count );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( cell-range, selection-criteria )" args:"( cell-range, selection-criteria )"
...@@ -308,176 +308,176 @@ cFormulaFunction.Statistical = { ...@@ -308,176 +308,176 @@ cFormulaFunction.Statistical = {
} }
return r; return r;
}, },
'COUNTIFS' : function(){ 'COUNTIFS':function () {
var r = new cBaseFunction("COUNTIFS"); var r = new cBaseFunction( "COUNTIFS" );
return r; return r;
}, },
'COVAR' : function(){ 'COVAR':function () {
var r = new cBaseFunction("COVAR"); var r = new cBaseFunction( "COVAR" );
return r; return r;
}, },
'CRITBINOM' : function(){ 'CRITBINOM':function () {
var r = new cBaseFunction("CRITBINOM"); var r = new cBaseFunction( "CRITBINOM" );
return r; return r;
}, },
'DEVSQ' : function(){ 'DEVSQ':function () {
var r = new cBaseFunction("DEVSQ"); var r = new cBaseFunction( "DEVSQ" );
return r; return r;
}, },
'EXPONDIST' : function(){ 'EXPONDIST':function () {
var r = new cBaseFunction("EXPONDIST"); var r = new cBaseFunction( "EXPONDIST" );
return r; return r;
}, },
'FDIST' : function(){ 'FDIST':function () {
var r = new cBaseFunction("FDIST"); var r = new cBaseFunction( "FDIST" );
return r; return r;
}, },
'FINV' : function(){ 'FINV':function () {
var r = new cBaseFunction("FINV"); var r = new cBaseFunction( "FINV" );
return r; return r;
}, },
'FISHER' : function(){ 'FISHER':function () {
var r = new cBaseFunction("FISHER"); var r = new cBaseFunction( "FISHER" );
return r; return r;
}, },
'FISHERINV' : function(){ 'FISHERINV':function () {
var r = new cBaseFunction("FISHERINV"); var r = new cBaseFunction( "FISHERINV" );
return r; return r;
}, },
'FORECAST' : function(){ 'FORECAST':function () {
var r = new cBaseFunction("FORECAST"); var r = new cBaseFunction( "FORECAST" );
return r; return r;
}, },
'FREQUENCY' : function(){ 'FREQUENCY':function () {
var r = new cBaseFunction("FREQUENCY"); var r = new cBaseFunction( "FREQUENCY" );
return r; return r;
}, },
'FTEST' : function(){ 'FTEST':function () {
var r = new cBaseFunction("FTEST"); var r = new cBaseFunction( "FTEST" );
return r; return r;
}, },
'GAMMADIST' : function(){ 'GAMMADIST':function () {
var r = new cBaseFunction("GAMMADIST"); var r = new cBaseFunction( "GAMMADIST" );
return r; return r;
}, },
'GAMMAINV' : function(){ 'GAMMAINV':function () {
var r = new cBaseFunction("GAMMAINV"); var r = new cBaseFunction( "GAMMAINV" );
return r; return r;
}, },
'GAMMALN' : function(){ 'GAMMALN':function () {
var r = new cBaseFunction("GAMMALN"); var r = new cBaseFunction( "GAMMALN" );
return r; return r;
}, },
'GEOMEAN' : function(){ 'GEOMEAN':function () {
var r = new cBaseFunction("GEOMEAN"); var r = new cBaseFunction( "GEOMEAN" );
return r; return r;
}, },
'GROWTH' : function(){ 'GROWTH':function () {
var r = new cBaseFunction("GROWTH"); var r = new cBaseFunction( "GROWTH" );
return r; return r;
}, },
'HARMEAN' : function(){ 'HARMEAN':function () {
var r = new cBaseFunction("HARMEAN"); var r = new cBaseFunction( "HARMEAN" );
return r; return r;
}, },
'HYPGEOMDIST' : function(){ 'HYPGEOMDIST':function () {
var r = new cBaseFunction("HYPGEOMDIST"); var r = new cBaseFunction( "HYPGEOMDIST" );
return r; return r;
}, },
'INTERCEPT' : function(){ 'INTERCEPT':function () {
var r = new cBaseFunction("INTERCEPT"); var r = new cBaseFunction( "INTERCEPT" );
return r; return r;
}, },
'KURT' : function(){ 'KURT':function () {
var r = new cBaseFunction("KURT"); var r = new cBaseFunction( "KURT" );
return r; return r;
}, },
'LARGE' : function(){ 'LARGE':function () {
var r = new cBaseFunction("LARGE"); var r = new cBaseFunction( "LARGE" );
return r; return r;
}, },
'LINEST' : function(){ 'LINEST':function () {
var r = new cBaseFunction("LINEST"); var r = new cBaseFunction( "LINEST" );
return r; return r;
}, },
'LOGEST' : function(){ 'LOGEST':function () {
var r = new cBaseFunction("LOGEST"); var r = new cBaseFunction( "LOGEST" );
return r; return r;
}, },
'LOGINV' : function(){ 'LOGINV':function () {
var r = new cBaseFunction("LOGINV"); var r = new cBaseFunction( "LOGINV" );
return r; return r;
}, },
'LOGNORMDIST' : function(){ 'LOGNORMDIST':function () {
var r = new cBaseFunction("LOGNORMDIST"); var r = new cBaseFunction( "LOGNORMDIST" );
return r; return r;
}, },
'MAX' : function(){ 'MAX':function () {
var r = new cBaseFunction("MAX"); var r = new cBaseFunction( "MAX" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var argI, argIVal, max = new cNumber ( Number.NEGATIVE_INFINITY ); var argI, argIVal, max = new cNumber( Number.NEGATIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ){ for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue(); argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ){ if ( argI instanceof cRef || argI instanceof cRef3D ) {
if( argIVal instanceof cError ) if ( argIVal instanceof cError )
return this.value = argIVal; return this.value = argIVal;
if( argIVal instanceof cNumber || argIVal instanceof cBool || argIVal instanceof cEmpty){ if ( argIVal instanceof cNumber || argIVal instanceof cBool || argIVal instanceof cEmpty ) {
var v = argIVal.tocNumber(); var v = argIVal.tocNumber();
if ( v.getValue() > max.getValue() ) if ( v.getValue() > max.getValue() )
max = v; max = v;
} }
} }
else if ( argI instanceof cArea || argI instanceof cArea3D ){ else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue(); var argArr = argI.getValue();
for( var j = 0; j < argArr.length; j++ ){ for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty){ if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty ) {
var v = argArr[j].tocNumber(); var v = argArr[j].tocNumber();
if ( v.getValue() > max.getValue() ) if ( v.getValue() > max.getValue() )
max = v; max = v;
} }
else if ( argArr[j] instanceof cError ){ else if ( argArr[j] instanceof cError ) {
return this.value = argArr[j]; return this.value = argArr[j];
} }
} }
} }
else if( argI instanceof cError ) else if ( argI instanceof cError )
return this.value = argI; return this.value = argI;
else if ( argI instanceof cString ){ else if ( argI instanceof cString ) {
var v = argI.tocNumber(); var v = argI.tocNumber();
if ( v instanceof cNumber ) if ( v instanceof cNumber )
if ( v.getValue() > max.getValue() ) if ( v.getValue() > max.getValue() )
max = v; max = v;
} }
else if ( argI instanceof cBool || argI instanceof cEmpty ){ else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber(); var v = argI.tocNumber();
if ( v.getValue() > max.getValue() ) if ( v.getValue() > max.getValue() )
max = v; max = v;
} }
else if( argI instanceof cArray ){ else if ( argI instanceof cArray ) {
argI.foreach(function(elem){ argI.foreach( function ( elem ) {
if( elem instanceof cNumber ){ if ( elem instanceof cNumber ) {
if ( elem.getValue() > max.getValue() ) if ( elem.getValue() > max.getValue() )
max = elem; max = elem;
} }
else if( elem instanceof cError ){ else if ( elem instanceof cError ) {
max = elem; max = elem;
return true; return true;
} }
}) } )
if( max instanceof cError ){ if ( max instanceof cError ) {
return this.value = max; return this.value = max;
} }
} }
else{ else {
if ( argI.getValue() > max.getValue() ) if ( argI.getValue() > max.getValue() )
max = argI; max = argI;
} }
} }
return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber(0) : max ); return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : max );
}; };
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(number1, number2, ...)" args:"(number1, number2, ...)"
...@@ -485,17 +485,17 @@ cFormulaFunction.Statistical = { ...@@ -485,17 +485,17 @@ cFormulaFunction.Statistical = {
} }
return r; return r;
}, },
'MAXA' : function(){ 'MAXA':function () {
var r = new cBaseFunction("MAXA"); var r = new cBaseFunction( "MAXA" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var argI, max = new cNumber ( Number.NEGATIVE_INFINITY ); var argI, max = new cNumber( Number.NEGATIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ){ for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue(); argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ){ if ( argI instanceof cRef || argI instanceof cRef3D ) {
if( argIVal instanceof cError ) if ( argIVal instanceof cError )
return this.value = argIVal; return this.value = argIVal;
var v = argIVal.tocNumber(); var v = argIVal.tocNumber();
...@@ -503,11 +503,11 @@ cFormulaFunction.Statistical = { ...@@ -503,11 +503,11 @@ cFormulaFunction.Statistical = {
if ( v instanceof cNumber && v.getValue() > max.getValue() ) if ( v instanceof cNumber && v.getValue() > max.getValue() )
max = v; max = v;
} }
else if ( argI instanceof cArea || argI instanceof cArea3D ){ else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue(); var argArr = argI.getValue();
for( var j = 0; j < argArr.length; j++ ){ for ( var j = 0; j < argArr.length; j++ ) {
if( argArr[j] instanceof cError ) if ( argArr[j] instanceof cError )
return this.value = argArr[j]; return this.value = argArr[j];
var v = argArr[j].tocNumber(); var v = argArr[j].tocNumber();
...@@ -516,43 +516,43 @@ cFormulaFunction.Statistical = { ...@@ -516,43 +516,43 @@ cFormulaFunction.Statistical = {
max = v; max = v;
} }
} }
else if( argI instanceof cError ) else if ( argI instanceof cError )
return this.value = argI; return this.value = argI;
else if ( argI instanceof cString ){ else if ( argI instanceof cString ) {
var v = argI.tocNumber(); var v = argI.tocNumber();
if ( v instanceof cNumber ) if ( v instanceof cNumber )
if ( v.getValue() > max.getValue() ) if ( v.getValue() > max.getValue() )
max = v; max = v;
} }
else if ( argI instanceof cBool || argI instanceof cEmpty ){ else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber(); var v = argI.tocNumber();
if ( v.getValue() > max.getValue() ) if ( v.getValue() > max.getValue() )
max = v; max = v;
} }
else if( argI instanceof cArray ){ else if ( argI instanceof cArray ) {
argI.foreach(function(elem){ argI.foreach( function ( elem ) {
if( elem instanceof cError ){ if ( elem instanceof cError ) {
max = elem; max = elem;
return true; return true;
} }
elem = elem.tocNumber(); elem = elem.tocNumber();
if( elem instanceof cNumber && elem.getValue() > max.getValue() ){ if ( elem instanceof cNumber && elem.getValue() > max.getValue() ) {
max = elem; max = elem;
} }
}) } )
if( max instanceof cError ){ if ( max instanceof cError ) {
return this.value = max; return this.value = max;
} }
} }
else{ else {
if ( argI.getValue() > max.getValue() ) if ( argI.getValue() > max.getValue() )
max = argI; max = argI;
} }
} }
return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber(0) : max ) return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : max )
}; };
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(number1, number2, ...)" args:"(number1, number2, ...)"
...@@ -560,77 +560,77 @@ cFormulaFunction.Statistical = { ...@@ -560,77 +560,77 @@ cFormulaFunction.Statistical = {
} }
return r; return r;
}, },
'MEDIAN' : function(){ 'MEDIAN':function () {
var r = new cBaseFunction("MEDIAN"); var r = new cBaseFunction( "MEDIAN" );
return r; return r;
}, },
'MIN' : function(){ 'MIN':function () {
var r = new cBaseFunction("MIN"); var r = new cBaseFunction( "MIN" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var argI, argIVal, min = new cNumber ( Number.POSITIVE_INFINITY ); var argI, argIVal, min = new cNumber( Number.POSITIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ){ for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue(); argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ){ if ( argI instanceof cRef || argI instanceof cRef3D ) {
if( argIVal instanceof cError ) if ( argIVal instanceof cError )
return this.value = argIVal; return this.value = argIVal;
if( argIVal instanceof cNumber || argIVal instanceof cBool || argIVal instanceof cEmpty){ if ( argIVal instanceof cNumber || argIVal instanceof cBool || argIVal instanceof cEmpty ) {
var v = argIVal.tocNumber(); var v = argIVal.tocNumber();
if ( v.getValue() < min.getValue() ) if ( v.getValue() < min.getValue() )
min = v; min = v;
} }
} }
else if ( argI instanceof cArea || argI instanceof cArea3D ){ else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue(); var argArr = argI.getValue();
for( var j = 0; j < argArr.length; j++ ){ for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty){ if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty ) {
var v = argArr[j].tocNumber(); var v = argArr[j].tocNumber();
if ( v.getValue() < min.getValue() ) if ( v.getValue() < min.getValue() )
min = v; min = v;
continue; continue;
} }
else if ( argArr[j] instanceof cError ){ else if ( argArr[j] instanceof cError ) {
return this.value = argArr[j]; return this.value = argArr[j];
} }
} }
} }
else if( argI instanceof cError ) else if ( argI instanceof cError )
return this.value = argI; return this.value = argI;
else if ( argI instanceof cString ){ else if ( argI instanceof cString ) {
var v = argI.tocNumber(); var v = argI.tocNumber();
if ( v instanceof cNumber ) if ( v instanceof cNumber )
if ( v.getValue() < min.getValue() ) if ( v.getValue() < min.getValue() )
min = v; min = v;
} }
else if ( argI instanceof cBool || argI instanceof cEmpty){ else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber(); var v = argI.tocNumber();
if ( v.getValue() < min.getValue() ) if ( v.getValue() < min.getValue() )
min = v; min = v;
} }
else if( argI instanceof cArray ){ else if ( argI instanceof cArray ) {
argI.foreach(function(elem){ argI.foreach( function ( elem ) {
if( elem instanceof cNumber ){ if ( elem instanceof cNumber ) {
if ( elem.getValue() < min.getValue() ) if ( elem.getValue() < min.getValue() )
min = elem; min = elem;
} }
else if( elem instanceof cError ){ else if ( elem instanceof cError ) {
min = elem; min = elem;
return true; return true;
} }
}) } )
if( min instanceof cError ){ if ( min instanceof cError ) {
return this.value = min; return this.value = min;
} }
} }
else{ else {
if ( argI.getValue() < min.getValue() ) if ( argI.getValue() < min.getValue() )
min = argI; min = argI;
} }
} }
return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber(0) : min ); return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : min );
}; };
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(number1, number2, ...)" args:"(number1, number2, ...)"
...@@ -638,17 +638,17 @@ cFormulaFunction.Statistical = { ...@@ -638,17 +638,17 @@ cFormulaFunction.Statistical = {
} }
return r; return r;
}, },
'MINA' : function(){ 'MINA':function () {
var r = new cBaseFunction("MINA"); var r = new cBaseFunction( "MINA" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var argI, min = new cNumber ( Number.POSITIVE_INFINITY ); var argI, min = new cNumber( Number.POSITIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ){ for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue(); argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ){ if ( argI instanceof cRef || argI instanceof cRef3D ) {
if( argIVal instanceof cError ) if ( argIVal instanceof cError )
return this.value = argIVal; return this.value = argIVal;
var v = argIVal.tocNumber(); var v = argIVal.tocNumber();
...@@ -656,11 +656,11 @@ cFormulaFunction.Statistical = { ...@@ -656,11 +656,11 @@ cFormulaFunction.Statistical = {
if ( v instanceof cNumber && v.getValue() < min.getValue() ) if ( v instanceof cNumber && v.getValue() < min.getValue() )
min = v; min = v;
} }
else if ( argI instanceof cArea || argI instanceof cArea3D ){ else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue(); var argArr = argI.getValue();
for( var j = 0; j < argArr.length; j++ ){ for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cError ){ if ( argArr[j] instanceof cError ) {
return this.value = argArr[j]; return this.value = argArr[j];
} }
...@@ -670,44 +670,44 @@ cFormulaFunction.Statistical = { ...@@ -670,44 +670,44 @@ cFormulaFunction.Statistical = {
min = v; min = v;
} }
} }
else if( argI instanceof cError ) else if ( argI instanceof cError )
return this.value = argI; return this.value = argI;
else if ( argI instanceof cString ){ else if ( argI instanceof cString ) {
var v = argI.tocNumber(); var v = argI.tocNumber();
if ( v instanceof cNumber ) if ( v instanceof cNumber )
if ( v.getValue() < min.getValue() ) if ( v.getValue() < min.getValue() )
min = v; min = v;
} }
else if ( argI instanceof cBool || argI instanceof cEmpty ){ else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber(); var v = argI.tocNumber();
if ( v.getValue() < min.getValue() ) if ( v.getValue() < min.getValue() )
min = v; min = v;
} }
else if( argI instanceof cArray ){ else if ( argI instanceof cArray ) {
argI.foreach(function(elem){ argI.foreach( function ( elem ) {
if( elem instanceof cError ){ if ( elem instanceof cError ) {
min = elem; min = elem;
return true; return true;
} }
elem = elem.tocNumber(); elem = elem.tocNumber();
if( elem instanceof cNumber && elem.getValue() < min.getValue() ){ if ( elem instanceof cNumber && elem.getValue() < min.getValue() ) {
min = elem; min = elem;
} }
}) } )
if( min instanceof cError ){ if ( min instanceof cError ) {
return this.value = min; return this.value = min;
} }
} }
else{ else {
if ( argI.getValue() < min.getValue() ) if ( argI.getValue() < min.getValue() )
min = argI; min = argI;
} }
} }
return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber(0) : min ); return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : min );
}; };
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(number1, number2, ...)" args:"(number1, number2, ...)"
...@@ -715,202 +715,203 @@ cFormulaFunction.Statistical = { ...@@ -715,202 +715,203 @@ cFormulaFunction.Statistical = {
} }
return r; return r;
}, },
'MODE' : function(){ 'MODE':function () {
var r = new cBaseFunction("MODE"); var r = new cBaseFunction( "MODE" );
return r; return r;
}, },
'NEGBINOMDIST' : function(){ 'NEGBINOMDIST':function () {
var r = new cBaseFunction("NEGBINOMDIST"); var r = new cBaseFunction( "NEGBINOMDIST" );
return r; return r;
}, },
'NORMDIST' : function(){ 'NORMDIST':function () {
var r = new cBaseFunction("NORMDIST"); var r = new cBaseFunction( "NORMDIST" );
return r; return r;
}, },
'NORMINV' : function(){ 'NORMINV':function () {
var r = new cBaseFunction("NORMINV"); var r = new cBaseFunction( "NORMINV" );
return r; return r;
}, },
'NORMSDIST' : function(){ 'NORMSDIST':function () {
var r = new cBaseFunction("NORMSDIST"); var r = new cBaseFunction( "NORMSDIST" );
return r; return r;
}, },
'NORMSINV' : function(){ 'NORMSINV':function () {
var r = new cBaseFunction("NORMSINV"); var r = new cBaseFunction( "NORMSINV" );
return r; return r;
}, },
'PEARSON' : function(){ 'PEARSON':function () {
var r = new cBaseFunction("PEARSON"); var r = new cBaseFunction( "PEARSON" );
return r; return r;
}, },
'PERCENTILE' : function(){ 'PERCENTILE':function () {
var r = new cBaseFunction("PERCENTILE"); var r = new cBaseFunction( "PERCENTILE" );
return r; return r;
}, },
'PERCENTRANK' : function(){ 'PERCENTRANK':function () {
var r = new cBaseFunction("PERCENTRANK"); var r = new cBaseFunction( "PERCENTRANK" );
return r; return r;
}, },
'PERMUT' : function(){ 'PERMUT':function () {
var r = new cBaseFunction("PERMUT"); var r = new cBaseFunction( "PERMUT" );
return r; return r;
}, },
'POISSON' : function(){ 'POISSON':function () {
var r = new cBaseFunction("POISSON"); var r = new cBaseFunction( "POISSON" );
return r; return r;
}, },
'PROB' : function(){ 'PROB':function () {
var r = new cBaseFunction("PROB"); var r = new cBaseFunction( "PROB" );
return r; return r;
}, },
'QUARTILE' : function(){ 'QUARTILE':function () {
var r = new cBaseFunction("QUARTILE"); var r = new cBaseFunction( "QUARTILE" );
return r; return r;
}, },
'RANK' : function(){ 'RANK':function () {
var r = new cBaseFunction("RANK"); var r = new cBaseFunction( "RANK" );
return r; return r;
}, },
'RSQ' : function(){ 'RSQ':function () {
var r = new cBaseFunction("RSQ"); var r = new cBaseFunction( "RSQ" );
return r; return r;
}, },
'SKEW' : function(){ 'SKEW':function () {
var r = new cBaseFunction("SKEW"); var r = new cBaseFunction( "SKEW" );
return r; return r;
}, },
'SLOPE' : function(){ 'SLOPE':function () {
var r = new cBaseFunction("SLOPE"); var r = new cBaseFunction( "SLOPE" );
return r; return r;
}, },
'SMALL' : function(){ 'SMALL':function () {
var r = new cBaseFunction("SMALL"); var r = new cBaseFunction( "SMALL" );
return r; return r;
}, },
'STANDARDIZE' : function(){ 'STANDARDIZE':function () {
var r = new cBaseFunction("STANDARDIZE"); var r = new cBaseFunction( "STANDARDIZE" );
return r; return r;
}, },
'STDEV' : function(){ 'STDEV':function () {
var r = new cBaseFunction("STDEV"); var r = new cBaseFunction( "STDEV" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var count = 0, sum = new cNumber(0), member = []; var count = 0, sum = new cNumber( 0 ), member = [];
for ( var i = 0; i < arg.length; i++){ for ( var i = 0; i < arg.length; i++ ) {
var _arg = arg[i]; var _arg = arg[i];
if( _arg instanceof cRef || _arg instanceof cRef3D){ if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue(); var _argV = _arg.getValue();
if ( _argV instanceof cNumber ){ if ( _argV instanceof cNumber ) {
member.push(_argV); member.push( _argV );
sum = _func[sum.type][_argV.type](sum,_argV,"+"); sum = _func[sum.type][_argV.type]( sum, _argV, "+" );
count++; count++;
} }
} }
else if ( _arg instanceof cArea || _arg instanceof cArea3D){ else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue(); var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++){ for ( var j = 0; j < _argAreaValue.length; j++ ) {
var __arg = _argAreaValue[j]; var __arg = _argAreaValue[j];
if ( __arg instanceof cNumber ){ if ( __arg instanceof cNumber ) {
member.push(__arg); member.push( __arg );
sum = _func[sum.type][__arg.type](sum,__arg,"+"); sum = _func[sum.type][__arg.type]( sum, __arg, "+" );
count++; count++;
} }
} }
} }
else if( _arg instanceof cArray ){ else if ( _arg instanceof cArray ) {
_arg.foreach(function(elem){ _arg.foreach( function ( elem ) {
var e = elem.tocNumber(); var e = elem.tocNumber();
if( e instanceof cNumber ){ if ( e instanceof cNumber ) {
member.push(e); member.push( e );
sum = _func[sum.type][e.type](sum,e,"+"); sum = _func[sum.type][e.type]( sum, e, "+" );
count++; count++;
} }
}) } )
} }
else{ else {
_arg = _arg.tocNumber(); _arg = _arg.tocNumber();
if( _arg instanceof cNumber ){ if ( _arg instanceof cNumber ) {
member.push(_arg); member.push( _arg );
sum = _func[sum.type][_arg.type](sum,_arg,"+"); sum = _func[sum.type][_arg.type]( sum, _arg, "+" );
count++; count++;
} }
} }
} }
var average = sum.getValue() / count, res = 0, av; var average = sum.getValue() / count, res = 0, av;
for( var i = 0; i < member.length; i++ ){ for ( var i = 0; i < member.length; i++ ) {
av = member[i] - average; av = member[i] - average;
res += av * av; res += av * av;
} }
return this.value = new cNumber ( Math.sqrt(res / (count-1)) );STDEV(123,134,143,173,112,109) return this.value = new cNumber( Math.sqrt( res / (count - 1) ) );
STDEV( 123, 134, 143, 173, 112, 109 )
}; };
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( argument-list )" args:"( argument-list )"
}; };
} }
r.setFormat(r.formatType.noneFormat); r.setFormat( r.formatType.noneFormat );
return r; return r;
}, },
'STDEVA' : function(){ 'STDEVA':function () {
var r = new cBaseFunction("STDEVA"); var r = new cBaseFunction( "STDEVA" );
return r; return r;
}, },
'STDEVP' : function(){ 'STDEVP':function () {
var r = new cBaseFunction("STDEVP"); var r = new cBaseFunction( "STDEVP" );
return r; return r;
}, },
'STDEVPA' : function(){ 'STDEVPA':function () {
var r = new cBaseFunction("STDEVPA"); var r = new cBaseFunction( "STDEVPA" );
return r; return r;
}, },
'STEYX' : function(){ 'STEYX':function () {
var r = new cBaseFunction("STEYX"); var r = new cBaseFunction( "STEYX" );
return r; return r;
}, },
'TDIST' : function(){ 'TDIST':function () {
var r = new cBaseFunction("TDIST"); var r = new cBaseFunction( "TDIST" );
return r; return r;
}, },
'TINV' : function(){ 'TINV':function () {
var r = new cBaseFunction("TINV"); var r = new cBaseFunction( "TINV" );
return r; return r;
}, },
'TREND' : function(){ 'TREND':function () {
var r = new cBaseFunction("TREND"); var r = new cBaseFunction( "TREND" );
return r; return r;
}, },
'TRIMMEAN' : function(){ 'TRIMMEAN':function () {
var r = new cBaseFunction("TRIMMEAN"); var r = new cBaseFunction( "TRIMMEAN" );
return r; return r;
}, },
'TTEST' : function(){ 'TTEST':function () {
var r = new cBaseFunction("TTEST"); var r = new cBaseFunction( "TTEST" );
return r; return r;
}, },
'VAR' : function(){ 'VAR':function () {
var r = new cBaseFunction("VAR"); var r = new cBaseFunction( "VAR" );
return r; return r;
}, },
'VARA' : function(){ 'VARA':function () {
var r = new cBaseFunction("VARA"); var r = new cBaseFunction( "VARA" );
return r; return r;
}, },
'VARP' : function(){ 'VARP':function () {
var r = new cBaseFunction("VARP"); var r = new cBaseFunction( "VARP" );
return r; return r;
}, },
'VARPA' : function(){ 'VARPA':function () {
var r = new cBaseFunction("VARPA"); var r = new cBaseFunction( "VARPA" );
return r; return r;
}, },
'WEIBULL' : function(){ 'WEIBULL':function () {
var r = new cBaseFunction("WEIBULL"); var r = new cBaseFunction( "WEIBULL" );
return r; return r;
}, },
'ZTEST' : function(){ 'ZTEST':function () {
var r = new cBaseFunction("ZTEST"); var r = new cBaseFunction( "ZTEST" );
return r; return r;
} }
} }
\ No newline at end of file
...@@ -6,49 +6,49 @@ ...@@ -6,49 +6,49 @@
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
cFormulaFunction.TextAndData = { cFormulaFunction.TextAndData = {
'groupName' : "TextAndData", 'groupName':"TextAndData",
'ASC' : function(){ 'ASC':function () {
var r = new cBaseFunction("ASC"); var r = new cBaseFunction( "ASC" );
return r; return r;
}, },
'BAHTTEXT' : function(){ 'BAHTTEXT':function () {
var r = new cBaseFunction("BAHTTEXT"); var r = new cBaseFunction( "BAHTTEXT" );
return r; return r;
}, },
'CHAR' : function(){ 'CHAR':function () {
var r = new cBaseFunction("CHAR"); var r = new cBaseFunction( "CHAR" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
else if( arg0 instanceof cArray){ else if ( arg0 instanceof cArray ) {
var ret = new cArray(); var ret = new cArray();
arg0.foreach(function(elem,r,c){ arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocNumber(); var _elem = elem.tocNumber();
if(!ret.array[r]) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
if( _elem instanceof cError ) if ( _elem instanceof cError )
ret.addElement(_elem); ret.addElement( _elem );
else else
ret.addElement( new cString( String.fromCharCode(_elem.getValue()) ) ); ret.addElement( new cString( String.fromCharCode( _elem.getValue() ) ) );
}) } )
return this.value = ret; return this.value = ret;
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
if( arg0 instanceof cError ){ if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
return this.value = new cString( String.fromCharCode(arg0.getValue()) ); return this.value = new cString( String.fromCharCode( arg0.getValue() ) );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( number )" args:"( number )"
...@@ -56,32 +56,32 @@ cFormulaFunction.TextAndData = { ...@@ -56,32 +56,32 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'CLEAN' : function(){ 'CLEAN':function () {
var r = new cBaseFunction("CLEAN"); var r = new cBaseFunction( "CLEAN" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if( arg0 instanceof cArray ){ if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
var v = arg0.getValue(), l = v.length, res = ""; var v = arg0.getValue(), l = v.length, res = "";
for( var i = 0; i < l; i++){ for ( var i = 0; i < l; i++ ) {
if( v.charCodeAt(i) > 0x1f ) if ( v.charCodeAt( i ) > 0x1f )
res+=v[i]; res += v[i];
} }
return this.value = new cString( res ); return this.value = new cString( res );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string )" args:"( string )"
...@@ -89,40 +89,40 @@ cFormulaFunction.TextAndData = { ...@@ -89,40 +89,40 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'CODE' : function(){ 'CODE':function () {
var r = new cBaseFunction("CODE"); var r = new cBaseFunction( "CODE" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if( arg0 instanceof cArray){ else if ( arg0 instanceof cArray ) {
var ret = new cArray(); var ret = new cArray();
arg0.foreach(function(elem,r,c){ arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocString(); var _elem = elem.tocString();
if(!ret.array[r]) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
if( _elem instanceof cError ) if ( _elem instanceof cError )
ret.addElement(_elem); ret.addElement( _elem );
else else
ret.addElement(new cNumber( _elem.toString().charCodeAt() )); ret.addElement( new cNumber( _elem.toString().charCodeAt() ) );
}) } )
return this.value = ret; return this.value = ret;
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if( arg0 instanceof cError ){ if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
return this.value = new cNumber( arg0.toString().charCodeAt() ); return this.value = new cNumber( arg0.toString().charCodeAt() );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string )" args:"( string )"
...@@ -130,32 +130,32 @@ cFormulaFunction.TextAndData = { ...@@ -130,32 +130,32 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'CONCATENATE' : function(){ 'CONCATENATE':function () {
var r = new cBaseFunction("CONCATENATE"); var r = new cBaseFunction( "CONCATENATE" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(255); r.setArgumentsMax( 255 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = new cString(""), argI; var arg0 = new cString( "" ), argI;
for(var i = 0; i < this.argumentsCurrent; i++){ for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i]; argI = arg[i];
if( argI instanceof cArea || argI instanceof cArea3D ){ if ( argI instanceof cArea || argI instanceof cArea3D ) {
argI = argI.cross(arguments[1].first); argI = argI.cross( arguments[1].first );
} }
argI = argI.tocString(); argI = argI.tocString();
if (argI instanceof cError) { if ( argI instanceof cError ) {
return this.value = argI; return this.value = argI;
} }
else if( argI instanceof cArray ){ else if ( argI instanceof cArray ) {
argI.foreach(function(elem){ argI.foreach( function ( elem ) {
if( elem instanceof cError ){ if ( elem instanceof cError ) {
arg0 = elem; arg0 = elem;
return true; return true;
} }
arg0 = new cString( arg0.toString().concat( elem.toString() ) ); arg0 = new cString( arg0.toString().concat( elem.toString() ) );
}) } )
if( arg0 instanceof cError ){ if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
} }
...@@ -164,7 +164,7 @@ cFormulaFunction.TextAndData = { ...@@ -164,7 +164,7 @@ cFormulaFunction.TextAndData = {
} }
return this.value = arg0; return this.value = arg0;
}; };
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(text1, text2, ...)" args:"(text1, text2, ...)"
...@@ -172,18 +172,18 @@ cFormulaFunction.TextAndData = { ...@@ -172,18 +172,18 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'DOLLAR' : function(){ 'DOLLAR':function () {
var r = new cBaseFunction("DOLLAR"); var r = new cBaseFunction( "DOLLAR" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(2); r.setArgumentsMax( 2 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var res = cFormulaFunction.TextAndData["FIXED"]().Calculate(arg); var res = cFormulaFunction.TextAndData["FIXED"]().Calculate( arg );
if( res instanceof cError ) if ( res instanceof cError )
return this.value = res; return this.value = res;
return this.value = new cString("$"+res.getValue()); return this.value = new cString( "$" + res.getValue() );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( number [ , num-decimal ] )" args:"( number [ , num-decimal ] )"
...@@ -191,31 +191,31 @@ cFormulaFunction.TextAndData = { ...@@ -191,31 +191,31 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'EXACT' : function(){ 'EXACT':function () {
var r = new cBaseFunction("EXACT"); var r = new cBaseFunction( "EXACT" );
r.setArgumentsMin(2); r.setArgumentsMin( 2 );
r.setArgumentsMax(2); r.setArgumentsMax( 2 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if( arg0 instanceof cArray && arg1 instanceof cArray ){ if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if( arg0 instanceof cArray ){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if( arg1 instanceof cArray ){ else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
...@@ -224,7 +224,7 @@ cFormulaFunction.TextAndData = { ...@@ -224,7 +224,7 @@ cFormulaFunction.TextAndData = {
var arg0val = arg0.getValue(), arg1val = arg1.getValue(); var arg0val = arg0.getValue(), arg1val = arg1.getValue();
return this.value = new cBool( arg0val === arg1val ); return this.value = new cBool( arg0val === arg1val );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(text1, text2)" args:"(text1, text2)"
...@@ -232,44 +232,44 @@ cFormulaFunction.TextAndData = { ...@@ -232,44 +232,44 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'FIND' : function(){ 'FIND':function () {
var r = new cBaseFunction("FIND"); var r = new cBaseFunction( "FIND" );
r.setArgumentsMin(2); r.setArgumentsMin( 2 );
r.setArgumentsMax(3); r.setArgumentsMax( 3 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = this.getArguments() == 3 ? arg[2] : null, res, str, searchStr, pos = -1; var arg0 = arg[0], arg1 = arg[1], arg2 = this.getArguments() == 3 ? arg[2] : null, res, str, searchStr, pos = -1;
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if( arg2 !== null ){ if ( arg2 !== null ) {
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){ if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross(arguments[1].first); arg2 = arg2.cross( arguments[1].first );
} }
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if( arg2 instanceof cArray ){ if ( arg2 instanceof cArray ) {
arg2 = arg1.getElementRowCol(0,0); arg2 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof cError ) return this.value = arg2; if ( arg2 instanceof cError ) return this.value = arg2;
pos = arg2.getValue(); pos = arg2.getValue();
pos = pos > 0 ? pos-1 : pos; pos = pos > 0 ? pos - 1 : pos;
} }
if( arg0 instanceof cArray ){ if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if( arg1 instanceof cArray ){ if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
...@@ -278,26 +278,26 @@ cFormulaFunction.TextAndData = { ...@@ -278,26 +278,26 @@ cFormulaFunction.TextAndData = {
str = arg1.getValue(); str = arg1.getValue();
searchStr = arg0.getValue(); searchStr = arg0.getValue();
if( arg2 ){ if ( arg2 ) {
if( pos > str.length || pos < 0 ) if ( pos > str.length || pos < 0 )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
str = str.substring(pos); str = str.substring( pos );
res = str.search( searchStr ); res = str.search( searchStr );
if( res >= 0 ) if ( res >= 0 )
res += pos; res += pos;
} }
else else
res = str.search( searchStr ); res = str.search( searchStr );
if( res < 0 ) if ( res < 0 )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new cNumber( res+1 ); return this.value = new cNumber( res + 1 );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string-1 , string-2 [ , start-pos ] )" args:"( string-1 , string-2 [ , start-pos ] )"
...@@ -305,170 +305,175 @@ cFormulaFunction.TextAndData = { ...@@ -305,170 +305,175 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'FINDB' : function(){ 'FINDB':function () {
var r = cFormulaFunction.TextAndData["FIND"]() var r = cFormulaFunction.TextAndData["FIND"]()
r.setName("FINDB"); r.setName( "FINDB" );
return r; return r;
}, },
'FIXED' : function(){ 'FIXED':function () {
var r = new cBaseFunction("FIXED"); var r = new cBaseFunction( "FIXED" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(3); r.setArgumentsMax( 3 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
function SignZeroPositive(number){ function SignZeroPositive( number ) {
return number < 0 ? -1 : 1; return number < 0 ? -1 : 1;
} }
function truncate(n) {
return Math[n > 0 ? "floor" : "ceil"](n); function truncate( n ) {
return Math[n > 0 ? "floor" : "ceil"]( n );
} }
function sign(n){
function sign( n ) {
return n == 0 ? 0 : n < 0 ? -1 : 1 return n == 0 ? 0 : n < 0 ? -1 : 1
} }
function Floor(number, significance){
function Floor( number, significance ) {
var quotient = number / significance; var quotient = number / significance;
if (quotient == 0){ if ( quotient == 0 ) {
return 0; return 0;
} }
var nolpiat = 5 * sign(quotient) * Math.pow(10, Math.floor( Math.log ( Math.abs(quotient) ) / Math.log ( 10 ) ) - cExcelSignificantDigits); var nolpiat = 5 * sign( quotient ) * Math.pow( 10, Math.floor( Math.log( Math.abs( quotient ) ) / Math.log( 10 ) ) - cExcelSignificantDigits );
return truncate(quotient + nolpiat) * significance; return truncate( quotient + nolpiat ) * significance;
} }
function roundHelper(number,num_digits){
if(num_digits > cExcelMaxExponent){ function roundHelper( number, num_digits ) {
if (Math.abs(number) < 1 || num_digits < 1e10) // The values are obtained experimentally if ( num_digits > cExcelMaxExponent ) {
if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally
{ {
return new cNumber(number); return new cNumber( number );
} }
return new cNumber(0); return new cNumber( 0 );
} }
else if (num_digits < cExcelMinExponent) else if ( num_digits < cExcelMinExponent ) {
{ if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally
if (Math.abs(number) < 0.01) // The values are obtained experimentally
{ {
return new cNumber(number); return new cNumber( number );
} }
return new cNumber(0); return new cNumber( 0 );
} }
var significance = SignZeroPositive(number) * Math.pow(10, -truncate(num_digits)); var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) );
number += significance / 2; number += significance / 2;
if ( number/significance == Infinity){ if ( number / significance == Infinity ) {
return new cNumber( number ); return new cNumber( number );
} }
return new cNumber( Floor(number, significance) ); return new cNumber( Floor( number, significance ) );
} }
function toFix(str,skip){
function toFix( str, skip ) {
var res, _int, _dec, _tmp = "" var res, _int, _dec, _tmp = ""
if(skip) if ( skip )
return str; return str;
res = str.split("."); res = str.split( "." );
_int = res[0]; _int = res[0];
if( res.length == 2) if ( res.length == 2 )
_dec = res[1]; _dec = res[1];
_int = _int.split("").reverse().join("").match(/([^]{1,3})/ig) _int = _int.split( "" ).reverse().join( "" ).match( /([^]{1,3})/ig )
for( var i = _int.length-1; i >= 0; i--){ for ( var i = _int.length - 1; i >= 0; i-- ) {
_tmp += _int[i].split("").reverse().join(""); _tmp += _int[i].split( "" ).reverse().join( "" );
if( i != 0 ) if ( i != 0 )
_tmp += ","; _tmp += ",";
} }
if( undefined != _dec) if ( undefined != _dec )
while( _dec.length < arg1.getValue() ) _dec+="0"; while ( _dec.length < arg1.getValue() ) _dec += "0";
return "" + _tmp + ( res.length == 2 ? "."+_dec+"" : ""); return "" + _tmp + ( res.length == 2 ? "." + _dec + "" : "");
} }
var arg0 = arg[0], var arg0 = arg[0],
arg1 = arg[1] ? arg[1] : new cNumber(2), arg1 = arg[1] ? arg[1] : new cNumber( 2 ),
arg2 = arg[2] ? arg[2] : new cBool(false); arg2 = arg[2] ? arg[2] : new cBool( false );
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first); arg1 = arg1.cross( arguments[1].first );
} }
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){ if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross(arguments[1].first); arg2 = arg2.cross( arguments[1].first );
} }
if( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if( arg2 instanceof cError ) return this.value = arg2; if ( arg2 instanceof cError ) return this.value = arg2;
if( arg0 instanceof cRef || arg0 instanceof cRef3D ){ if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
if(arg0 instanceof cError) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
else if(arg0 instanceof cString) return this.value = new cError(cErrorType.wrong_value_type); else if ( arg0 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
} }
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
if( arg1 instanceof cRef || arg1 instanceof cRef3D ){ if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
if(arg1 instanceof cError) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
else if(arg1 instanceof cString) return this.value = new cError(cErrorType.wrong_value_type); else if ( arg1 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
} }
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
if( arg0 instanceof cArray && arg1 instanceof cArray ){ if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
if( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ){ if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) {
return this.value = new cError( cErrorType.not_available ); return this.value = new cError( cErrorType.not_available );
} }
else{ else {
arg0.foreach(function(elem,r,c){ arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
b = arg1.getElementRowCol(r,c); b = arg1.getElementRowCol( r, c );
if( a instanceof cNumber && b instanceof cNumber ){ if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix(res.toString(),arg2.toBool()); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
}) } )
return this.value = arg0; return this.value = arg0;
} }
} }
else if( arg0 instanceof cArray ){ else if ( arg0 instanceof cArray ) {
arg0.foreach(function(elem,r,c){ arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
b = arg1; b = arg1;
if( a instanceof cNumber && b instanceof cNumber ){ if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix(res.toString(),arg2.toBool()); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
}) } )
return this.value = arg0; return this.value = arg0;
} }
else if( arg1 instanceof cArray ){ else if ( arg1 instanceof cArray ) {
arg1.foreach(function(elem,r,c){ arg1.foreach( function ( elem, r, c ) {
var a = arg0; var a = arg0;
b = elem; b = elem;
if( a instanceof cNumber && b instanceof cNumber ){ if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix(res.toString(),arg2.toBool()); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
}) } )
return this.value = arg1; return this.value = arg1;
} }
var number = arg0.getValue(), num_digits = arg1.getValue(); var number = arg0.getValue(), num_digits = arg1.getValue();
return this.value = new cString(toFix(roundHelper(number,num_digits).toString(), arg2.toBool())); return this.value = new cString( toFix( roundHelper( number, num_digits ).toString(), arg2.toBool() ) );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( number [ , [ num-decimal ] [ , suppress-commas-flag ] ] )" args:"( number [ , [ num-decimal ] [ , suppress-commas-flag ] ] )"
...@@ -476,46 +481,46 @@ cFormulaFunction.TextAndData = { ...@@ -476,46 +481,46 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'JIS' : function(){ 'JIS':function () {
var r = new cBaseFunction("JIS"); var r = new cBaseFunction( "JIS" );
return r; return r;
}, },
'LEFT' : function(){ 'LEFT':function () {
var r = new cBaseFunction("LEFT"); var r = new cBaseFunction( "LEFT" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(2); r.setArgumentsMax( 2 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber(1) : arg[1]; var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if( arg0 instanceof cArray && arg1 instanceof cArray ){ if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if( arg0 instanceof cArray ){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if( arg1 instanceof cArray ){ else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new cString( arg0.getValue().substring(0, arg1.getValue()) ) return this.value = new cString( arg0.getValue().substring( 0, arg1.getValue() ) )
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string [ , number-chars ] )" args:"( string [ , number-chars ] )"
...@@ -523,25 +528,25 @@ cFormulaFunction.TextAndData = { ...@@ -523,25 +528,25 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'LEFTB' : function(){ 'LEFTB':function () {
var r = cFormulaFunction.TextAndData["LEFT"]() var r = cFormulaFunction.TextAndData["LEFT"]()
r.setName("LEFTB"); r.setName( "LEFTB" );
return r; return r;
}, },
'LEN' : function(){ 'LEN':function () {
var r = new cBaseFunction("LEN"); var r = new cBaseFunction( "LEN" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if( arg0 instanceof cArray ){ if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
...@@ -549,7 +554,7 @@ cFormulaFunction.TextAndData = { ...@@ -549,7 +554,7 @@ cFormulaFunction.TextAndData = {
return this.value = new cNumber( arg0.getValue().length ) return this.value = new cNumber( arg0.getValue().length )
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string )" args:"( string )"
...@@ -557,30 +562,30 @@ cFormulaFunction.TextAndData = { ...@@ -557,30 +562,30 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'LENB' : function(){ 'LENB':function () {
var r = cFormulaFunction.TextAndData["LEN"](); var r = cFormulaFunction.TextAndData["LEN"]();
r.setName("LENB"); r.setName( "LENB" );
return r; return r;
}, },
'LOWER' : function(){ 'LOWER':function () {
var r = new cBaseFunction("LOWER"); var r = new cBaseFunction( "LOWER" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ) if ( arg0 instanceof cArea || arg0 instanceof cArea3D )
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if( arg0 instanceof cArray ) if ( arg0 instanceof cArray )
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
if( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
return this.value = new cString( arg0.getValue().toLowerCase() ); return this.value = new cString( arg0.getValue().toLowerCase() );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(text)" args:"(text)"
...@@ -588,54 +593,54 @@ cFormulaFunction.TextAndData = { ...@@ -588,54 +593,54 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'MID' : function(){ 'MID':function () {
var r = new cBaseFunction("MID"); var r = new cBaseFunction( "MID" );
r.setArgumentsMin(3); r.setArgumentsMin( 3 );
r.setArgumentsMax(3); r.setArgumentsMax( 3 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first); arg1 = arg1.cross( arguments[1].first );
} }
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){ if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross(arguments[1].first); arg2 = arg2.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if( arg0 instanceof cArray ){ if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if( arg1 instanceof cArray ){ if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if( arg2 instanceof cArray ){ if ( arg2 instanceof cArray ) {
arg2 = arg2.getElementRowCol(0,0); arg2 = arg2.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2; if ( arg2 instanceof cError ) return this.value = arg2;
if( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
if( arg2.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg2.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
var l = arg0.getValue().length; var l = arg0.getValue().length;
if( arg1.getValue() > l ) if ( arg1.getValue() > l )
return this.value = new cString(""); return this.value = new cString( "" );
/* if( arg1.getValue() < l ) /* if( arg1.getValue() < l )
return this.value = arg0; */ return this.value = arg0; */
return this.value = new cString( arg0.getValue().substr( arg1.getValue() == 0 ? 0 : arg1.getValue()-1, arg2.getValue() ) ) return this.value = new cString( arg0.getValue().substr( arg1.getValue() == 0 ? 0 : arg1.getValue() - 1, arg2.getValue() ) )
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string , start-pos , number-chars )" args:"( string , start-pos , number-chars )"
...@@ -643,32 +648,32 @@ cFormulaFunction.TextAndData = { ...@@ -643,32 +648,32 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'MIDB' : function(){ 'MIDB':function () {
var r = cFormulaFunction.TextAndData["MID"](); var r = cFormulaFunction.TextAndData["MID"]();
r.setName("MIDB"); r.setName( "MIDB" );
return r; return r;
}, },
'PHONETIC' : function(){ 'PHONETIC':function () {
var r = new cBaseFunction("PHONETIC"); var r = new cBaseFunction( "PHONETIC" );
return r; return r;
}, },
'PROPER' : function(){ 'PROPER':function () {
var r = new cBaseFunction("PROPER"); var r = new cBaseFunction( "PROPER" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var reg_PROPER = new RegExp("[-#$+*/^&%<\\[\\]='?_\\@!~`\">: ;.\\)\\(,]|\\d|\\s"), arg0 = arg[0]; var reg_PROPER = new RegExp( "[-#$+*/^&%<\\[\\]='?_\\@!~`\">: ;.\\)\\(,]|\\d|\\s" ), arg0 = arg[0];
function proper(str){ function proper( str ) {
var canUpper = true, retStr = "", regTest; var canUpper = true, retStr = "", regTest;
for( var i=0; i< str.length; i++ ){ for ( var i = 0; i < str.length; i++ ) {
regTest = reg_PROPER.test(str[i]); regTest = reg_PROPER.test( str[i] );
if( regTest ){ if ( regTest ) {
canUpper = true; canUpper = true;
} }
else{ else {
if( canUpper ){ if ( canUpper ) {
retStr += str[i].toUpperCase(); retStr += str[i].toUpperCase();
canUpper = false; canUpper = false;
continue; continue;
...@@ -681,33 +686,33 @@ cFormulaFunction.TextAndData = { ...@@ -681,33 +686,33 @@ cFormulaFunction.TextAndData = {
return retStr; return retStr;
} }
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if( arg0 instanceof cArray){ else if ( arg0 instanceof cArray ) {
var ret = new cArray(); var ret = new cArray();
arg0.foreach(function(elem,r,c){ arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocString(); var _elem = elem.tocString();
if(!ret.array[r]) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
if( _elem instanceof cError ) if ( _elem instanceof cError )
ret.addElement(_elem); ret.addElement( _elem );
else else
ret.addElement(new cString( proper(_elem.toString()) )); ret.addElement( new cString( proper( _elem.toString() ) ) );
}) } )
return this.value = ret; return this.value = ret;
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if( arg0 instanceof cError ){ if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
return this.value = new cString( proper(arg0.toString() ) ); return this.value = new cString( proper( arg0.toString() ) );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string )" args:"( string )"
...@@ -715,74 +720,74 @@ cFormulaFunction.TextAndData = { ...@@ -715,74 +720,74 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'REPLACE' : function(){ 'REPLACE':function () {
var r = new cBaseFunction("REPLACE"); var r = new cBaseFunction( "REPLACE" );
r.setArgumentsMin(4); r.setArgumentsMin( 4 );
r.setArgumentsMax(4); r.setArgumentsMax( 4 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if( arg0 instanceof cArray){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement(0).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first).tocNumber(); arg1 = arg1.cross( arguments[1].first ).tocNumber();
} }
else if( arg1 instanceof cArray){ else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement(0).tocNumber(); arg1 = arg1.getElement( 0 ).tocNumber();
} }
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){ if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross(arguments[1].first).tocNumber(); arg2 = arg2.cross( arguments[1].first ).tocNumber();
} }
else if( arg2 instanceof cArray){ else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement(0).tocNumber(); arg2 = arg2.getElement( 0 ).tocNumber();
} }
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if( arg3 instanceof cArea || arg3 instanceof cArea3D ){ if ( arg3 instanceof cArea || arg3 instanceof cArea3D ) {
arg3 = arg3.cross(arguments[1].first).tocString(); arg3 = arg3.cross( arguments[1].first ).tocString();
} }
else if( arg3 instanceof cArray){ else if ( arg3 instanceof cArray ) {
arg3 = arg3.getElement(0).tocString(); arg3 = arg3.getElement( 0 ).tocString();
} }
arg3 = arg3.tocString(); arg3 = arg3.tocString();
if( arg0 instanceof cError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if( arg1 instanceof cError ) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
if( arg2 instanceof cError ) if ( arg2 instanceof cError )
return this.value = arg2; return this.value = arg2;
if( arg3 instanceof cError ) if ( arg3 instanceof cError )
return this.value = arg3; return this.value = arg3;
if( arg1.getValue() < 1 || arg2.getValue() < 0 ){ if ( arg1.getValue() < 1 || arg2.getValue() < 0 ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
var string1 = arg0.getValue(), string2 = arg3.getValue(), res = ""; var string1 = arg0.getValue(), string2 = arg3.getValue(), res = "";
string1 = string1.split(""); string1 = string1.split( "" );
string1.splice(arg1.getValue()-1,arg2.getValue(),string2); string1.splice( arg1.getValue() - 1, arg2.getValue(), string2 );
for( var i = 0; i < string1.length; i++){ for ( var i = 0; i < string1.length; i++ ) {
res += string1[i]; res += string1[i];
} }
return this.value = new cString(res); return this.value = new cString( res );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string-1, start-pos, number-chars, string-2 )" args:"( string-1, start-pos, number-chars, string-2 )"
...@@ -790,61 +795,61 @@ cFormulaFunction.TextAndData = { ...@@ -790,61 +795,61 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'REPLACEB' : function(){ 'REPLACEB':function () {
var r = cFormulaFunction.TextAndData["REPLACE"](); var r = cFormulaFunction.TextAndData["REPLACE"]();
r.setName("REPLACEB"); r.setName( "REPLACEB" );
return r; return r;
}, },
'REPT' : function(){ 'REPT':function () {
var r = new cBaseFunction("REPT"); var r = new cBaseFunction( "REPT" );
r.setArgumentsMin(2); r.setArgumentsMin( 2 );
r.setArgumentsMax(2); r.setArgumentsMax( 2 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], res = ""; var arg0 = arg[0], arg1 = arg[1], res = "";
if( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if( arg0 instanceof cArray && arg1 instanceof cArray ){ if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if( arg0 instanceof cArray ){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if( arg1 instanceof cArray ){ else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if (arg0 instanceof cError) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first).tocNumber(); arg1 = arg1.cross( arguments[1].first ).tocNumber();
} }
else if( arg1 instanceof cRef || arg1 instanceof cRef3D ){ else if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
} }
if(arg1 instanceof cError) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
else if(arg1 instanceof cString) else if ( arg1 instanceof cString )
return this.value = new cError(cErrorType.wrong_value_type); return this.value = new cError( cErrorType.wrong_value_type );
else else
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if( arg1.getValue() < 0 ) return this.value = new cError(cErrorType.wrong_value_type); if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
for ( var i = 0; i < arg1.getValue(); i++){ for ( var i = 0; i < arg1.getValue(); i++ ) {
res = res.concat(arg0.getValue()); res = res.concat( arg0.getValue() );
} }
return this.value = new cString( res ); return this.value = new cString( res );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(text, number_of_times)" args:"(text, number_of_times)"
...@@ -852,42 +857,42 @@ cFormulaFunction.TextAndData = { ...@@ -852,42 +857,42 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'RIGHT' : function(){ 'RIGHT':function () {
var r = new cBaseFunction("RIGHT"); var r = new cBaseFunction( "RIGHT" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(2); r.setArgumentsMax( 2 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber(1) : arg[1]; var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if( arg0 instanceof cArray && arg1 instanceof cArray ){ if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if( arg0 instanceof cArray ){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if( arg1 instanceof cArray ){ else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
if( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
var l = arg0.getValue().length, _number = l-arg1.getValue(); var l = arg0.getValue().length, _number = l - arg1.getValue();
return this.value = new cString( arg0.getValue().substring( _number < 0 ? 0 : _number , l) ) return this.value = new cString( arg0.getValue().substring( _number < 0 ? 0 : _number, l ) )
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string [ , number-chars ] )" args:"( string [ , number-chars ] )"
...@@ -895,82 +900,81 @@ cFormulaFunction.TextAndData = { ...@@ -895,82 +900,81 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'RIGHTB' : function(){ 'RIGHTB':function () {
var r = cFormulaFunction.TextAndData["RIGHT"]() var r = cFormulaFunction.TextAndData["RIGHT"]()
r.setName("RIGHTB"); r.setName( "RIGHTB" );
return r; return r;
}, },
'SEARCH' : function(){ 'SEARCH':function () {
var r = new cBaseFunction("SEARCH"); var r = new cBaseFunction( "SEARCH" );
r.setArgumentsMin(2); r.setArgumentsMin( 2 );
r.setArgumentsMax(3); r.setArgumentsMax( 3 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber(1); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber( 1 );
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if( arg0 instanceof cArray){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement(0).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first).tocString(); arg1 = arg1.cross( arguments[1].first ).tocString();
} }
else if( arg1 instanceof cArray){ else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement(0).tocString(); arg1 = arg1.getElement( 0 ).tocString();
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){ if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross(arguments[1].first).tocNumber(); arg2 = arg2.cross( arguments[1].first ).tocNumber();
} }
else if( arg2 instanceof cArray){ else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement(0).tocNumber(); arg2 = arg2.getElement( 0 ).tocNumber();
} }
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if( arg0 instanceof cError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if( arg1 instanceof cError ) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
if( arg2 instanceof cError ) if ( arg2 instanceof cError )
return this.value = arg2; return this.value = arg2;
if( arg2.getValue() < 1 || arg2.getValue() > arg1.getValue().length ){ if ( arg2.getValue() < 1 || arg2.getValue() > arg1.getValue().length ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
var string1 = arg0.getValue(), string2 = arg1.getValue(), res = 0, var string1 = arg0.getValue(), string2 = arg1.getValue(),
valueForSearching = string1 valueForSearching = string1
.replace(/(~)?\*/g, function($0, $1){ .replace( /(~)?\*/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]*'; return $1 ? $0 : '[\\w\\W]*';
}) } )
.replace(/(~)?\?/g, function($0, $1){ .replace( /(~)?\?/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]{1,1}'; return $1 ? $0 : '[\\w\\W]{1,1}';
}) } )
.replace(/\~/g, "\\"); .replace( /(~\*)/g, "\\*" ).replace( /(~\?)/g, "\\?" );
valueForSearching = new RegExp( valueForSearching, "ig") valueForSearching = new RegExp( valueForSearching, "ig" )
if( string1 == "" ) if ( string1 == "" )
return this.value = arg2; return this.value = arg2;
res = string2.substring( arg2.getValue() - 1 ).search( valueForSearching ) + arg2.getValue() - 1;
res = string2.substring(arg2.getValue()-1).search( valueForSearching ) + arg2.getValue()-1; if ( res < 0 )
if( res < 0 )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new cNumber(res+1); return this.value = new cNumber( res + 1 );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string-1 , string-2 [ , start-pos ] )" args:"( string-1 , string-2 [ , start-pos ] )"
...@@ -978,82 +982,82 @@ cFormulaFunction.TextAndData = { ...@@ -978,82 +982,82 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'SEARCHB' : function(){ 'SEARCHB':function () {
var r = cFormulaFunction.TextAndData["SEARCH"](); var r = cFormulaFunction.TextAndData["SEARCH"]();
r.setName("SEARCHB"); r.setName( "SEARCHB" );
return r; return r;
}, },
'SUBSTITUTE' : function(){ 'SUBSTITUTE':function () {
var r = new cBaseFunction("SUBSTITUTE"); var r = new cBaseFunction( "SUBSTITUTE" );
r.setArgumentsMin(3); r.setArgumentsMin( 3 );
r.setArgumentsMax(4); r.setArgumentsMax( 4 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new cNumber(0); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new cNumber( 0 );
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if( arg0 instanceof cArray){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement(0).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){ if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first).tocString(); arg1 = arg1.cross( arguments[1].first ).tocString();
} }
else if( arg1 instanceof cArray){ else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement(0).tocString(); arg1 = arg1.getElement( 0 ).tocString();
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){ if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross(arguments[1].first).tocString(); arg2 = arg2.cross( arguments[1].first ).tocString();
} }
else if( arg2 instanceof cArray){ else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement(0).tocString(); arg2 = arg2.getElement( 0 ).tocString();
} }
arg2 = arg2.tocString(); arg2 = arg2.tocString();
if( arg3 instanceof cArea || arg3 instanceof cArea3D ){ if ( arg3 instanceof cArea || arg3 instanceof cArea3D ) {
arg3 = arg3.cross(arguments[1].first).tocNumber(); arg3 = arg3.cross( arguments[1].first ).tocNumber();
} }
else if( arg3 instanceof cArray){ else if ( arg3 instanceof cArray ) {
arg3 = arg3.getElement(0).tocNumber(); arg3 = arg3.getElement( 0 ).tocNumber();
} }
arg3 = arg3.tocNumber(); arg3 = arg3.tocNumber();
if( arg0 instanceof cError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if( arg1 instanceof cError ) if ( arg1 instanceof cError )
return this.value = arg1; return this.value = arg1;
if( arg2 instanceof cError ) if ( arg2 instanceof cError )
return this.value = arg2; return this.value = arg2;
if( arg3 instanceof cError ) if ( arg3 instanceof cError )
return this.value = arg3; return this.value = arg3;
if( arg3.getValue() < 0 ){ if ( arg3.getValue() < 0 ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
var string = arg0.getValue(), old_string = arg1.getValue(), new_string = arg2.getValue(), index = 0, res; var string = arg0.getValue(), old_string = arg1.getValue(), new_string = arg2.getValue(), index = 0, res;
res = string.replace(new RegExp(old_string,"g"),function(equal, p1, source){ res = string.replace( new RegExp( old_string, "g" ), function ( equal, p1, source ) {
index++; index++;
if( arg3.getValue() == 0 || arg3.getValue() > source.length ) if ( arg3.getValue() == 0 || arg3.getValue() > source.length )
return new_string; return new_string;
else if( arg3.getValue() == index ){ else if ( arg3.getValue() == index ) {
return new_string; return new_string;
} }
return equal; return equal;
}) } )
return this.value = new cString( res ); return this.value = new cString( res );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string , old-string , new-string [ , occurence ] )" args:"( string , old-string , new-string [ , occurence ] )"
...@@ -1061,30 +1065,30 @@ cFormulaFunction.TextAndData = { ...@@ -1061,30 +1065,30 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'T' : function(){ 'T':function () {
var r = new cBaseFunction("T"); var r = new cBaseFunction( "T" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cRef || arg0 instanceof cRef3D){ if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
else if( arg0 instanceof cString || arg0 instanceof cError ) else if ( arg0 instanceof cString || arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){ else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
else if( arg[0] instanceof cArray ){ else if ( arg[0] instanceof cArray ) {
arg0 = arg[0].getElementRowCol(0,0); arg0 = arg[0].getElementRowCol( 0, 0 );
} }
if( arg0 instanceof cString || arg0 instanceof cError ) if ( arg0 instanceof cString || arg0 instanceof cError )
return this.value = arg[0]; return this.value = arg[0];
else else
return this.value = new cEmpty(); return this.value = new cEmpty();
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( value )" args:"( value )"
...@@ -1092,30 +1096,30 @@ cFormulaFunction.TextAndData = { ...@@ -1092,30 +1096,30 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'TEXT' : function(){ 'TEXT':function () {
var r = new cBaseFunction("TEXT"); var r = new cBaseFunction( "TEXT" );
r.setArgumentsMin(2); r.setArgumentsMin( 2 );
r.setArgumentsMax(2); r.setArgumentsMax( 2 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if( arg0 instanceof cRef || arg0 instanceof cRef3D){ if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){ else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
else if( arg0 instanceof cArray ){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if( arg1 instanceof cRef || arg1 instanceof cRef3D){ if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
} }
else if ( arg1 instanceof cArea || arg1 instanceof cArea3D ){ else if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross(arguments[1].first); arg1 = arg1.cross( arguments[1].first );
} }
else if( arg1 instanceof cArray ){ else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol(0,0); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
...@@ -1124,29 +1128,28 @@ cFormulaFunction.TextAndData = { ...@@ -1124,29 +1128,28 @@ cFormulaFunction.TextAndData = {
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof cError ) return this.value = arg1;
var _tmp = arg0.tocNumber(); var _tmp = arg0.tocNumber();
if( _tmp instanceof cNumber ) if ( _tmp instanceof cNumber )
arg0 = _tmp; arg0 = _tmp;
var oFormat = oNumFormatCache.get(arg1.toString()); var oFormat = oNumFormatCache.get( arg1.toString() );
var aText = oFormat.format(arg0.getValue(), arg0 instanceof cNumber ? CellValueType.Number : CellValueType.String, gc_nMaxDigCountView, null); var aText = oFormat.format( arg0.getValue(), arg0 instanceof cNumber ? CellValueType.Number : CellValueType.String, gc_nMaxDigCountView, null );
var text = ""; var text = "";
for(var i = 0, length = aText.length; i < length; ++i) for ( var i = 0, length = aText.length; i < length; ++i ) {
{
if(aText[i].format && aText[i].format.skip ){ if ( aText[i].format && aText[i].format.skip ) {
text += " "; text += " ";
continue; continue;
} }
if(aText[i].format && aText[i].format.repeat ) if ( aText[i].format && aText[i].format.repeat )
continue; continue;
text += aText[i].text; text += aText[i].text;
} }
return this.value = new cString(text); return this.value = new cString( text );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( value , format )" args:"( value , format )"
...@@ -1154,28 +1157,32 @@ cFormulaFunction.TextAndData = { ...@@ -1154,28 +1157,32 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'TRIM' : function(){ 'TRIM':function () {
var r = new cBaseFunction("TRIM"); var r = new cBaseFunction( "TRIM" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if( arg0 instanceof cArray){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement(0).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if( arg0 instanceof cError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
return this.value = new cString( arg0.getValue().replace(/\s/g, function($0, $1, $2){ var r; /\s/.test($2[$1+1]) ? r = "" : r = $2[$1]; return r; }).replace(/^\s|\s$/g,"") ) return this.value = new cString( arg0.getValue().replace( /\s/g,function ( $0, $1, $2 ) {
var r;
/\s/.test( $2[$1 + 1] ) ? r = "" : r = $2[$1];
return r;
} ).replace( /^\s|\s$/g, "" ) )
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string )" args:"( string )"
...@@ -1183,24 +1190,24 @@ cFormulaFunction.TextAndData = { ...@@ -1183,24 +1190,24 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'UPPER' : function(){ 'UPPER':function () {
var r = new cBaseFunction("UPPER"); var r = new cBaseFunction( "UPPER" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
if( arg0 instanceof cArray ) if ( arg0 instanceof cArray )
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof cError ) return this.value = arg0;
return this.value = new cString( arg0.getValue().toUpperCase() ); return this.value = new cString( arg0.getValue().toUpperCase() );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"(text)" args:"(text)"
...@@ -1208,18 +1215,18 @@ cFormulaFunction.TextAndData = { ...@@ -1208,18 +1215,18 @@ cFormulaFunction.TextAndData = {
} }
return r; return r;
}, },
'VALUE' : function(){ 'VALUE':function () {
var r = new cBaseFunction("VALUE"); var r = new cBaseFunction( "VALUE" );
r.setArgumentsMin(1); r.setArgumentsMin( 1 );
r.setArgumentsMax(1); r.setArgumentsMax( 1 );
r.Calculate = function(arg){ r.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){ if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross( arguments[1].first );
} }
else if( arg0 instanceof cArray ){ else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol(0,0); arg0 = arg0.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
...@@ -1227,21 +1234,21 @@ cFormulaFunction.TextAndData = { ...@@ -1227,21 +1234,21 @@ cFormulaFunction.TextAndData = {
if ( arg0 instanceof cError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
var res = g_oFormatParser.parse(arg0.getValue()); var res = g_oFormatParser.parse( arg0.getValue() );
if( res ) if ( res )
return this.value = new cNumber( res.value ); return this.value = new cNumber( res.value );
else else
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
r.getInfo = function(){ r.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( string )" args:"( string )"
}; };
} }
r.setFormat(r.formatType.noneFormat); r.setFormat( r.formatType.noneFormat );
return r; return r;
} }
} }
\ No newline at end of file
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