public void ConvertRange() { FSharpTransformationRule T = new FSharpTransformationRule(); FSharpTransform.Formula F = T.CreateFSharpTree(ExcelFormulaParser.Parse("A1:B7")); Assert.IsNotNull(F); }
public void ConvertSheetReference() { string Cell = "Sheet!A1"; FSharpTransformationRule T = new FSharpTransformationRule(); FSharpTransform.Formula F = T.CreateFSharpTree(ExcelFormulaParser.Parse(Cell)); Assert.IsNotNull(F); }
public void ConvertFunction() { string Cell = "SUM(A1:B7)"; FSharpTransformationRule T = new FSharpTransformationRule(); FSharpTransform.Formula F = T.CreateFSharpTree(ExcelFormulaParser.Parse(Cell)); Assert.IsNotNull(F); }
public void Dynamic_Range_Transform() { var Original = ExcelFormulaParser.Parse("SUM(A1:B1)"); FSharpTransformationRule T = new FSharpTransformationRule(); T.from = T.ParseToTree("SUM({r})"); T.to = T.ParseToTree("SUM({r})+1"); FSharpTransform.Formula Result = T.ApplyOn(Original); Assert.AreEqual("SUM(A1:B1)+1", T.Print(Result)); }
public void SUM_COUNT_AVERAGE() { var Original = ExcelFormulaParser.Parse("SUM(A1:A5)/COUNT(A1:A5)"); FSharpTransformationRule S = new FSharpTransformationRule(); S.from = S.ParseToTree("SUM({r})/COUNT({r})"); S.to = S.ParseToTree("AVERAGE(A1:A5)"); FSharpTransform.Formula Result = S.ApplyOn(Original); Assert.AreEqual("AVERAGE(A1:A5)", S.Print(Result)); }
public void Merge_Some_Ranges() { var Original = ExcelFormulaParser.Parse("SUM(A1,A2,A3)"); FSharpTransformationRule S = new FSharpTransformationRule(); S.from = S.ParseToTree("SUM({i,j}, {i,j+1}, {r})"); S.to = S.ParseToTree("SUM({i,j}:{i,j+1}, {r})"); FSharpTransform.Formula Result = S.ApplyOn(Original); Assert.AreEqual("SUM(A1:A2,A3)", S.Print(Result)); }
public void Double_Transform() { var Original = ExcelFormulaParser.Parse("(A1+A2)*(A1+A2)"); FSharpTransformationRule T = new FSharpTransformationRule(); T.from = (ExcelFormulaParser.Parse("A1+A2")); T.to = (ExcelFormulaParser.Parse("SUM(A1:A2)")); FSharpTransform.Formula Result = T.ApplyOn(Original); Assert.AreEqual("(SUM(A1:A2))*(SUM(A1:A2))", T.Print(Result)); }
public void Super_Simple_Transform() { var Original = ExcelFormulaParser.Parse("A1"); FSharpTransformationRule T = new FSharpTransformationRule(); T.from = (ExcelFormulaParser.Parse("A1")); T.to = (ExcelFormulaParser.Parse("A2")); FSharpTransform.Formula Result = T.ApplyOn(Original); Assert.AreEqual("A2", T.Print(Result)); }
public void Transform_Dynamic_Cell_Calculation() { var Original = ExcelFormulaParser.Parse("A1"); FSharpTransformationRule T = new FSharpTransformationRule(); T.from = T.ParseToTree("{i,j}"); T.to = T.ParseToTree("{i,j+1}"); FSharpTransform.Formula Result = T.ApplyOn(Original); ParseTreeNode Expected = (ExcelFormulaParser.Parse("A2")); Assert.AreEqual("A2", T.Print(Result)); }
public void Transform_in_Arguments() { var Original = ExcelFormulaParser.Parse("(A1+A2)/3"); FSharpTransformationRule T = new FSharpTransformationRule(); T.from = (ExcelFormulaParser.Parse("A1+A2")); T.to = (ExcelFormulaParser.Parse("SUM(A1:A2)")); bool x = T.CanBeAppliedonBool(Original); FSharpTransform.Formula Result = T.ApplyOn(Original); Assert.AreEqual("(SUM(A1:A2))/3", T.Print(Result)); }
public void Merge_Ranges() { var Original = ExcelFormulaParser.Parse("SUM(A1,A2)"); FSharpTransformationRule T = new FSharpTransformationRule(); T.from = T.ParseToTree("SUM({i,j}, {i,j+1})"); T.to = T.ParseToTree("SUM({i,j}:{i,j+1})"); //hier heb je een gewone range met dt=ynamische cellen Assert.IsTrue(T.CanBeAppliedonBool(Original)); FSharpTransform.Formula Result = T.ApplyOn(Original); Assert.AreEqual("SUM(A1:A2)", T.Print(Result)); }
/// <summary> /// Print a F# tree to a formula string /// </summary> public static string Print(this FSharpTransform.Formula result) { if (result.IsS) { var y = (FSharpTransform.Formula.S)result; var Cell = y.Item; var CCell = (FSharpTransform.SuperCell.C)Cell; string CellName = new Location(CCell.Item.Item1, CCell.Item.Item2).ToString(); return(CellName); } if (result.IsRange) { var y = (FSharpTransform.Formula.Range)result; var Cell1 = y.Item1; var Cell2 = y.Item2; string CellName1; string CellName2; if (Cell1.IsC) { var CCell1 = (FSharpTransform.SuperCell.C)Cell1; CellName1 = new Location(CCell1.Item.Item1, CCell1.Item.Item2).ToString(); } else { throw new ArgumentException("Unable to print dynamic tree"); } if (Cell2.IsC) { var CCell2 = (FSharpTransform.SuperCell.C)Cell2; CellName2 = new Location(CCell2.Item.Item1, CCell2.Item.Item2).ToString(); } else { throw new ArgumentException("Unable to print dynamic tree"); } return(CellName1 + ":" + CellName2); } if (result.IsFunction) { var y = (FSharpTransform.Formula.Function)result; string FunctionName = y.Item1; if (FunctionName.Contains("(")) //it is a prefix function { string Arguments = PrintArguments(y.Item2); return(FunctionName + Arguments + ")"); } if (FunctionName == "") { string Arguments = PrintArguments(y.Item2); return("(" + FunctionName + Arguments + ")"); } else //infix { return(Print(y.Item2.First()) + FunctionName + Print(y.Item2.ElementAt(1))); } } if (result.IsConstant) { var y = (FSharpTransform.Formula.Constant)result; return(y.Item); } if (result.IsArgumentList) { var y = (FSharpTransform.Formula.ArgumentList)result; return(PrintArguments(y.Item)); } throw new ArgumentException("Unable to print dynamic tree"); }
/// <summary> /// Print a F# tree to a formula string /// </summary> public string Print(FSharpTransform.Formula result) { return(result.Print()); }