使い方のメモ。
githubからコードを入手
https://github.com/Excel-DNA
ExcelDna\Sourceにあるソリューションを開いてでビルドする。
ExcelDna\Build\build.batを実行。
新しいC#プロジェクトを作成。
ExcelDna\DistributionにあるExcelDna.Integrationを参照に追加。
namespace Excel { public class Export { public static double Add(double x, double y) { return x + y; } } }
ExcelDna.dnaを編集
<DnaLibrary RuntimeVersion="v4.0"> <ExternalLibrary Path="Excel.dll" /> </DnaLibrary>
ExcelDna.xllを開いて、新しいbookを作成し、Addを呼んでみる。
動いた!
Rangeを返す。
public static object[] ReturnArray(int n) { object[] array = new object[n]; for (int i = 0; i < n; ++i) { array[i] = i; } return array; } public static object[,] ReturnMatrix(int n) { object[,] array = new object[n, n]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { array[i, j] = i + j; } } return array; }
Rangeを受け取る
public static string UpdateRange(object[,] range) { for (int i = 0; i < range.GetLength(0); ++i) { for (int j = 0; j < range.GetLength(1); ++j) { range[i, j] = i + j; } } return "success!!"; }
ん?? 更新できない・・・
できないことはないようだが、推奨されていないみたい。
https://groups.google.com/forum/#!topic/exceldna/SCPBnuw7Cl8