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 @@
<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="../../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 type="text/javascript" src="../../Common/3rdparty/Underscore/underscore-min.js"></script>
......@@ -19,6 +19,7 @@
<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/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/FontFile.js"></script>
......@@ -27,7 +28,6 @@
<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/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="../model/clipboard.js"></script>
......@@ -36,10 +36,12 @@
<script type="text/javascript" src="../graphics/DrawingContext.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-workbook2.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/dateandtimeFunctions.js"></script>
<script type="text/javascript" src="../model/engineeringFunctions.js"></script>
......@@ -75,14 +77,20 @@
<script type="text/javascript" src="../api.js"></script>
<!--for presentation-->
<script type="text/javascript" src="../Common/PresentationSerializeAdapter.js"></script>
<script type="text/javascript" src="../../Common/PresentationSerializeAdapter.js"></script>
<!--for theme-->
<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/SerializeWriter.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>
<!--for chart-->
......@@ -120,17 +128,34 @@
<script src="../../Common/Charts/libraries/rgbcolor.js"></script>
<!--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/DrawingDocument.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/Image.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/RotateTracks.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 type="text/javascript" src="FormulaTests.js"></script>
......
$(function () {
$( function () {
var ver = 2;
var oParser, wb, ws, date1, date2, dif = 1e-9,
data = getTestWorkbook(),
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 wb = new Workbook(sUrlPath, new Asc.asc_CHandlersList(),null);
var wb = new Workbook( sUrlPath, new Asc.asc_CHandlersList(), null );
wb.initGlobalObjects();
var oBinaryFileReader = new BinaryFileReader(sUrlPath);
oBinaryFileReader.Read(sData, wb);
var oBinaryFileReader = new BinaryFileReader( sUrlPath );
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 );
});
module("Formula");
test("Test: \"Absolute reference\"",function(){
ws.getRange2("A7").setValue("1");
ws.getRange2("A8").setValue("2");
ws.getRange2("A9").setValue("3");
oParser = new parserFormula('A$7+A8',"A1",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(),3);
oParser = new parserFormula('A$7+A$8',"A1",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(),3);
oParser = new parserFormula('$A$7+$A$8',"A1",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(),3);
oParser = new parserFormula('SUM($A$7:$A$9)',"A1",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(),6);
})
test("Test: \"1+3\"",function(){
oParser = new parserFormula('1+3',"A1",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(),4);
})
test("Test: \"(1+2)*4+3\"",function(){
oParser = new parserFormula('(1+2)*4+3',"A1",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), (1+2)*4+3);
})
test("Test: \"2^52\"",function(){
oParser = new parserFormula('2^52',"A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), Math.pow(2,52) );
})
test("Test: \"-10\"",function(){
oParser = new parserFormula('-10',"A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), -10);
})
test("Test: \"-10*2\"",function (){
oParser = new parserFormula('-10*2',"A1",ws);
ok(oParser.parse());
} );
module( "Formula" );
test( "Test: \"Absolute reference\"", function () {
ws.getRange2( "A7" ).setValue( "1" );
ws.getRange2( "A8" ).setValue( "2" );
ws.getRange2( "A9" ).setValue( "3" );
oParser = new parserFormula( 'A$7+A8', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( 'A$7+A$8', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( '$A$7+$A$8', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( 'SUM($A$7:$A$9)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6 );
} )
test( "Test: \"1+3\"", function () {
oParser = new parserFormula( '1+3', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
} )
test( "Test: \"(1+2)*4+3\"", function () {
oParser = new parserFormula( '(1+2)*4+3', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), (1 + 2) * 4 + 3 );
} )
test( "Test: \"2^52\"", function () {
oParser = new parserFormula( '2^52', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), Math.pow( 2, 52 ) );
} )
test( "Test: \"-10\"", function () {
oParser = new parserFormula( '-10', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -10 );
} )
test( "Test: \"-10*2\"", function () {
oParser = new parserFormula( '-10*2', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -20 );
})
} )
test("Test: \"-10+10\"",function(){
oParser = new parserFormula('-10+10',"A1",ws);
ok(oParser.parse());
test( "Test: \"-10+10\"", function () {
oParser = new parserFormula( '-10+10', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
})
} )
test("Test: \"12%\"",function(){
oParser = new parserFormula('12%',"A1",ws);
ok(oParser.parse());
test( "Test: \"12%\"", function () {
oParser = new parserFormula( '12%', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0.12 );
})
test("Test: \"SIN have wrong arguments count\"",function(){
oParser = new parserFormula('SIN(3.1415926,3.1415926*2)',"A1",ws);
ok(!oParser.parse());
})
test("Test: \"sin(3.1415926)\"",function(){
oParser = new parserFormula('SIN(3.1415926)',"A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), parseFloat(Math.sin(3.1415926).toFixed(15)) );
})
test("Test: \"COS(PI()/2)\"",function(){
oParser = new parserFormula('COS(PI()/2)',"A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), parseFloat(Math.cos(Math.PI/2).toFixed(15)) );
})
test("Test: \"SUM(1,2,3)\"",function(){
oParser = new parserFormula('SUM(1,2,3)',"A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1+2+3);
})
test("Test: \"-\"12\"+2\"",function(){
oParser = new parserFormula("-\"12\"+2","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), -10);
})
test("Test: \"-TRUE\"",function(){
oParser = new parserFormula("-TRUE","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), -1);
})
test("Test: \"\"s\"&5\"",function(){
oParser = new parserFormula("\"s\"&5","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "s5");
})
test("Test: \"2<>\"3\"\"", function(){
oParser = new parserFormula("2<>\"3\"","A1",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(),"TRUE","2<>\"3\"")
})
test("Test: \"2=\"3\"\" & \"2>\"3\"\"",function(){
oParser = new parserFormula("2=\"3\"","A1",ws);
ok(oParser.parse());
} )
test( "Test: \"SIN have wrong arguments count\"", function () {
oParser = new parserFormula( 'SIN(3.1415926,3.1415926*2)', "A1", ws );
ok( !oParser.parse() );
} )
test( "Test: \"sin(3.1415926)\"", function () {
oParser = new parserFormula( 'SIN(3.1415926)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), parseFloat( Math.sin( 3.1415926 ).toFixed( 15 ) ) );
} )
test( "Test: \"COS(PI()/2)\"", function () {
oParser = new parserFormula( 'COS(PI()/2)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), parseFloat( Math.cos( Math.PI / 2 ).toFixed( 15 ) ) );
} )
test( "Test: \"SUM(1,2,3)\"", function () {
oParser = new parserFormula( 'SUM(1,2,3)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 + 2 + 3 );
} )
test( "Test: \"-\"12\"+2\"", function () {
oParser = new parserFormula( "-\"12\"+2", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -10 );
} )
test( "Test: \"-TRUE\"", function () {
oParser = new parserFormula( "-TRUE", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1 );
} )
test( "Test: \"\"s\"&5\"", function () {
oParser = new parserFormula( "\"s\"&5", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "s5" );
} )
test( "Test: \"2<>\"3\"\"", function () {
oParser = new parserFormula( "2<>\"3\"", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "TRUE", "2<>\"3\"" )
} )
test( "Test: \"2=\"3\"\" & \"2>\"3\"\"", function () {
oParser = new parserFormula( "2=\"3\"", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "FALSE", "2=\"3\"" );
oParser = new parserFormula("2>\"3\"","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "FALSE", "2>\"3\"");
})
oParser = new parserFormula( "2>\"3\"", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "FALSE", "2>\"3\"" );
} )
test("Test: \"\"f\">\"3\"\" & \"\"f\">\"3\"\"",function(){
oParser = new parserFormula("\"f\">\"3\"","A1",ws);
ok(oParser.parse());
test( "Test: \"\"f\">\"3\"\" & \"\"f\">\"3\"\"", function () {
oParser = new parserFormula( "\"f\">\"3\"", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "TRUE" );
oParser = new parserFormula("\"f\"<\"3\"","A1",ws);
ok(oParser.parse());
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( "\"f\"<\"3\"", "A1", ws );
ok( oParser.parse() );
strictEqual( "FALSE", oParser.calculate().getValue(), "FALSE" );
} )
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: \"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: \"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);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 4);
test( "Test: \"MAX\"", function () {
oParser = new parserFormula( "MAX(S5:T5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
} )
oParser = new parserFormula("SEARCH(\"?c*e\",\"abcdEF\")","B2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
test( "Test: \"MAXA\"", function () {
oParser = new parserFormula( "MAXA(S5:T5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
} )
oParser = new parserFormula("SEARCH(\"de\",\"dEFabcdEF\",3)","C2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 7);
test( "Test: \"MIN\"", function () {
oParser = new parserFormula( "MIN(S5:T5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
} )
oParser = new parserFormula("SEARCH(\"de\",\"dEFabcdEF\",30)","C2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "#VALUE!");
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 );
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);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "xxbcxxAxxbcxx");
oParser = new parserFormula( "SUBSTITUTE(\"abcaAabca\",\"a\",\"xx\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "xxbcxxAxxbcxx" );
oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\")","B2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "xxbcxxxxxxbcxx");
oParser = new parserFormula( "SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\")", "B2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "xxbcxxxxxxbcxx" );
oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"\",10)","C2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "bcbc");
oParser = new parserFormula( "SUBSTITUTE(\"abcaaabca\",\"a\",\"\",10)", "C2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "bcbc" );
oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\",3)","C2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "abcaxxabca");
oParser = new parserFormula( "SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\",3)", "C2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "abcaxxabca" );
})
} )
test("Test: \"TRIM\"",function(){
test( "Test: \"TRIM\"", function () {
oParser = new parserFormula("TRIM(\" abc def \")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "abc def");
oParser = new parserFormula( "TRIM(\" abc def \")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "abc def" );
})
} )
test("Test: \"DOLLAR\"",function(){
test( "Test: \"DOLLAR\"", function () {
oParser = new parserFormula("DOLLAR(1234.567)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "$1,234.57");
oParser = new parserFormula( "DOLLAR(1234.567)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "$1,234.57" );
oParser = new parserFormula("DOLLAR(1234.567,-2)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "$1,200");
oParser = new parserFormula( "DOLLAR(1234.567,-2)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "$1,200" );
oParser = new parserFormula("DOLLAR(-1234.567,4)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "$-1,234.5670");
oParser = new parserFormula( "DOLLAR(-1234.567,4)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "$-1,234.5670" );
})
} )
test("Test: \"VALUE\"",function(){
test( "Test: \"VALUE\"", function () {
oParser = new parserFormula("VALUE(\"123.456\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 123.456);
oParser = new parserFormula( "VALUE(\"123.456\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 123.456 );
oParser = new parserFormula("VALUE(\"$1,000\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "#VALUE!");
oParser = new parserFormula( "VALUE(\"$1,000\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
oParser = new parserFormula("VALUE(\"23-Mar-2002\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 37338);
oParser = new parserFormula( "VALUE(\"23-Mar-2002\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37338 );
oParser = new parserFormula("VALUE(\"03-26-2006\")","A2",ws);
ok(oParser.parse());
oParser = new parserFormula( "VALUE(\"03-26-2006\")", "A2", ws );
ok( oParser.parse() );
if( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 37340);
if ( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 37340 );
else
strictEqual( oParser.calculate().getValue(), 38802);
strictEqual( oParser.calculate().getValue(), 38802 );
oParser = new parserFormula("VALUE(\"16:48:00\")-VALUE(\"12:17:12\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 0.188055555555556);
oParser = new parserFormula( "VALUE(\"16:48:00\")-VALUE(\"12:17:12\")", "A2", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 40461);
oParser = new parserFormula( "DATEVALUE(\"10-10-2010 10:26\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 40461 );
oParser = new parserFormula("DATEVALUE(\"10-10-2010 10:26\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 40461);
oParser = new parserFormula( "DATEVALUE(\"10-10-2010 10:26\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 40461 );
ws.getRange2("A7").setValue("3-Mar");
oParser = new parserFormula("DATEVALUE(A7)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 41336);
ws.getRange2( "A7" ).setValue( "3-Mar" );
oParser = new parserFormula( "DATEVALUE(A7)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 41336 );
oParser = new parserFormula("DATEVALUE(\"$1,000\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "#VALUE!");
oParser = new parserFormula( "DATEVALUE(\"$1,000\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
oParser = new parserFormula("DATEVALUE(\"23-Mar-2002\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 37338);
oParser = new parserFormula( "DATEVALUE(\"23-Mar-2002\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37338 );
oParser = new parserFormula("DATEVALUE(\"03-26-2006\")","A2",ws);
ok(oParser.parse());
oParser = new parserFormula( "DATEVALUE(\"03-26-2006\")", "A2", ws );
ok( oParser.parse() );
if( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 37340);
if ( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 37340 );
else
strictEqual( oParser.calculate().getValue(), 38802);
})
strictEqual( oParser.calculate().getValue(), 38802 );
} )
test("Test: \"EDATE\"",function(){
test( "Test: \"EDATE\"", function () {
if( !g_bDate1904 ){
oParser = new parserFormula("EDATE(DATE(2006,1,31),5)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 38898);
if ( !g_bDate1904 ) {
oParser = new parserFormula( "EDATE(DATE(2006,1,31),5)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38898 );
oParser = new parserFormula("EDATE(DATE(2004,2,29),12)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 38411);
oParser = new parserFormula( "EDATE(DATE(2004,2,29),12)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38411 );
ws.getRange2("A7").setValue("02-28-2004");
oParser = new parserFormula("EDATE(A7,12)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 38411);
ws.getRange2( "A7" ).setValue( "02-28-2004" );
oParser = new parserFormula( "EDATE(A7,12)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38411 );
oParser = new parserFormula("EDATE(DATE(2004,1,15),-23)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 37302);
oParser = new parserFormula( "EDATE(DATE(2004,1,15),-23)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37302 );
}
else{
oParser = new parserFormula("EDATE(DATE(2006,1,31),5)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 37436);
oParser = new parserFormula("EDATE(DATE(2004,2,29),12)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 36949);
ws.getRange2("A7").setValue("02-28-2004");
oParser = new parserFormula("EDATE(A7,12)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 36949);
oParser = new parserFormula("EDATE(DATE(2004,1,15),-23)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 35840);
else {
oParser = new parserFormula( "EDATE(DATE(2006,1,31),5)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37436 );
oParser = new parserFormula( "EDATE(DATE(2004,2,29),12)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 36949 );
ws.getRange2( "A7" ).setValue( "02-28-2004" );
oParser = new parserFormula( "EDATE(A7,12)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 36949 );
oParser = new parserFormula( "EDATE(DATE(2004,1,15),-23)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 35840 );
}
})
} )
test("Test: \"EOMONTH\"",function(){
test( "Test: \"EOMONTH\"", function () {
if( !g_bDate1904 ){
oParser = new parserFormula("EOMONTH(DATE(2006,1,31),5)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 38898);
if ( !g_bDate1904 ) {
oParser = new parserFormula( "EOMONTH(DATE(2006,1,31),5)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38898 );
oParser = new parserFormula("EOMONTH(DATE(2004,2,29),12)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 38411);
oParser = new parserFormula( "EOMONTH(DATE(2004,2,29),12)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38411 );
ws.getRange2("A7").setValue("02-28-2004");
oParser = new parserFormula("EOMONTH(A7,12)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 38411);
ws.getRange2( "A7" ).setValue( "02-28-2004" );
oParser = new parserFormula( "EOMONTH(A7,12)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38411 );
oParser = new parserFormula("EOMONTH(DATE(2004,1,15),-23)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 37315);
oParser = new parserFormula( "EOMONTH(DATE(2004,1,15),-23)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37315 );
}
else{
oParser = new parserFormula("EOMONTH(DATE(2006,1,31),5)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 37436);
oParser = new parserFormula("EOMONTH(DATE(2004,2,29),12)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 36949);
ws.getRange2("A7").setValue("02-28-2004");
oParser = new parserFormula("EOMONTH(A7,12)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 36949);
oParser = new parserFormula("EOMONTH(DATE(2004,1,15),-23)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 35853);
else {
oParser = new parserFormula( "EOMONTH(DATE(2006,1,31),5)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 37436 );
oParser = new parserFormula( "EOMONTH(DATE(2004,2,29),12)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 36949 );
ws.getRange2( "A7" ).setValue( "02-28-2004" );
oParser = new parserFormula( "EOMONTH(A7,12)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 36949 );
oParser = new parserFormula( "EOMONTH(DATE(2004,1,15),-23)", "A2", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 22);
oParser = new parserFormula( "NETWORKDAYS(DATE(2006,1,1),DATE(2006,1,31))", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 22 );
oParser = new parserFormula("NETWORKDAYS(DATE(2006,1,31),DATE(2006,1,1))","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), -22);
oParser = new parserFormula( "NETWORKDAYS(DATE(2006,1,31),DATE(2006,1,1))", "A2", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 21);
oParser = new parserFormula( "NETWORKDAYS(DATE(2006,1,1),DATE(2006,2,1),{\"01-02-2006\",\"01-16-2006\"})", "A2", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
oParser = new parserFormula( "PV(0.08/12,12*20,500,,0)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -59777.14585118638 );
oParser = new parserFormula("PV(0,12*20,500,,0)","A2",ws);
ok(oParser.parse());
oParser = new parserFormula( "PV(0,12*20,500,,0)", "A2", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
oParser = new parserFormula( "NPV(0.1,-10000,3000,4200,6800)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1188.4434123352216 );
})
} )
test("Test: \"SUMIF\"",function(){
test( "Test: \"SUMIF\"", function () {
ws.getRange2("A2").setValue("100000");
ws.getRange2("A3").setValue("200000");
ws.getRange2("A4").setValue("300000");
ws.getRange2("A5").setValue("400000");
ws.getRange2( "A2" ).setValue( "100000" );
ws.getRange2( "A3" ).setValue( "200000" );
ws.getRange2( "A4" ).setValue( "300000" );
ws.getRange2( "A5" ).setValue( "400000" );
ws.getRange2("B2").setValue("7000");
ws.getRange2("B3").setValue("14000");
ws.getRange2("B4").setValue("21000");
ws.getRange2("B5").setValue("28000");
ws.getRange2( "B2" ).setValue( "7000" );
ws.getRange2( "B3" ).setValue( "14000" );
ws.getRange2( "B4" ).setValue( "21000" );
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);
ok(oParser.parse());
oParser = new parserFormula( "SUMIF(A2:A5,\">160000\",B2:B5)", "A7", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 63000 );
oParser = new parserFormula("SUMIF(A2:A5,\">160000\")","A8",ws);
ok(oParser.parse());
oParser = new parserFormula( "SUMIF(A2:A5,\">160000\")", "A8", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 900000 );
oParser = new parserFormula("SUMIF(A2:A5,300000,B2:B5)","A9",ws);
ok(oParser.parse());
oParser = new parserFormula( "SUMIF(A2:A5,300000,B2:B5)", "A9", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 21000 );
oParser = new parserFormula("SUMIF(A2:A5,\">\" & C2,B2:B5)","A10",ws);
ok(oParser.parse());
oParser = new parserFormula( "SUMIF(A2:A5,\">\" & C2,B2:B5)", "A10", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 49000 );
ws.getRange2("A12").setValue("Vegetables");
ws.getRange2("A13").setValue("Vegetables");
ws.getRange2("A14").setValue("Fruits");
ws.getRange2("A15").setValue("");
ws.getRange2("A16").setValue("Vegetables");
ws.getRange2("A17").setValue("Fruits");
ws.getRange2("B12").setValue("Tomatoes");
ws.getRange2("B13").setValue("Celery");
ws.getRange2("B14").setValue("Oranges");
ws.getRange2("B15").setValue("Butter");
ws.getRange2("B16").setValue("Carrots");
ws.getRange2("B17").setValue("Apples");
ws.getRange2("C12").setValue("2300");
ws.getRange2("C13").setValue("5500");
ws.getRange2("C14").setValue("800");
ws.getRange2("C15").setValue("400");
ws.getRange2("C16").setValue("4200");
ws.getRange2("C17").setValue("1200");
oParser = new parserFormula("SUMIF(A12:A17,\"Fruits\",C12:C17)","A19",ws);
ok(oParser.parse());
ws.getRange2( "A12" ).setValue( "Vegetables" );
ws.getRange2( "A13" ).setValue( "Vegetables" );
ws.getRange2( "A14" ).setValue( "Fruits" );
ws.getRange2( "A15" ).setValue( "" );
ws.getRange2( "A16" ).setValue( "Vegetables" );
ws.getRange2( "A17" ).setValue( "Fruits" );
ws.getRange2( "B12" ).setValue( "Tomatoes" );
ws.getRange2( "B13" ).setValue( "Celery" );
ws.getRange2( "B14" ).setValue( "Oranges" );
ws.getRange2( "B15" ).setValue( "Butter" );
ws.getRange2( "B16" ).setValue( "Carrots" );
ws.getRange2( "B17" ).setValue( "Apples" );
ws.getRange2( "C12" ).setValue( "2300" );
ws.getRange2( "C13" ).setValue( "5500" );
ws.getRange2( "C14" ).setValue( "800" );
ws.getRange2( "C15" ).setValue( "400" );
ws.getRange2( "C16" ).setValue( "4200" );
ws.getRange2( "C17" ).setValue( "1200" );
oParser = new parserFormula( "SUMIF(A12:A17,\"Fruits\",C12:C17)", "A19", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2000 );
oParser = new parserFormula("SUMIF(A12:A17,\"Vegetables\",C12:C17)","A20",ws);
ok(oParser.parse());
oParser = new parserFormula( "SUMIF(A12:A17,\"Vegetables\",C12:C17)", "A20", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 12000 );
oParser = new parserFormula("SUMIF(B12:B17,\"*es\",C12:C17)","A21",ws);
ok(oParser.parse());
oParser = new parserFormula( "SUMIF(B12:B17,\"*es\",C12:C17)", "A21", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4300 );
oParser = new parserFormula("SUMIF(A12:A17,\"\",C12:C17)","A22",ws);
ok(oParser.parse());
oParser = new parserFormula( "SUMIF(A12:A17,\"\",C12:C17)", "A22", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
oParser = new parserFormula( "TEXT(1234.567,\"$0.00\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "$1234.57" );
oParser = new parserFormula("TEXT(0.125,\"0.0%\")","A2",ws);
ok(oParser.parse());
oParser = new parserFormula( "TEXT(0.125,\"0.0%\")", "A2", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
oParser = new parserFormula( "WORKDAY(DATE(2006,1,1),0)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38718 );
oParser = new parserFormula("WORKDAY(DATE(2006,1,1),10)","A2",ws);
ok(oParser.parse());
oParser = new parserFormula( "WORKDAY(DATE(2006,1,1),10)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38730 );
oParser = new parserFormula("WORKDAY(DATE(2006,1,1),-10)","A2",ws);
ok(oParser.parse());
oParser = new parserFormula( "WORKDAY(DATE(2006,1,1),-10)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 38705 );
oParser = new parserFormula("WORKDAY(DATE(2006,1,1),20,{\"1-2-2006\",\"1-16-2006\"})","A2",ws);
ok(oParser.parse());
oParser = new parserFormula( "WORKDAY(DATE(2006,1,1),20,{\"1-2-2006\",\"1-16-2006\"})", "A2", ws );
ok( oParser.parse() );
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;
if( type === undefined || type === null )
if ( type === undefined || type === null )
type = 0;
if( pv === undefined || pv === null )
if ( pv === undefined || pv === null )
pv = 0;
if( rate != 0 ){
res = -1 * ( pv * Math.pow( 1 + rate, nper ) + pmt * ( 1 + rate * type ) * ( Math.pow( 1 + rate ,nper ) - 1) / rate );
if ( rate != 0 ) {
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 );
}
return res;
}
oParser = new parserFormula("FV(0.06/12,10,-200,-500,1)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), fv(0.06/12,10,-200,-500,1) );
oParser = new parserFormula( "FV(0.06/12,10,-200,-500,1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), fv( 0.06 / 12, 10, -200, -500, 1 ) );
oParser = new parserFormula("FV(0.12/12,12,-1000)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), fv(0.12/12,12,-1000) );
oParser = new parserFormula( "FV(0.12/12,12,-1000)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), fv( 0.12 / 12, 12, -1000 ) );
oParser = new parserFormula("FV(0.11/12,35,-2000,,1)","A2",ws);
ok(oParser.parse());
ok( Math.abs(oParser.calculate().getValue() - fv(0.11/12,35,-2000,null,1)) < dif );
oParser = new parserFormula( "FV(0.11/12,35,-2000,,1)", "A2", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
ok( Math.abs(oParser.calculate().getValue() - fv(0.06/12,12,-100,-1000,1)) < dif );
oParser = new parserFormula( "FV(0.06/12,12,-100,-1000,1)", "A2", ws );
ok( oParser.parse() );
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;
for( var i = 0; i < arguments.length; i++){
for ( var i = 0; i < arguments.length; i++ ) {
average += arguments[i] / arguments.length;
}
for( var i = 0; i < arguments.length; i++){
res += (arguments[i] - average)*(arguments[i] - average);
for ( var i = 0; i < arguments.length; i++ ) {
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);
ok(oParser.parse());
ok( Math.abs(oParser.calculate().getValue() - stdev(123,134,143,173,112,109)) < dif );
oParser = new parserFormula( "STDEV(123,134,143,173,112,109)", "A2", ws );
ok( oParser.parse() );
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;
if( type === undefined || type === null )
if ( type === undefined || type === null )
type = 0;
if( fv === undefined || fv === null )
if ( fv === undefined || fv === null )
fv = 0;
if( rate != 0 ){
res = -1*( pv * Math.pow( 1 + rate, nper ) + fv ) /
if ( rate != 0 ) {
res = -1 * ( pv * Math.pow( 1 + rate, nper ) + fv ) /
( ( 1 + rate * type ) * ( Math.pow( 1 + rate, nper ) - 1 ) / rate );
}
else{
res = -1*( pv + fv )/ nper;
else {
res = -1 * ( pv + fv ) / nper;
}
return res;
}
oParser = new parserFormula("PMT(0.08/12,10,10000)","A2",ws);
ok(oParser.parse());
ok( Math.abs(oParser.calculate().getValue() - pmt(0.08/12,10,10000)) < dif );
oParser = new parserFormula( "PMT(0.08/12,10,10000)", "A2", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
ok( Math.abs(oParser.calculate().getValue() - pmt(0.08/12,10,10000,0,1)) < dif );
oParser = new parserFormula( "PMT(0.08/12,10,10000,0,1)", "A2", ws );
ok( oParser.parse() );
ok( Math.abs( oParser.calculate().getValue() - pmt( 0.08 / 12, 10, 10000, 0, 1 ) ) < dif );
})
} )
test("Test: \"TIMEVALUE\"",function(){
oParser = new parserFormula("timevalue(\"10:02:34\")","A2",ws);
ok(oParser.parse());
ok( Math.abs(oParser.calculate().getValue() - 0.4184490740740740) < dif );
test( "Test: \"TIMEVALUE\"", function () {
oParser = new parserFormula( "timevalue(\"10:02:34\")", "A2", ws );
ok( oParser.parse() );
ok( Math.abs( oParser.calculate().getValue() - 0.4184490740740740 ) < dif );
oParser = new parserFormula("timevalue(\"02-01-2006 10:15:29 AM\")","A2",ws);
ok(oParser.parse());
ok( Math.abs(oParser.calculate().getValue() - 0.4274189814823330) < dif );
oParser = new parserFormula( "timevalue(\"02-01-2006 10:15:29 AM\")", "A2", ws );
ok( oParser.parse() );
ok( Math.abs( oParser.calculate().getValue() - 0.4274189814823330 ) < dif );
oParser = new parserFormula("timevalue(\"22:02\")","A2",ws);
ok(oParser.parse());
ok( Math.abs(oParser.calculate().getValue() - 0.9180555555555560) < dif );
})
oParser = new parserFormula( "timevalue(\"22:02\")", "A2", ws );
ok( oParser.parse() );
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);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), 1198);
oParser = new parserFormula( "DAYS360(DATE(2002,2,3),DATE(2005,5,31))", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1198 );
oParser = new parserFormula("DAYS360(DATE(2005,5,31),DATE(2002,2,3))","A2",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), -1197);
oParser = new parserFormula( "DAYS360(DATE(2005,5,31),DATE(2002,2,3))", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1197 );
oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31),FALSE)","A2",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), 1198);
oParser = new parserFormula( "DAYS360(DATE(2002,2,3),DATE(2005,5,31),FALSE)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1198 );
oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31),TRUE)","A2",ws);
ok(oParser.parse());
strictEqual(oParser.calculate().getValue(), 1197);
oParser = new parserFormula( "DAYS360(DATE(2002,2,3),DATE(2005,5,31),TRUE)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1197 );
})
} )
test("Test: \"WEEKNUM\"",function(){
oParser = new parserFormula("WEEKNUM(DATE(2006,1,1))","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
test( "Test: \"WEEKNUM\"", function () {
oParser = new parserFormula( "WEEKNUM(DATE(2006,1,1))", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2006,1,1),17)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2006,1,1),17)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2006,1,1),1)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2006,1,1),1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2006,1,1),21)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 52);
oParser = new parserFormula( "WEEKNUM(DATE(2006,1,1),21)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 52 );
oParser = new parserFormula("WEEKNUM(DATE(2006,2,1),1)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 5);
oParser = new parserFormula( "WEEKNUM(DATE(2006,2,1),1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5 );
oParser = new parserFormula("WEEKNUM(DATE(2006,2,1),2)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 6);
oParser = new parserFormula( "WEEKNUM(DATE(2006,2,1),2)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6 );
oParser = new parserFormula("WEEKNUM(DATE(2006,2,1),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 6);
oParser = new parserFormula( "WEEKNUM(DATE(2006,2,1),11)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6 );
oParser = new parserFormula("WEEKNUM(DATE(2007,1,1),15)","A2",ws);//понед
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2007,1,1),15)", "A2", ws );//понед
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,1),15)","A2",ws);//втор
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2008,1,1),15)", "A2", ws );//втор
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2003,1,1),15)","A2",ws);//сред
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2003,1,1),15)", "A2", ws );//сред
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2009,1,1),15)","A2",ws);//чет
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2009,1,1),15)", "A2", ws );//чет
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2010,1,1),15)","A2",ws);//пят
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2010,1,1),15)", "A2", ws );//пят
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2011,1,1),15)","A2",ws);//суб
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2011,1,1),15)", "A2", ws );//суб
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2012,1,1),11)","A2",ws);//вск
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2012,1,1),11)", "A2", ws );//вск
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,4),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2008,1,4),11)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,10),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
oParser = new parserFormula( "WEEKNUM(DATE(2008,1,10),11)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,11),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
oParser = new parserFormula( "WEEKNUM(DATE(2008,1,11),11)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,17),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 3);
oParser = new parserFormula( "WEEKNUM(DATE(2008,1,17),11)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,18),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 3);
oParser = new parserFormula( "WEEKNUM(DATE(2008,1,18),11)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula("WEEKNUM(DATE(2008,1,24),11)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 4);
oParser = new parserFormula( "WEEKNUM(DATE(2008,1,24),11)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
oParser = new parserFormula("WEEKNUM(DATE(2013,1,1),21)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1);
oParser = new parserFormula( "WEEKNUM(DATE(2013,1,1),21)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula("WEEKNUM(DATE(2013,1,7))","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 2);
oParser = new parserFormula( "WEEKNUM(DATE(2013,1,7))", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
})
} )
test("Test: \"YEARFRAC\"",function(){
function okWrapper(a,b){
ok( Math.abs(a - b) < dif );
test( "Test: \"YEARFRAC\"", function () {
function okWrapper( a, b ) {
ok( Math.abs( a - b ) < dif );
}
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,3,26))","A2",ws);
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());
okWrapper( oParser.calculate().getValue(), 0.236111111);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1))","A2",ws);
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());
okWrapper( oParser.calculate().getValue(), 1.666666667);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),0)","A2",ws);
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());
okWrapper( oParser.calculate().getValue(), 0.495890411);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),2)","A2",ws);
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());
okWrapper( oParser.calculate().getValue(), 0.495890411);
oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),4)","A2",ws);
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());
okWrapper( oParser.calculate().getValue(), 1.998175182481752);
})
test("Test: \"DATEDIF\"",function(){
oParser = new parserFormula("DATEDIF(DATE(2001,1,1),DATE(2003,1,1),\"Y\")","A2",ws);
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());
strictEqual( oParser.calculate().getValue(), 440);
oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"YD\")","A2",ws);
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());
strictEqual( oParser.calculate().getValue(), 14);
})
test("Test: \"SUMPRODUCT\"",function(){
oParser = new parserFormula("SUMPRODUCT({2,3})","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 5);
oParser = new parserFormula("SUMPRODUCT({2,3},{4,5})","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 23);
oParser = new parserFormula("SUMPRODUCT({2,3},{4,5},{2,2})","A2",ws);
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());
strictEqual( oParser.calculate().getValue(), 42);
ws.getRange2("N44").setValue("1");
ws.getRange2("N45").setValue("2");
ws.getRange2("N46").setValue("3");
ws.getRange2("N47").setValue("4");
ws.getRange2("O44").setValue("5");
ws.getRange2("O45").setValue("6");
ws.getRange2("O46").setValue("7");
ws.getRange2("O47").setValue("8");
ws.getRange2("P44").setValue("9");
ws.getRange2("P45").setValue("10");
ws.getRange2("P46").setValue("11");
ws.getRange2("P47").setValue("12");
oParser = new parserFormula("SUMPRODUCT(N44:N47,O44:O47,P44:P47)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 780);
})
});
oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,3,26))", "A2", ws );
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() );
okWrapper( oParser.calculate().getValue(), 0.236111111 );
oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1))", "A2", ws );
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() );
okWrapper( oParser.calculate().getValue(), 1.666666667 );
oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),0)", "A2", ws );
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() );
okWrapper( oParser.calculate().getValue(), 0.495890411 );
oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),2)", "A2", ws );
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() );
okWrapper( oParser.calculate().getValue(), 0.495890411 );
oParser = new parserFormula( "YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),4)", "A2", ws );
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() );
okWrapper( oParser.calculate().getValue(), 1.998175182481752 );
} )
test( "Test: \"DATEDIF\"", function () {
oParser = new parserFormula( "DATEDIF(DATE(2001,1,1),DATE(2003,1,1),\"Y\")", "A2", ws );
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() );
strictEqual( oParser.calculate().getValue(), 440 );
oParser = new parserFormula( "DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"YD\")", "A2", ws );
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() );
strictEqual( oParser.calculate().getValue(), 14 );
} )
test( "Test: \"SUMPRODUCT\"", function () {
oParser = new parserFormula( "SUMPRODUCT({2,3})", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5 );
oParser = new parserFormula( "SUMPRODUCT({2,3},{4,5})", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 23 );
oParser = new parserFormula( "SUMPRODUCT({2,3},{4,5},{2,2})", "A2", ws );
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() );
strictEqual( oParser.calculate().getValue(), 42 );
ws.getRange2( "N44" ).setValue( "1" );
ws.getRange2( "N45" ).setValue( "2" );
ws.getRange2( "N46" ).setValue( "3" );
ws.getRange2( "N47" ).setValue( "4" );
ws.getRange2( "O44" ).setValue( "5" );
ws.getRange2( "O45" ).setValue( "6" );
ws.getRange2( "O46" ).setValue( "7" );
ws.getRange2( "O47" ).setValue( "8" );
ws.getRange2( "P44" ).setValue( "9" );
ws.getRange2( "P45" ).setValue( "10" );
ws.getRange2( "P46" ).setValue( "11" );
ws.getRange2( "P47" ).setValue( "12" );
oParser = new parserFormula( "SUMPRODUCT(N44:N47,O44:O47,P44:P47)", "A2", ws );
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 @@
api.asc_registerCallback("asc_onActiveSheetChanged", onActiveSheetChanged);
// api.asc_registerCallback("asc_onCellTextChanged", function(){console.log(arguments)});
api.asc_registerCallback("asc_onConfirmAction", function(){
var arg = arguments;
$("#ConfirmMess")
......@@ -485,7 +487,7 @@
});
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) {
......
......@@ -6,123 +6,123 @@
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Financial = {
'groupName' : "Financial",
'ACCRINT' : function(){
var r = new cBaseFunction("ACCRINT");
'groupName':"Financial",
'ACCRINT':function () {
var r = new cBaseFunction( "ACCRINT" );
return r;
},
'ACCRINTM' : function(){
var r = new cBaseFunction("ACCRINTM");
'ACCRINTM':function () {
var r = new cBaseFunction( "ACCRINTM" );
return r;
},
'AMORDEGRC' : function(){
var r = new cBaseFunction("AMORDEGRC");
'AMORDEGRC':function () {
var r = new cBaseFunction( "AMORDEGRC" );
return r;
},
'AMORLINC' : function(){
var r = new cBaseFunction("AMORLINC");
'AMORLINC':function () {
var r = new cBaseFunction( "AMORLINC" );
return r;
},
'COUPDAYBS' : function(){
var r = new cBaseFunction("COUPDAYBS");
'COUPDAYBS':function () {
var r = new cBaseFunction( "COUPDAYBS" );
return r;
},
'COUPDAYS' : function(){
var r = new cBaseFunction("COUPDAYS");
'COUPDAYS':function () {
var r = new cBaseFunction( "COUPDAYS" );
return r;
},
'COUPDAYSNC' : function(){
var r = new cBaseFunction("COUPDAYSNC");
'COUPDAYSNC':function () {
var r = new cBaseFunction( "COUPDAYSNC" );
return r;
},
'COUPNCD' : function(){
var r = new cBaseFunction("COUPNCD");
'COUPNCD':function () {
var r = new cBaseFunction( "COUPNCD" );
return r;
},
'COUPNUM' : function(){
var r = new cBaseFunction("COUPNUM");
'COUPNUM':function () {
var r = new cBaseFunction( "COUPNUM" );
return r;
},
'COUPPCD' : function(){
var r = new cBaseFunction("COUPPCD");
'COUPPCD':function () {
var r = new cBaseFunction( "COUPPCD" );
return r;
},
'CUMIPMT' : function(){
var r = new cBaseFunction("CUMIPMT");
'CUMIPMT':function () {
var r = new cBaseFunction( "CUMIPMT" );
return r;
},
'CUMPRINC' : function(){
var r = new cBaseFunction("CUMPRINC");
'CUMPRINC':function () {
var r = new cBaseFunction( "CUMPRINC" );
return r;
},
'DB' : function(){
var r = new cBaseFunction("DB");
'DB':function () {
var r = new cBaseFunction( "DB" );
return r;
},
'DDB' : function(){
var r = new cBaseFunction("DDB");
'DDB':function () {
var r = new cBaseFunction( "DDB" );
return r;
},
'DISC' : function(){
var r = new cBaseFunction("DISC");
'DISC':function () {
var r = new cBaseFunction( "DISC" );
return r;
},
'DOLLARDE' : function(){
var r = new cBaseFunction("DOLLARDE");
'DOLLARDE':function () {
var r = new cBaseFunction( "DOLLARDE" );
return r;
},
'DOLLARFR' : function(){
var r = new cBaseFunction("DOLLARFR");
'DOLLARFR':function () {
var r = new cBaseFunction( "DOLLARFR" );
return r;
},
'DURATION' : function(){
var r = new cBaseFunction("DURATION");
'DURATION':function () {
var r = new cBaseFunction( "DURATION" );
return r;
},
'EFFECT' : function(){
var r = new cBaseFunction("EFFECT");
'EFFECT':function () {
var r = new cBaseFunction( "EFFECT" );
return r;
},
'FV' : function(){
var r = new cBaseFunction("FV");
r.setArgumentsMin(3);
r.setArgumentsMax(5);
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);
'FV':function () {
var r = new cBaseFunction( "FV" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 5 );
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 );
if ( rate instanceof cArea || rate instanceof cArea3D ){
rate = rate.cross(arguments[1].first);
if ( rate instanceof cArea || rate instanceof cArea3D ) {
rate = rate.cross( arguments[1].first );
}
else if( rate instanceof cArray ){
rate = rate.getElementRowCol(0,0);
else if ( rate instanceof cArray ) {
rate = rate.getElementRowCol( 0, 0 );
}
if ( nper instanceof cArea || nper instanceof cArea3D ){
nper = nper.cross(arguments[1].first);
if ( nper instanceof cArea || nper instanceof cArea3D ) {
nper = nper.cross( arguments[1].first );
}
else if( nper instanceof cArray ){
nper = nper.getElementRowCol(0,0);
else if ( nper instanceof cArray ) {
nper = nper.getElementRowCol( 0, 0 );
}
if ( pmt instanceof cArea || pmt instanceof cArea3D ){
pmt = pmt.cross(arguments[1].first);
if ( pmt instanceof cArea || pmt instanceof cArea3D ) {
pmt = pmt.cross( arguments[1].first );
}
else if( pmt instanceof cArray ){
pmt = pmt.getElementRowCol(0,0);
else if ( pmt instanceof cArray ) {
pmt = pmt.getElementRowCol( 0, 0 );
}
if ( pv instanceof cArea || pv instanceof cArea3D ){
pv = pv.cross(arguments[1].first);
if ( pv instanceof cArea || pv instanceof cArea3D ) {
pv = pv.cross( arguments[1].first );
}
else if( pv instanceof cArray ){
pv = pv.getElementRowCol(0,0);
else if ( pv instanceof cArray ) {
pv = pv.getElementRowCol( 0, 0 );
}
if ( type instanceof cArea || type instanceof cArea3D ){
type = type.cross(arguments[1].first);
if ( type instanceof cArea || type instanceof cArea3D ) {
type = type.cross( arguments[1].first );
}
else if( type instanceof cArray ){
type = type.getElementRowCol(0,0);
else if ( type instanceof cArray ) {
type = type.getElementRowCol( 0, 0 );
}
rate = rate.tocNumber();
......@@ -140,76 +140,147 @@ cFormulaFunction.Financial = {
if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric );
var res;
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() );
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() );
}
else{
res = -1*( pv.getValue()+pmt.getValue()*nper.getValue() );
else {
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 {
name:this.name,
args:"( rate , nper , pmt [ , [ pv ] [ ,[ type ] ] ] )"
};
}
r.setFormat(r.formatType.noneFormat);
r.setFormat( r.formatType.noneFormat );
return r;
},
'FVSCHEDULE' : function(){
var r = new cBaseFunction("FVSCHEDULE");
'FVSCHEDULE':function () {
var r = new cBaseFunction( "FVSCHEDULE" );
return r;
},
'INTRATE' : function(){
var r = new cBaseFunction("INTRATE");
'INTRATE':function () {
var r = new cBaseFunction( "INTRATE" );
return r;
},
'IPMT' : function(){
var r = new cBaseFunction("IPMT");
'IPMT':function () {
var r = new cBaseFunction( "IPMT" );
return r;
},
'IRR' : function(){
var r = new cBaseFunction("IRR");
'IRR':function () {
var r = new cBaseFunction( "IRR" );
return r;
},
'ISPMT' : function(){
var r = new cBaseFunction("ISPMT");
'ISPMT':function () {
var r = new cBaseFunction( "ISPMT" );
return r;
},
'MDURATION' : function(){
var r = new cBaseFunction("MDURATION");
'MDURATION':function () {
var r = new cBaseFunction( "MDURATION" );
return r;
},
'MIRR' : function(){
var r = new cBaseFunction("MIRR");
'MIRR':function () {
var r = new cBaseFunction( "MIRR" );
return r;
},
'NOMINAL' : function(){
var r = new cBaseFunction("NOMINAL");
'NOMINAL':function () {
var r = new cBaseFunction( "NOMINAL" );
return r;
},
'NPER' : function(){
var r = new cBaseFunction("NPER");
'NPER':function () {
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;
},
'NPV' : function(){
var r = new cBaseFunction("NPV");
r.setArgumentsMin(2);
r.setArgumentsMax(255);
r.Calculate = function(arg){
'NPV':function () {
var r = new cBaseFunction( "NPV" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], iStart = 1, res = 0, rate;
function elemCalc(rate,value,step){
return value / Math.pow(1+rate,step);
function elemCalc( rate, value, step ) {
return value / Math.pow( 1 + rate, step );
}
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
arg0 = arg0.tocNumber();
......@@ -219,107 +290,107 @@ cFormulaFunction.Financial = {
rate = arg0.getValue();
if( rate == -1)
if ( rate == -1 )
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];
if( argI instanceof cArea || argI instanceof cArea3D ){
if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argIArr = argI.getValue();
for (var j = 0; j < argIArr.length; j++){
if( argIArr[j] instanceof cNumber ){
for ( var j = 0; j < argIArr.length; j++ ) {
if ( argIArr[j] instanceof cNumber ) {
res += elemCalc( rate, argIArr[j].getValue(), iStart++ );
}
}
continue;
}
else if( argI instanceof cArray ){
argI.foreach(function(elem,r,c){
if( elem instanceof cNumber ){
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem, r, c ) {
if ( elem instanceof cNumber ) {
res += elemCalc( rate, elem.getValue(), iStart++ );
}
})
} )
continue;
}
argI = argI.tocNumber();
if( argI instanceof cError )
if ( argI instanceof cError )
continue;
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 {
name:this.name,
args:"( rate , argument-list )"
};
};
r.setFormat(r.formatType.noneFormat);
r.setFormat( r.formatType.noneFormat );
return r;
},
'ODDFPRICE' : function(){
var r = new cBaseFunction("ODDFPRICE");
'ODDFPRICE':function () {
var r = new cBaseFunction( "ODDFPRICE" );
return r;
},
'ODDFYIELD' : function(){
var r = new cBaseFunction("ODDFYIELD");
'ODDFYIELD':function () {
var r = new cBaseFunction( "ODDFYIELD" );
return r;
},
'ODDLPRICE' : function(){
var r = new cBaseFunction("ODDLPRICE");
'ODDLPRICE':function () {
var r = new cBaseFunction( "ODDLPRICE" );
return r;
},
'ODDLYIELD' : function(){
var r = new cBaseFunction("ODDLYIELD");
'ODDLYIELD':function () {
var r = new cBaseFunction( "ODDLYIELD" );
return r;
},
'PMT' : function(){
var r = new cBaseFunction("PMT");
r.setArgumentsMin(3);
r.setArgumentsMax(5);
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);
'PMT':function () {
var r = new cBaseFunction( "PMT" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 5 );
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 );
if ( rate instanceof cArea || rate instanceof cArea3D ){
rate = rate.cross(arguments[1].first);
if ( rate instanceof cArea || rate instanceof cArea3D ) {
rate = rate.cross( arguments[1].first );
}
else if( rate instanceof cArray ){
rate = rate.getElementRowCol(0,0);
else if ( rate instanceof cArray ) {
rate = rate.getElementRowCol( 0, 0 );
}
if ( nper instanceof cArea || nper instanceof cArea3D ){
nper = nper.cross(arguments[1].first);
if ( nper instanceof cArea || nper instanceof cArea3D ) {
nper = nper.cross( arguments[1].first );
}
else if( nper instanceof cArray ){
nper = nper.getElementRowCol(0,0);
else if ( nper instanceof cArray ) {
nper = nper.getElementRowCol( 0, 0 );
}
if ( pv instanceof cArea || pv instanceof cArea3D ){
pv = pv.cross(arguments[1].first);
if ( pv instanceof cArea || pv instanceof cArea3D ) {
pv = pv.cross( arguments[1].first );
}
else if( pv instanceof cArray ){
pv = pv.getElementRowCol(0,0);
else if ( pv instanceof cArray ) {
pv = pv.getElementRowCol( 0, 0 );
}
if ( fv instanceof cArea || fv instanceof cArea3D ){
fv = fv.cross(arguments[1].first);
if ( fv instanceof cArea || fv instanceof cArea3D ) {
fv = fv.cross( arguments[1].first );
}
else if( fv instanceof cArray ){
fv = fv.getElementRowCol(0,0);
else if ( fv instanceof cArray ) {
fv = fv.getElementRowCol( 0, 0 );
}
if ( type instanceof cArea || type instanceof cArea3D ){
type = type.cross(arguments[1].first);
if ( type instanceof cArea || type instanceof cArea3D ) {
type = type.cross( arguments[1].first );
}
else if( type instanceof cArray ){
type = type.getElementRowCol(0,0);
else if ( type instanceof cArray ) {
type = type.getElementRowCol( 0, 0 );
}
rate = rate.tocNumber();
......@@ -340,81 +411,81 @@ cFormulaFunction.Financial = {
if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric );
var res;
if( rate.getValue() != 0 ){
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() );
if ( rate.getValue() != 0 ) {
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() );
}
else{
res = -1*( pv.getValue()+fv.getValue() )/ nper.getValue();
else {
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 {
name:this.name,
args:"( rate , nper , pv [ , [ fv ] [ ,[ type ] ] ] )"
};
}
r.setFormat(r.formatType.noneFormat);
r.setFormat( r.formatType.noneFormat );
return r;
},
'PPMT' : function(){
var r = new cBaseFunction("PPMT");
'PPMT':function () {
var r = new cBaseFunction( "PPMT" );
return r;
},
'PRICE' : function(){
var r = new cBaseFunction("PRICE");
'PRICE':function () {
var r = new cBaseFunction( "PRICE" );
return r;
},
'PRICEDISC' : function(){
var r = new cBaseFunction("PRICEDISC");
'PRICEDISC':function () {
var r = new cBaseFunction( "PRICEDISC" );
return r;
},
'PRICEMAT' : function(){
var r = new cBaseFunction("PRICEMAT");
'PRICEMAT':function () {
var r = new cBaseFunction( "PRICEMAT" );
return r;
},
'PV' : function(){
var r = new cBaseFunction("PV");
r.setArgumentsMin(3);
r.setArgumentsMax(5);
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);
'PV':function () {
var r = new cBaseFunction( "PV" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 5 );
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 );
if ( rate instanceof cArea || rate instanceof cArea3D ){
rate = rate.cross(arguments[1].first);
if ( rate instanceof cArea || rate instanceof cArea3D ) {
rate = rate.cross( arguments[1].first );
}
else if( rate instanceof cArray ){
rate = rate.getElementRowCol(0,0);
else if ( rate instanceof cArray ) {
rate = rate.getElementRowCol( 0, 0 );
}
if ( nper instanceof cArea || nper instanceof cArea3D ){
nper = nper.cross(arguments[1].first);
if ( nper instanceof cArea || nper instanceof cArea3D ) {
nper = nper.cross( arguments[1].first );
}
else if( nper instanceof cArray ){
nper = nper.getElementRowCol(0,0);
else if ( nper instanceof cArray ) {
nper = nper.getElementRowCol( 0, 0 );
}
if ( pmt instanceof cArea || pmt instanceof cArea3D ){
pmt = pmt.cross(arguments[1].first);
if ( pmt instanceof cArea || pmt instanceof cArea3D ) {
pmt = pmt.cross( arguments[1].first );
}
else if( pmt instanceof cArray ){
pmt = pmt.getElementRowCol(0,0);
else if ( pmt instanceof cArray ) {
pmt = pmt.getElementRowCol( 0, 0 );
}
if ( fv instanceof cArea || fv instanceof cArea3D ){
fv = fv.cross(arguments[1].first);
if ( fv instanceof cArea || fv instanceof cArea3D ) {
fv = fv.cross( arguments[1].first );
}
else if( fv instanceof cArray ){
fv = fv.getElementRowCol(0,0);
else if ( fv instanceof cArray ) {
fv = fv.getElementRowCol( 0, 0 );
}
if ( type instanceof cArea || type instanceof cArea3D ){
type = type.cross(arguments[1].first);
if ( type instanceof cArea || type instanceof cArea3D ) {
type = type.cross( arguments[1].first );
}
else if( type instanceof cArray ){
type = type.getElementRowCol(0,0);
else if ( type instanceof cArray ) {
type = type.getElementRowCol( 0, 0 );
}
rate = rate.tocNumber();
......@@ -432,74 +503,74 @@ cFormulaFunction.Financial = {
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())
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()*nper.getValue() );
else {
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 {
name:this.name,
args:"( rate , nper , pmt [ , [ fv ] [ ,[ type ] ] ] )"
};
}
r.setFormat(r.formatType.noneFormat);
r.setFormat( r.formatType.noneFormat );
return r;
},
'RATE' : function(){
var r = new cBaseFunction("RATE");
'RATE':function () {
var r = new cBaseFunction( "RATE" );
return r;
},
'RECEIVED' : function(){
var r = new cBaseFunction("RECEIVED");
'RECEIVED':function () {
var r = new cBaseFunction( "RECEIVED" );
return r;
},
'SLN' : function(){
var r = new cBaseFunction("SLN");
'SLN':function () {
var r = new cBaseFunction( "SLN" );
return r;
},
'SYD' : function(){
var r = new cBaseFunction("SYD");
'SYD':function () {
var r = new cBaseFunction( "SYD" );
return r;
},
'TBILLEQ' : function(){
var r = new cBaseFunction("TBILLEQ");
'TBILLEQ':function () {
var r = new cBaseFunction( "TBILLEQ" );
return r;
},
'TBILLPRICE' : function(){
var r = new cBaseFunction("TBILLPRICE");
'TBILLPRICE':function () {
var r = new cBaseFunction( "TBILLPRICE" );
return r;
},
'TBILLYIELD' : function(){
var r = new cBaseFunction("TBILLYIELD");
'TBILLYIELD':function () {
var r = new cBaseFunction( "TBILLYIELD" );
return r;
},
'VDB' : function(){
var r = new cBaseFunction("VDB");
'VDB':function () {
var r = new cBaseFunction( "VDB" );
return r;
},
'XIRR' : function(){
var r = new cBaseFunction("XIRR");
'XIRR':function () {
var r = new cBaseFunction( "XIRR" );
return r;
},
'XNPV' : function(){
var r = new cBaseFunction("XNPV");
'XNPV':function () {
var r = new cBaseFunction( "XNPV" );
return r;
},
'YIELD' : function(){
var r = new cBaseFunction("YIELD");
'YIELD':function () {
var r = new cBaseFunction( "YIELD" );
return r;
},
'YIELDDISC' : function(){
var r = new cBaseFunction("YIELDDISC");
'YIELDDISC':function () {
var r = new cBaseFunction( "YIELDDISC" );
return r;
},
'YIELDMAT' : function(){
var r = new cBaseFunction("YIELDMAT");
'YIELDMAT':function () {
var r = new cBaseFunction( "YIELDMAT" );
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 @@
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Statistical = {
'groupName' : "Statistical",
'AVEDEV' : function(){
var r = new cBaseFunction("AVEDEV");
return r;
},
'AVERAGE' : function(){
var r = new cBaseFunction("AVERAGE");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
var count = 0, sum = new cNumber(0);
for ( var i = 0; i < arg.length; i++){
'groupName':"Statistical",
'AVEDEV':function () {
var r = new cBaseFunction( "AVEDEV" );
return r;
},
'AVERAGE':function () {
var r = new cBaseFunction( "AVERAGE" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var count = 0, sum = new cNumber( 0 );
for ( var i = 0; i < arg.length; i++ ) {
var _arg = arg[i];
if( _arg instanceof cRef || _arg instanceof cRef3D){
if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue();
if ( _argV instanceof cNumber ){
sum = _func[sum.type][_argV.type](sum,_argV,"+");
if ( _argV instanceof cNumber ) {
sum = _func[sum.type][_argV.type]( sum, _argV, "+" );
count++;
}
}
else if ( _arg instanceof cArea || _arg instanceof cArea3D){
else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++){
for ( var j = 0; j < _argAreaValue.length; j++ ) {
var __arg = _argAreaValue[j];
if ( __arg instanceof cNumber ){
sum = _func[sum.type][__arg.type](sum,__arg,"+");
if ( __arg instanceof cNumber ) {
sum = _func[sum.type][__arg.type]( sum, __arg, "+" );
count++;
}
}
}
else if( _arg instanceof cArray ){
_arg.foreach(function(elem){
else if ( _arg instanceof cArray ) {
_arg.foreach( function ( elem ) {
var e = elem.tocNumber();
if( e instanceof cNumber ){
sum = _func[sum.type][e.type](sum,e,"+");
if ( e instanceof cNumber ) {
sum = _func[sum.type][e.type]( sum, e, "+" );
count++;
}
})
} )
}
else{
if( _arg instanceof cError )
else {
if ( _arg instanceof cError )
continue;
sum = _func[sum.type][_arg.type](sum,_arg,"+");
sum = _func[sum.type][_arg.type]( sum, _arg, "+" );
count++;
}
}
return this.value = new cNumber (sum.getValue() / count);
return this.value = new cNumber( sum.getValue() / count );
};
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(number1, number2, ...)"
......@@ -62,153 +62,153 @@ cFormulaFunction.Statistical = {
}
return r;
},
'AVERAGEA' : function(){
var r = new cBaseFunction("AVERAGEA");
'AVERAGEA':function () {
var r = new cBaseFunction( "AVERAGEA" );
return r;
},
'AVERAGEIF' : function(){
var r = new cBaseFunction("AVERAGEIF");
'AVERAGEIF':function () {
var r = new cBaseFunction( "AVERAGEIF" );
return r;
},
'AVERAGEIFS' : function(){
var r = new cBaseFunction("AVERAGEIFS");
'AVERAGEIFS':function () {
var r = new cBaseFunction( "AVERAGEIFS" );
return r;
},
'BETADIST' : function(){
var r = new cBaseFunction("BETADIST");
'BETADIST':function () {
var r = new cBaseFunction( "BETADIST" );
return r;
},
'BETAINV' : function(){
var r = new cBaseFunction("BETAINV");
'BETAINV':function () {
var r = new cBaseFunction( "BETAINV" );
return r;
},
'BINOMDIST' : function(){
var r = new cBaseFunction("BINOMDIST");
'BINOMDIST':function () {
var r = new cBaseFunction( "BINOMDIST" );
return r;
},
'CHIDIST' : function(){
var r = new cBaseFunction("CHIDIST");
'CHIDIST':function () {
var r = new cBaseFunction( "CHIDIST" );
return r;
},
'CHIINV' : function(){
var r = new cBaseFunction("CHIINV");
'CHIINV':function () {
var r = new cBaseFunction( "CHIINV" );
return r;
},
'CHITEST' : function(){
var r = new cBaseFunction("CHITEST");
'CHITEST':function () {
var r = new cBaseFunction( "CHITEST" );
return r;
},
'CONFIDENCE' : function(){
var r = new cBaseFunction("CONFIDENCE");
'CONFIDENCE':function () {
var r = new cBaseFunction( "CONFIDENCE" );
return r;
},
'CORREL' : function(){
var r = new cBaseFunction("CORREL");
'CORREL':function () {
var r = new cBaseFunction( "CORREL" );
return r;
},
'COUNT' : function(){
var r = new cBaseFunction("COUNT");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
'COUNT':function () {
var r = new cBaseFunction( "COUNT" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var count = 0;
for ( var i = 0; i < arg.length; i++){
for ( var i = 0; i < arg.length; i++ ) {
var _arg = arg[i];
if( _arg instanceof cRef || _arg instanceof cRef3D){
if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue();
if ( _argV instanceof cNumber ){
if ( _argV instanceof cNumber ) {
count++;
}
}
else if ( _arg instanceof cArea || _arg instanceof cArea3D){
else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++){
if ( _argAreaValue[j] instanceof cNumber ){
for ( var j = 0; j < _argAreaValue.length; j++ ) {
if ( _argAreaValue[j] instanceof cNumber ) {
count++;
}
}
}
else if( _arg instanceof cNumber || _arg instanceof cBool || _arg instanceof cEmpty ){
else if ( _arg instanceof cNumber || _arg instanceof cBool || _arg instanceof cEmpty ) {
count++;
}
else if( _arg instanceof cString ){
if (_arg.tocNumber() instanceof cNumber)
else if ( _arg instanceof cString ) {
if ( _arg.tocNumber() instanceof cNumber )
count++;
}
else if( _arg instanceof cArray ){
_arg.foreach(function(elem){
else if ( _arg instanceof cArray ) {
_arg.foreach( function ( elem ) {
var e = elem.tocNumber();
if( e instanceof cNumber ){
if ( e instanceof cNumber ) {
count++;
}
})
} )
}
}
return this.value = new cNumber( count );
};
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( argument-list )"
};
}
r.setFormat(r.formatType.noneFormat);
r.setFormat( r.formatType.noneFormat );
return r;
},
'COUNTA' : function(){
var r = new cBaseFunction("COUNTA");
'COUNTA':function () {
var r = new cBaseFunction( "COUNTA" );
return r;
},
'COUNTBLANK' : function(){
var r = new cBaseFunction("COUNTBLANK");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'COUNTBLANK':function () {
var r = new cBaseFunction( "COUNTBLANK" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D )
if ( arg0 instanceof cArea || arg0 instanceof cArea3D )
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 );
}
else
return this.value = new cError( cErrorType.bad_reference );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( argument-list )"
};
}
r.setFormat(r.formatType.noneFormat);
r.setFormat( r.formatType.noneFormat );
return r;
},
'COUNTIF' : function(){
var r = new cBaseFunction("COUNTIF");
r.setArgumentsMin(2);
r.setArgumentsMax(2);
r.Calculate = function(arg){
'COUNTIF':function () {
var r = new cBaseFunction( "COUNTIF" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
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 );
}
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
else if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
}
arg1 = arg1.tocString();
if( !(arg1 instanceof cString) ){
if ( !(arg1 instanceof cString) ) {
return this.value = new cError( cErrorType.wrong_value_type );
}
function matching(x,y,oper){
function matching( x, y, oper ) {
var res = 0;
if( typeof x === typeof y ){
switch(oper){
if ( typeof x === typeof y ) {
switch ( oper ) {
case "<>":
res = (x.value != y.value);
break;
......@@ -235,72 +235,72 @@ cFormulaFunction.Statistical = {
}
arg1 = arg1.toString();
var operators = new RegExp("^ *[<=> ]+ *"), searchOperators = new RegExp("^ *[*?]")
var match = arg1.match(operators);
if( match || parseNum(arg1) ){
var operators = new RegExp( "^ *[<=> ]+ *" ), searchOperators = new RegExp( "^ *[*?]" )
var match = arg1.match( operators );
if ( match || parseNum( arg1 ) ) {
var search, oper, val;
if( match ){
if ( match ) {
search = arg1.substr( match[0].length );
oper = match[0].replace(/\s/g,"");
oper = match[0].replace( /\s/g, "" );
}
else{
else {
search = arg1;
}
valueForSearching = parseNum( search ) ? new cNumber( search ) : new cString( search );
if( arg0 instanceof cArea ){
if ( arg0 instanceof cArea ) {
val = arg0.getValue();
for( var i = 0; i < val.length; i++ ){
matching( val[i], valueForSearching, oper);
for ( var i = 0; i < val.length; i++ ) {
matching( val[i], valueForSearching, oper );
}
}
else if( arg0 instanceof cArea3D ){
else if ( arg0 instanceof cArea3D ) {
val = arg0.getValue();
for(var i = 0; i < val.length; i++){
matching( val[i], valueForSearching, oper);
for ( var i = 0; i < val.length; i++ ) {
matching( val[i], valueForSearching, oper );
}
}
else{
else {
val = arg0.getValue();
matching( val, valueForSearching, oper);
matching( val, valueForSearching, oper );
}
}
else{
match = arg1.match(searchOperators)
if( match ){
else {
match = arg1.match( searchOperators )
if ( match ) {
valueForSearching = arg1
.replace(/(~)?\*/g, function($0, $1){
.replace( /(~)?\*/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]*';
})
.replace(/(~)?\?/g, function($0, $1){
} )
.replace( /(~)?\?/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]{1,1}';
})
.replace(/\~/g, "\\");
regexpSearch = new RegExp(valueForSearching+"$","i");
if( arg0 instanceof cArea ){
} )
.replace( /(~\*)/g, "\\*" ).replace( /(~\?)/g, "\\?" )
regexpSearch = new RegExp( valueForSearching + "$", "i" );
if ( arg0 instanceof cArea ) {
val = arg0.getValue();
for( var i = 0; i < val.length; i++ ){
_count += regexpSearch.test(val[i].value);
for ( var i = 0; i < val.length; i++ ) {
_count += regexpSearch.test( val[i].value );
}
}
else if( arg0 instanceof cArea3D ){
else if ( arg0 instanceof cArea3D ) {
val = arg0.getValue();
for(var i in val){
for(var j in val[i]){
_count += regexpSearch.test(val[i][j].value);
for ( var i in val ) {
for ( var j in val[i] ) {
_count += regexpSearch.test( val[i][j].value );
}
}
}
else{
else {
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 {
name:this.name,
args:"( cell-range, selection-criteria )"
......@@ -308,176 +308,176 @@ cFormulaFunction.Statistical = {
}
return r;
},
'COUNTIFS' : function(){
var r = new cBaseFunction("COUNTIFS");
'COUNTIFS':function () {
var r = new cBaseFunction( "COUNTIFS" );
return r;
},
'COVAR' : function(){
var r = new cBaseFunction("COVAR");
'COVAR':function () {
var r = new cBaseFunction( "COVAR" );
return r;
},
'CRITBINOM' : function(){
var r = new cBaseFunction("CRITBINOM");
'CRITBINOM':function () {
var r = new cBaseFunction( "CRITBINOM" );
return r;
},
'DEVSQ' : function(){
var r = new cBaseFunction("DEVSQ");
'DEVSQ':function () {
var r = new cBaseFunction( "DEVSQ" );
return r;
},
'EXPONDIST' : function(){
var r = new cBaseFunction("EXPONDIST");
'EXPONDIST':function () {
var r = new cBaseFunction( "EXPONDIST" );
return r;
},
'FDIST' : function(){
var r = new cBaseFunction("FDIST");
'FDIST':function () {
var r = new cBaseFunction( "FDIST" );
return r;
},
'FINV' : function(){
var r = new cBaseFunction("FINV");
'FINV':function () {
var r = new cBaseFunction( "FINV" );
return r;
},
'FISHER' : function(){
var r = new cBaseFunction("FISHER");
'FISHER':function () {
var r = new cBaseFunction( "FISHER" );
return r;
},
'FISHERINV' : function(){
var r = new cBaseFunction("FISHERINV");
'FISHERINV':function () {
var r = new cBaseFunction( "FISHERINV" );
return r;
},
'FORECAST' : function(){
var r = new cBaseFunction("FORECAST");
'FORECAST':function () {
var r = new cBaseFunction( "FORECAST" );
return r;
},
'FREQUENCY' : function(){
var r = new cBaseFunction("FREQUENCY");
'FREQUENCY':function () {
var r = new cBaseFunction( "FREQUENCY" );
return r;
},
'FTEST' : function(){
var r = new cBaseFunction("FTEST");
'FTEST':function () {
var r = new cBaseFunction( "FTEST" );
return r;
},
'GAMMADIST' : function(){
var r = new cBaseFunction("GAMMADIST");
'GAMMADIST':function () {
var r = new cBaseFunction( "GAMMADIST" );
return r;
},
'GAMMAINV' : function(){
var r = new cBaseFunction("GAMMAINV");
'GAMMAINV':function () {
var r = new cBaseFunction( "GAMMAINV" );
return r;
},
'GAMMALN' : function(){
var r = new cBaseFunction("GAMMALN");
'GAMMALN':function () {
var r = new cBaseFunction( "GAMMALN" );
return r;
},
'GEOMEAN' : function(){
var r = new cBaseFunction("GEOMEAN");
'GEOMEAN':function () {
var r = new cBaseFunction( "GEOMEAN" );
return r;
},
'GROWTH' : function(){
var r = new cBaseFunction("GROWTH");
'GROWTH':function () {
var r = new cBaseFunction( "GROWTH" );
return r;
},
'HARMEAN' : function(){
var r = new cBaseFunction("HARMEAN");
'HARMEAN':function () {
var r = new cBaseFunction( "HARMEAN" );
return r;
},
'HYPGEOMDIST' : function(){
var r = new cBaseFunction("HYPGEOMDIST");
'HYPGEOMDIST':function () {
var r = new cBaseFunction( "HYPGEOMDIST" );
return r;
},
'INTERCEPT' : function(){
var r = new cBaseFunction("INTERCEPT");
'INTERCEPT':function () {
var r = new cBaseFunction( "INTERCEPT" );
return r;
},
'KURT' : function(){
var r = new cBaseFunction("KURT");
'KURT':function () {
var r = new cBaseFunction( "KURT" );
return r;
},
'LARGE' : function(){
var r = new cBaseFunction("LARGE");
'LARGE':function () {
var r = new cBaseFunction( "LARGE" );
return r;
},
'LINEST' : function(){
var r = new cBaseFunction("LINEST");
'LINEST':function () {
var r = new cBaseFunction( "LINEST" );
return r;
},
'LOGEST' : function(){
var r = new cBaseFunction("LOGEST");
'LOGEST':function () {
var r = new cBaseFunction( "LOGEST" );
return r;
},
'LOGINV' : function(){
var r = new cBaseFunction("LOGINV");
'LOGINV':function () {
var r = new cBaseFunction( "LOGINV" );
return r;
},
'LOGNORMDIST' : function(){
var r = new cBaseFunction("LOGNORMDIST");
'LOGNORMDIST':function () {
var r = new cBaseFunction( "LOGNORMDIST" );
return r;
},
'MAX' : function(){
var r = new cBaseFunction("MAX");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
var argI, argIVal, max = new cNumber ( Number.NEGATIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ){
'MAX':function () {
var r = new cBaseFunction( "MAX" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argI, argIVal, max = new cNumber( Number.NEGATIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ){
if( argIVal instanceof cError )
if ( argI instanceof cRef || argI instanceof cRef3D ) {
if ( argIVal instanceof cError )
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();
if ( v.getValue() > max.getValue() )
max = v;
}
}
else if ( argI instanceof cArea || argI instanceof cArea3D ){
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue();
for( var j = 0; j < argArr.length; j++ ){
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty){
for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty ) {
var v = argArr[j].tocNumber();
if ( v.getValue() > max.getValue() )
max = v;
}
else if ( argArr[j] instanceof cError ){
else if ( argArr[j] instanceof cError ) {
return this.value = argArr[j];
}
}
}
else if( argI instanceof cError )
else if ( argI instanceof cError )
return this.value = argI;
else if ( argI instanceof cString ){
else if ( argI instanceof cString ) {
var v = argI.tocNumber();
if ( v instanceof cNumber )
if ( v.getValue() > max.getValue() )
max = v;
}
else if ( argI instanceof cBool || argI instanceof cEmpty ){
else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber();
if ( v.getValue() > max.getValue() )
max = v;
}
else if( argI instanceof cArray ){
argI.foreach(function(elem){
if( elem instanceof cNumber ){
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) {
if ( elem instanceof cNumber ) {
if ( elem.getValue() > max.getValue() )
max = elem;
}
else if( elem instanceof cError ){
else if ( elem instanceof cError ) {
max = elem;
return true;
}
})
if( max instanceof cError ){
} )
if ( max instanceof cError ) {
return this.value = max;
}
}
else{
else {
if ( argI.getValue() > max.getValue() )
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 {
name:this.name,
args:"(number1, number2, ...)"
......@@ -485,17 +485,17 @@ cFormulaFunction.Statistical = {
}
return r;
},
'MAXA' : function(){
var r = new cBaseFunction("MAXA");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
var argI, max = new cNumber ( Number.NEGATIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ){
'MAXA':function () {
var r = new cBaseFunction( "MAXA" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argI, max = new cNumber( Number.NEGATIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ) {
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;
var v = argIVal.tocNumber();
......@@ -503,11 +503,11 @@ cFormulaFunction.Statistical = {
if ( v instanceof cNumber && v.getValue() > max.getValue() )
max = v;
}
else if ( argI instanceof cArea || argI instanceof cArea3D ){
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
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];
var v = argArr[j].tocNumber();
......@@ -516,43 +516,43 @@ cFormulaFunction.Statistical = {
max = v;
}
}
else if( argI instanceof cError )
else if ( argI instanceof cError )
return this.value = argI;
else if ( argI instanceof cString ){
else if ( argI instanceof cString ) {
var v = argI.tocNumber();
if ( v instanceof cNumber )
if ( v.getValue() > max.getValue() )
max = v;
}
else if ( argI instanceof cBool || argI instanceof cEmpty ){
else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber();
if ( v.getValue() > max.getValue() )
max = v;
}
else if( argI instanceof cArray ){
argI.foreach(function(elem){
if( elem instanceof cError ){
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) {
if ( elem instanceof cError ) {
max = elem;
return true;
}
elem = elem.tocNumber();
if( elem instanceof cNumber && elem.getValue() > max.getValue() ){
if ( elem instanceof cNumber && elem.getValue() > max.getValue() ) {
max = elem;
}
})
if( max instanceof cError ){
} )
if ( max instanceof cError ) {
return this.value = max;
}
}
else{
else {
if ( argI.getValue() > max.getValue() )
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 {
name:this.name,
args:"(number1, number2, ...)"
......@@ -560,77 +560,77 @@ cFormulaFunction.Statistical = {
}
return r;
},
'MEDIAN' : function(){
var r = new cBaseFunction("MEDIAN");
'MEDIAN':function () {
var r = new cBaseFunction( "MEDIAN" );
return r;
},
'MIN' : function(){
var r = new cBaseFunction("MIN");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
var argI, argIVal, min = new cNumber ( Number.POSITIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ){
'MIN':function () {
var r = new cBaseFunction( "MIN" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argI, argIVal, min = new cNumber( Number.POSITIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ){
if( argIVal instanceof cError )
if ( argI instanceof cRef || argI instanceof cRef3D ) {
if ( argIVal instanceof cError )
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();
if ( v.getValue() < min.getValue() )
min = v;
}
}
else if ( argI instanceof cArea || argI instanceof cArea3D ){
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue();
for( var j = 0; j < argArr.length; j++ ){
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty){
for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty ) {
var v = argArr[j].tocNumber();
if ( v.getValue() < min.getValue() )
min = v;
continue;
}
else if ( argArr[j] instanceof cError ){
else if ( argArr[j] instanceof cError ) {
return this.value = argArr[j];
}
}
}
else if( argI instanceof cError )
else if ( argI instanceof cError )
return this.value = argI;
else if ( argI instanceof cString ){
else if ( argI instanceof cString ) {
var v = argI.tocNumber();
if ( v instanceof cNumber )
if ( v.getValue() < min.getValue() )
min = v;
}
else if ( argI instanceof cBool || argI instanceof cEmpty){
else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber();
if ( v.getValue() < min.getValue() )
min = v;
}
else if( argI instanceof cArray ){
argI.foreach(function(elem){
if( elem instanceof cNumber ){
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) {
if ( elem instanceof cNumber ) {
if ( elem.getValue() < min.getValue() )
min = elem;
}
else if( elem instanceof cError ){
else if ( elem instanceof cError ) {
min = elem;
return true;
}
})
if( min instanceof cError ){
} )
if ( min instanceof cError ) {
return this.value = min;
}
}
else{
else {
if ( argI.getValue() < min.getValue() )
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 {
name:this.name,
args:"(number1, number2, ...)"
......@@ -638,17 +638,17 @@ cFormulaFunction.Statistical = {
}
return r;
},
'MINA' : function(){
var r = new cBaseFunction("MINA");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
var argI, min = new cNumber ( Number.POSITIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ){
'MINA':function () {
var r = new cBaseFunction( "MINA" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argI, min = new cNumber( Number.POSITIVE_INFINITY );
for ( var i = 0; i < this.argumentsCurrent; i++ ) {
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;
var v = argIVal.tocNumber();
......@@ -656,11 +656,11 @@ cFormulaFunction.Statistical = {
if ( v instanceof cNumber && v.getValue() < min.getValue() )
min = v;
}
else if ( argI instanceof cArea || argI instanceof cArea3D ){
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
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];
}
......@@ -670,44 +670,44 @@ cFormulaFunction.Statistical = {
min = v;
}
}
else if( argI instanceof cError )
else if ( argI instanceof cError )
return this.value = argI;
else if ( argI instanceof cString ){
else if ( argI instanceof cString ) {
var v = argI.tocNumber();
if ( v instanceof cNumber )
if ( v.getValue() < min.getValue() )
min = v;
}
else if ( argI instanceof cBool || argI instanceof cEmpty ){
else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber();
if ( v.getValue() < min.getValue() )
min = v;
}
else if( argI instanceof cArray ){
argI.foreach(function(elem){
if( elem instanceof cError ){
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) {
if ( elem instanceof cError ) {
min = elem;
return true;
}
elem = elem.tocNumber();
if( elem instanceof cNumber && elem.getValue() < min.getValue() ){
if ( elem instanceof cNumber && elem.getValue() < min.getValue() ) {
min = elem;
}
})
if( min instanceof cError ){
} )
if ( min instanceof cError ) {
return this.value = min;
}
}
else{
else {
if ( argI.getValue() < min.getValue() )
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 {
name:this.name,
args:"(number1, number2, ...)"
......@@ -715,202 +715,203 @@ cFormulaFunction.Statistical = {
}
return r;
},
'MODE' : function(){
var r = new cBaseFunction("MODE");
'MODE':function () {
var r = new cBaseFunction( "MODE" );
return r;
},
'NEGBINOMDIST' : function(){
var r = new cBaseFunction("NEGBINOMDIST");
'NEGBINOMDIST':function () {
var r = new cBaseFunction( "NEGBINOMDIST" );
return r;
},
'NORMDIST' : function(){
var r = new cBaseFunction("NORMDIST");
'NORMDIST':function () {
var r = new cBaseFunction( "NORMDIST" );
return r;
},
'NORMINV' : function(){
var r = new cBaseFunction("NORMINV");
'NORMINV':function () {
var r = new cBaseFunction( "NORMINV" );
return r;
},
'NORMSDIST' : function(){
var r = new cBaseFunction("NORMSDIST");
'NORMSDIST':function () {
var r = new cBaseFunction( "NORMSDIST" );
return r;
},
'NORMSINV' : function(){
var r = new cBaseFunction("NORMSINV");
'NORMSINV':function () {
var r = new cBaseFunction( "NORMSINV" );
return r;
},
'PEARSON' : function(){
var r = new cBaseFunction("PEARSON");
'PEARSON':function () {
var r = new cBaseFunction( "PEARSON" );
return r;
},
'PERCENTILE' : function(){
var r = new cBaseFunction("PERCENTILE");
'PERCENTILE':function () {
var r = new cBaseFunction( "PERCENTILE" );
return r;
},
'PERCENTRANK' : function(){
var r = new cBaseFunction("PERCENTRANK");
'PERCENTRANK':function () {
var r = new cBaseFunction( "PERCENTRANK" );
return r;
},
'PERMUT' : function(){
var r = new cBaseFunction("PERMUT");
'PERMUT':function () {
var r = new cBaseFunction( "PERMUT" );
return r;
},
'POISSON' : function(){
var r = new cBaseFunction("POISSON");
'POISSON':function () {
var r = new cBaseFunction( "POISSON" );
return r;
},
'PROB' : function(){
var r = new cBaseFunction("PROB");
'PROB':function () {
var r = new cBaseFunction( "PROB" );
return r;
},
'QUARTILE' : function(){
var r = new cBaseFunction("QUARTILE");
'QUARTILE':function () {
var r = new cBaseFunction( "QUARTILE" );
return r;
},
'RANK' : function(){
var r = new cBaseFunction("RANK");
'RANK':function () {
var r = new cBaseFunction( "RANK" );
return r;
},
'RSQ' : function(){
var r = new cBaseFunction("RSQ");
'RSQ':function () {
var r = new cBaseFunction( "RSQ" );
return r;
},
'SKEW' : function(){
var r = new cBaseFunction("SKEW");
'SKEW':function () {
var r = new cBaseFunction( "SKEW" );
return r;
},
'SLOPE' : function(){
var r = new cBaseFunction("SLOPE");
'SLOPE':function () {
var r = new cBaseFunction( "SLOPE" );
return r;
},
'SMALL' : function(){
var r = new cBaseFunction("SMALL");
'SMALL':function () {
var r = new cBaseFunction( "SMALL" );
return r;
},
'STANDARDIZE' : function(){
var r = new cBaseFunction("STANDARDIZE");
'STANDARDIZE':function () {
var r = new cBaseFunction( "STANDARDIZE" );
return r;
},
'STDEV' : function(){
var r = new cBaseFunction("STDEV");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
var count = 0, sum = new cNumber(0), member = [];
for ( var i = 0; i < arg.length; i++){
'STDEV':function () {
var r = new cBaseFunction( "STDEV" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var count = 0, sum = new cNumber( 0 ), member = [];
for ( var i = 0; i < arg.length; i++ ) {
var _arg = arg[i];
if( _arg instanceof cRef || _arg instanceof cRef3D){
if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue();
if ( _argV instanceof cNumber ){
member.push(_argV);
sum = _func[sum.type][_argV.type](sum,_argV,"+");
if ( _argV instanceof cNumber ) {
member.push( _argV );
sum = _func[sum.type][_argV.type]( sum, _argV, "+" );
count++;
}
}
else if ( _arg instanceof cArea || _arg instanceof cArea3D){
else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++){
for ( var j = 0; j < _argAreaValue.length; j++ ) {
var __arg = _argAreaValue[j];
if ( __arg instanceof cNumber ){
member.push(__arg);
sum = _func[sum.type][__arg.type](sum,__arg,"+");
if ( __arg instanceof cNumber ) {
member.push( __arg );
sum = _func[sum.type][__arg.type]( sum, __arg, "+" );
count++;
}
}
}
else if( _arg instanceof cArray ){
_arg.foreach(function(elem){
else if ( _arg instanceof cArray ) {
_arg.foreach( function ( elem ) {
var e = elem.tocNumber();
if( e instanceof cNumber ){
member.push(e);
sum = _func[sum.type][e.type](sum,e,"+");
if ( e instanceof cNumber ) {
member.push( e );
sum = _func[sum.type][e.type]( sum, e, "+" );
count++;
}
})
} )
}
else{
else {
_arg = _arg.tocNumber();
if( _arg instanceof cNumber ){
member.push(_arg);
sum = _func[sum.type][_arg.type](sum,_arg,"+");
if ( _arg instanceof cNumber ) {
member.push( _arg );
sum = _func[sum.type][_arg.type]( sum, _arg, "+" );
count++;
}
}
}
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;
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 {
name:this.name,
args:"( argument-list )"
};
}
r.setFormat(r.formatType.noneFormat);
r.setFormat( r.formatType.noneFormat );
return r;
},
'STDEVA' : function(){
var r = new cBaseFunction("STDEVA");
'STDEVA':function () {
var r = new cBaseFunction( "STDEVA" );
return r;
},
'STDEVP' : function(){
var r = new cBaseFunction("STDEVP");
'STDEVP':function () {
var r = new cBaseFunction( "STDEVP" );
return r;
},
'STDEVPA' : function(){
var r = new cBaseFunction("STDEVPA");
'STDEVPA':function () {
var r = new cBaseFunction( "STDEVPA" );
return r;
},
'STEYX' : function(){
var r = new cBaseFunction("STEYX");
'STEYX':function () {
var r = new cBaseFunction( "STEYX" );
return r;
},
'TDIST' : function(){
var r = new cBaseFunction("TDIST");
'TDIST':function () {
var r = new cBaseFunction( "TDIST" );
return r;
},
'TINV' : function(){
var r = new cBaseFunction("TINV");
'TINV':function () {
var r = new cBaseFunction( "TINV" );
return r;
},
'TREND' : function(){
var r = new cBaseFunction("TREND");
'TREND':function () {
var r = new cBaseFunction( "TREND" );
return r;
},
'TRIMMEAN' : function(){
var r = new cBaseFunction("TRIMMEAN");
'TRIMMEAN':function () {
var r = new cBaseFunction( "TRIMMEAN" );
return r;
},
'TTEST' : function(){
var r = new cBaseFunction("TTEST");
'TTEST':function () {
var r = new cBaseFunction( "TTEST" );
return r;
},
'VAR' : function(){
var r = new cBaseFunction("VAR");
'VAR':function () {
var r = new cBaseFunction( "VAR" );
return r;
},
'VARA' : function(){
var r = new cBaseFunction("VARA");
'VARA':function () {
var r = new cBaseFunction( "VARA" );
return r;
},
'VARP' : function(){
var r = new cBaseFunction("VARP");
'VARP':function () {
var r = new cBaseFunction( "VARP" );
return r;
},
'VARPA' : function(){
var r = new cBaseFunction("VARPA");
'VARPA':function () {
var r = new cBaseFunction( "VARPA" );
return r;
},
'WEIBULL' : function(){
var r = new cBaseFunction("WEIBULL");
'WEIBULL':function () {
var r = new cBaseFunction( "WEIBULL" );
return r;
},
'ZTEST' : function(){
var r = new cBaseFunction("ZTEST");
'ZTEST':function () {
var r = new cBaseFunction( "ZTEST" );
return r;
}
}
\ No newline at end of file
......@@ -6,49 +6,49 @@
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.TextAndData = {
'groupName' : "TextAndData",
'ASC' : function(){
var r = new cBaseFunction("ASC");
'groupName':"TextAndData",
'ASC':function () {
var r = new cBaseFunction( "ASC" );
return r;
},
'BAHTTEXT' : function(){
var r = new cBaseFunction("BAHTTEXT");
'BAHTTEXT':function () {
var r = new cBaseFunction( "BAHTTEXT" );
return r;
},
'CHAR' : function(){
var r = new cBaseFunction("CHAR");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'CHAR':function () {
var r = new cBaseFunction( "CHAR" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first).tocNumber();
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber();
}
else if( arg0 instanceof cArray){
else if ( arg0 instanceof cArray ) {
var ret = new cArray();
arg0.foreach(function(elem,r,c){
arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocNumber();
if(!ret.array[r])
if ( !ret.array[r] )
ret.addRow();
if( _elem instanceof cError )
ret.addElement(_elem);
if ( _elem instanceof cError )
ret.addElement( _elem );
else
ret.addElement( new cString( String.fromCharCode(_elem.getValue()) ) );
})
ret.addElement( new cString( String.fromCharCode( _elem.getValue() ) ) );
} )
return this.value = ret;
}
arg0 = arg0.tocNumber();
if( arg0 instanceof cError ){
if ( arg0 instanceof cError ) {
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 {
name:this.name,
args:"( number )"
......@@ -56,32 +56,32 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'CLEAN' : function(){
var r = new cBaseFunction("CLEAN");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'CLEAN':function () {
var r = new cBaseFunction( "CLEAN" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first).tocNumber();
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber();
}
if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
arg0 = arg0.tocString();
var v = arg0.getValue(), l = v.length, res = "";
for( var i = 0; i < l; i++){
if( v.charCodeAt(i) > 0x1f )
res+=v[i];
for ( var i = 0; i < l; i++ ) {
if ( v.charCodeAt( i ) > 0x1f )
res += v[i];
}
return this.value = new cString( res );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( string )"
......@@ -89,40 +89,40 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'CODE' : function(){
var r = new cBaseFunction("CODE");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'CODE':function () {
var r = new cBaseFunction( "CODE" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first).tocString();
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString();
}
else if( arg0 instanceof cArray){
else if ( arg0 instanceof cArray ) {
var ret = new cArray();
arg0.foreach(function(elem,r,c){
arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocString();
if(!ret.array[r])
if ( !ret.array[r] )
ret.addRow();
if( _elem instanceof cError )
ret.addElement(_elem);
if ( _elem instanceof cError )
ret.addElement( _elem );
else
ret.addElement(new cNumber( _elem.toString().charCodeAt() ));
})
ret.addElement( new cNumber( _elem.toString().charCodeAt() ) );
} )
return this.value = ret;
}
arg0 = arg0.tocString();
if( arg0 instanceof cError ){
if ( arg0 instanceof cError ) {
return this.value = arg0;
}
return this.value = new cNumber( arg0.toString().charCodeAt() );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( string )"
......@@ -130,32 +130,32 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'CONCATENATE' : function(){
var r = new cBaseFunction("CONCATENATE");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
var arg0 = new cString(""), argI;
for(var i = 0; i < this.argumentsCurrent; i++){
'CONCATENATE':function () {
var r = new cBaseFunction( "CONCATENATE" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var arg0 = new cString( "" ), argI;
for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i];
if( argI instanceof cArea || argI instanceof cArea3D ){
argI = argI.cross(arguments[1].first);
if ( argI instanceof cArea || argI instanceof cArea3D ) {
argI = argI.cross( arguments[1].first );
}
argI = argI.tocString();
if (argI instanceof cError) {
if ( argI instanceof cError ) {
return this.value = argI;
}
else if( argI instanceof cArray ){
argI.foreach(function(elem){
if( elem instanceof cError ){
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) {
if ( elem instanceof cError ) {
arg0 = elem;
return true;
}
arg0 = new cString( arg0.toString().concat( elem.toString() ) );
})
if( arg0 instanceof cError ){
} )
if ( arg0 instanceof cError ) {
return this.value = arg0;
}
}
......@@ -164,7 +164,7 @@ cFormulaFunction.TextAndData = {
}
return this.value = arg0;
};
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(text1, text2, ...)"
......@@ -172,18 +172,18 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'DOLLAR' : function(){
var r = new cBaseFunction("DOLLAR");
r.setArgumentsMin(1);
r.setArgumentsMax(2);
r.Calculate = function(arg){
var res = cFormulaFunction.TextAndData["FIXED"]().Calculate(arg);
if( res instanceof cError )
'DOLLAR':function () {
var r = new cBaseFunction( "DOLLAR" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
var res = cFormulaFunction.TextAndData["FIXED"]().Calculate( arg );
if ( res instanceof cError )
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 {
name:this.name,
args:"( number [ , num-decimal ] )"
......@@ -191,31 +191,31 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'EXACT' : function(){
var r = new cBaseFunction("EXACT");
r.setArgumentsMin(2);
r.setArgumentsMax(2);
r.Calculate = function(arg){
'EXACT':function () {
var r = new cBaseFunction( "EXACT" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
arg0 = arg0.tocString();
arg1 = arg1.tocString();
if( arg0 instanceof cArray && arg1 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
arg1 = arg1.getElementRowCol(0,0);
if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 );
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
else if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
}
if ( arg0 instanceof cError ) return this.value = arg0;
......@@ -224,7 +224,7 @@ cFormulaFunction.TextAndData = {
var arg0val = arg0.getValue(), arg1val = arg1.getValue();
return this.value = new cBool( arg0val === arg1val );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(text1, text2)"
......@@ -232,44 +232,44 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'FIND' : function(){
var r = new cBaseFunction("FIND");
r.setArgumentsMin(2);
r.setArgumentsMax(3);
r.Calculate = function(arg){
'FIND':function () {
var r = new cBaseFunction( "FIND" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 3 );
r.Calculate = function ( arg ) {
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 ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
arg0 = arg0.tocString();
arg1 = arg1.tocString();
if( arg2 !== null ){
if ( arg2 !== null ) {
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){
arg2 = arg2.cross(arguments[1].first);
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first );
}
arg2 = arg2.tocNumber();
if( arg2 instanceof cArray ){
arg2 = arg1.getElementRowCol(0,0);
if ( arg2 instanceof cArray ) {
arg2 = arg1.getElementRowCol( 0, 0 );
}
if ( arg2 instanceof cError ) return this.value = arg2;
pos = arg2.getValue();
pos = pos > 0 ? pos-1 : pos;
pos = pos > 0 ? pos - 1 : pos;
}
if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
}
if ( arg0 instanceof cError ) return this.value = arg0;
......@@ -278,26 +278,26 @@ cFormulaFunction.TextAndData = {
str = arg1.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 );
str = str.substring(pos);
str = str.substring( pos );
res = str.search( searchStr );
if( res >= 0 )
if ( res >= 0 )
res += pos;
}
else
res = str.search( searchStr );
if( res < 0 )
if ( res < 0 )
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 {
name:this.name,
args:"( string-1 , string-2 [ , start-pos ] )"
......@@ -305,170 +305,175 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'FINDB' : function(){
'FINDB':function () {
var r = cFormulaFunction.TextAndData["FIND"]()
r.setName("FINDB");
r.setName( "FINDB" );
return r;
},
'FIXED' : function(){
var r = new cBaseFunction("FIXED");
r.setArgumentsMin(1);
r.setArgumentsMax(3);
r.Calculate = function(arg){
'FIXED':function () {
var r = new cBaseFunction( "FIXED" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 3 );
r.Calculate = function ( arg ) {
function SignZeroPositive(number){
function SignZeroPositive( number ) {
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
}
function Floor(number, significance){
function Floor( number, significance ) {
var quotient = number / significance;
if (quotient == 0){
if ( quotient == 0 ) {
return 0;
}
var nolpiat = 5 * sign(quotient) * Math.pow(10, Math.floor( Math.log ( Math.abs(quotient) ) / Math.log ( 10 ) ) - cExcelSignificantDigits);
return truncate(quotient + nolpiat) * significance;
var nolpiat = 5 * sign( quotient ) * Math.pow( 10, Math.floor( Math.log( Math.abs( quotient ) ) / Math.log( 10 ) ) - cExcelSignificantDigits );
return truncate( quotient + nolpiat ) * significance;
}
function roundHelper(number,num_digits){
if(num_digits > cExcelMaxExponent){
if (Math.abs(number) < 1 || num_digits < 1e10) // The values are obtained experimentally
function roundHelper( number, num_digits ) {
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)
{
if (Math.abs(number) < 0.01) // The values are obtained experimentally
else if ( num_digits < cExcelMinExponent ) {
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;
if ( number/significance == Infinity){
if ( number / significance == Infinity ) {
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 = ""
if(skip)
if ( skip )
return str;
res = str.split(".");
res = str.split( "." );
_int = res[0];
if( res.length == 2)
if ( res.length == 2 )
_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--){
_tmp += _int[i].split("").reverse().join("");
if( i != 0 )
for ( var i = _int.length - 1; i >= 0; i-- ) {
_tmp += _int[i].split( "" ).reverse().join( "" );
if ( i != 0 )
_tmp += ",";
}
if( undefined != _dec)
while( _dec.length < arg1.getValue() ) _dec+="0";
if ( undefined != _dec )
while ( _dec.length < arg1.getValue() ) _dec += "0";
return "" + _tmp + ( res.length == 2 ? "."+_dec+"" : "");
return "" + _tmp + ( res.length == 2 ? "." + _dec + "" : "");
}
var arg0 = arg[0],
arg1 = arg[1] ? arg[1] : new cNumber(2),
arg2 = arg[2] ? arg[2] : new cBool(false);
arg1 = arg[1] ? arg[1] : new cNumber( 2 ),
arg2 = arg[2] ? arg[2] : new cBool( false );
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){
arg2 = arg2.cross(arguments[1].first);
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first );
}
if( arg0 instanceof cError ) return this.value = arg0;
if( arg1 instanceof cError ) return this.value = arg1;
if( arg2 instanceof cError ) return this.value = arg2;
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
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();
if(arg0 instanceof cError) return this.value = arg0;
else if(arg0 instanceof cString) return this.value = new cError(cErrorType.wrong_value_type);
if ( arg0 instanceof cError ) return this.value = arg0;
else if ( arg0 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
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();
if(arg1 instanceof cError) return this.value = arg1;
else if(arg1 instanceof cString) return this.value = new cError(cErrorType.wrong_value_type);
if ( arg1 instanceof cError ) return this.value = arg1;
else if ( arg1 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else arg1 = arg1.tocNumber();
}
else arg1 = arg1.tocNumber();
if( arg0 instanceof cArray && arg1 instanceof cArray ){
if( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ){
if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) {
return this.value = new cError( cErrorType.not_available );
}
else{
arg0.foreach(function(elem,r,c){
else {
arg0.foreach( function ( elem, r, c ) {
var a = elem;
b = arg1.getElementRowCol(r,c);
if( a instanceof cNumber && b instanceof cNumber ){
b = arg1.getElementRowCol( r, c );
if ( a instanceof cNumber && b instanceof cNumber ) {
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
this.array[r][c] = new cError( cErrorType.wrong_value_type );
})
} )
return this.value = arg0;
}
}
else if( arg0 instanceof cArray ){
arg0.foreach(function(elem,r,c){
else if ( arg0 instanceof cArray ) {
arg0.foreach( function ( elem, r, c ) {
var a = elem;
b = arg1;
if( a instanceof cNumber && b instanceof cNumber ){
if ( a instanceof cNumber && b instanceof cNumber ) {
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
this.array[r][c] = new cError( cErrorType.wrong_value_type );
})
} )
return this.value = arg0;
}
else if( arg1 instanceof cArray ){
arg1.foreach(function(elem,r,c){
else if ( arg1 instanceof cArray ) {
arg1.foreach( function ( elem, r, c ) {
var a = arg0;
b = elem;
if( a instanceof cNumber && b instanceof cNumber ){
if ( a instanceof cNumber && b instanceof cNumber ) {
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
this.array[r][c] = new cError( cErrorType.wrong_value_type );
})
} )
return this.value = arg1;
}
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 {
name:this.name,
args:"( number [ , [ num-decimal ] [ , suppress-commas-flag ] ] )"
......@@ -476,46 +481,46 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'JIS' : function(){
var r = new cBaseFunction("JIS");
'JIS':function () {
var r = new cBaseFunction( "JIS" );
return r;
},
'LEFT' : function(){
var r = new cBaseFunction("LEFT");
r.setArgumentsMin(1);
r.setArgumentsMax(2);
r.Calculate = function(arg){
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber(1) : arg[1];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
'LEFT':function () {
var r = new cBaseFunction( "LEFT" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
arg0 = arg0.tocString();
arg1 = arg1.tocNumber();
if( arg0 instanceof cArray && arg1 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
arg1 = arg1.getElementRowCol(0,0);
if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 );
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
else if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
}
if ( arg0 instanceof cError ) return this.value = arg0;
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 {
name:this.name,
args:"( string [ , number-chars ] )"
......@@ -523,25 +528,25 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'LEFTB' : function(){
'LEFTB':function () {
var r = cFormulaFunction.TextAndData["LEFT"]()
r.setName("LEFTB");
r.setName( "LEFTB" );
return r;
},
'LEN' : function(){
var r = new cBaseFunction("LEN");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'LEN':function () {
var r = new cBaseFunction( "LEN" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
arg0 = arg0.tocString();
if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
if ( arg0 instanceof cError ) return this.value = arg0;
......@@ -549,7 +554,7 @@ cFormulaFunction.TextAndData = {
return this.value = new cNumber( arg0.getValue().length )
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( string )"
......@@ -557,30 +562,30 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'LENB' : function(){
'LENB':function () {
var r = cFormulaFunction.TextAndData["LEN"]();
r.setName("LENB");
r.setName( "LENB" );
return r;
},
'LOWER' : function(){
var r = new cBaseFunction("LOWER");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'LOWER':function () {
var r = new cBaseFunction( "LOWER" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D )
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D )
arg0 = arg0.cross( arguments[1].first );
arg0 = arg0.tocString();
if( arg0 instanceof cArray )
arg0 = arg0.getElementRowCol(0,0);
if ( arg0 instanceof cArray )
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() );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(text)"
......@@ -588,54 +593,54 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'MID' : function(){
var r = new cBaseFunction("MID");
r.setArgumentsMin(3);
r.setArgumentsMax(3);
r.Calculate = function(arg){
'MID':function () {
var r = new cBaseFunction( "MID" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 3 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){
arg2 = arg2.cross(arguments[1].first);
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first );
}
arg0 = arg0.tocString();
arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber();
if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
}
if( arg2 instanceof cArray ){
arg2 = arg2.getElementRowCol(0,0);
if ( arg2 instanceof cArray ) {
arg2 = arg2.getElementRowCol( 0, 0 );
}
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2;
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 ( 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 );
var l = arg0.getValue().length;
if( arg1.getValue() > l )
return this.value = new cString("");
if ( arg1.getValue() > l )
return this.value = new cString( "" );
/* if( arg1.getValue() < l )
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 {
name:this.name,
args:"( string , start-pos , number-chars )"
......@@ -643,32 +648,32 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'MIDB' : function(){
'MIDB':function () {
var r = cFormulaFunction.TextAndData["MID"]();
r.setName("MIDB");
r.setName( "MIDB" );
return r;
},
'PHONETIC' : function(){
var r = new cBaseFunction("PHONETIC");
'PHONETIC':function () {
var r = new cBaseFunction( "PHONETIC" );
return r;
},
'PROPER' : function(){
var r = new cBaseFunction("PROPER");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
var reg_PROPER = new RegExp("[-#$+*/^&%<\\[\\]='?_\\@!~`\">: ;.\\)\\(,]|\\d|\\s"), arg0 = arg[0];
function proper(str){
'PROPER':function () {
var r = new cBaseFunction( "PROPER" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var reg_PROPER = new RegExp( "[-#$+*/^&%<\\[\\]='?_\\@!~`\">: ;.\\)\\(,]|\\d|\\s" ), arg0 = arg[0];
function proper( str ) {
var canUpper = true, retStr = "", regTest;
for( var i=0; i< str.length; i++ ){
regTest = reg_PROPER.test(str[i]);
for ( var i = 0; i < str.length; i++ ) {
regTest = reg_PROPER.test( str[i] );
if( regTest ){
if ( regTest ) {
canUpper = true;
}
else{
if( canUpper ){
else {
if ( canUpper ) {
retStr += str[i].toUpperCase();
canUpper = false;
continue;
......@@ -681,33 +686,33 @@ cFormulaFunction.TextAndData = {
return retStr;
}
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first).tocString();
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString();
}
else if( arg0 instanceof cArray){
else if ( arg0 instanceof cArray ) {
var ret = new cArray();
arg0.foreach(function(elem,r,c){
arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocString();
if(!ret.array[r])
if ( !ret.array[r] )
ret.addRow();
if( _elem instanceof cError )
ret.addElement(_elem);
if ( _elem instanceof cError )
ret.addElement( _elem );
else
ret.addElement(new cString( proper(_elem.toString()) ));
})
ret.addElement( new cString( proper( _elem.toString() ) ) );
} )
return this.value = ret;
}
arg0 = arg0.tocString();
if( arg0 instanceof cError ){
if ( arg0 instanceof cError ) {
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 {
name:this.name,
args:"( string )"
......@@ -715,74 +720,74 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'REPLACE' : function(){
var r = new cBaseFunction("REPLACE");
r.setArgumentsMin(4);
r.setArgumentsMax(4);
r.Calculate = function(arg){
'REPLACE':function () {
var r = new cBaseFunction( "REPLACE" );
r.setArgumentsMin( 4 );
r.setArgumentsMax( 4 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first).tocString();
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString();
}
else if( arg0 instanceof cArray){
arg0 = arg0.getElement(0).tocString();
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ).tocString();
}
arg0 = arg0.tocString();
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first).tocNumber();
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocNumber();
}
else if( arg1 instanceof cArray){
arg1 = arg1.getElement(0).tocNumber();
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 ).tocNumber();
}
arg1 = arg1.tocNumber();
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){
arg2 = arg2.cross(arguments[1].first).tocNumber();
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ).tocNumber();
}
else if( arg2 instanceof cArray){
arg2 = arg2.getElement(0).tocNumber();
else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement( 0 ).tocNumber();
}
arg2 = arg2.tocNumber();
if( arg3 instanceof cArea || arg3 instanceof cArea3D ){
arg3 = arg3.cross(arguments[1].first).tocString();
if ( arg3 instanceof cArea || arg3 instanceof cArea3D ) {
arg3 = arg3.cross( arguments[1].first ).tocString();
}
else if( arg3 instanceof cArray){
arg3 = arg3.getElement(0).tocString();
else if ( arg3 instanceof cArray ) {
arg3 = arg3.getElement( 0 ).tocString();
}
arg3 = arg3.tocString();
if( arg0 instanceof cError )
if ( arg0 instanceof cError )
return this.value = arg0;
if( arg1 instanceof cError )
if ( arg1 instanceof cError )
return this.value = arg1;
if( arg2 instanceof cError )
if ( arg2 instanceof cError )
return this.value = arg2;
if( arg3 instanceof cError )
if ( arg3 instanceof cError )
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 );
}
var string1 = arg0.getValue(), string2 = arg3.getValue(), res = "";
string1 = string1.split("");
string1.splice(arg1.getValue()-1,arg2.getValue(),string2);
for( var i = 0; i < string1.length; i++){
string1 = string1.split( "" );
string1.splice( arg1.getValue() - 1, arg2.getValue(), string2 );
for ( var i = 0; i < string1.length; i++ ) {
res += string1[i];
}
return this.value = new cString(res);
return this.value = new cString( res );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( string-1, start-pos, number-chars, string-2 )"
......@@ -790,61 +795,61 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'REPLACEB' : function(){
'REPLACEB':function () {
var r = cFormulaFunction.TextAndData["REPLACE"]();
r.setName("REPLACEB");
r.setName( "REPLACEB" );
return r;
},
'REPT' : function(){
var r = new cBaseFunction("REPT");
r.setArgumentsMin(2);
r.setArgumentsMax(2);
r.Calculate = function(arg){
'REPT':function () {
var r = new cBaseFunction( "REPT" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], res = "";
if( arg0 instanceof cError ) return this.value = arg0;
if( arg1 instanceof cError ) return this.value = arg1;
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
if( arg0 instanceof cArray && arg1 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
arg1 = arg1.getElementRowCol(0,0);
if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 );
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
else if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
}
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
arg0 = arg0.tocString();
if (arg0 instanceof cError)
if ( arg0 instanceof cError )
return this.value = arg0;
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first).tocNumber();
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
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();
}
if(arg1 instanceof cError)
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();
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++){
res = res.concat(arg0.getValue());
for ( var i = 0; i < arg1.getValue(); i++ ) {
res = res.concat( arg0.getValue() );
}
return this.value = new cString( res );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(text, number_of_times)"
......@@ -852,42 +857,42 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'RIGHT' : function(){
var r = new cBaseFunction("RIGHT");
r.setArgumentsMin(1);
r.setArgumentsMax(2);
r.Calculate = function(arg){
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber(1) : arg[1];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
'RIGHT':function () {
var r = new cBaseFunction( "RIGHT" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
arg0 = arg0.tocString();
arg1 = arg1.tocNumber();
if( arg0 instanceof cArray && arg1 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
arg1 = arg1.getElementRowCol(0,0);
if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 );
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
else if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
}
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
if( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
var l = arg0.getValue().length, _number = l-arg1.getValue();
return this.value = new cString( arg0.getValue().substring( _number < 0 ? 0 : _number , l) )
if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
var l = arg0.getValue().length, _number = l - arg1.getValue();
return this.value = new cString( arg0.getValue().substring( _number < 0 ? 0 : _number, l ) )
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( string [ , number-chars ] )"
......@@ -895,82 +900,81 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'RIGHTB' : function(){
'RIGHTB':function () {
var r = cFormulaFunction.TextAndData["RIGHT"]()
r.setName("RIGHTB");
r.setName( "RIGHTB" );
return r;
},
'SEARCH' : function(){
var r = new cBaseFunction("SEARCH");
r.setArgumentsMin(2);
r.setArgumentsMax(3);
r.Calculate = function(arg){
'SEARCH':function () {
var r = new cBaseFunction( "SEARCH" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 3 );
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 ){
arg0 = arg0.cross(arguments[1].first).tocString();
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString();
}
else if( arg0 instanceof cArray){
arg0 = arg0.getElement(0).tocString();
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ).tocString();
}
arg0 = arg0.tocString();
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first).tocString();
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocString();
}
else if( arg1 instanceof cArray){
arg1 = arg1.getElement(0).tocString();
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 ).tocString();
}
arg1 = arg1.tocString();
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){
arg2 = arg2.cross(arguments[1].first).tocNumber();
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ).tocNumber();
}
else if( arg2 instanceof cArray){
arg2 = arg2.getElement(0).tocNumber();
else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement( 0 ).tocNumber();
}
arg2 = arg2.tocNumber();
if( arg0 instanceof cError )
if ( arg0 instanceof cError )
return this.value = arg0;
if( arg1 instanceof cError )
if ( arg1 instanceof cError )
return this.value = arg1;
if( arg2 instanceof cError )
if ( arg2 instanceof cError )
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 );
}
var string1 = arg0.getValue(), string2 = arg1.getValue(), res = 0,
var string1 = arg0.getValue(), string2 = arg1.getValue(),
valueForSearching = string1
.replace(/(~)?\*/g, function($0, $1){
.replace( /(~)?\*/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]*';
})
.replace(/(~)?\?/g, function($0, $1){
} )
.replace( /(~)?\?/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]{1,1}';
})
.replace(/\~/g, "\\");
} )
.replace( /(~\*)/g, "\\*" ).replace( /(~\?)/g, "\\?" );
valueForSearching = new RegExp( valueForSearching, "ig")
if( string1 == "" )
valueForSearching = new RegExp( valueForSearching, "ig" )
if ( string1 == "" )
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 cNumber(res+1);
return this.value = new cNumber( res + 1 );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( string-1 , string-2 [ , start-pos ] )"
......@@ -978,82 +982,82 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'SEARCHB' : function(){
'SEARCHB':function () {
var r = cFormulaFunction.TextAndData["SEARCH"]();
r.setName("SEARCHB");
r.setName( "SEARCHB" );
return r;
},
'SUBSTITUTE' : function(){
var r = new cBaseFunction("SUBSTITUTE");
r.setArgumentsMin(3);
r.setArgumentsMax(4);
r.Calculate = function(arg){
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new cNumber(0);
'SUBSTITUTE':function () {
var r = new cBaseFunction( "SUBSTITUTE" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 4 );
r.Calculate = function ( arg ) {
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 ){
arg0 = arg0.cross(arguments[1].first).tocString();
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString();
}
else if( arg0 instanceof cArray){
arg0 = arg0.getElement(0).tocString();
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ).tocString();
}
arg0 = arg0.tocString();
if( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first).tocString();
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocString();
}
else if( arg1 instanceof cArray){
arg1 = arg1.getElement(0).tocString();
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 ).tocString();
}
arg1 = arg1.tocString();
if( arg2 instanceof cArea || arg2 instanceof cArea3D ){
arg2 = arg2.cross(arguments[1].first).tocString();
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first ).tocString();
}
else if( arg2 instanceof cArray){
arg2 = arg2.getElement(0).tocString();
else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement( 0 ).tocString();
}
arg2 = arg2.tocString();
if( arg3 instanceof cArea || arg3 instanceof cArea3D ){
arg3 = arg3.cross(arguments[1].first).tocNumber();
if ( arg3 instanceof cArea || arg3 instanceof cArea3D ) {
arg3 = arg3.cross( arguments[1].first ).tocNumber();
}
else if( arg3 instanceof cArray){
arg3 = arg3.getElement(0).tocNumber();
else if ( arg3 instanceof cArray ) {
arg3 = arg3.getElement( 0 ).tocNumber();
}
arg3 = arg3.tocNumber();
if( arg0 instanceof cError )
if ( arg0 instanceof cError )
return this.value = arg0;
if( arg1 instanceof cError )
if ( arg1 instanceof cError )
return this.value = arg1;
if( arg2 instanceof cError )
if ( arg2 instanceof cError )
return this.value = arg2;
if( arg3 instanceof cError )
if ( arg3 instanceof cError )
return this.value = arg3;
if( arg3.getValue() < 0 ){
if ( arg3.getValue() < 0 ) {
return this.value = new cError( cErrorType.wrong_value_type );
}
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++;
if( arg3.getValue() == 0 || arg3.getValue() > source.length )
if ( arg3.getValue() == 0 || arg3.getValue() > source.length )
return new_string;
else if( arg3.getValue() == index ){
else if ( arg3.getValue() == index ) {
return new_string;
}
return equal;
})
} )
return this.value = new cString( res );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( string , old-string , new-string [ , occurence ] )"
......@@ -1061,30 +1065,30 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'T' : function(){
var r = new cBaseFunction("T");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'T':function () {
var r = new cBaseFunction( "T" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cRef || arg0 instanceof cRef3D){
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
else if( arg0 instanceof cString || arg0 instanceof cError )
else if ( arg0 instanceof cString || arg0 instanceof cError )
return this.value = arg0;
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if( arg[0] instanceof cArray ){
arg0 = arg[0].getElementRowCol(0,0);
else if ( arg[0] instanceof cArray ) {
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];
else
return this.value = new cEmpty();
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( value )"
......@@ -1092,30 +1096,30 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'TEXT' : function(){
var r = new cBaseFunction("TEXT");
r.setArgumentsMin(2);
r.setArgumentsMax(2);
r.Calculate = function(arg){
'TEXT':function () {
var r = new cBaseFunction( "TEXT" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
if( arg0 instanceof cRef || arg0 instanceof cRef3D){
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
if( arg1 instanceof cRef || arg1 instanceof cRef3D){
if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
arg1 = arg1.getValue();
}
else if ( arg1 instanceof cArea || arg1 instanceof cArea3D ){
arg1 = arg1.cross(arguments[1].first);
else if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
else if( arg1 instanceof cArray ){
arg1 = arg1.getElementRowCol(0,0);
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
}
arg1 = arg1.tocString();
......@@ -1124,29 +1128,28 @@ cFormulaFunction.TextAndData = {
if ( arg1 instanceof cError ) return this.value = arg1;
var _tmp = arg0.tocNumber();
if( _tmp instanceof cNumber )
if ( _tmp instanceof cNumber )
arg0 = _tmp;
var oFormat = oNumFormatCache.get(arg1.toString());
var aText = oFormat.format(arg0.getValue(), arg0 instanceof cNumber ? CellValueType.Number : CellValueType.String, gc_nMaxDigCountView, null);
var oFormat = oNumFormatCache.get( arg1.toString() );
var aText = oFormat.format( arg0.getValue(), arg0 instanceof cNumber ? CellValueType.Number : CellValueType.String, gc_nMaxDigCountView, null );
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 += " ";
continue;
}
if(aText[i].format && aText[i].format.repeat )
if ( aText[i].format && aText[i].format.repeat )
continue;
text += aText[i].text;
}
return this.value = new cString(text);
return this.value = new cString( text );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( value , format )"
......@@ -1154,28 +1157,32 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'TRIM' : function(){
var r = new cBaseFunction("TRIM");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'TRIM':function () {
var r = new cBaseFunction( "TRIM" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first).tocString();
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString();
}
else if( arg0 instanceof cArray){
arg0 = arg0.getElement(0).tocString();
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 ).tocString();
}
arg0 = arg0.tocString();
if( arg0 instanceof cError )
if ( arg0 instanceof cError )
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 {
name:this.name,
args:"( string )"
......@@ -1183,24 +1190,24 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'UPPER' : function(){
var r = new cBaseFunction("UPPER");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'UPPER':function () {
var r = new cBaseFunction( "UPPER" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if( arg0 instanceof cArray )
arg0 = arg0.getElementRowCol(0,0);
if ( arg0 instanceof cArray )
arg0 = arg0.getElementRowCol( 0, 0 );
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() );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(text)"
......@@ -1208,18 +1215,18 @@ cFormulaFunction.TextAndData = {
}
return r;
},
'VALUE' : function(){
var r = new cBaseFunction("VALUE");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'VALUE':function () {
var r = new cBaseFunction( "VALUE" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElementRowCol( 0, 0 );
}
arg0 = arg0.tocString();
......@@ -1227,21 +1234,21 @@ cFormulaFunction.TextAndData = {
if ( arg0 instanceof cError )
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 );
else
return this.value = new cError( cErrorType.wrong_value_type );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( string )"
};
}
r.setFormat(r.formatType.noneFormat);
r.setFormat( r.formatType.noneFormat );
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