zoukankan      html  css  js  c++  java
  • RubyWin32Api Win32OLE

    #ruby提供了多种运行外部程序的方法
    #1.%x %x不需要使用引号包含。
    #2. system方法 
    #3.exec类似system但是会中断当前的代码执行
    #system和exec不能捕获执行程序的输出。
    list=%x(dir d:\) #捕获到输出结果
    system('notepad')
    p 'system'
    exec('notepad')
    p 'exec'#被exec中断,不会执行下面的代码
    
    require 'Win32API'#调用Win32api
    get_cur=Win32API.new("user32","GetCursorPos",['P'],'V')
    set_cur=Win32API.new("user32","SetCursorPos",['i']*2,'V')
    lpoint=" "*8
    get_cur.call(lpoint)
    x,y=lpoint.unpack("LL")
    p "当前鼠标的坐标为:X:#{x},Y:#{y}"
    new_xy=[12,12]
    set_cur.call new_xy[0],new_xy[1]
    
    
    require 'win32ole'#调用win32ole
    excel=WIN32OLE.new('excel.application')
    excel.Visible=true
    excel.WorkBooks.Add
     
    excel.Range("a1").value=3
    excel.Range('a2').value=2
    excel.Range('a3').value=1
    excel.Range('b1').value="win32ole操作excel栗子"
    excel.Range('a1:a3').select
    
    excel_chart=excel.charts.add
    excel_chart.type=-4100
    excel.ActiveWorkbook.SaveAs("c:\test.xls")
    excel.ActiveWorkbook.Close(0)
    excel.Quit
    
    
    word=WIN32OLE.new('word.application')
    word.Visible=true
    word.Documents.Add
    word.Selection.TypeText("你好")
    word.Selection.TypeParagraph
    word.Selection.TypeText("win32ole操作word栗子")
    #word.Selection.TypeParagraph
    
    word.Selection.InlineShapes.AddPicture("http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png")#本地和网络图片均可
    
    word.ActiveDocument.SaveAs("c:test.doc")
    word.ActiveDocument.close
    word.quit
    
    
    ie=WIN32OLE.new('internetexplorer.application')
    ie.visible=true
    ie.left=100
    ie.top=100
    ie.width=700
    ie.height=500
    ie.navigate 'http://www.baidu.com/s?wd=你好'
    sleep 0.1 while ie.busy
    script=ie.document.script
    script.alert('这是ruby调用的js脚本')
    #script.eval('document.location=$("h3>a:eq(0)").attr("href")')#这是个问题。。怎么执行呢
    ie.Document.title='修改它的标题'
    puts ie.document
    ie.quit
  • 相关阅读:
    函数終探------匿名函数
    再探函数2---函数的嵌套与装饰器
    无需触摸芯片的触摸电路
    单芯片移动电源方案——1A同步升压5V--TP4351B
    HTML列表元素
    HTML表格元素
    HTML基本元素
    创建HTML5文档
    HTML5环境安装
    windows本地搭建https环境,tomcat使用https协议
  • 原文地址:https://www.cnblogs.com/smailxiaobai/p/4213723.html
Copyright © 2011-2022 走看看