{"id":203522,"date":"2013-11-25T12:54:03","date_gmt":"2013-11-25T08:54:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=203522"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=203522","title":{"rendered":"<span class=\"post_title\">Excel \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f OpenXML<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0420\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e, \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Excel \u0444\u0430\u0439\u043b \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u0438 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 Excel.<br \/>  \u041d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0451 \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435, \u0434\u0430\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435, \u0443\u0439\u0442\u0438 \u043e\u0442 MS Office, \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438.<br \/>  \u0423 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u201cMicrosoft.Office. Interop.Excel\u201d \u0438 \u043c\u043d\u043e\u0433\u043e \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0434\u043b\u044f \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438 \u0442\u0435\u0445 \u0438\u043b\u0438 \u0438\u043d\u044b\u0445 \u043e\u0442\u0447\u0451\u0442\u043e\u0432.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0442\u0438 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0443\u044e \u0441 \u043e\u0444\u0438\u0441\u043e\u043c. \u0418 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043f\u043e \u0442\u043e\u0439 \u0436\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0447\u0442\u043e \u0438 \u0440\u0430\u043d\u044c\u0448\u0435. \u0418\u0431\u043e \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c.<br \/>  \u0412\u043e\u0442 \u044f \u0438 \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 OpenXML. \u0418 \u0434\u0443\u043c\u0430\u043b, \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e \u0431\u044b\u0441\u0442\u0440\u043e\u043c\u0443 \u043d\u0430\u0439\u0434\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0438 \u0432\u0441\u0451 \u0433\u043e\u0442\u043e\u0432\u043e (\u0442.\u043a. \u043d\u0430 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043e \u043c\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438). \u041d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0442\u0430\u043a \u0438 \u043d\u0435 \u043d\u0430\u0448\u0451\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u0434\u043b\u044f \u0442\u0435\u0445 \u0443 \u043a\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442, \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. <br \/>  \u0421\u0430\u043c\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e \u0441 \u0441\u0430\u0439\u0442\u0430 Micrisoft (\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 OpenXML sdk 2.5 \u201c OpenXMLSDKV25.msi \u201d)<br \/>  <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=30425\">\u0437\u0434\u0435\u0441\u044c<\/a>.<br \/>  \u041f\u043e\u0441\u043b\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u201cOpenXMLSDKV25.msi \u201d, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0438 \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043f\u0430\u043f\u043a\u0443<br \/>  \u201cC:\\Program Files\\Open XML SDK\\V2.5\\lib\u201d \u0442\u0430\u043c \u043b\u0435\u0436\u0438\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f, \u043c\u044b \u0435\u0451 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443 (\u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043e, \u043a\u0430\u043a).<br \/>  \u041f\u0440\u043e\u0435\u043a\u0442 \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 Visual Studio 2010 (Framework 4.0).<br \/>  \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 (\u0441\u0434\u0435\u043b\u0430\u043d \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430) \u201cC:\\Templates\\template.xlsx\u201d.<br \/>  <a name=\"habracut\"><\/a><br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/2f7\/d84\/9cf\/2f7d849cf052cfb11e3a5c858d5ac4a6.png\" alt=\"image\"\/><\/p>\n<p>  \u0418 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432 \u0438\u0442\u043e\u0433\u0435, \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438).<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/201\/6c7\/2d2\/2016c72d27844afa100d07d8cc4ba32c.png\" alt=\"image\"\/><\/p>\n<p>  \u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430:<br \/>  DataField: \u2014 \u041e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u044b \u043d\u0430\u0448\u0438 \u0431\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 DataTable. <br \/>  DataField:[\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u043f\u043e\u043b\u044f]<br \/>  Label: \u2014 \u041e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0434\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0438\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u044f<br \/>  Label:[\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435]<br \/>  \u0410 \u044d\u0442\u043e \u0444\u0430\u0439\u043b \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u201cC:\\Loading\\ReadMePlease.xlsx\u201d.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/087\/35f\/597\/08735f597c195ea4832dd39c22c102ef.png\" alt=\"image\"\/><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432 VS2010, \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 4 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<br \/>  1) OpenXmlPrj \u2013 \u044d\u0442\u043e \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0435\u0441\u0442\u0430.<br \/>  2) Interfaces \u2013 \u044d\u0442\u043e \u043f\u0440\u043e\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 \u201c\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u201d, \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438.<br \/>  3) Framework \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 \u201c\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u201d, \u0442\u0443\u0442 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 Excel-\u0435\u043c.<br \/>  4) Converter \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 \u201c\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u201d, \u0434\u043b\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 DataTable (\u0442.\u043a. \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 DataTable).<br \/>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/765\/2c9\/b08\/7652c9b086e59158c9a781aca67e9439.png\" alt=\"image\"\/><br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u201cFramework\u201d \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0432\u0435 \u043f\u0430\u043f\u043a\u0438 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 OpenXML \u0438 WindowsBase:<br \/>   \u201cCreate\u201d \u2013 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>  \u201cLoad\u201d \u2013 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>  \u201clib\u201d \u2013 \u0432 \u043f\u0430\u043f\u043a\u0443, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 OpenXML.<br \/>  \u0412 \u043f\u0430\u043f\u043a\u0435 \u201cCreate\u201d \u0441\u043e\u0437\u0434\u0430\u0451\u043c 4 \u043a\u043b\u0430\u0441\u0441\u0430.<br \/>  1) Worker \u2013 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.  <\/p>\n<pre><code class=\"cs\">using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text.RegularExpressions; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet;  namespace Framework.Create {     \/\/\/ &lt;summary&gt;     \/\/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Excel \u0444\u0430\u0439\u043b\u0430     \/\/\/ &lt;\/summary&gt;     public class Worker     {         \/\/\/ &lt;summary&gt;         \/\/\/ \u043f\u0443\u0442\u044c \u043a \u043f\u0430\u043f\u043a\u0435 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438          \/\/\/ &lt;\/summary&gt;         private const String TemplateFolder = &quot;C:\\\\Templates\\\\&quot;;          \/\/\/ &lt;summary&gt;         \/\/\/ \u041f\u0430\u043f\u043a\u0430, \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432         \/\/\/ &lt;\/summary&gt;         public static String Directory         {             get             {                 const string excelFilesPath = @&quot;C:\\xlsx_repository\\&quot;;                 if (System.IO.Directory.Exists(excelFilesPath) == false)                 {                     System.IO.Directory.CreateDirectory(excelFilesPath);                 }                  return excelFilesPath;             }         }          public void Export(System.Data.DataTable dataTable, System.Collections.Hashtable hashtable, String templateName)         {             var filePath = CreateFile(templateName);              OpenForRewriteFile(filePath, dataTable, hashtable);              OpenFile(filePath);         }          private String CreateFile(String templateName)         {             if (!File.Exists(TemplateFolder + templateName + &quot;.xlsx&quot;))             {                 throw new Exception(String.Format(&quot;\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \\n\\&quot;{0}\\&quot;!&quot;, TemplateFolder + templateName + &quot;.xlsx&quot;));             }             var filePath = Directory + templateName + &quot;_&quot; + Regex.Replace((DateTime.Now.ToString(CultureInfo.InvariantCulture)), @&quot;[^a-z0-9]+&quot;, &quot;&quot;) + &quot;.xlsx&quot;;             File.Copy(TemplateFolder + templateName + &quot;.xlsx&quot;, filePath, true);             return filePath;         }          private void OpenForRewriteFile(String filePath, System.Data.DataTable dataTable, System.Collections.Hashtable hashtable)         {             Row rowTemplate = null;             var footer = new List&lt;Footer&gt;();             var firsIndexFlag = false;             using (var document = SpreadsheetDocument.Open(filePath, true))             {                 Sheet sheet;                 try                 {                     sheet = document.WorkbookPart.Workbook.GetFirstChild&lt;Sheets&gt;().Elements&lt;Sheet&gt;().SingleOrDefault(s =&gt; s.Name == &quot;\u041b\u0438\u0441\u04421&quot;);                 }                 catch (Exception ex)                 {                     throw new Exception(&quot;\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u043b\u0438\u0441\u0442\u0430 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \\&quot;\u041b\u0438\u0441\u04421\\&quot;!\\n&quot;, ex);                 }                  if (sheet == null)                 {                     throw new Exception(&quot;\u0412 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d \u041b\u0438\u0441\u04421!\\n&quot;);                 }                  var worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheet.Id.Value);                 var sheetData = worksheetPart.Worksheet.GetFirstChild&lt;SheetData&gt;();                  var rowsForRemove = new List&lt;Row&gt;();                 var fields = new List&lt;Field&gt;();                 foreach (var row in worksheetPart.Worksheet.GetFirstChild&lt;SheetData&gt;().Elements&lt;Row&gt;())                 {                     var celsForRemove = new List&lt;Cell&gt;();                     foreach (var cell in row.Descendants&lt;Cell&gt;())                     {                         if (cell == null)                         {                             continue;                         }                          var value = GetCellValue(cell, document.WorkbookPart);                         if (value.IndexOf(&quot;DataField:&quot;, StringComparison.Ordinal) != -1)                         {                             if (!firsIndexFlag)                             {                                 firsIndexFlag = true;                                 rowTemplate = row;                             }                             fields.Add(new Field(Convert.ToUInt32(Regex.Replace(cell.CellReference.Value, @&quot;[^\\d]+&quot;, &quot;&quot;))                                 , new string(cell.CellReference.Value.ToCharArray().Where(p =&gt; !char.IsDigit(p)).ToArray())                                 , value.Replace(&quot;DataField:&quot;, &quot;&quot;)));                          }                          if (value.IndexOf(&quot;Label:&quot;, StringComparison.Ordinal) != -1 && rowTemplate == null)                         {                             if (!hashtable.ContainsKey(value.Replace(&quot;Label:&quot;, &quot;&quot;).Trim()))                             {                                 throw new Exception(&quot;\u041d\u0435\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u043b\u044d\u0439\u0431\u043b\u0430 &quot; + value.Replace(&quot;Label:&quot;, &quot;&quot;).Trim());                             }                             cell.CellValue = new CellValue(hashtable[value.Replace(&quot;Label:&quot;, &quot;&quot;).Trim()].ToString());                             cell.DataType = new EnumValue&lt;CellValues&gt;(CellValues.String);                          }                          if (rowTemplate == null || row.RowIndex &lt;= rowTemplate.RowIndex || String.IsNullOrWhiteSpace(value))                         {                             continue;                         }                         var item = footer.SingleOrDefault(p =&gt; p._Row.RowIndex == row.RowIndex);                         if (item == null)                         {                             footer.Add(new Footer(row, cell, value.IndexOf(&quot;Label:&quot;, StringComparison.Ordinal) != -1 ? hashtable[value.Replace(&quot;Label:&quot;, &quot;&quot;).Trim()].ToString() : value));                         }                         else                         {                             item.AddMoreCell(cell, value.IndexOf(&quot;Label:&quot;, StringComparison.Ordinal) != -1 ? hashtable[value.Replace(&quot;Label:&quot;, &quot;&quot;).Trim()].ToString() : value);                         }                         celsForRemove.Add(cell);                     }                      foreach (var cell in celsForRemove)                     {                         cell.Remove();                     }                      if (rowTemplate != null && row.RowIndex != rowTemplate.RowIndex)                     {                         rowsForRemove.Add(row);                     }                 }                  if (rowTemplate == null || rowTemplate.RowIndex == null || rowTemplate.RowIndex &lt; 0)                 {                     throw new Exception(&quot;\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f, \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f!&quot;);                 }                  foreach (var row in rowsForRemove)                 {                     row.Remove();                 }                  var index = rowTemplate.RowIndex;                 foreach (var row in from System.Data.DataRow item in dataTable.Rows select CreateRow(rowTemplate, index, item, fields))                 {                     sheetData.InsertBefore(row, rowTemplate);                     index++;                 }                  foreach (var newRow in footer.Select(item =&gt; CreateLabel(item, (UInt32)dataTable.Rows.Count)))                 {                     sheetData.InsertBefore(newRow, rowTemplate);                 }                  rowTemplate.Remove();             }         }          private Row CreateLabel(Footer item, uint count)         {             var row = item._Row;             row.RowIndex = new UInt32Value(item._Row.RowIndex + (count - 1));             foreach (var cell in item.Cells)             {                 cell._Cell.CellReference = new StringValue(cell._Cell.CellReference.Value.Replace(Regex.Replace(cell._Cell.CellReference.Value, @&quot;[^\\d]+&quot;, &quot;&quot;), row.RowIndex.ToString()));                 cell._Cell.CellValue = new CellValue(cell.Value);                 cell._Cell.DataType = new EnumValue&lt;CellValues&gt;(CellValues.String);                 row.Append(cell._Cell);             }             return row;         }          private Row CreateRow(Row rowTemplate, uint index, System.Data.DataRow item, List&lt;Field&gt; fields)         {             var newRow = (Row)rowTemplate.Clone();             newRow.RowIndex = new UInt32Value(index);              foreach (var cell in newRow.Elements&lt;Cell&gt;())             {                 cell.CellReference = new StringValue(cell.CellReference.Value.Replace(Regex.Replace(cell.CellReference.Value, @&quot;[^\\d]+&quot;, &quot;&quot;), index.ToString(CultureInfo.InvariantCulture)));                 foreach (var fil in fields.Where(fil =&gt; cell.CellReference == fil.Column + index))                 {                     cell.CellValue = new CellValue(item[fil._Field].ToString());                     cell.DataType = new EnumValue&lt;CellValues&gt;(CellValues.String);                 }             }             return newRow;         }           private string GetCellValue(Cell cell, WorkbookPart wbPart)         {             var value = cell.InnerText;              if (cell.DataType == null)             {                 return value;             }             switch (cell.DataType.Value)             {                 case CellValues.SharedString:                      var stringTable = wbPart.GetPartsOfType&lt;SharedStringTablePart&gt;().FirstOrDefault();                      if (stringTable != null)                     {                         value = stringTable.SharedStringTable.ElementAt(int.Parse(value)).InnerText;                     }                     break;             }              return value;         }          private void OpenFile(string filePath)         {             if (!File.Exists(filePath))             {                 throw new Exception(String.Format(&quot;\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0444\u0430\u0439\u043b \\&quot;{0}\\&quot;!&quot;, filePath));             }              var process = Process.Start(filePath);             if (process != null)             {                 process.WaitForExit();             }         }     } } <\/code><\/pre>\n<p>  2) Footer \u2013 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0438\u0445 \u044f\u0447\u0435\u0439\u043a\u0438 \u0438\u0434\u0443\u0449\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.  <\/p>\n<pre><code class=\"cs\">using System; using System.Collections.Generic; using DocumentFormat.OpenXml.Spreadsheet;  namespace Framework.Create {     public class Footer     {         \/\/\/ &lt;summary&gt;         \/\/\/ \u0441\u0442\u0440\u043e\u043a\u0430         \/\/\/ &lt;\/summary&gt;         public Row _Row { get; private set; }         \/\/\/ &lt;summary&gt;         \/\/\/ \u044f\u0447\u0435\u0439\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438         \/\/\/ &lt;\/summary&gt;         public List&lt;CellForFooter&gt; Cells { get; private set; }          public Footer(Row row, Cell cell, String cellValue)         {             _Row = new Row((Row)row.Clone()) { RowIndex = row.RowIndex };             var _Cell = (Cell)cell.Clone();             _Cell.CellReference = cell.CellReference;             Cells = new List&lt;CellForFooter&gt; { new CellForFooter(_Cell, cellValue) };         }          public void AddMoreCell(Cell cell, String cellValue)         {             var _Cell = (Cell)cell.Clone();             _Cell.CellReference = cell.CellReference;             Cells.Add(new CellForFooter(_Cell, cellValue));         }     } } <\/code><\/pre>\n<p>  3) CellForFooter \u2013 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u044f\u0447\u0435\u0439\u043a\u0438 \u0438 \u0435\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Footer-\u0435.  <\/p>\n<pre><code class=\"cs\">using System; using DocumentFormat.OpenXml.Spreadsheet;  namespace Framework.Create {     public class CellForFooter     {         \/\/\/ &lt;summary&gt;         \/\/\/ \u044f\u0447\u0435\u0439\u043a\u0430         \/\/\/ &lt;\/summary&gt;         public Cell _Cell { get; private set; }         \/\/\/ &lt;summary&gt;         \/\/\/ \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435         \/\/\/ &lt;\/summary&gt;         public String Value { get; private set; }          public CellForFooter(Cell cell, String value)         {             _Cell = cell;             Value = value;         }     } } <\/code><\/pre>\n<p>  4) Field \u2013 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0442\u0440\u043e\u043a\u0438, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f DataField, \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u044f\u0447\u0435\u0435\u043a \u0441 DataField \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438.  <\/p>\n<pre><code class=\"cs\">using System;  namespace Framework.Create {     public class Field     {         \/\/\/ &lt;summary&gt;         \/\/\/ \u0418\u043d\u0434\u0435\u043a\u0441 \u0441\u0442\u0440\u043e\u043a\u0438         \/\/\/ &lt;\/summary&gt;         public uint Row { get; private set; }         \/\/\/ &lt;summary&gt;         \/\/\/ \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043a\u043e\u043b\u043e\u043d\u043a\u0438         \/\/\/ &lt;\/summary&gt;         public String Column { get; private set; }         \/\/\/ &lt;summary&gt;         \/\/\/ \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445         \/\/\/ &lt;\/summary&gt;         public String _Field { get; private set; }          public Field(uint row, String column, String field)         {             Row = row;             Column = column;             _Field = field;         }     } } <\/code><\/pre>\n<p>  \u0412 \u043f\u0430\u043f\u043a\u0435 \u201cLoad\u201d \u0441\u043e\u0437\u0434\u0430\u0451\u043c 2 \u043a\u043b\u0430\u0441\u0441\u0430.<br \/>  1) Worker \u2013 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.   <\/p>\n<pre><code class=\"cs\">using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet;  namespace Framework.Load {     \/\/\/ &lt;summary&gt;     \/\/\/ \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 Excel     \/\/\/ &lt;\/summary&gt;     public class Worker     {         \/\/\/ &lt;summary&gt;         \/\/\/ \u041f\u043e\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u044b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 .xlsx         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;param name=&quot;path&quot;&gt;&lt;\/param&gt;         \/\/\/ &lt;returns&gt;&lt;\/returns&gt;         public System.Data.DataTable ReadFile(String path)         {             CheckFile(path);             return OpenDocumentForRead(path);         }          private System.Data.DataTable OpenDocumentForRead(string path)         {             System.Data.DataTable data = null;             using (var document = SpreadsheetDocument.Open(path, false))             {                 Sheet sheet;                 try                 {                     sheet = document.WorkbookPart.Workbook.GetFirstChild&lt;Sheets&gt;().Elements&lt;Sheet&gt;().SingleOrDefault(s =&gt; s.Name == &quot;\u041b\u0438\u0441\u04421&quot;);                 }                 catch (Exception ex)                 {                     throw new Exception(&quot;\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u043b\u0438\u0441\u0442\u0430 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \\&quot;\u041b\u0438\u0441\u04421\\&quot;!\\n&quot;, ex);                 }                  if (sheet == null)                 {                     throw new Exception(&quot;\u0412 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d \u041b\u0438\u0441\u04421!\\n&quot;);                 }                  var relationshipId = sheet.Id.Value;                 var worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(relationshipId);                 var sheetData = worksheetPart.Worksheet.GetFirstChild&lt;SheetData&gt;();                  var firstRow = true;                 var columsNames = new List&lt;ColumnName&gt;();                 foreach (Row row in sheetData.Elements&lt;Row&gt;())                 {                     if (firstRow)                     {                         columsNames.AddRange(GetNames(row, document.WorkbookPart));                         data = GetTable(columsNames);                         firstRow = false;                         continue;                     }                      var item = data.NewRow();                     foreach (var line in columsNames)                     {                         var cc = row.Elements&lt;Cell&gt;().SingleOrDefault(p =&gt; p.CellReference == line.Liter + row.RowIndex);                         if (cc == null)                         {                             throw new Exception(&quot;\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u044f\u0447\u0435\u0439\u043a\u0443 &quot; + line.Liter + row.RowIndex + &quot;!&quot;);                         }                         item[line.Name.Trim()] = GetVal(cc, document.WorkbookPart);                      }                     data.Rows.Add(item);                 }             }              return data;         }          private System.Data.DataTable GetTable(IEnumerable&lt;ColumnName&gt; columsNames)         {             var teb = new System.Data.DataTable(&quot;ExelTable&quot;);              foreach (var col in columsNames.Select(columnName =&gt; new System.Data.DataColumn { DataType = typeof(String), ColumnName = columnName.Name.Trim() }))             {                 teb.Columns.Add(col);             }              return teb;         }          private IEnumerable&lt;ColumnName&gt; GetNames(Row row, WorkbookPart wbPart)         {             return (from cell in row.Elements&lt;Cell&gt;()                     where cell != null                     let                         text = GetVal(cell, wbPart)                     where !String.IsNullOrWhiteSpace(text)                     select                     new ColumnName(text, Regex.Replace(cell.CellReference.Value, @&quot;[\\0-9]&quot;, &quot;&quot;))).ToList();         }          private string GetVal(Cell cell, WorkbookPart wbPart)         {             string value = cell.InnerText;              if (cell.DataType == null)             {                 return value;             }             switch (cell.DataType.Value)             {                 case CellValues.SharedString:                      var stringTable =                         wbPart.GetPartsOfType&lt;SharedStringTablePart&gt;()                             .FirstOrDefault();                      if (stringTable != null)                     {                         value =                             stringTable.SharedStringTable                                 .ElementAt(int.Parse(value)).InnerText;                     }                     break;             }              return value;         }          private void CheckFile(String path)         {             if (String.IsNullOrWhiteSpace(path) || !File.Exists(path))             {                 throw new Exception(String.Format(&quot;\u0422\u0430\u043a\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \\&quot;{0}\\&quot; \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442!&quot;, path));             }         }     } } <\/code><\/pre>\n<p>  2) ColumnName \u2013 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445   <\/p>\n<pre><code class=\"cs\">using System;  namespace Framework.Load {     public class ColumnName     {         \/\/\/ &lt;summary&gt;         \/\/\/ \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445         \/\/\/ &lt;\/summary&gt;         public String Name { get; private set; }         \/\/\/ &lt;summary&gt;         \/\/\/ \u0431\u0443\u043a\u0432\u0430 \u043a\u043e\u043b\u043e\u043d\u043a\u0438         \/\/\/ &lt;\/summary&gt;         public String Liter { get; private set; }          public ColumnName(string name, string liter)         {             Name = name;             Liter = liter;         }     } } <\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u201cInterfaces\u201d \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<br \/>  IDataForTest  <\/p>\n<pre><code class=\"cs\">using System;  namespace Interfaces {     public interface IDataForTest     {         String A { get; }         String B { get; }         String C { get; }     } } <\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u201cConverter\u201d \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441<br \/>  ConvertToDataTable \u2013 \u0434\u043b\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 DataTable.  <\/p>\n<pre><code class=\"cs\">using System; using System.Collections; using System.Collections.Generic; using System.Data; using Interfaces;  namespace Converter {     public class ConvertToDataTable     {         public DataTable ExcelTableLines(IEnumerable&lt;IDataForTest&gt; lines)         {             var dt = CreateTable();             foreach (var line in lines)             {                 var row = dt.NewRow();                 row[&quot;AAA&quot;] = line.A;                 row[&quot;BBB&quot;] = line.B;                 row[&quot;CCC&quot;] = line.C;                 dt.Rows.Add(row);             }             return dt;         }          public Hashtable ExcelTableHeader(Int32 count)         {             var head = new Dictionary&lt;String, String&gt; { { &quot;Date&quot;, DateTime.Today.Date.ToShortDateString() }, { &quot;Count&quot;, count.ToString() } };             return new Hashtable(head);         }          private DataTable CreateTable()         {             var dt = new DataTable(&quot;ExelTable&quot;);             var col = new DataColumn { DataType = typeof(String), ColumnName = &quot;AAA&quot; };             dt.Columns.Add(col);             col = new DataColumn { DataType = typeof(String), ColumnName = &quot;BBB&quot; };             dt.Columns.Add(col);             col = new DataColumn { DataType = typeof(String), ColumnName = &quot;CCC&quot; };             dt.Columns.Add(col);             return dt;         }     } } <\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u201cOpenXmlPrj\u201d <br \/>  \u0411\u0443\u0434\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u201cProgram\u201d  <\/p>\n<pre><code class=\"cs\">using System; using System.Collections.Generic; using System.Data;  namespace OpenXmlPrj {     class Program     {         static void Main(string[] args)         {             \/\/\u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438             var myData = new List&lt;DataForTest&gt;             {                 new DataForTest(&quot;a1&quot;,&quot;b1&quot;,&quot;c1&quot;),                 new DataForTest(&quot;a2&quot;,&quot;b2&quot;,&quot;c2&quot;),                 new DataForTest(&quot;a3&quot;,&quot;b3&quot;,&quot;c3&quot;),                 new DataForTest(&quot;a4&quot;,&quot;b4&quot;,&quot;c4&quot;),                 new DataForTest(&quot;a5&quot;,&quot;b5&quot;,&quot;c5&quot;)             };              var ex = new Converter.ConvertToDataTable();             \/\/ex.ExcelTableLines(myData) - \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 DataTable             \/\/ex.ExcelTableHeader(myData.Count) - \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f Label             \/\/template - \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430  - \u0448\u0430\u0431\u043b\u043e\u043d\u0430             new Framework.Create.Worker().Export(ex.ExcelTableLines(myData), ex.ExcelTableHeader(myData.Count), &quot;template&quot;);              Console.WriteLine(&quot;Excel File Has Created!\\nFor Read Data From Excel, press any key!&quot;);             Console.ReadKey();             \/\/&quot;C:\\\\Loading\\\\ReadMePlease.xlsx&quot; - \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u044f\u0435\u0442 \u043d\u0430\u043c DataTable)             var dt = new Framework.Load.Worker().ReadFile(&quot;C:\\\\Loading\\\\ReadMePlease.xlsx&quot;);             var myDataFromExcel = new List&lt;DataForTest&gt;();             \/\/\u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438\u0437 DataTable             foreach (DataRow item in dt.Rows)             {                 myDataFromExcel.Add(new DataForTest(item));             }              Console.WriteLine(&quot;---------- Data ---------------------&quot;);             \/\/\u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435             foreach (var line in myDataFromExcel)             {                 Console.WriteLine(&quot;{0} | {1} | {2}&quot;, line.A, line.B, line.C);             }              Console.WriteLine(&quot;Done. Press any key, for exit!&quot;);             Console.ReadKey();         }     } } <\/code><\/pre>\n<p>  \u0418 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u201cDataForTest\u201d  <\/p>\n<pre><code class=\"cs\">using System; using System.Data; using Interfaces;  namespace OpenXmlPrj {     public class DataForTest : IDataForTest     {         public String A { get; private set; }         public String B { get; private set; }         public String C { get; private set; }          public DataForTest(String a, String b, String c)         {             A = a;             B = b;             C = c;         }          public DataForTest(DataRow item)         {             A = item[&quot;MyFieldA&quot;].ToString();             B = item[&quot;MyFieldB&quot;].ToString();             C = item[&quot;MyFieldC&quot;].ToString();         }     } } <\/code><\/pre>\n<p>  \u0418 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u201cOpenXmlPrj\u201d \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b: Interfaces, Framework, Converter<br \/>  \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430:<br \/>  1. Excel \u043b\u0438\u0441\u0442, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u201c\u041b\u0438\u0441\u04421\u201d (\u043d\u0443 \u0438\u043b\u0438 \u0435\u0441\u043b\u0438 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0442\u043e\u0436\u0435).<br \/>  2. \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 DataField: \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0442\u0440\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f\u043c\u0438 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0432 DataTable.<br \/>  3. \u0428\u0430\u0431\u043b\u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u201c.xlsx\u201d.<br \/>  \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435:<br \/>  1. Excel \u043b\u0438\u0441\u0442, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u201c\u041b\u0438\u0441\u04421\u201d (\u043d\u0443 \u0438\u043b\u0438 \u0435\u0441\u043b\u0438 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0442\u043e\u0436\u0435).<br \/>  2. \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043e\u043a, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u043f\u043e\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u043c \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. <\/p>\n<p>  \u0420.S. \u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438, \u043a\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442, \u043c\u043e\u0433\u0443 \u0441\u043a\u0438\u043d\u0443\u0442\u044c \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 (\u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0445, \u0441\u043a\u0438\u043d\u0443). \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/203522\/\"> http:\/\/habrahabr.ru\/post\/203522\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0420\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e, \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Excel \u0444\u0430\u0439\u043b \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u0438 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 Excel.<br \/>  \u041d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0451 \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435, \u0434\u0430\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435, \u0443\u0439\u0442\u0438 \u043e\u0442 MS Office, \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438.<br \/>  \u0423 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u201cMicrosoft.Office. Interop.Excel\u201d \u0438 \u043c\u043d\u043e\u0433\u043e \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0434\u043b\u044f \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438 \u0442\u0435\u0445 \u0438\u043b\u0438 \u0438\u043d\u044b\u0445 \u043e\u0442\u0447\u0451\u0442\u043e\u0432.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0442\u0438 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0443\u044e \u0441 \u043e\u0444\u0438\u0441\u043e\u043c. \u0418 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043f\u043e \u0442\u043e\u0439 \u0436\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0447\u0442\u043e \u0438 \u0440\u0430\u043d\u044c\u0448\u0435. \u0418\u0431\u043e \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c.<br \/>  \u0412\u043e\u0442 \u044f \u0438 \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 OpenXML. \u0418 \u0434\u0443\u043c\u0430\u043b, \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e \u0431\u044b\u0441\u0442\u0440\u043e\u043c\u0443 \u043d\u0430\u0439\u0434\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0438 \u0432\u0441\u0451 \u0433\u043e\u0442\u043e\u0432\u043e (\u0442.\u043a. \u043d\u0430 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043e \u043c\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438). \u041d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0442\u0430\u043a \u0438 \u043d\u0435 \u043d\u0430\u0448\u0451\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u0434\u043b\u044f \u0442\u0435\u0445 \u0443 \u043a\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442, \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. <br \/>  \u0421\u0430\u043c\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e \u0441 \u0441\u0430\u0439\u0442\u0430 Micrisoft (\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 OpenXML sdk 2.5 \u201c OpenXMLSDKV25.msi \u201d)<br \/>  <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=30425\">\u0437\u0434\u0435\u0441\u044c<\/a>.<br \/>  \u041f\u043e\u0441\u043b\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u201cOpenXMLSDKV25.msi \u201d, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0438 \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043f\u0430\u043f\u043a\u0443<br \/>  \u201cC:\\Program Files\\Open XML SDK\\V2.5\\lib\u201d \u0442\u0430\u043c \u043b\u0435\u0436\u0438\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f, \u043c\u044b \u0435\u0451 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443 (\u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043e, \u043a\u0430\u043a).<br \/>  \u041f\u0440\u043e\u0435\u043a\u0442 \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 Visual Studio 2010 (Framework 4.0).<br \/>  \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 (\u0441\u0434\u0435\u043b\u0430\u043d \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430) \u201cC:\\Templates\\template.xlsx\u201d.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-203522","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203522"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/203522\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}