Ruby 打开 Word 文档并插入数据
Ruby 打开 Word 文档并插入数据
[代码] ruby代码
view sourceprint?
1
require 'win32ole'
2
3
4
word=WIN32OLE.new("word.application")
5
word['Visible']=TRUE
6
worddoc=word.documents.add()
7
worddoc.Content.Text="asdf"
8
worddoc.SaveAs "Graph.doc"
9
worddoc.close
[代码] ruby代码
01
require 'win32ole'
02
# Creates OLE object to word
03
word = WIN32OLE.new("word.application")
04
word['Visible'] = TRUE;
05
word.documents.Add
06
0.upto(10){
07
word.selection.TypeText(Text="Hello Ruby Relatives!")
08
word.selection.TypeParagraph
09
}
10
word.close()