static void Main(string[] args) { //Create a workbook Workbook workbook = new Workbook(); //Access first worksheet Worksheet worksheet = workbook.Worksheets[0]; //Put 20 in cell A1 Cell cellA1 = worksheet.Cells["A1"]; cellA1.PutValue(20); //Put 30 in cell A2 Cell cellA2 = worksheet.Cells["A2"]; cellA2.PutValue(30); //Calculate the Sum of A1 and A2 var results = worksheet.CalculateFormula("=Sum(A1:A2)"); Cell cellA3 = worksheet.Cells["A3"]; cellA3.PutValue(results); //Print the output Debug.WriteLine("Value of A1: " + cellA1.StringValue); Debug.WriteLine("Value of A2: " + cellA2.StringValue); Debug.WriteLine("Result of Sum(A1:A2): " + results.ToString()); workbook.Save("Calulate Any Formula.xls"); }
public static void Run() { // Create a workbook Workbook wb = new Workbook(); // Accesss first worksheet Worksheet ws = wb.Worksheets[0]; // Add some text in cell A1 ws.Cells["A1"].PutValue("Welcome to "); // Create a calculation options with custom engine CalculationOptions opts = new CalculationOptions(); opts.CustomEngine = new ICustomEngine(); // This line shows how you can call your own custom function without // a need to write it in any worksheet cell // After the execution of this line, it will return // Welcome to Aspose.Cells. object ret = ws.CalculateFormula("=A1 & MyCompany.CustomFunction()", opts); // Print the calculated value on Console Console.WriteLine("Calculated Value: " + ret); }
public static void Main(string[] args) { //ExStart:1 // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } //Create a workbook Workbook workbook = new Workbook(); //Access first worksheet Worksheet worksheet = workbook.Worksheets[0]; //Put 20 in cell A1 Cell cellA1 = worksheet.Cells["A1"]; cellA1.PutValue(20); //Put 30 in cell A2 Cell cellA2 = worksheet.Cells["A2"]; cellA2.PutValue(30); //Calculate the Sum of A1 and A2 var results = worksheet.CalculateFormula("=Sum(A1:A2)"); //Print the output System.Console.WriteLine("Value of A1: " + cellA1.StringValue); System.Console.WriteLine("Value of A2: " + cellA2.StringValue); System.Console.WriteLine("Result of Sum(A1:A2): " + results.ToString()); //ExEnd:1 }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } //Create a workbook Workbook workbook = new Workbook(); //Access first worksheet Worksheet worksheet = workbook.Worksheets[0]; //Put 20 in cell A1 Cell cellA1 = worksheet.Cells["A1"]; cellA1.PutValue(20); //Put 30 in cell A2 Cell cellA2 = worksheet.Cells["A2"]; cellA2.PutValue(30); //Calculate the Sum of A1 and A2 var results = worksheet.CalculateFormula("=Sum(A1:A2)"); //Print the output System.Console.WriteLine("Value of A1: " + cellA1.StringValue); System.Console.WriteLine("Value of A2: " + cellA2.StringValue); System.Console.WriteLine("Result of Sum(A1:A2): " + results.ToString()); }