首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

RUBY运用WIN32OLE与windows应用程序交互

2012-12-28 
RUBY使用WIN32OLE与windows应用程序交互require win32oleword WIN32OLE.new(Word.Application)word.

RUBY使用WIN32OLE与windows应用程序交互

require 'win32ole' word = WIN32OLE.new('Word.Application') word.visible=true #是否打开文件 word.Documents.Add() for i in(0..100) word.Selection.Font.Size=12 word.Selection.Font.ColorIndex = 2 word.Selection.TypeText("Word with Ruby \n") end word.DefaultSaveFormat word.Documents.close()

require 'win32ole' outlook = WIN32OLE('Outlook.Application') message = outlook.CreateItem(0) message.Subject = 'Subject line here' message.Body = 'This is the body of your message.' message.To = 'xiaofan2350@yahoo.com.cn' message.Attachments.Add('c:\really\one.txt', 1) message.Send ?

require 'win32ole' excel = WIN32OLE.new('Excel.Application') book = excel.workbooks.add sheets = book.worksheets(1) cells = sheets.cells("A1:A5") cells.each do |cell| cell.value = 10 end

excel = WIN32OLE.new("Excel.Application") excel.Visible = true #是否打开文件 excel.WorkBooks.Open("d:\\really.xls") #打开excel worksheet = excel.ActiveWorkbook.WorkSheets(1) # Output the sheet count of the current work book. rows = worksheet.UsedRange.Rows #得到excel文件的行数 worksheet.Range('A1:D1').value = ['North','South','East','West'] #往excel指定区域写入数据 worksheet.Range('A2')['value'] = "really" worksheet.Range('B2')['value'] = "notreally" worksheet.Range('C2')['value'] = "javaeye" worksheet.Range('D2')['value'] = "notreally.javaeye.com" excel.ActiveWorkbook.WorkSheets.add({'count'=>1, 'after'=>worksheet}) #添加一个excel工作区 excel.ActiveWorkbook.Close #关闭工作区 excel.Quit() ?

require "win32ole" #包含库 ie = WIN32OLE.new('InternetExplorer.Application') ie.visible = true #这个时候就可以看到一个ie的界面出来了 ie.navigate('http://www.ask123.net') #转到这个页面 ?

?

参考:http://www.ruby-doc.org/stdlib/libdoc/win32ole/rdoc/

热点排行