WIN32OLE objects represent OLE Automation object in Ruby.
By using WIN32OLE, you can access OLE server like VBScript.
Here is sample script.
require 'win32ole' excel = WIN32OLE.new('Excel.Application') excel.visible = true workbook = excel.Workbooks.Add(); worksheet = workbook.Worksheets(1); worksheet.Range("A1:D1").value = ["North","South","East","West"]; worksheet.Range("A2:B2").value = [5.2, 10]; worksheet.Range("C2").value = 8; worksheet.Range("D2").value = 20; range = worksheet.Range("A1:D2"); range.select chart = workbook.Charts.Add; workbook.saved = true; excel.ActiveWorkbook.Close(0); excel.Quit();
Unfortunately, Win32OLE doesn’t support the argument passed by reference directly. Instead, Win32OLE provides WIN32OLE::ARGV or WIN32OLE_VARIANT object. If you want to get the result value of argument passed by reference, you can use WIN32OLE::ARGV or WIN32OLE_VARIANT.
oleobj.method(arg1, arg2, refargv3) puts WIN32OLE::ARGV[2] # the value of refargv3 after called oleobj.method
or
refargv3 = WIN32OLE_VARIANT.new(XXX, WIN32OLE::VARIANT::VT_BYREF|WIN32OLE::VARIANT::VT_XXX) oleobj.method(arg1, arg2, refargv3) p refargv3.value # the value of refargv3 after called oleobj.method.
Constants
LOCALE_USER_DEFAULT = 0x0400
LOCALE_SYSTEM_DEFAULT = 0x0800
CP_UTF8 = 65001
CP_UTF7 = 65000
CP_SYMBOL = 42
CP_THREAD_ACP = 3
CP_MACCP = RB_INT2FIX(CP_MACCP)
CP_OEMCP = 1
CP_ACP = 0
ARGV = After invoking OLE methods with reference arguments, you can access the value of arguments by using ARGV. If the method of OLE(COM) server written by C#.NET is following: void calcsum(int a, int b, out int c) { c = a + b; } then, the Ruby OLE(COM) client script to retrieve the value of argument c after invoking calcsum method is following: a = 10 b = 20 c = 0 comserver.calcsum(a, b, c) p c # => 0 p WIN32OLE::ARGV # => [10, 20, 30] You can use WIN32OLE_VARIANT object to retrieve the value of reference arguments instead of referring WIN32OLE:
VERSION = rb_str_new2(WIN32OLE_VERSION)