Create Excel spreadsheets in a fast and easy way

EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).
EPPlus supports ranges, cell styling, charts, pictures, shapes, comments, tables, protection, encryption and a lot of other stuff.

Overview

ExcelPackage was a great project to start from. It had the basic functionallity needed to read and write the spreadsheets.
So what is new in this project?
Custom styling and ranges has been added.

To give you an example how it works, take look at this function from a web app that loads a datatable, formats it and returns it to the client...
        private void DumpExcel(DataTable tbl)
        {
            using (ExcelPackage pck = new ExcelPackage())
            {
                //Create the worksheet
                ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");

                //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
                ws.Cells["A1"].LoadFromDataTable(tbl, true);

                //Format the header for column 1-3
                using (ExcelRange rng = ws.Cells["A1:C1"])
                {
                    rng.Style.Font.Bold = true;
                    rng.Style.Fill.PatternType = ExcelFillStyle.Solid;                      //Set Pattern for the background to Solid
                    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));  //Set color to dark blue
                    rng.Style.Font.Color.SetColor(Color.White);
                }

                //Example how to Format Column 1 as numeric 
                using (ExcelRange col = ws.Cells[2, 1, 2 + tbl.Rows.Count, 1])
                {
                    col.Style.Numberformat.Format = "#,##0.00";
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
                }

                //Write it back to the client
                Response.ContentType = "Application/vnd.ms-Excel";
                Response.AddHeader("content-disposition", "attachment;  filename=ExcelDemo.xlsx");
                Response.BinaryWrite(pck.GetAsByteArray());
            }
        }

There is also som VERY basic support for drawings (shapes and charts). Have a look att the sample project for more information.



Last edited Nov 29, 2009 at 10:32 AM by JanKallman, version 5