Excelファイルを開いて、[1行目、1列目](“A1”)の内容を表示。
require 'win32ole' def fullpath fn fo = WIN32OLE.new('Scripting.FileSystemObject') fo.GetAbsolutePathName(fn) end fn = fullpath('test.xls') xls = WIN32OLE.new('Excel.Application') xls.visible = true book = xls.Workbooks.Open(fn) sheet = book.Worksheets(1) p sheet.Cells.Item(1,1).value
GetAbsolutePathName は絶対パス
xls.visible = true にしておくと、Excelのウィンドウが表示される。falseにすると非表示。
sheet.Cells.Item(1,1) 1行、1列、つまり A1。
あるいは、Cells.Range(“A1”).value と指定する。
require 'win32ole' def fullpath fn fo = WIN32OLE.new('Scripting.FileSystemObject') fo.GetAbsolutePathName(fn) end fn = fullpath('test.xls') xls = WIN32OLE.new('Excel.Application') xls.visible = true book = xls.Workbooks.Open(fn) sheet = book.Worksheets(1) p sheet.Range("A1").value
![](https://images-na.ssl-images-amazon.com/images/I/51PXVm6-xDL._SX351_BO1,204,203,200_.jpg)
![](http://thumbnail.image.rakuten.co.jp/@0_mall/surugaya-a-too/cabinet/4576/bo483945m.jpg?_ex=500x500)