{"id":153,"date":"2017-03-29T20:48:57","date_gmt":"2017-03-29T11:48:57","guid":{"rendered":"http:\/\/shinke1987.net\/?p=153"},"modified":"2017-04-07T16:22:34","modified_gmt":"2017-04-07T07:22:34","slug":"post-153","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=153","title":{"rendered":"C#\u3067Excel\u306e\u30bb\u30eb\u306e\u5024\u3092\u8868\u793a\u3002"},"content":{"rendered":"<h2>\u74b0\u5883<\/h2>\n<p>OS\uff1aWindows7 Pro<br \/>\nVisualStudio\uff1a2013 Professional<br \/>\n.NET Framework\uff1a4.6.1<\/p>\n<p>VisualStudio\u3092\u30ea\u30ea\u30fc\u30b9\u30e2\u30fc\u30c9\u3067\u3001<br \/>\n\u30c7\u30d0\u30c3\u30b0\u7121\u3057\u3067\u958b\u59cb(Ctrl + F5)\u3067<br \/>\nExcel\u306e\u30d7\u30ed\u30bb\u30b9\u306f\u6b8b\u3089\u306a\u3044\u3002<\/p>\n<p>\u53c2\u7167\u8a2d\u5b9a\u3067\u3001<br \/>\n\u300c<span class=\"red\">Microsoft.CSharp<\/span>\u300d<br \/>\n\u300c<span class=\"red\">Microsoft.Office.Interop.Excel<\/span>\u300d<br \/>\n\u3092\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n<h2>\u30b3\u30fc\u30c9<\/h2>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing System;\r\nusing Excel = Microsoft.Office.Interop.Excel;\r\n\r\npublic class Program\r\n{\r\n    public static void Main()\r\n    {\r\n        \/\/ Excel\u8d77\u52d5\u3002\r\n        Excel.Application mApp = new Excel.Application();\r\n        \/\/ \u8d77\u52d5\u3057\u305fExcel\u304b\u3089\u30ef\u30fc\u30af\u30d6\u30c3\u30af\u306e\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u8868\u3059\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3002\r\n        Excel.Workbooks mWorkBooks = mApp.Workbooks;\r\n        \/\/ \u6307\u5b9a\u3057\u305fExcel\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u3002\r\n        Excel.Workbook mWorkBook = mWorkBooks.Open(&quot;D:\\\\CSharp\\\\20170310_ExcelTest\\\\temp.xlsm&quot;);\r\n        \/\/ \u958b\u3044\u305fExcel\u30d5\u30a1\u30a4\u30eb\u306e\u30b7\u30fc\u30c8\u306e\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u53d6\u5f97\u3002\r\n        Excel.Sheets mSheets = mWorkBook.Worksheets;\r\n        \/\/ 1\u756a\u76ee\u306e\u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u3092\u53d6\u5f97\u3002\r\n        Excel.Worksheet mWorkSheet = mSheets&#x5B;1];\r\n        \r\n        \/\/ \u6307\u5b9a\u3057\u305f\u30bb\u30eb\u306e\u5024\u3092\u53d6\u5f97\u3002\r\n        Excel.Range mRange = mWorkSheet.Cells&#x5B;1, 1];\r\n\r\n        \/\/ \u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u306b\u8868\u793a\u3002\r\n        Console.WriteLine(mRange.Value);\r\n\r\n        \/\/ Excel\u3092\u8868\u793a\u3002\r\n        \/\/ mApp.Visible = true;\r\n\r\n        \/\/ \u30ef\u30fc\u30af\u30d6\u30c3\u30af\u3092\u9589\u3058\u308b\u3002\r\n        mWorkBook.Close();\r\n        \/\/ Excel\u3092\u9589\u3058\u308b\u3002\r\n        mApp.Quit();\r\n        \/\/ \u30ac\u30d9\u30fc\u30b8\u30b3\u30ec\u30af\u30bf\u3092\u5b9f\u884c\u3002\r\n        GC.Collect();\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u74b0\u5883 OS\uff1aWindows7 Pro VisualStudio\uff1a2013 Professional .NET Framework\uff1a4.6.1 VisualStudio\u3092\u30ea\u30ea\u30fc\u30b9\u30e2\u30fc\u30c9\u3067\u3001 \u30c7\u30d0\u30c3\u30b0\u7121\u3057\u3067\u958b\u59cb(Ctrl + [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[36,22],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-c-sharp","tag-c-sharp","tag-excel"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=153"}],"version-history":[{"count":3,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":158,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions\/158"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}