{"id":9653,"date":"2019-02-03T00:02:17","date_gmt":"2019-02-02T15:02:17","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=9653"},"modified":"2019-02-03T00:02:17","modified_gmt":"2019-02-02T15:02:17","slug":"closedxml%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%80%81%e8%b6%85%e9%ab%98%e9%80%9f%e3%81%abexcel%e3%81%8b%e3%82%89sql-server%e3%81%b8%e3%83%87%e3%83%bc%e3%82%bf%e8%bb%a2%e9%80%81%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/9653","title":{"rendered":"ClosedXML\u3092\u4f7f\u3063\u3066\u3001\u8d85\u9ad8\u901f\u306bExcel\u304b\u3089SQL Server\u3078\u30c7\u30fc\u30bf\u8ee2\u9001\u3059\u308b"},"content":{"rendered":"<p>SQL Server\u306e\u30c7\u30fc\u30bf\u3092\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3059\u308b\u3068\u304d\u6b63\u5f0f\u306a\u65b9\u6cd5\u306a\u3089\u3070\u3001SQL Server\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\/\u5fa9\u5143\u3092\u3059\u308c\u3070\u3088\u3044\u3002\u306e\u3060\u304c\u3001\u5225\u306a\u5834\u6240\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u79fb\u3057\u305f\u3044\u3068\u304d\u4f7f\u3046\u306b\u306f\u3044\u3055\u3055\u304b\u9762\u5012\u304f\u3055\u3044\u3053\u3068\u304c\u8d77\u3053\u308b\u3002\u76f8\u4e92\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u540c\u3058\u306a\u3089\u3070\u3001\u305d\u306e\u3042\u3063\u307e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\/\u5fa9\u5143\u3092\u7e70\u308a\u8fd4\u305b\u3070\u3088\u3044\u306e\u3060\u304c\u3001\u3061\u3087\u3063\u3068\u3067\u3082\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u9055\u3046\u3068\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3002\u4ed5\u65b9\u304c\u306a\u3044\u306e\u3067\u3001Access\u3092\u5a92\u4ecb\u3059\u308b\u65b9\u6cd5\u3092\u3088\u304f\u3068\u308b\u306e\u3060\u304c\u3001\u578b\u304c\u5fae\u5999\u306b\u9055\u3063\u3066\u3044\u308b\u306e\u3067\uff08\u7279\u306b\u6587\u5b57\u5217\u306e\u9577\u3055\u304c\u7570\u306a\u3063\u3066\u30a8\u30e9\u30fc\u306b\u306a\u308b\uff09\u82e5\u5e72\u306e\u624b\u52d5\u306e\u8abf\u7bc0\u304c\u5fc5\u8981\u306b\u306a\u3063\u3066\u304f\u308b\u3002MySQL\u306a\u3089\u3070\u3001\u30c0\u30f3\u30d7\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3063\u3066\u3048\u3044\u3063\u3068SQL\u306b\u76f4\u3057\u3066\u3057\u307e\u3046\u3068\u3053\u308d\u306a\u306e\u3060\u304c\u3001SQL Server\u306b\u306f\u305d\u3093\u306a\u3082\u306e\u306f\u306a\u3044\u3002<\/p>\n<h2>Excel\u3092\u5a92\u4ecb\u306b\u3057\u3066\u307f\u308b<\/h2>\n<p>\u9069\u5f53\u306a\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30c4\u30fc\u30eb\u3092\u4f5c\u308b\u306e\u3082\u3088\u3044\u306e\u3060\u304c\u3001\u3053\u3053\u306f Excel \u3092\u4f7f\u3063\u3066\u5a92\u4ecb\u3057\u3066\u307f\u3088\u3046\u3001\u3068\u8003\u3048\u305f\u3002SQL Server Management Studio\u306b\u306f\u30c7\u30fc\u30bf\u306e\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u5148\u306b\u3001Access\u3084Excel\u3092\u9078\u3076\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u5f53\u7136\u3001Excel \u304b\u3089\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u306e\u3060\u304c\u3001ID \u306e\u8a2d\u5b9a\u3067\u3061\u3087\u3063\u3068\u624b\u52d5\u306a\u3068\u3053\u308d\u304c\u3042\u308b\u3002\u3067\u304d\u308b\u3053\u3068\u306a\u3089\u3070\u3001\u4e00\u767a\u3067\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u305f\u3044\u3068\u3053\u308d\u3060\u3002\u305d\u308c\u306b\u3001Access \u3058\u3083\u306a\u304f Excel \u3067\u30a4\u30f3\u30dd\u30fc\u30c8\u3067\u304d\u308c\u3070\u3001\u3061\u3087\u3063\u3068\u3057\u305f\u4fee\u6b63\u306a\u3089\u3070 Excel \u3067\u4fee\u6b63\u3057\u305f\u5f8c\u306b\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u76f4\u3059\u3068\u3044\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u3044\u308f\u3086\u308b\u30de\u30b9\u30bf\u30fc\u30c6\u30fc\u30d6\u30eb\u306e\u4fee\u6b63\u3092\u3001Excel \u3067\u66f8\u304d\u8fbc\u3093\u3067\u3001SQL Server\u306b\u66f8\u304d\u623b\u3059\u3053\u3068\u304c\u3067\u304d\u308c\u3070\u4fbf\u5229\u3060\u308d\u3046\u3001\u3068\u601d\u305f\u305f\u308f\u3051\u306a\u306e\u3060\u304c\u3002<\/p>\n<p>\u8a66\u3057\u306b Microsoft.Office.Interop.Excel \u3092\u4f7f\u3063\u3066 Cells \u3067\u53c2\u7167\u3057\u306a\u304c\u3089\u3061\u307e\u3061\u307e\u8aad\u307f\u8fbc\u3093\u3067\u3001SqlBulkCopy \u3092\u4f7f\u3063\u3066\u4e00\u6c17\u306b\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308c\u3070\u9ad8\u901f\u306b\u306a\u308b\u3060\u308d\u3046\u3001\u3068\u601d\u3063\u305f\u306e\u3060\u304c&#8230;\u3042\u3042\u3001\u3068\u3066\u3064\u3082\u306a\u304f\u9045\u3044\u3002\u3069\u3046\u3082 COM \u7d4c\u7531\u3067 Cells \u3092\u53c2\u7167\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u304c\u3080\u3061\u3083\u304f\u3061\u3083\u9045\u304f\u3066\u30011000\u4ef6\u4f4d\u306e\u8aad\u307f\u8fbc\u307f\u3067\u30825,6\u5206\u306f\u304b\u304b\u3063\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u4f53\u305f\u3089\u304f\u3060\u3002\u305f\u3063\u305f1\u4e07\u4ef6\u3067\u30821\u6642\u9593\u7a0b\u5ea6\u304b\u304b\u3063\u3066\u3057\u307e\u3046\u898b\u8fbc\u307f\u306a\u306e\u3067\u3001\u3053\u308c\u306f\u3061\u3087\u3063\u3068\u5b9f\u7528\u306b\u8010\u3048\u306a\u3044\u3002<br \/>\n\u3061\u306a\u307f\u306b\u3001Range \u3092\u4f7f\u3063\u3066\u4e8c\u6b21\u5143\u914d\u5217\u306b\u8aad\u307f\u8fbc\u3093\u3067\u3068\u3044\u3046\u65b9\u6cd5\u3092\u4f7f\u3046\u3068\u9ad8\u901f\u5316\u3067\u304d\u308b\u306e\u3060\u304c\u3001\u3061\u3087\u3063\u3068\u30bb\u30eb\u3092\u30a2\u30af\u30bb\u30b9\u3092\u3059\u308b\u3068\u9045\u304f\u306a\u308b\u306e\u3068\u3001\u30c7\u30d0\u30c3\u30b0\u5b9f\u884c\u306a\u3069\u3067 COM \u306a Excel \u304c\u6b8b\u3063\u305f\u308a\u3057\u3066\u7d50\u69cb\u9762\u5012\u306a\u3053\u3068\u304c\u591a\u3044\u3002<br \/>\nRange \u3092\u4e8c\u6b21\u5143\u914d\u5217\u3067\u8aad\u307f\u53d6\u308b\u65b9\u6cd5\u306f\u3001\u5f8c\u65e5\u793a\u3057\u3066\u304a\u304d\u305f\u3044\u3002\u624b\u8efd\u306a\u65b9\u6cd5\u3067\u306f\u3042\u308b\u306e\u3067\u3002<\/p>\n<h2>ClosedXML \u306b\u5207\u308a\u66ff\u3048\u308b<\/h2>\n<p>XML\u5f62\u5f0f\u3067\u4fdd\u5b58\u3055\u308c\u308b xlsx \u306e\u307b\u3046\u306a\u3089\u3070\u3001Open XML\u304c\u4f7f\u3048\u308b\u3002\u3069\u3046\u3084\u3089 ClosedXML \u306f\u5185\u90e8\u7684\u306bOpen XML SDK \u3092\u4f7f\u3063\u3066\u3044\u308b\u305d\u3046\u306a\u306e\u3067\u3001\u3053\u308c\u3092\u4f7f\u3063\u3066\u307f\u308b\u3002\u751f\u306e OpenXML \u3092\u4f7f\u3046\u3088\u308a\u3082\u65ad\u7136 ClosedXML \u306e\u307b\u3046\u304c\u4f7f\u3044\u3084\u3059\u3044\u3068\u3044\u3046\u8a18\u4e8b\u304c\u3042\u308b\u306e\u3067\u3001\u53c2\u8003\u306b\u3055\u305b\u3066\u3082\u3089\u3046\u3002<\/p>\n<p>\u3010C#\u3011Excel\u306e\u53d6\u308a\u6271\u3044\u306bClosedXML\u3092\u4f7f\u7528\u3059\u308b &#8211; \u3042\u305f\u3082\u6280\u8853\u30d6\u30ed\u30b0<br \/>\n<a href=\"http:\/\/atamo-dev.hatenablog.com\/entry\/2017\/07\/23\/180026\">http:\/\/atamo-dev.hatenablog.com\/entry\/2017\/07\/23\/180026<\/a><\/p>\n<p>ClosedXML\u3092\u4f7f\u3063\u305f\u3001Excel\u64cd\u4f5c\u306e\u4f8b ClosedXML<br \/>\n<a href=\"http:\/\/closedxml.codeplex.com\/ https:\/\/gist.github.com\/ishisaka\/6128639\">http:\/\/closedxml.codeplex.com\/ https:\/\/gist.github.com\/ishisaka\/6128639<\/a><\/p>\n<p>\u679c\u305f\u3057\u3066\u3069\u308c\u3060\u3051\u30b9\u30d4\u30fc\u30c9\u30a2\u30c3\u30d7\u3059\u308b\u306e\u304b\uff1f\u3068\u601d\u3063\u3066\u8a66\u3057\u3066\u307f\u305f\u306e\u3060\u304c\u3001\u4f53\u611f\u7684\u306b\u306f Microsoft.Office.Interop.Excel \u3088\u308a ClosedXML \u306e\u307b\u3046\u304c100\u500d\u4f4d\u65e9\u3044\u3002\u6700\u521d\u306b xlsx \u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u3068\u304d\u306b\u306f\u7d50\u69cb\u6642\u9593\u304c\u639b\u304b\u308b\uff08\u3068\u8a00\u3063\u3066\u308210\u79d2\u4f4d\uff09\u3002\u304a\u305d\u3089\u304f XML \u30d5\u30a1\u30a4\u30eb\u5168\u3066\u3092\u8aad\u307f\u8fbc\u307f\u30d1\u30fc\u30b9\u3059\u308b\u306e\u3067\u6642\u9593\u304c\u639b\u304b\u3063\u3066\u3044\u308b\u306e\u3060\u308d\u3046\u3051\u3069\u3001\u5168\u4f53\u3067\u304b\u304b\u308b\u6642\u9593\u304b\u3089\u3059\u308c\u3070\u5168\u7136\u5927\u3057\u305f\u3053\u3068\u306f\u306a\u3044\u3002<\/p>\n<h2>ClosedXML \u3067\u8aad\u307f\u8fbc\u3093\u3067 SqlBulkCopy \u3059\u308b<\/h2>\n<p>Excel \u304b\u3089\u66f8\u304d\u623b\u3059\u306e\u304c\u76ee\u7684\u306a\u306e\u3067\u3001INSERT\u306b\u306fSqlBulkCopy\u3092\u4f7f\u3046\u3002SqlBulkCopy\u306b\u6e21\u3059\u306e\u306fDataTable\u306b\u306a\u308b\u306e\u3067\u3001EF\u306e\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\uff08\u5358\u7d14\u306a\u5024\u30af\u30e9\u30b9\uff09\u304b\u3089DataTable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u63db\u3057\u305f\u95a2\u6570\u3092\u4f7f\u3046\u3002<\/p>\n<p>NuGet \u3067 ClosedXML \u3092\u53d6\u308a\u8fbc\u3093\u3067\u3001XLWorkbook \u30af\u30e9\u30b9\u3067 WorkBook \u3092\u8aad\u307f\u8fbc\u3080\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing ClosedXML.Excel;\r\n\r\nprivate void clickReadClosedXml(object sender, RoutedEventArgs e)\r\n{\r\n    \/\/ 0.\u30c6\u30fc\u30d6\u30eb\u540d\u3092\u6307\u5b9a\r\n    string tableName = &amp;quot;\u55b6\u696d\u696d\u52d9\u30c7\u30fc\u30bf&amp;quot;;\r\n    \/\/ 1.Excel \u3092\u958b\u304f\r\n    string path = @&amp;quot;\u55b6\u696d\u7ba1\u7406_20190201.xlsx&amp;quot;;\r\n    using (var wb = new XLWorkbook(path))\r\n    {\r\n        var sh = wb.Worksheets.FirstOrDefault(t =&gt; t.Name == tableName);\r\n        \/\/ 2.\u30b7\u30fc\u30c8\u304b\u3089EF\u306b\u8aad\u307f\u8fbc\u307f\r\n        var rc = new ClosedXmlRangeConverter&lt;\u55b6\u696d\u696d\u52d9\u30c7\u30fc\u30bf&gt;(sh);\r\n        var items = rc.ToList();\r\n        \/\/ 3.\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u300c\u55b6\u696d\u696d\u52d9\u30c7\u30fc\u30bf\u300d\u306b\u66f8\u304d\u8fbc\u307f\r\n        var ent = new testdbEntities();\r\n        var dt = items.AsDataTable();\r\n        var cn = ent.Database.Connection as SqlConnection;\r\n        var bc = new SqlBulkCopy(cn);\r\n        bc.DestinationTableName = tableName;\r\n        cn.Open();\r\n        bc.WriteToServer(dt);\r\n        cn.Close();\r\n        MessageBox.Show(&amp;quot;\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u307e\u3057\u305f&amp;quot;);\r\n    }\r\n}\r\n<\/pre>\n<p>SSMS \u304b\u3089 Excel \u306b\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u3068\u30b7\u30fc\u30c8\u6bce\u306b\u30c6\u30fc\u30d6\u30eb\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u304c\u4f5c\u3089\u308c\u308b\u3002\u3053\u308c\u3092 wb.Worksheets.FirstOrDefault \u3067\u898b\u3064\u3051\u308b\u3002Excel \u304b\u3089\u30bb\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067 List \u306b\u8fd4\u3059\u81ea\u4f5c\u306e\u30b3\u30f3\u30d0\u30fc\u30bf\u30fc ClosedXmlRangeConverter \u3092\u4f5c\u3063\u3066\u3044\u308b\u3002<br \/>\nList \u3092 DataTable \u306b\u66f8\u304d\u76f4\u3059\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9 AsDataTable \u3092\u4f5c\u3063\u3066\u304a\u3044\u3066 SqlBulkCopy\u306eWriteToServer \u306b\u6e21\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u5909\u63db\u5143\u306e\u55b6\u696d\u696d\u52d9\u30c7\u30fc\u30bf\u30af\u30e9\u30b9\u306f\u3001EF\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u81ea\u52d5\u751f\u6210\u3055\u305b\u305f\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u3092\u305d\u306e\u307e\u307e\u4f7f\u3063\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic partial class \u55b6\u696d\u696d\u52d9\u30c7\u30fc\u30bf\r\n{\r\n    public int \u696d\u52d9\u756a\u53f7 { get; set; }\r\n    public Nullable&lt;int&gt; \u652f\u5e97\u30b3\u30fc\u30c9 { get; set; }\r\n    public string \u652f\u5e97\u540d { get; set; }\r\n    public Nullable&lt;int&gt; \u53d7\u6ce8\u756a\u53f7\u5e74\u5ea6 { get; set; }\r\n    public Nullable&lt;int&gt; \u53d7\u6ce8\u756a\u53f7 { get; set; }\r\n    public Nullable&lt;int&gt; \u53d7\u6ce8\u756a\u53f7\u679d\u756a { get; set; }\r\n    public Nullable&lt;int&gt; \u672a\u5951\u7d04\u756a\u53f7\u5e74\u5ea6 { get; set; }\r\n    public string \u672a\u5951\u7d04\u756a\u53f7 { get; set; }\r\n    public string \u793e\u5185\u696d\u52d9\u756a\u53f7 { get; set; }\r\n    public Nullable&lt;int&gt; \u55b6\u696d\u62c5\u5f53\u8005\u30b3\u30fc\u30c9 { get; set; }\r\n    public string \u55b6\u696d\u62c5\u5f53\u8005\u540d { get; set; }\r\n    public Nullable&lt;int&gt; \u767a\u6ce8\u8005\u30b3\u30fc\u30c9 { get; set; }\r\n    public string \u767a\u6ce8\u8005\u540d { get; set; }\r\n    public string \u767a\u6ce8\u756a\u53f7 { get; set; }\r\n\t...\r\n<\/pre>\n<p>\u3053\u3093\u306a\u98a8\u306a\u30c6\u30fc\u30d6\u30eb\u306b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<h3>?IXLCell\u306e\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>IXLCell \u81ea\u4f53\u306f GetValue() \u3067\u578b\u5909\u63db\u304c\u3067\u304d\u308b\u306e\u3060\u304c\u3001\u4eca\u56de\u306f\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u306e\u5404\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u578b\u306b\u5408\u308f\u305b\u308b\u306e\u3067\u3001\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u306ePropertyInfo\u30af\u30e9\u30b9\u3067\u5bfe\u8c61\u306e\u578b\u306b\u5909\u63db\u3067\u304d\u308b\u3088\u3046\u306b\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u3063\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/\/ CloseXml\u306eIXLCell\u306e\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\r\npublic static class ClosedXmlCellExtensions\r\n{\r\n    public static int ToInt(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return 0;\r\n        int result = 0;\r\n        return int.TryParse(cell.Value.ToString(), out result) ? result : 0;\r\n    }\r\n    public static int? ToNullableInt(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return (int?)null;\r\n        int result = 0;\r\n        return int.TryParse(cell.Value.ToString(), out result) ? result : (int?)null;\r\n    }\r\n    public static double ToDouble(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return 0.0;\r\n        double result = 0.0;\r\n        return double.TryParse(cell.Value.ToString(), out result) ? result : 0.0;\r\n    }\r\n    public static double? ToNullableDouble(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return (double?)null;\r\n        double result = 0.0;\r\n        return double.TryParse(cell.Value.ToString(), out result) ? result : (double?)null;\r\n    }\r\n    public static decimal ToDecimal(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return 0;\r\n        decimal result = 0;\r\n        return decimal.TryParse(cell.Value.ToString(), out result) ? result : 0;\r\n    }\r\n    public static decimal? ToNullableDecimal(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return (decimal?)null;\r\n        decimal result = 0;\r\n        return decimal.TryParse(cell.Value.ToString(), out result) ? result : (decimal?)null;\r\n    }\r\n    public static DateTime ToDateTime(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return new DateTime();\r\n        DateTime result = new DateTime();\r\n        return DateTime.TryParse(cell.Value.ToString(), out result) ? result : new DateTime();\r\n    }\r\n    public static DateTime? ToNullableDateTime(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return (DateTime?)null;\r\n        DateTime result = new DateTime();\r\n        return DateTime.TryParse(cell.Value.ToString(), out result) ? result : (DateTime?)null;\r\n    }\r\n    public static bool ToBoolean(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return false;\r\n        bool result = false;\r\n        return bool.TryParse(cell.Value.ToString(), out result) ? result : false;\r\n    }\r\n    public static bool? ToNullableBoolean(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return (bool?)null;\r\n        bool result = false;\r\n        return bool.TryParse(cell.Value.ToString(), out result) ? result : (bool?)null;\r\n    }\r\n    public static string ToText(this IXLCell cell)\r\n    {\r\n        if (cell.Value == null) return &quot;&quot;;\r\n        return cell.Value.ToString();\r\n    }\r\n\r\n    public static object To(this IXLCell cell, System.Reflection.PropertyInfo pi)\r\n    {\r\n        var pt = pi.PropertyType;\r\n        if (pt == typeof(int)) return cell.ToInt();\r\n        if (pt == typeof(int?)) return cell.ToNullableInt();\r\n        if (pt == typeof(double)) return cell.ToDouble();\r\n        if (pt == typeof(double?)) return cell.ToNullableDouble();\r\n        if (pt == typeof(bool)) return cell.ToBoolean();\r\n        if (pt == typeof(bool?)) return cell.ToNullableBoolean();\r\n        if (pt == typeof(DateTime)) return cell.ToDateTime();\r\n        if (pt == typeof(DateTime?)) return cell.ToNullableDateTime();\r\n        if (pt == typeof(string)) return cell.ToText();\r\n\r\n        return null;\r\n    }\r\n}\r\n<\/pre>\n<h3>\u30b3\u30f3\u30d0\u30fc\u30bf\u30fc ClosedXmlRangeConverter \u30af\u30e9\u30b9<\/h3>\n<p>IXLWorksheet \u306e\u5185\u5bb9\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3001\u76ee\u7684\u306e\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u306e\u30ea\u30b9\u30c8\u3092\u4f5c\u308b\u305f\u3081\u306e\u30b3\u30f3\u30d0\u30fc\u30bf\u30fc\u3092\u4f5c\u6210\u3059\u308b\u3002\u30b7\u30fc\u30c8\u306e1\u884c\u76ee\u306b\u30c6\u30fc\u30d6\u30eb\u306e\u5217\u540d\u304c\u5165\u3063\u3066\u3044\u308b\u60f3\u5b9a\u3067\u4f5c\u3063\u3066\u3042\u308b\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/\/ Range\u304b\u3089EF\u3078\u306e\u30b3\u30f3\u30d0\u30fc\u30bf\u30fc\r\n\/\/\/ Entity Framework\u3067\u5229\u7528\u3059\u308b\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u306b\u8aad\u307f\u8fbc\u3080\r\n\/\/\/ \u4e3b\u306b ClosedXml\u306eExcel \u304b\u3089\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u307f\u3001EF \u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u51fa\u529b\u3059\u308b\u3068\u304d\u306b\u4f7f\u3046\r\npublic class ClosedXmlRangeConverter&lt;T&gt; where T : class, new()\r\n{\r\n    protected List&lt;System.Reflection.PropertyInfo&gt; _Columns = new List&lt;System.Reflection.PropertyInfo&gt;();\r\n    protected IXLWorksheet _sh;\r\n    \/\/\/ \u30b3\u30f3\u30d0\u30fc\u30bf\u30fc\u306e\u4f5c\u6210\r\n    public ClosedXmlRangeConverter(IXLWorksheet sh)\r\n    {\r\n        _sh = sh;\r\n        \/\/ \u6700\u521d\u306e\u884c\u3092\u30b3\u30f3\u30d0\u30fc\u30c8\u5148\u306e\u30c6\u30fc\u30d6\u30eb\u3068\u7167\u5408\u3059\u308b\r\n        var props = typeof(T).GetProperties();\r\n        int col = 1;\r\n        while (sh.Cell(1, col).Value.ToString() != &amp;quot;&amp;quot;)\r\n        {\r\n            var text = sh.Cell(1, col).Value.ToString();\r\n            var prop = props.FirstOrDefault(t =&gt; t.Name == text);\r\n            if (prop != null)\r\n            {\r\n                _Columns.Add(prop);\r\n            }\r\n            col++;\r\n        }\r\n    }\r\n\r\n    \/\/\/ \u884c\u5358\u4f4d\u3067\u30b3\u30f3\u30d0\u30fc\u30c8\r\n    public T ToItem(int row)\r\n    {\r\n        var item = new T();\r\n        for (int col = 0; col &lt; this._Columns.Count; col++)\r\n        {\r\n            var prop = _Columns&#x5B;col];\r\n            var o = _sh.Cell(row, col + 1).To(prop);\r\n            prop.SetValue(item, o);\r\n        }\r\n        return item;\r\n    }\r\n    \/\/\/ \u5168\u3066\u306e\u30c7\u30fc\u30bf\u3092\u30b3\u30f3\u30d0\u30fc\u30c8\r\n    public List&lt;T&gt; ToList()\r\n    {\r\n        var items = new List&lt;T&gt;();\r\n        int r = 2;\r\n        while (_sh.Cell(r, 1).GetValue&lt;string&gt;() != &amp;quot;&amp;quot;)\r\n        {\r\n            var item = this.ToItem(r);\r\n            items.Add(item);\r\n            r++;\r\n        }\r\n        return items;\r\n    }\r\n}\r\n<\/pre>\n<h3>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092DataTable\u306b\u5909\u63db\u3059\u308b\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>DbSet \u304b\u3089 DataTable \u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e AsDataTable() \u3092\u4f5c\u308b\u3002\u305d\u306e\u307e\u307e\u3067\u306f\u3001DataRow \u306e\u578b\u306b Nullable \u304c\u5165\u3089\u306a\u3044\u306e\u3067\u3001DBNull \u3078\u306e\u5207\u308a\u66ff\u3048\u3092\u884c\u3063\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/\/ \r\n&lt;summary&gt;\r\n\/\/\/ DbSet\u3092DataTable\u306b\u5909\u63db\r\n\/\/\/ &lt;\/summary&gt;\r\n\r\npublic static class DataTableExtenstions\r\n{\r\n    public static DataTable AsDataTable&lt;T&gt;(this DbSet&lt;T&gt; src) where T : class\r\n    {\r\n        return DataTableExtenstions.AsDataTable(src.Local);\r\n    }\r\n    public static DataTable AsDataTable&lt;T&gt;(this IEnumerable&lt;T&gt; src) where T : class\r\n    {\r\n        var properties = typeof(T).GetProperties();\r\n        var dest = new DataTable();\r\n        \/\/ \u30c6\u30fc\u30d6\u30eb\u30ec\u30a4\u30a2\u30a6\u30c8\u306e\u4f5c\u6210\r\n        foreach (var prop in properties)\r\n        {\r\n            if ( prop.PropertyType.IsGenericType == true &amp;amp;&amp;amp;\r\n                    prop.PropertyType.GetGenericTypeDefinition().Name == &amp;quot;Nullable`1&amp;quot;)\r\n            {\r\n                \/\/\/ Nullable&lt;int&gt;\u306e\u3068\u304d\u306f\u3001\r\n                \/\/\/ DataRow\u306e\u4e2d\u8eab\u3092 DBNull \u3068 int \u306e\u6642\u306b\u5206\u3051\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u3002\r\n                var originalType = prop.PropertyType.GetProperty(&amp;quot;Value&amp;quot;).PropertyType;\r\n                var column = new DataColumn();\r\n                column.DataType = originalType;\r\n                column.AllowDBNull = true;\r\n                column.ColumnName = prop.Name;\r\n                dest.Columns.Add(column);\r\n            }\r\n            else\r\n            {\r\n                dest.Columns.Add(prop.Name, prop.PropertyType);\r\n            }\r\n        }\r\n        \/\/ \u5024\u306e\u6295\u3052\u8fbc\u307f\r\n        foreach (var item in src)\r\n        {\r\n            var row = dest.NewRow();\r\n            foreach (var prop in properties)\r\n            {\r\n                var itemValue = prop.GetValue(item, new object&#x5B;] { });\r\n                row&#x5B;prop.Name] = itemValue ?? System.DBNull.Value;\r\n            }\r\n            dest.Rows.Add(row);\r\n        }\r\n        return dest;\r\n    }\r\n}\r\n<\/pre>\n<h2>\u8a08\u6e2c\u306f\u3042\u3068\u3067<\/h2>\n<p>\u3053\u308c\u3067 Excel \u30b7\u30fc\u30c8\u304b\u3089 SQL Server \u3078\u306e\u66f8\u304d\u623b\u3057\u304c\u9ad8\u901f\u306b\u884c\u3048\u308b\u3002\u5168\u3066\u306e\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u3053\u623b\u3057\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u30d4\u30f3\u30dd\u30a4\u30f3\u30c8\u3067\u4fee\u6b63\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u304c\u30de\u30b9\u30bf\u30fc\u30c6\u30fc\u30d6\u30eb\u306e\u66f8\u304d\u63db\u3048\u3068\u304b\u3092 Excel \u4e0a\u3067\u884c\u3063\u3066\u3001SQL Server \u306b\u623b\u3059\u3053\u3068\u304c\u3067\u304d\u308c\u3070\u7d50\u69cb\u4fbf\u5229\u3060\u3068\u601d\u3046\u3002\u4fee\u6b63\u81ea\u4f53\u3082\u304a\u5ba2\u3055\u3093\u306b\u884c\u3063\u3066\u8cb0\u3046\u3053\u3068\u3082\u3067\u304d\u305d\u3046\u3060\u3057\u3002<\/p>\n<p>\u30b9\u30d4\u30fc\u30c9\u306f\u3001COM \u7d4c\u7531\u3088\u308a\u3082100\u500d\u4f4d\u65e9\u3044\u306e\u3060\u304c\u3001\u3053\u308c\u306f\u5f8c\u3067\u5b9f\u6e2c\u3057\u3066\u307f\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL Server\u306e\u30c7\u30fc\u30bf\u3092\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3059\u308b\u3068\u304d\u6b63\u5f0f\u306a\u65b9\u6cd5\u306a\u3089\u3070\u3001SQL Server\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\/\u5fa9\u5143\u3092\u3059\u308c\u3070\u3088\u3044\u3002\u306e\u3060\u304c\u3001\u5225\u306a\u5834\u6240\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u79fb\u3057\u305f\u3044\u3068\u304d\u4f7f\u3046\u306b\u306f\u3044\u3055\u3055\u304b\u9762\u5012\u304f\u3055\u3044\u3053\u3068 &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/9653\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-9653","post","type-post","status-publish","format-standard","hentry","category-dev"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/9653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=9653"}],"version-history":[{"count":3,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/9653\/revisions"}],"predecessor-version":[{"id":9656,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/9653\/revisions\/9656"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=9653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=9653"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=9653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}