らくがき

2008/03/29

ExcelでC#やVBやF#を利用する

"ExcelDna"(http://exceldna.typepad.com/) ExcelのセルにてC#/VB/F#で書いた関数を利用できるようになる DLLの関数を利用する場合は、.NETの言語であればなんでもいいみたい ".xll"と".dna"ファイルが対になって動作するようになっているので "test1.xll" と "test1.dna" のように名前部分を同じにする ".xll"ファイルは、ZIPに同梱されている"ExcelDna.xll"ファイルをリネームして使う C#で書いた関数を利用する場合 [test1.dna]
<DnaLibrary Language="CS">
  <![CDATA[
     using ExcelDna.Integration;
   
     public class MyFunctions
     {
         [ExcelFunction(Description="Joins a string to a number", Category="Useful functions")]
         public static string JoinThem(string str, double val)
         {
             return str + val;
         }
     }
  ]]>
</DnaLibrary>
F#で書いた関数を利用する場合
<DnaLibrary Language="Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider, FSharp.Compiler.CodeDom, Version=1.9.3.14, Culture=neutral, PublicKeyToken=a19089b1c74d0809">

      let sayhello () = "Hello from F#"
      let add x y = x + y

</DnaLibrary>
"FSharp.Compiler.CodeDom.dll"のVersionとPublicKeyTokenを合わせる

0 Comments:

Post a Comment

<< Home