Win32ole为标准Ruby发行版的一部分。Win32ole是访问Windows自动化的接口,可以让Ruby和Windows应用进行交互。具体说来Win32ole可以操作Word,Excel,IE,Outlook等。
以下均为代码片段
Word
创建一个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()