Class: Konjac::Office::Mac::Word::WordItem

Inherits:
Item
  • Object
show all
Defined in:
lib/konjac/office/mac/word.rb

Overview

A basic class to deal with Word’s ridiculously awful handling of replacing text in paragraphs. Instead of simply setting the paragraph’s text to something new, you have to select all but the last character (which is a newline) then write. Otherwise, your paragraph might inherit the formatting of the line below it, which is especially a problem with tables.

Instance Method Summary collapse

Instance Method Details

#write(text) ⇒ Object

Writes to a Word item



15
16
17
18
19
20
21
22
# File 'lib/konjac/office/mac/word.rb', line 15

def write(text)
  para_start = @ref.text_object.start_of_content.get
  para_end   = @ref.text_object.end_of_content.get
  range      = @opts[:document].create_range(:start => para_start,
                                             :end_ => para_end - 1)
  range.select
  @opts[:application].selection.type_text :text => text
end