Class: Tables::WordTableReader
- Inherits:
-
TableReader
- Object
- TableReader
- Tables::WordTableReader
- Defined in:
- lib/tables/word_table_reader.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Attributes inherited from TableReader
Instance Method Summary collapse
- #exit ⇒ Object
- #extract_table(idx) ⇒ Object
-
#initialize(filename, opts = {}) ⇒ WordTableReader
constructor
A new instance of WordTableReader.
- #table_count ⇒ Object
Methods inherited from TableReader
#extract_all_tables, #get_tables, #merge_tables
Constructor Details
#initialize(filename, opts = {}) ⇒ WordTableReader
Returns a new instance of WordTableReader.
14 15 16 17 18 19 20 |
# File 'lib/tables/word_table_reader.rb', line 14 def initialize(filename, opts={}) fso=WIN32OLE.new('Scripting.FileSystemObject') path=fso.GetAbsolutePathName(filename) @app=WIN32OLE.new("Word.Application") @doc=@app.Documents.Open(path, opts) super() end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
12 13 14 |
# File 'lib/tables/word_table_reader.rb', line 12 def doc @doc end |
Instance Method Details
#exit ⇒ Object
47 48 49 |
# File 'lib/tables/word_table_reader.rb', line 47 def exit @app.quit end |
#extract_table(idx) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tables/word_table_reader.rb', line 26 def extract_table(idx) name="Table #{idx+1}" table=@doc.tables(idx+1) result=[] jdx=0 table.rows.each do |row| jdx+=1 begin result << WordTableReader.extract_row(row) rescue Exception=>e1 puts "ERROR: Error extracting row #{jdx} from table '#{name}'" puts "ERROR: #{e1.}" end end Table.new(result, name) rescue Exception=>e2 puts "ERROR: Error extracting table '#{name}'" puts "ERROR: #{e2.}" end |
#table_count ⇒ Object
22 23 24 |
# File 'lib/tables/word_table_reader.rb', line 22 def table_count @doc.tables.count end |