Watir: Win32ole对于excel某些指令无法操作的时候有如下解决方案

Similar Threads
1. WIN32OLE - failed to create WIN32OLE
2. WIN32OLE#[] and WIN32OLE#[]= method in Ruby 1.9 (or later) 

For example, 
  excel = WIN32OLE.excel("Excel.Application")
  excel["Visible"] = true
is NG.
Instead, You must write
  excel = WIN32OLE.excel("Excel.Application")
  excel.Visible = true
 
For more,
   installer = WIN32OLE.new("WindowsInstaller.Installer")
   record = installer.CreateRecord(2)
   record ["StringData", 1] = 'dddd'
 
is NG. Instead,
   installer = WIN32OLE.new("WindowsInstaller.Installer")
   record = installer.CreateRecord(2)
   record.setproperty("StringData", 1, 'dddd')
 
By using new featuer, You can write
 
  worksheet.cells[1,2] = 10
 
in Excel. 
 
For more, you can write
 
  WIN32OLE.new("WScript.Shell")
  env = sh.Environment("User")
  p env["FOO"]
  env["FOO"] = "BARBAZ"
 
For more, you can write
 
  ado = WIN32OLE.new("ADODB.Connection")
  ado.Open("...")
  rs = ado.Execute("SELECT * from TABLE01")
  while !rs.EOF
      puts rs.Fields.Item("id").value
      puts rs.Fields("id").value
      puts rs["id"].value # This is new feature!
      rs.MoveNext
  end
posted @ 2013-08-16 16:57  chenpassion  阅读(377)  评论(0编辑  收藏  举报