0
에 텍스트를 대체 할 수 없습니다루비 win32ole는 - 내가 너무 같은 문서에서 텍스트를 대체하기 위해 노력하고있어 워드 문서
require 'win32ole'
def replace_doc(doc, find, repl)
begin
word = WIN32OLE.new('Word.Application')
word.Visible = true
doc = word.Documents.Open(doc)
word.Selection.HomeKey(unit=6)
finder = word.Selection.Find
finder.Text = "[#{find}]"
while word.Selection.Find.Execute
word.Selection.TypeText(text=repl)
end
doc.SaveAs(doc)
doc.Close
rescue Exception => e
puts e.message
puts "Unable to edit file."
end
end
def main()
puts "File: "
doc = gets.chomp()
puts "Find: "
find = gets.chomp()
puts "Replace with: "
repl = gets.chomp()
replace_doc(doc, find, repl)
end
main()
을 나는 Windows XP에서 루비 2.0을 실행하고 있습니다. WINWORD.exe 프로세스가 시작되고 (작업 관리자에서 볼 수 있음) 예외가 발생하지 않습니다. 그러나 내가 문서로 갈 때, 대체 될 것으로 예상되는 텍스트는 없습니다. 무슨 일 이니? here의 코드 (일부 제외)를 복사했습니다.