How to create Excel file using C# without Microsoft office & interop?

Hello, I would like to know how can I generate excel file in my C# project without installing Microsoft Excel/office or interop on server?Can you please provide me step by step guide or easy tutorial links, anything will work, thanks.

Asked by:- Sam
: 96 At:- 5/28/2018 3:40:39 PM
C# Excel without office

1 Answers
profileImage Answered by:- jaya

You can create Excel file in C# without using Office or Interop by using Epplus in your project, here are the steps

  1. Install EPPlus in your project using Nuget Package manager console.
    PM > Install-Package EPPlus?
  2. Now, you need to create it's object & empty worksheet
    // Create the package and make sure you wrap it in a using statement
    using (ExcelPackage excel = new ExcelPackage())
         // add a new worksheet to the empty workbook
         ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Test");
        // --------- Creating file, Data and styling goes here -------------- //
  3. Add data/header in Worksheet using C#
    using (ExcelPackage excel = new ExcelPackage())
                    //Add Worksheets in Excel file
                    //Create Excel file in Uploads folder of your project
                    FileInfo excelFile = new FileInfo(Server.MapPath("~/ExcelFile/test.xlsx"));
                    //Add header row columns name in string list array
                    var headerRow = new List<string[]>()
                        new string[] { "Full Name","Email" }
                    // Get the header range
                    string Range = "A1:" + Char.ConvertFromUtf32(headerRow[0].Length + 64) + "1";
                    // get the workSheet in which you want to create header
                    var worksheet = excel.Workbook.Worksheets["TestSheet1"];
                    // Popular header row data
                    //show header cells with different style
                    worksheet.Cells[Range].Style.Font.Bold = true;
                    worksheet.Cells[Range].Style.Font.Size = 16;
                    //Now add some data in rows for each column
                    var Data = new List<object[]>()
                          new object[] {"Test",""},
                          new object[] {"Test2",""},
                          new object[] {"Test3",""},
                    //add the data in worksheet, here .Cells[2,1] 2 is rowNumber while 1 is column number
                    worksheet.Cells[2, 1].LoadFromArrays(Data);
                    //Save Excel file
  4. Here is the complete tutorial to generate Excel file using EPPlus in MVC/C#
  5. Another article, which generates excel with data from the database using EPPlus

At:- 5/31/2018 6:36:49 PM
Good answer, I have checked the article in step 4/5 which provides EPPlus complete details, thanks. 0
By : Sam - at :- 6/1/2018 2:30:39 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use