C#ã§ä½æããã¢ã»ã³ããªãExcelããå¼ã³åºã
ã¡ãã£ã¨ä»äºã§å¿
è¦ã ã£ãã®ã§èª¿ã¹ã¦ã¿ã¾ãããåºæ¬çã«ã¯COMãã.NETå¼ã³åºããªã®ã§CCWã¨ãªãã®ã§ãããã°ã°ã£ã¦ã¿ãã¨VB.NETã«ã¦ComClasså±æ§ã使ãã¨ããä¾ãçºè¦ãComClasså±æ§ã¯VBã®ã¿ãªã®ã§C#ããã¯ç´æ¥Excelå
¬éã¯åºæ¥ãªããã¨ããæãã§ãããããç´å¾ãè¡ããªãã®ã§ãã¡ã¾ã¡ã¾è©¦ãã¦ãããC#ã§ãå
¬éã§ãã¾ãããã£ã¦ãããããç°¡åã§ãããæåã«æ¢ããè¨äºã¯VS.NETæ代ã®ãªã®ã§ãVS2005ããåºæ¥ãããã«ãªã£ãã®ããããã¾ããï¼
æé ã¯ä»¥ä¸ã®éãã
Excelããå¼ã³åºãç°¡åãªã¢ã»ã³ããªãä½æãã¾ããã©ã¤ãã©ãªããã¸ã§ã¯ããä½ã£ã¦ã以ä¸ã®ã³ã¼ããæ¸ãã¾ãã
using System; using System.Runtime.InteropServices; namespace MyClassLibrary { [ClassInterface(ClassInterfaceType.AutoDual)] public class Calc { public int Add(int x, int y) { return x + y; } public int Sub(int x, int y) { return x - y; } } }
- ClassInterfaceå±æ§
- publicãªã¡ã½ãããããããã£
- ããã©ã«ãã³ã³ã¹ãã©ã¯ã¿
ããããå¿ è¦ãªæ¡ä»¶ã§ããå¼æ°ãåãã³ã³ã¹ãã©ã¯ã¿ãç¨æããå ´åã¯ãå¼æ°ãªããç¨æãã¦ãããã¨ãå¿ããªãããã«æ³¨æã§ãã
ã§ã¯ããããExcelããå¼ã³åºããããã«ããã¸ã§ã¯ãã®è¨å®ãè¡ãã¾ãã
ãããããAssembly Informationãã¿ã³ãæ¼ãã¾ãã
Make assembly COM-Visibleã«ãã§ãã¯ãå
¥ãã¾ãã
Register for COM interopã«ãã§ãã¯ãå
¥ãã¾ãã
ããã§ãã«ãããã°ãExcelãã使ããã¨ãã§ãã¾ãã
ã§ã¯ãExcelå´ã
æ®éã®COMåæ§ãåç
§è¨å®ãè¡ãã¾ãã
ããã¨ããããªæãã