GH C# Component tips_ExcelのデータをGrasshopperに読み込む(任意のExcelファイルがあらかじめ開かれていることを前提とした記述)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void RunScript(bool getParam, string filePath, ref object A, ref object B, ref object C) | |
{ | |
if(getParam) | |
{ | |
Microsoft.Office.Interop.Excel.Application exlApp = | |
(Microsoft.Office.Interop.Excel.Application) | |
System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); | |
//今開いているExcelファイルを取得する | |
Microsoft.Office.Interop.Excel.Workbook wb = exlApp.ActiveWorkbook; | |
//シートの情報を取得する | |
Microsoft.Office.Interop.Excel.Worksheet ws1 = (Worksheet) wb.Sheets[1]; | |
//Type.Missingの説明について | |
//http://d.hatena.ne.jp/ron_s-nakazawa/20120924/1348452525#20120924f1 | |
ws1.Select(Type.Missing); | |
Range range23 = (Range) ws1.Cells[2, 3]; | |
A = range23.Value; | |
Range range33 = (Range) ws1.Cells[3, 3]; | |
B = range33.Value; | |
//Cellsプロパティよりもget_RangeメソッドでRangeを取得した方が速いという話も・・・(未検証)。 | |
//こちらは単数セルから複数セルまで色んな方法でのセルの取得が可能。 | |
//参考:【NetOffice】Rangeメソッドでセルを指定する(単一・範囲・複数) http://pro.art55.jp/?eid=1304060 | |
C = ws1.get_Range("A1", "C3").Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment