.NET Excel Examples
Set a Formula in an Excel Cell with the Syncfusion .NET Excel Library
Video illustration
Watch this video to learn how to set a formula in an Excel cell using the Syncfusion .NET Excel Library:
Overview
The Syncfusion® .NET Excel Library (XlsIO) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. Using this library, you can set a formula in an Excel cell using C#.
Set a formula in an Excel cell
Follow these steps to set a formula in an Excel cell using the Syncfusion .NET Excel Library.
Step 1: Create a new project
Start by creating a new C# Console Application project.
Step 2: Install the NuGet package
Add the Syncfusion.XlsIO.Net.Core package to your project from NuGet.org.
Step 3: Include namespaces
Add the following namespaces to your Program.cs file:
using System.IO;
using Syncfusion.XlsIO;Step 4: Add code to set a formula in an Excel cell
Use the following code in Program.cs to create an Excel document file and set a formula in an Excel cell.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
// Set values to the cells.
sheet.Range["A1"].Number = 10;
sheet.Range["B1"].Number = 10;
#region Set Formula
// Set formula in the cell.
sheet.Range["C1"].Formula = "=SUM(A1,B1)";
#endregion
#region Save
// Save the workbook.
FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Formula.xlsx"), FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
#endregion
// Dispose streams.
outputStream.Dispose();
}GitHub project
NuGet installation
Get started quickly by downloading the installer and and checking license information on the Downloads page.
Table of contents
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Learning
Technical support
