Class: Tables::WordTableWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/tables/word_table_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWordTableWriter

Returns a new instance of WordTableWriter.



13
14
15
16
17
# File 'lib/tables/word_table_writer.rb', line 13

def initialize
  @app=WIN32OLE.new 'Word.Application'
  @doc=@app.Documents.Add
  super()
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



11
12
13
# File 'lib/tables/word_table_writer.rb', line 11

def doc
  @doc
end

Instance Method Details

#append_table(table, caption = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tables/word_table_writer.rb', line 31

def append_table(table, caption=nil)
  @app.Selection.EndKey(6)
  word_table=@doc.Tables.Add(@app.Selection.Range, table.row_count, table.column_count)
  table.each_row_with_index do |row, idx|
    word_row=word_table.Rows(idx+1)
    row.each_with_index do |cell_value, jdx|
      word_row.Cells(jdx+1).Range.Text=cell_value.to_s
    end
  end

  style_borders(word_table)
  set_caption(word_table,caption) unless caption.nil?
end

#exit(save_changes = true) ⇒ Object



25
26
27
28
29
# File 'lib/tables/word_table_writer.rb', line 25

def exit(save_changes=true)
  code=-1
  code=0 unless save_changes
  @app.quit(code)
end

#save_as(filename) ⇒ Object



19
20
21
22
23
# File 'lib/tables/word_table_writer.rb', line 19

def save_as(filename)
  fso=WIN32OLE.new('Scripting.FileSystemObject')
  @path=fso.GetAbsolutePathName(filename)
  @doc.SaveAs(@path)
end