{"id":1678,"date":"2017-05-01T10:00:00","date_gmt":"2017-05-01T08:00:00","guid":{"rendered":"https:\/\/demo.sidekick.be\/itenium\/create-xlsx-excel-with-epplus-csharp-import\/"},"modified":"2025-11-28T13:31:46","modified_gmt":"2025-11-28T12:31:46","slug":"create-xlsx-excel-with-epplus-csharp-import","status":"publish","type":"post","link":"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/","title":{"rendered":"Create Excels with C# and EPPlus: Import"},"content":{"rendered":"<p><\/p>\n<hr \/>\n<p><\/p>\n<h1 id=\"thats-fine\">That\u2019s fine!<\/h1>\n<h1 class=\"hide-from-excerpt\" id=\"ienumerable-objects\">IEnumerable objects<\/h1>\n<p>Exporting data to an Excel doesn\u2019t get easier than this<\/p>\n<pre><code class=\"language-c#\">using (var package = new ExcelPackage())\n{\n\tvar sheet = package.Workbook.Worksheets.Add(\"IEnumerable\");\n\tvar data = new[]\n\t{\n\t\tnew {Name = \"A\", Value = 1},\n\t\tnew {Name = \"B\", Value = 2},\n\t\tnew {Name = \"C\", Value = 3},\n\t};\n\tbool generateHeaders = true;\n\tsheet.Cells[\"A1\"].LoadFromCollection(data, generateHeaders);\n\n\t\/\/ Overwrite headers with something fancier\n\tsheet.Cells[\"A1\"].SetHeaders(\"Name\", \"Value\");\n\tpackage.SaveAs(new FileInfo(@\"\"));\n}\n<\/code><\/pre>\n<p>Which would result in the following xlsx.<\/p>\n<table class=\"table-excel\">\n<thead>\n<tr>\n<th><\/th>\n<th>A<\/th>\n<th>B<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>Name<\/td>\n<td>Value<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>A<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>B<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>C<\/td>\n<td>3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>There are overloads for<\/p>\n<ul>\n<li>Writing headers or not<\/li>\n<li><code>TableStyles<\/code>: Style the table in one of the predefined formats<\/li>\n<li><code>BindingFlags<\/code> + <code>MemberInfo<\/code>: Allow you to export specific (private) fields<\/li>\n<\/ul>\n<p>The pretty blue background for the header is done with an extension method. The LoadFromXXX methods do not set any header styling themselves.<\/p>\n<pre><code class=\"language-c#\">public static void SetHeaders(this ExcelRangeBase cell, params string[] headers)\n{\n\tforeach (string text in headers)\n\t{\n\t\tcell.Value = text;\n\t\tcell.Style.Font.Bold = true;\n\t\tcell.Style.Fill.PatternType = ExcelFillStyle.Solid;\n\t\tcell.Style.Fill.BackgroundColor.SetColor(Color.DarkBlue);\n\t\tcell.Style.Font.Color.SetColor(Color.White);\n\n\t\tcell = cell.Offset(0, 1);\n\t}\n}\n<\/code><\/pre>\n<p><strong>LoadFromArrays<\/strong>:<\/p>\n<pre><code class=\"language-c#\">using (var package = new ExcelPackage())\n{\n\tvar sheet = package.Workbook.Worksheets.Add(\"Arrays\");\n\tvar data = new[]\n\t{\n\t\tnew[] {\"A1\", \"B1\", \"C1\"},\n\t\tnew[] {\"A2\", \"B2\", \"C3\"},\n\t};\n\tsheet.Cells[\"A1\"].LoadFromArrays(data);\n\tpackage.SaveAs(new FileInfo(@\"\"));\n}\n<\/code><\/pre>\n<h1 id=\"csv-file\">CSV file<\/h1>\n<pre><code class=\"language-c#\">using (var package = new ExcelPackage())\n{\n\tvar sheet = package.Workbook.Worksheets.Add(\"CSV\");\n\tvar file = new FileInfo(\"LoadFromText.csv\");\n\n\tvar format = new ExcelTextFormat()\n\t{\n\t\tDelimiter = ',',\n\t\tCulture = CultureInfo.InvariantCulture,\n\n\t\t\/\/ Escape character for values containing the Delimiter\n\t\t\/\/ ex: \"A,Name\",1 --&gt; two cells, not three\n\t\tTextQualifier = '\"'\n\n\t\t\/\/ Other properties\n\t\t\/\/ EOL, DataTypes, Encoding, SkipLinesBeginning\/End\n\t};\n\tsheet.Cells[\"A1\"].LoadFromText(file, format);\n\tpackage.SaveAs(new FileInfo(@\"\"));\n}\n<\/code><\/pre>\n<h1 id=\"datareader--datatable\">DataReader &amp; DataTable<\/h1>\n<p>In case you ever need it, it\u2019s there \ud83d\ude42<\/p>\n<pre><code class=\"language-c#\">sheet.Cells[\"A1\"].LoadFromDataTable(new DataTable(), true);\n<\/code><\/pre>\n<h1>Also in this series<\/h1>\n<ul>\n<li>Part 1: <a href=\"\/dotnet\/create-xlsx-excel-with-epplus-csharp\/\">Create Excels with C# and EPPlus: A tutorial<\/a><\/li>\n<li>Part 2: <a href=\"\/dotnet\/create-xlsx-excel-with-epplus-csharp-formulas-and-datavalidation\/\">Create Excels with C# and EPPlus: Formulas &#038; DataValidation<\/a><\/li>\n<li>This Part: Create Excels with C# and EPPlus: Import<\/li>\n<li>Part 4: <a href=\"\/dotnet\/create-xlsx-excel-with-epplus-csharp-miscellaneous\/\">Create Excels with C# and EPPlus: Miscellaneous<\/a><\/li>\n<li>Part 5: <a href=\"\/dotnet\/excel-formulas-cheat-sheet\/\">Excel formulas cheat sheet<\/a><\/li>\n<li>Part 6: <a href=\"\/dotnet\/epplus-pay-to-play\/\">EPPlus: No longer free to use in a commercial setting<\/a><\/li>\n<\/ul>\n<h1>Extras<\/h1>\n<p><b>Stuff that came into being during the making of this post<\/b><\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/itenium-be\/EPPlusTutorial\">The accompanying source on GitHub<\/a><\/li>\n<\/ul>\n<h1> Package Versions <i class=\"fa fa-info-circle\" style=\"float: right; color: cornflowerblue; font-size: 28px\" title=\"Package versions used for this post and in the accompanying code on Github\"><\/i><\/h1>\n<div><a href=\"https:\/\/github.com\/JanKallman\/EPPlus\" class=\"github\"><img decoding=\"async\" src=\"https:\/\/img.shields.io\/github\/stars\/JanKallman\/EPPlus.svg?style=social&#038;label=Star\" \/><\/a><a href=\"https:\/\/github.com\/JanKallman\/EPPlus\">JanKallman\/EPPlus<\/a>: v4.1.0 <\/div>\n","protected":false},"excerpt":{"rendered":"<p class=\"notice--danger\"><strong>Version 4.5.3.3 is the last version of EPPlus you can use without a license for commercial use.<\/strong><br \/> See <a href=\"\/blog\/dotnet\/epplus-pay-to-play\/\">some alternatives<\/a> if that is a dealbreaker for you!<\/p>\n<p class=\"notice--info\"><strong>We now have a blog series on an alternative Excel package <a href=\"\/blog\/dotnet\/create-xlsx-excel-with-closedxml-csharp\">ClosedXML<\/a><\/strong><br \/> Which is basically on equal footing with EPPlus.<\/p>\n","protected":false},"author":1,"featured_media":2113,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[11],"tags":[12,6],"class_list":["post-1678","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","tag-excel","tag-tutorial"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create Excels with C# and EPPlus: Import - Itenium<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Excels with C# and EPPlus: Import - Itenium\" \/>\n<meta property=\"og:description\" content=\"Version 4.5.3.3 is the last version of EPPlus you can use without a license for commercial use. See some alternatives if that is a dealbreaker for you!We now have a blog series on an alternative Excel package ClosedXML Which is basically on equal footing with EPPlus.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/\" \/>\n<meta property=\"og:site_name\" content=\"Itenium\" \/>\n<meta property=\"article:published_time\" content=\"2017-05-01T08:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-28T12:31:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/excel-import.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"360\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Usdevelop\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Usdevelop\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/\",\"url\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/\",\"name\":\"Create Excels with C# and EPPlus: Import - Itenium\",\"isPartOf\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/excel-import.jpg\",\"datePublished\":\"2017-05-01T08:00:00+00:00\",\"dateModified\":\"2025-11-28T12:31:46+00:00\",\"author\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022\"},\"breadcrumb\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#primaryimage\",\"url\":\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/excel-import.jpg\",\"contentUrl\":\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/excel-import.jpg\",\"width\":360,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/demo.sidekick.be\/itenium\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create Excels with C# and EPPlus: Import\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#website\",\"url\":\"https:\/\/demo.sidekick.be\/itenium\/\",\"name\":\"Itenium\",\"description\":\"We build software. We build careers.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/demo.sidekick.be\/itenium\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022\",\"name\":\"Usdevelop\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g\",\"caption\":\"Usdevelop\"},\"sameAs\":[\"https:\/\/demo.sidekick.be\/itenium\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create Excels with C# and EPPlus: Import - Itenium","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Create Excels with C# and EPPlus: Import - Itenium","og_description":"Version 4.5.3.3 is the last version of EPPlus you can use without a license for commercial use. See some alternatives if that is a dealbreaker for you!We now have a blog series on an alternative Excel package ClosedXML Which is basically on equal footing with EPPlus.","og_url":"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/","og_site_name":"Itenium","article_published_time":"2017-05-01T08:00:00+00:00","article_modified_time":"2025-11-28T12:31:46+00:00","og_image":[{"width":360,"height":300,"url":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/excel-import.jpg","type":"image\/jpeg"}],"author":"Usdevelop","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Usdevelop","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/","url":"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/","name":"Create Excels with C# and EPPlus: Import - Itenium","isPartOf":{"@id":"https:\/\/demo.sidekick.be\/itenium\/#website"},"primaryImageOfPage":{"@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#primaryimage"},"image":{"@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#primaryimage"},"thumbnailUrl":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/excel-import.jpg","datePublished":"2017-05-01T08:00:00+00:00","dateModified":"2025-11-28T12:31:46+00:00","author":{"@id":"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022"},"breadcrumb":{"@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#primaryimage","url":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/excel-import.jpg","contentUrl":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/excel-import.jpg","width":360,"height":300},{"@type":"BreadcrumbList","@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dotnet\/create-xlsx-excel-with-epplus-csharp-import\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/demo.sidekick.be\/itenium\/"},{"@type":"ListItem","position":2,"name":"Create Excels with C# and EPPlus: Import"}]},{"@type":"WebSite","@id":"https:\/\/demo.sidekick.be\/itenium\/#website","url":"https:\/\/demo.sidekick.be\/itenium\/","name":"Itenium","description":"We build software. We build careers.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/demo.sidekick.be\/itenium\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022","name":"Usdevelop","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g","caption":"Usdevelop"},"sameAs":["https:\/\/demo.sidekick.be\/itenium"]}]}},"_links":{"self":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts\/1678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/comments?post=1678"}],"version-history":[{"count":3,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts\/1678\/revisions"}],"predecessor-version":[{"id":2317,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts\/1678\/revisions\/2317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/media\/2113"}],"wp:attachment":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/media?parent=1678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/categories?post=1678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/tags?post=1678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}