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 ...
随机推荐
- [转载]实战Linux下VMware虚拟机根目录空间扩充
[转载]实战Linux下VMware虚拟机根目录空间扩充 (2011-07-31 21:34:34) 转载▼ 标签: 转载 原文地址:实战Linux下VMware虚拟机根目录空间扩充作者:shar ...
- 时间序列数据库武斗大会之 KairosDB 篇
[编者按] 刘斌,OneAPM后端研发工程师,拥有10多年编程经验,参与过大型金融.通信以及Android手机操作系的开发,熟悉Linux及后台开发技术.曾参与翻译过<第一本Docker书> ...
- Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...
- cf div2 234 E
E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...
- 分析windows宿主机Ping不通linux虚拟机的其中一种情况
ping不通的情况是由于设置网络选项的时候,可以看到界面名称的选择如下(当前选择的是无线网卡驱动):
- ibatis缓存初探(1)
一,IBATIS 缓存机制使用 1,sqlMapConfig.xml中配置 1.SqlMapConfig.xml中 <settings cacheModelsEnabled="tr ...
- 是谁决定了走redis缓存?当然是mybatis啊
1.是谁决定了走redis缓存?当然是mybatis啊 mybatis里默认实现数据的增删改查功能,这里要用到缓存啊 而且是mybatis这种orm框架采用缓存机制的,mybatis默认都有两层缓存了 ...
- WCF入门(十一)---WCF安全
一个强大的WCF服务安全系统,拥有两种安全模式或级别预期的客户端可以访问的服务.这是常见的分布式事务的安全威胁正在放缓,在很大程度上由WCF决定. 关键的安全功能 WCF服务有四个主要的安全功能,如下 ...
- Ossec常用命令
启动并查看httpd服务 systemctl start httpd systemctl status httpd.service 启动并查看mysql服务 systemctl start maria ...
- Servlet编写登录界面
package com.mhb; import java.io.IOException;import java.io.PrintWriter; import javax.servlet.Servlet ...