Skip to content

Instantly share code, notes, and snippets.

@saberma
Created November 25, 2009 09:20
Show Gist options
  • Save saberma/242590 to your computer and use it in GitHub Desktop.
Save saberma/242590 to your computer and use it in GitHub Desktop.
源代码输出至Word
#源代码输出至Word
require 'win32ole'
WIN32OLE.codepage = WIN32OLE::CP_UTF8
class Word
def initialize
@word = WIN32OLE.new('Word.Application')
@word.visible=true #是否打开文件
@word.Documents.Add()
@word.Selection.Font.Size=10.5
@word.Selection.Font.ColorIndex = 2
end
def get_info(dir)
Dir.foreach(dir) do |file|
next if %w(. .. conversation.rb user.rb survey.rb log.rb).include?(file)
path = File.join(dir, file)
if File.directory?(path)
get_info(path)
else
@word.Selection.TypeText("\nfile:#{path}\n")
#输出文件
f = File.open(path)
f.each do |line|
@word.Selection.TypeText(line)
end
end
end
end
end
w = Word.new
w.get_info('e:/app/models')
#word.DefaultSaveFormat
#word.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment