title: How to export data from C# from List<object> or IEnumerable to Excel (MS OpenXml)?
body: <p>I'm trying to export a <code>List&lt;dynamic&gt;</code> or <code>IEnumerable</code> to an Excel file using the library Open XML of Microsoft.</p>
  
  <p>Library: <a href="https://github.com/OfficeDev/Open-XML-SDK" rel="nofollow noreferrer">https://github.com/OfficeDev/Open-XML-SDK</a></p>
  
  <p>Example of similar request: <a href="https://www.codeproject.com/Articles/692121/Csharp-Export-data-to-Excel-using-OpenXML-librarie" rel="nofollow noreferrer">https://www.codeproject.com/Articles/692121/Csharp-Export-data-to-Excel-using-OpenXML-librarie</a></p>
  
  <p>The example above works pretty fine but have a lot of code between (As far works neat, but I searching for an optimization)</p>
  
  <p>But the documentation of this library does not extend (or hasn't many examples), and the examples that I saw around about how to export data to Excel it's using a <code>DataTable</code> or <code>Dataset</code>; so, they make the conversation from the <code>List</code> to <code>DataTable</code> to export the <code>DataTable</code>. And that seems pretty complex way to something that other libraries resolve easier.</p>
  
  <p>So, if someone has a sort of example of how to make the export quickly and generic, it will be appreciated. </p>