Ruby透过win32ole调用操作系统接口
Ruby通过win32ole调用操作系统接口
1 Word
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()
2 Outlook
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
3 Excel
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
require 'win32ole' excel = WIN32OLE.new("Excel.Application") excel.Visible = true excel.WorkBooks.Open("d:\\really.xls") worksheet = excel.ActiveWorkbook.WorkSheets(1) # Output the sheet count of the current work book. rows = worksheet.UsedRange.Rows worksheet.Range('A1:D1').value = ['North','South','East','West'] 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.ActiveWorkbook.Close excel.Quit()
4 IE
require "win32ole" #??? ie = WIN32OLE.new('InternetExplorer.Application') ie.visible = true ie.navigate('http://www.ask123.net')
参考: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/win32ole/rdoc/