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 ...
随机推荐
- Unity3D IOS IPhone添加Admob的方法
原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140403119293/ 首先阅读官方文档https://developers. ...
- Lua 简单的IO交互 和迷宫代码
function room1 () print("in room1") local move = io.read() if move == "south" th ...
- ZOJ3765 Lights Splay树
非常裸的一棵Splay树,需要询问的是区间gcd,但是区间上每个数分成了两种状态,做的时候分别存在val[2]的数组里就好.区间gcd的时候基本上不支持区间的操作了吧..不然你一个区间里加一个数gcd ...
- POJ2104 K-th Number Range Tree
又是区间第k大,这次选择这道题是为以后写线段树套平衡树铺路的.Range Tree可以理解成线段树套vector吧,相当于每个结点多存了对应区间的一个排好序的序列.画一下就会知道空间的消耗是nlogn ...
- POJ 1740
#include <iostream> #define MAXN 100 using namespace std; int _m[MAXN]; bool mark[MAXN]; int m ...
- 【Linux高频命令专题(11)】cp
概述 cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名,在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不管你是否使用-i参数.但是 ...
- 去掉eclipse的xml和js验证
一.XML Properties > Validation you have two options: 1- Configure Workspace Settings (disable the ...
- Rebound-Android的弹簧动画库
Rebound是facebook出品的一个弹簧动画库,与之对应的IOS版本有一个pop动画库,也是非常的强大给力.Facebook真是互联网企业中的楷模,开源了很多的实用开源库,大赞一个!!! 讲解R ...
- DOS命令 Net config server Net config workstation
DOS命令 Net config 作用:显示当前运行的可配置服务,或显示并修改某项服务的设置. 格式:net conifg service options 参数:(1)键入不带参数的net conif ...
- DoG 、Laplacian、图像金字塔详解
DoG(Difference of Gaussian) DoG (Difference of Gaussian)是灰度图像增强和角点检测的方法,其做法较简单,证明较复杂,具体讲解如下: Differe ...