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