{"id":3413,"date":"2011-07-31T03:36:42","date_gmt":"2011-07-30T18:36:42","guid":{"rendered":"http:\/\/mimumimu.net\/blog\/?p=3413"},"modified":"2012-04-21T18:23:46","modified_gmt":"2012-04-21T09:23:46","slug":"excel-%e3%81%ae%e3%83%9e%e3%82%af%e3%83%ad%e3%82%92-python-%e3%81%a7%e6%9b%b8%e3%81%8f%e3%80%82","status":"publish","type":"post","link":"https:\/\/mimumimu.net\/blog\/2011\/07\/31\/excel-%e3%81%ae%e3%83%9e%e3%82%af%e3%83%ad%e3%82%92-python-%e3%81%a7%e6%9b%b8%e3%81%8f%e3%80%82\/","title":{"rendered":"Excel \u306e\u30de\u30af\u30ed\u3092 Python \u3067\u66f8\u304f\u3002"},"content":{"rendered":"<p>\u307f\u3080\u3089\u3067\u3059\u3002IronPython \u3063\u3066\u306e\u304c\u3042\u308b\u306e\u3067\u3001\u3061\u3087\u3061\u3087\u3044\u3068\u3002<\/p>\n<p>\u4ed5\u7d44\u307f\u3068\u3057\u3066\u306f\u3001Visual Studio \u306e VSTO (Visual Studio Tools for Office) \u3092\u4f7f\u3063\u3066\u3001    <br \/>Office \u5411\u3051\u306e\u30a2\u30c9\u30a4\u30f3\u3092\u4f5c\u3063\u3066\u3001\u305d\u306e\u4e2d\u3067 IronPython \u3092\u52d5\u304b\u305d\u3046\u30fc\u3063\u3066\u3053\u3068\u3002<\/p>\n<p><a href=\"http:\/\/mimumimu.net\/blog\/wp-content\/uploads\/2011\/07\/359870206.png\"><img decoding=\"async\" style=\"background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px\" title=359870206 border=0 alt=359870206 src=\"http:\/\/mimumimu.net\/blog\/wp-content\/uploads\/2011\/07\/359870206_thumb.png\" width=525 height=477><\/a><\/p>\n<p>\u7d50\u679c\u3068\u3057\u3066\u306f\u3053\u3093\u306a\u611f\u3058\uff01<\/p>\n<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u3001VSTO \u306e\u66f8\u304d\u65b9\u3068\u304b\u306f\u5272\u611b\u3057\u3066\u3002<\/p>\n<p>\u30bd\u30fc\u30b9\u306f\u3053\u3053\u306b\uff1a    <br \/><a title=\"https:\/\/github.com\/mimura1133\/mm_Python_for_Excel\" href=\"https:\/\/github.com\/mimura1133\/mm_Python_for_Excel\">https:\/\/github.com\/mimura1133\/mm_Python_for_Excel<\/a><\/p>\n<div style=\"padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px\" id=\"scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:cbf3847b-5442-4dbe-9b79-d798cd91574d\" class=wlWriterEditableSmartContent>\n<pre class=\"brush: c#;\">using Microsoft.Scripting.Hosting;\r\nusing IronPython.Hosting;\r\n\r\nnamespace ExcelAddIn1\r\n{\r\n    public partial class ThisAddIn\r\n    {\r\n        public static string Code = &quot;&quot;;\r\n\r\n        static ScriptEngine _python;\r\n        static ScriptScope _python_scope;\r\n\r\n        private void ThisAddIn_Startup(object sender, System.EventArgs e)\r\n        {\r\n            _python = Python.CreateEngine();\r\n            _python_scope = _python.CreateScope();\r\n            _python_scope.SetVariable(&quot;Application&quot;, Application);\r\n            _python_scope.SetVariable(&quot;Function&quot;, Application.WorksheetFunction);\r\n            _python_scope.SetVariable(&quot;Cells&quot;, Application.Cells);\r\n        }\r\n\r\n        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)\r\n        {\r\n        }\r\n\r\n        public static void Run()\r\n        {\r\n            var cc =_python.CreateScriptSourceFromString(Code);\r\n            cc.Execute(_python_scope);\r\n        }\r\n\r\n        #region VSTO generated code\r\n\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/ Required method for Designer support - do not modify\r\n        \/\/\/ the contents of this method with the code editor.\r\n        \/\/\/ &lt;\/summary&gt;\r\n        private void InternalStartup()\r\n        {\r\n            this.Startup += new System.EventHandler(ThisAddIn_Startup);\r\n            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);\r\n        }\r\n\r\n        #endregion\r\n    }\r\n}\r\n<\/pre>\n<\/div>\n<p>\u30e1\u30a4\u30f3\u30bd\u30fc\u30b9\u306f\u3053\u3093\u306a\u611f\u3058\uff01<\/p>\n<p>Python.CreateEngine() \u3067\u3001 Python \u306e\u30a8\u30f3\u30b8\u30f3\u4f5c\u3063\u3066\u3001<\/p>\n<p>Scope \u306b\u5bfe\u3057\u3066\u3001 SetVariable \u3092\u4f7f\u3063\u3066\u3001\u53c2\u7167\u3092\u304c\u3057\u304c\u3057\u3002\uff08 python \u3067\u8a00\u3046\u3068\u3053\u308d\u306e\u3001 import \uff09<\/p>\n<p>\u3042\u3068\u3001\u3069\u3053\u304b\u304b\u3089 Run \u304c\u5b9f\u884c\u3055\u308c\u305f\u3089\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u5b9f\u884c\u3059\u308b\u4ed5\u639b\u3051\u3002<\/p>\n<p>\u52d5\u4f5c\u4f8b\u3067\u3059\u3068\u3001\u300cRun\u300d \u30dc\u30bf\u30f3\u3067\u3059\u306d\u3002<\/p>\n<\/p>\n<p>\u3053\u308c\u4f7f\u3063\u305f\u5834\u5408\u3001 Function \u4ee5\u4e0b\u306b\u3001Excel \u306e\u95a2\u6570\u304c\u5b58\u5728\u3057\u3066\u3044\u3066\u3001<\/p>\n<p>Cells \u4ee5\u4e0b\u306b\u3001\u5404\u30bb\u30eb\u60c5\u5831\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u30ad\u30fc\u5165\u529b\u3092\u6355\u307e\u3048\u3066\u304f\u308c\u3070\u3001Python \u306b\u3088\u308b\u30de\u30af\u30ed\u3082\u53ef\u80fd\u304b\u3082\u3002<\/p>\n<\/p>\n<p>\u5236\u4f5c\u6642\u959330\u5206\u3060\u304b\u3089\u3001\u3068\u3063\u3066\u3082\u6c5a\u304f\u3066\u3001\u5b9f\u88c5\u304c\u3075\u3056\u3051\u305f\u611f\u3058\u306b\u306a\u3063\u3066\u3044\u308b\u3051\u3069\u3001\u8a31\u3057\u3066\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u307f\u3080\u3089\u3067\u3059\u3002IronPython \u3063\u3066\u306e\u304c\u3042\u308b\u306e\u3067\u3001\u3061\u3087\u3061\u3087\u3044\u3068\u3002 \u4ed5\u7d44\u307f\u3068\u3057\u3066\u306f\u3001Visual Studio \u306e VSTO (Visual Studio Tools for Office) \u3092\u4f7f\u3063\u3066\u3001 Office \u5411 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,15,12,7],"tags":[165,584],"class_list":["post-3413","post","type-post","status-publish","format-standard","hentry","category-csharp","category-windows","category-software","category-dev","tag-excel","tag-python"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/posts\/3413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/comments?post=3413"}],"version-history":[{"count":0,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/posts\/3413\/revisions"}],"wp:attachment":[{"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/media?parent=3413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/categories?post=3413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/tags?post=3413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}