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
RubyWin32Api Win32OLE的更多相关文章
- ruby中 Win32ole的各应用操作方法(word excel Outlook IE)
Win32ole为标准Ruby发行版的一部分.Win32ole是访问Windows自动化的接口,可以让Ruby和Windows应用进行交互.具体说来Win32ole可以操作Word,Excel,IE, ...
- ruby中的win32ole使用
ruby中的win32ole是一个标准库,使用的时候只要添加require 'win32ole'就行. 下面是一段模拟一个登陆的代码 require 'win32ole' ie = WIN32OLE. ...
- 使用win32ole进行页面加载和跳转
require "win32ole" #包含库 ie = WIN32OLE.new('internetExplorer.Application') ie.visible = tru ...
- Watir: Win32ole对于excel某些指令无法操作的时候有如下解决方案
Similar Threads 1. WIN32OLE - failed to create WIN32OLE 2. WIN32OLE#[] and WIN32OLE#[]= method in Ru ...
- Ruby: Print WIN32OLE method names in Ruby
class WIN32OLE def list_ole_methods method_names = ole_methods.collect {|m| m.name} puts m ...
- 从0到1,教你实现基于Ruby的watir-webdriver自动化测试
一.为什么选择Ruby []完全开源. []多平台:Ruby可以运行在Linux, UNIX, Windows, MS-DOS, BeOS, OS/.. []多线程:线程就是指在一个程序中处理若干控制 ...
- ruby中excel简单操作以及文件读取操作方法
# -*-coding:utf-8 -*-#author:kanlijunrequire 'win32ole'require 'fileutils'class ResultAnalyse @@i=0 ...
- ruby + watir 自动化上传图片文件解决方案
watir自动化捕获上传图片元素: require 'watir' include Watir require 'test/unit' class TC_recorded < Test::Uni ...
- Ruby操作Excel的方法与技巧大全
测试工作中,批量的数据通常会放到excel表格中,测试输出的数据写回表格中,这样输入输出易于管理,同时清晰明了 使用ruby来操作excel文件首先需要在脚本里包含以下语句 require'win32 ...
随机推荐
- HTTP长轮询和短轮询
http 协议介绍: http 协议是请求/响应范式的, 每一个 http 响应都是由一个对应的 http 请求产生的; http 协议是无状态的, 多个 http 请求之间是没有关系的. http ...
- MongoDB 性能优化五个简单步骤
MongoDB 一直是最流行的 NoSQL,而根据 DB-Engines Ranking 最新的排行,时下 MongoDB 已经击败 PostgreSQL 跃居数据库总排行的第四位,仅次于 Oracl ...
- C# 构造函数的使用方法
C#构造函数是一个特殊的类方法.在很多方面,包括访问修饰符.重载以及参数列表的语法等方面,构造函数与普通的方法是类似的.然而,在使用方面以及行为方面,构造函数也具有许多特殊的语法和语义规则. 下面列出 ...
- hdu 4282 A very hard mathematic problem
由于k的范围是0-2^31,而且x,y,z都是正整数,由题易知道2<=z<31,1<=x<y;所以直接枚举就好了!!! #include<iostream> #in ...
- Android 异步加载
Android 4.0 后 貌似规定了 在主线程中不允许访问网络,在子线程中不允许修改UI. 否则会抛出NetworkOnMainThreadException 异常 解决办法: 采用继承 Async ...
- lintcode:Minimum Subarray 最小子数组
题目: 最小子数组 给定一个整数数组,找到一个具有最小和的子数组.返回其最小和. 样例 给出数组[1, -1, -2, 1],返回 -3 注意 子数组最少包含一个数字 解题: 和最大子数组 ,差不多的 ...
- VCL ActiveX 播放视频
播放网络视频 string[] options = new string[] { ":sout=#duplicate{dst=display} :no-overlay" }; st ...
- SqlDataAdapter用法
SqlDataAdapter和SqlCommand区别: SqlCommand就是是命令了,可以用它来执行SQL命令: SqlDataAdapter就是数据适配器了,它是用于在数据源和数据集之间通讯的 ...
- Orcle数据库查询练习复习:四
一.题目 1.找出张三的最高分和最低分以及对应的课程名 select * from course c,mark m where c.cid=m.cid and sid =(select sid fro ...
- 用 React 编写2048游戏
1.代码 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="U ...