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 ...
随机推荐
- CKFinder 1.4.3 任意文件上传漏洞
CKFinder 是国外一款非常流行的所见即所得文字编辑器,其1.4.3 asp.net版本存在任意文件上传漏洞,攻击者可以利用该漏洞上传任意文件. CKFinder在上传文件的时候,强制将文件名(不 ...
- ubuntu下opencv 3.0和python2.7安装测试
1.安装opencv所需的库(编译器.必须库.可选库) sudo apt-get install build-essential sudo apt-get install cmake git libg ...
- Javascript的动态运动(1)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- ios学习笔记block回调的应用(一个简单的例子)
一.什么是Blocks Block是一个C级别的语法以及运行时的一个特性,和标准C中的函数(函数指针)类似,但是其运行需要编译器和运行时支持,从ios4.0开始就很好的支持Block. 二. ...
- Unity UGUI —— 无限循环List(转载)
using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; ...
- 【Linux高频命令专题(16)】less
概述 less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大.less 的用法比起 more 更加的有弹性.在 more 的时候,我们并没有办法向 ...
- 前台将勾选的多个属性放到一个value里面,是一个字符串,传到后台
jq function changeStreet(a){ var valk=$(a).html(); $(a).parents(".select_box").children(&q ...
- 致诸位新程序员:来自Chuck Jazdzewski慈父般的忠告
记住这几句话,学无止境.(Never stop learning.)沟通至关重要.(Communication is critical.)履行承诺,胜过交付.(Under promise, over ...
- Arcgis Engine最短路径分析
ArcEngine 最短路径分析(源码) using System; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geometry; using ESRI ...
- Lua表的构造及遍历
关于lua中的table,主要的困惑来自于table既可以当array用又可以当record用,有时候就会混淆不清. lua中的table貌似是用map来实现的,array是语法糖,一种特例.下面是l ...