How To Create An Excel File (Development) Using EPPlus .NET Library (C#) - Part One

 What is EPPlus?
  • A library to manage Excel spreadsheets. EPPlus is a .NET library, which reads and writes Excel 2007/2010 or higher files, using Open Office XML format. It supports .XLSX, .XLSM Excel file format.
Why are we using EPPlus?
  • First of all EPPlus is a free tool.
  • We can do the same thing by using Microsoft interop Excel. When you like to do Server side office automation, which is not a supported scenario by Microsoft, follow the link :http://support.microsoft.com/kb/257757
How to attach EPPlus Library
  • Option 1- Download it from : http://epplus.codeplex.com/
  • Option 2- To install EPPlus, run the command given below in Package Manager Console.
    PM> : Install-Package EPPlus.
EPPlus supports folllowing
  • Cell Ranges
  • Cell styling (Border, Color, Fill, Font, Number, Alignments)
  • Charts
  • Pictures
  • Shapes
  • Comments
  • Tables
  • Protection
  • Encryption
  • Pivot tables
  • Data validation
  • Conditional formatting
  • VBA
  • Formula calculation..etc
We will learn 
  • Create a demo of an EPPlus project, using .NET technologies (Language C#).


Open Visual Studio (create a console Application).
  1. using OfficeOpenXml;  
  2. using System.IO;  
  3. using System;  
  4. //add these namespace  
  5. class Program {  
  6.     static void Main(string[] args) {  
  7.         ExcelPackage ExcelPkg = new ExcelPackage();  
  8.         ExcelWorksheet wsSheet1 = ExcelPkg.Workbook.Worksheets.Add("Sheet1");  
  9.         using(ExcelRange Rng = wsSheet1.Cells[2, 2, 2, 2]) {  
  10.             Rng.Value = "Welcome to Everyday be coding - tutorials for beginners";  
  11.             Rng.Style.Font.Size = 16;  
  12.             Rng.Style.Font.Bold = true;  
  13.             Rng.Style.Font.Italic = true;  
  14.         }  
  15.         wsSheet1.Protection.IsProtected = false;  
  16.         wsSheet1.Protection.AllowSelectLockedCells = false;  
  17.         ExcelPkg.SaveAs(new FileInfo(@ "D:\New.xlsx"));  
  18.     }  
  19. }  
Now, build & execute the given code. File is (New.xlsx), which is stored on D: drive of the computer.
Thank you for reading this blog.