robust_excel_ole 1.18.7 → 1.19.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4771313f6c9e4c85b4920e78e405fb003d80698be400454012138e9f650edd7b
4
- data.tar.gz: 9f77bb0ed78567fb6f5e78587b05d4e96f1e6a741f48beb995c6d25ec1662c00
3
+ metadata.gz: 708ee59b1de0837be9b9c43acfeafb381d40e4548394325d96f05f563db2b442
4
+ data.tar.gz: 1c1aae5be7989a82c359e56afa298fc8757adf7d50dee937f8cd8b17d6281653
5
5
  SHA512:
6
- metadata.gz: 106130a4e2c3e306eab4897ababcd7a26eef25dcdca1b4d41117699cb90326263b1a8263b5775c0123072aa51234d79984d74f30040a5589c5d0b94a2e71349d
7
- data.tar.gz: a31ac0a959e571862f4fe7c99bd2d0588e5ccc5b838f090494eb6da085bb491f9d5e1eb41213b2e91967c79908dd99e20154405dc7b1ed1424c8c1b9a51bc170
6
+ metadata.gz: 7406dead8ea47a8ba23289266e70820257c3367e019f4715e151e760225534637a009cd436be2215264cd820392c3faa95d51463cfb319c372253815859d11b1
7
+ data.tar.gz: b84d2f084ee989b10f870540e7bea9e111af45b72b9dc1263fa80ffa341c1b0991d5cc0fff971797ec94af43d1c0dbac5d8031a4b8f4e633966e69a9a7dfa00a
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ doc/*
10
10
  .yardoc
11
11
  TodoList.md
12
12
  spec/data/*.xls*
13
+ spec/data/workbook_listobjects.xlsx
data/Changelog CHANGED
@@ -2,7 +2,15 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
4
 
5
- ## [1.19] 2020-30-5
5
+ ## [1.20] 2020-12-07
6
+
7
+ ### Changed
8
+ - using pry in console
9
+
10
+ ### Added
11
+ - ListObject
12
+
13
+ ## [1.19] 2020-10-6
6
14
 
7
15
  ### Added
8
16
  - Workheet#values, each_rowvalue
@@ -11,26 +11,30 @@ It supports handling workbooks across Excel instances by keeping track of workbo
11
11
 
12
12
  Library references are supported.
13
13
 
14
- RobustExcelOle works by sending VBA methods via Win32OLE.
14
+ RobustExcelOle works by sending VBA methods via Win32OlE.
15
15
  Therefore, it runs on Windows only.
16
16
 
17
- == Feature list
17
+ == Features
18
+
19
+ RobustExcelOle supports
18
20
 
19
21
  - opening and processing workbooks across various Excel instances
20
- - reading and writing workbooks (cells and ranges)
21
- - reopening and unobtrusively opening workbooks
22
- - convenient methods for standard tasks (like opening, reading, writing, closing, saving workbooks, naming, adding, and copying ranges and worksheets)
23
- - dealing with various cases of Excel and user behaviour, e.g. managing conflicts when opening workbooks (e.g. blocking or unsaved workbooks),
24
- even with simultanously happening user interactions
22
+ - standard tasks like opening, reading, writing, saving, closing workbooks
23
+ - dealing with simultanously happening user interactions
24
+ - dealing with various cases of Excel and user behaviour
25
+ - managing conflicts when opening workbooks (e.g. blocking or unsaved workbooks)
25
26
  - workarounds for Excel bugs and JRuby bugs
26
- - various workbook formats, e.g. .xlsx, .xls, .xlsm are supported
27
- - library references are supported
28
- - console for convenient usage
29
-
30
- == What's new?
31
-
32
- - removing methods to operate on ranges directly from an Excel instance. However, you can use the method Excel.active_workbook to do so.
33
- See ChangeLogs.
27
+ - availability of all VBA methods
28
+ - availability of the Excel constants (in form if Ruby constants: Excel constant.capitalize)
29
+ - all standard Excel file formats (.xlsx, .xls, .xlsm)
30
+ - list objects
31
+ - reopening workbooks after closing them
32
+ - unobtrusively opening workbooks, i.e. opening and processing workbooks
33
+ while preserving their status, e.g. saved, readonly
34
+ - reading and writing workbooks, worksheets, list objects, ranges, rows, columns, cells
35
+ - naming, adding, and copying ranges and worksheets
36
+ - references to other Excel libraries
37
+ - console for interactive mode
34
38
 
35
39
  == Requirements
36
40
 
@@ -53,15 +57,13 @@ RobustExcelOle can be used either for scripts
53
57
  require 'robust_excel_ole'
54
58
  include RobustExcelOle
55
59
 
56
- or as a console. If you want to use RobustExcelOle as a console, you go (using 'cd') into the gem path that you find with help of
57
-
58
- gem env
59
-
60
- and go into the path of the gem 'robust_excel_ole'. There you start the console via the command
60
+ or as a console. You can start the console via the command
61
61
 
62
62
  reo
63
63
 
64
- If you don't want to use a version manager to switch between ruby and jruby, you can apply the command +reo+ when using ruby, and +jreo+ when using jruby.
64
+ If you want to start the console under jruby, and if you don't want to use a version manager to switch between ruby and jruby, then use the command
65
+
66
+ jreo
65
67
 
66
68
  The call of the console will include RobustExcelOle for you.
67
69
 
@@ -316,10 +318,37 @@ and set another value to that range.
316
318
 
317
319
  For more details about reading and writing contents of cells and ranges see {README_ranges}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_ranges.rdoc]
318
320
 
321
+ === Reading and writing list objects
322
+
323
+ We can define a list object (or table) from scratch.
324
+
325
+ table = ListObject.new(worksheet, "table 1", [1,1], 3,["Person","Amount"])
326
+
327
+ This command creates a list object in worksheet named "table 1", with upper left corner at position [1,1] (first cell), with 3 rows and the columns "Person" and "Amount".
328
+
329
+ A row in this table can be accessed with help of [], e.g.
330
+
331
+ table[1]
332
+
333
+ Now we can set and get the value of a cell of the table, e.g.
334
+
335
+ table[1].person = "John"
336
+ table[1].person
337
+ # => "John"
338
+
339
+ Likewise we can get a table with help of an existing Win32OlE table.
340
+
341
+ ole_listobject = worksheet.ListObjects.Item("Table 1")
342
+ table = ListObject.new(ole_listobject)
343
+
344
+ r4 = t4[1]
345
+ r4.person
346
+ # =>
347
+ r.person = "John"
319
348
 
320
349
  === More things
321
350
 
322
- You can convert some win32ole objects into a RobustExcelOle object.
351
+ You can convert some Win32Ole objects into a RobustExcelOle object.
323
352
 
324
353
  range = sheet.Names.Item("firstcell").to_reo
325
354
 
data/bin/jreo CHANGED
@@ -1,73 +1,4 @@
1
- #!/usr/bin/env jruby
2
- # -*- mode: jruby -*-
3
1
 
4
- require 'robust_excel_ole'
5
- include REO
6
- # include RobustExcelOle
7
- include General
2
+ @echo off
8
3
 
9
- require 'irb'
10
- require 'irb/completion'
11
- require 'irb/ext/save-history'
12
- gem 'jruby-readline'
13
-
14
- ARGV.concat ['--readline',
15
- '--prompt-mode',
16
- 'simple']
17
- # '-rjruby-readline']
18
-
19
- #IRB.conf[:PROMPT_MODE] = :SIMPLE
20
- #IRB.conf[:USE_READLINE] = true
21
- #IRB.conf[:AUTO_INDENT] = true
22
-
23
-
24
-
25
-
26
- # 250 entries in the list
27
- IRB.conf[:SAVE_HISTORY] = 250
28
-
29
- # Store results in home directory with specified file name
30
- # IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
31
- #IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
32
-
33
- IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
34
-
35
- # @private
36
- module Readline
37
- module Hist
38
- LOG = IRB.conf[:HISTORY_FILE]
39
- # LOG = "#{ENV['HOME']}/.irb-history"
40
-
41
- def self.write_log(line)
42
- File.open(LOG, 'ab') do |f|
43
- f << "#{line}
44
- "
45
- end
46
- end
47
-
48
- def self.start_session_log
49
- timestamp = proc { Time.now.strftime('%Y-%m-%d, %H:%M:%S') }
50
- # @private
51
- class <<timestamp
52
- alias_method :to_s, :call
53
- end
54
- write_log("###### session start: #{timestamp}")
55
- at_exit { write_log("###### session stop: #{timestamp}") }
56
- end
57
- end
58
-
59
- alias old_readline readline
60
- def readline(*args)
61
- ln = old_readline(*args)
62
- begin
63
- Hist.write_log(ln)
64
- rescue StandardError
65
- end
66
- ln
67
- end
68
- end
69
-
70
- Readline::Hist.start_session_log
71
- puts 'JREO console started'
72
-
73
- IRB.start
4
+ jruby reo
data/bin/reo CHANGED
@@ -1,61 +1,4 @@
1
- #!/usr/bin/env jruby
2
- # -*- mode: jruby -*-
3
1
 
4
- require 'robust_excel_ole'
5
- include REO
6
- # include RobustExcelOle
7
- include General
2
+ @echo off
8
3
 
9
- require 'irb'
10
- require 'irb/completion'
11
- require 'irb/ext/save-history'
12
-
13
- ARGV.concat ['--readline',
14
- '--prompt-mode',
15
- 'simple']
16
-
17
- # 250 entries in the list
18
- IRB.conf[:SAVE_HISTORY] = 250
19
-
20
- # Store results in home directory with specified file name
21
- # IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
22
- IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
23
-
24
- # @private
25
- module Readline
26
- module Hist
27
- LOG = IRB.conf[:HISTORY_FILE]
28
- # LOG = "#{ENV['HOME']}/.irb-history"
29
-
30
- def self.write_log(line)
31
- File.open(LOG, 'ab') do |f|
32
- f << "#{line}
33
- "
34
- end
35
- end
36
-
37
- def self.start_session_log
38
- timestamp = proc { Time.now.strftime('%Y-%m-%d, %H:%M:%S') }
39
- # @private
40
- class <<timestamp
41
- alias_method :to_s, :call
42
- end
43
- write_log("###### session start: #{timestamp}")
44
- at_exit { write_log("###### session stop: #{timestamp}") }
45
- end
46
- end
47
-
48
- alias old_readline readline
49
- def readline(*args)
50
- ln = old_readline(*args)
51
- begin
52
- Hist.write_log(ln)
53
- rescue StandardError
54
- end
55
- ln
56
- end
57
- end
58
-
59
- Readline::Hist.start_session_log
60
- puts 'REO console started'
61
- IRB.start
4
+ ruby reo
@@ -0,0 +1,21 @@
1
+ require 'pry'
2
+ require 'robust_excel_ole'
3
+ include REO
4
+ # include RobustExcelOle
5
+ include General
6
+
7
+ puts 'REO console started'
8
+ puts
9
+
10
+
11
+ # some pry configuration
12
+ Pry.config.windows_console_warning = false
13
+ Pry.config.history.should_save = true
14
+ #Pry.editor = 'notepad' # 'subl', 'vi'
15
+ #Pry.config.prompt =
16
+ # [
17
+ # ->(_obj, _nest_level, _) { ">> " },
18
+ # ->(*) { " " }
19
+ # ]
20
+
21
+ pry
@@ -67,7 +67,7 @@ or
67
67
 
68
68
  Now we copy the range. With help of VBA methods you would do
69
69
 
70
- range.Copy(:destination => sheet.range([4..6,5..8]).ole_range)
70
+ range.Copy(:destination => sheet.range([4,5]).ole_range)
71
71
 
72
72
  or with help of RobustExcelOle
73
73
 
@@ -124,7 +124,8 @@ Within a row or column range you can access a certain cell.
124
124
 
125
125
  === Deleting and inserting rows and columns
126
126
 
127
- As mentioned above, VBA methods can be applied to the RobustExcelOle objects, e.g. when deleting or inserting rows and columns.
127
+ For the following standard tasks no RobustExcelOle commands are provided, but VBA methods can be used.
128
+ Here are some examples:
128
129
 
129
130
  row1 = worksheet.row_range(1)
130
131
  row1.Delete
@@ -18,7 +18,7 @@ IRB.conf[:SAVE_HISTORY] = 250
18
18
  # IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
19
19
  IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
20
20
 
21
- IRB.conf[:PROMPT_MODE] = 'ert' #:SIMPLE
21
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
22
22
  #IRB.conf[:USE_READLINE] = true
23
23
  #IRB.conf[:AUTO_INDENT] = true
24
24
 
@@ -58,6 +58,5 @@ module Readline
58
58
  end
59
59
 
60
60
  Readline::Hist.start_session_log
61
- puts 'REO console started'
62
- IRB.start
63
-
61
+ puts 'REO console started: the changed one'
62
+ #IRB.start
@@ -14,6 +14,7 @@ require File.join(File.dirname(__FILE__), 'robust_excel_ole/workbook')
14
14
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/worksheet')
15
15
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/cell')
16
16
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/range')
17
+ require File.join(File.dirname(__FILE__), 'robust_excel_ole/list_object')
17
18
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/cygwin') if RUBY_PLATFORM =~ /cygwin/
18
19
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/version')
19
20
 
@@ -793,8 +793,3 @@ public
793
793
  Application = Excel
794
794
 
795
795
  end
796
-
797
- class WIN32OLE
798
- include Enumerable
799
- end
800
-
@@ -95,10 +95,18 @@ end
95
95
 
96
96
  # @private
97
97
  class WIN32OLE
98
+
99
+ include Enumerable
98
100
 
99
101
  # type-lifting WIN32OLE objects to RobustExcelOle objects
100
102
  def to_reo
101
- class2method = [{Excel => :Hwnd}, {Workbook => :FullName}, {Worksheet => :Copy}, {RobustExcelOle::Range => :Row}]
103
+ class2method = [
104
+ {Excel => :Hwnd},
105
+ {Workbook => :FullName},
106
+ {Worksheet => :Copy},
107
+ {RobustExcelOle::Range => :Row},
108
+ {ListObject => :ListRows}
109
+ ]
102
110
  class2method.each do |element|
103
111
  classname = element.first.first
104
112
  method = element.first.last
@@ -115,6 +123,17 @@ class WIN32OLE
115
123
  end
116
124
  raise TypeREOError, "given object cannot be type-lifted to a RobustExcelOle object"
117
125
  end
126
+
127
+ alias method_missing_before_implicit_typelift method_missing
128
+ def xx_method_missing(name, *args, &blk)
129
+ begin
130
+ reo_obj = self.to_reo
131
+ rescue
132
+ puts "$!.message: #{$!.message}"
133
+ method_missing_before_implicit_typelift(name, *args, &blk)
134
+ end
135
+ reo_obj.send(name, *args, &blk)
136
+ end
118
137
  end
119
138
 
120
139
  # @private
@@ -0,0 +1,129 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module RobustExcelOle
4
+
5
+ class ListRow
6
+ end
7
+
8
+ # This class essentially wraps a Win32Ole ListObject.
9
+ # You can apply all VBA methods (starting with a capital letter)
10
+ # that you would apply for a ListObject.
11
+ # See https://docs.microsoft.com/en-us/office/vba/api/excel.listobject#methods
12
+
13
+ class ListObject < VbaObjects
14
+
15
+ attr_reader :ole_table
16
+
17
+ # constructs a list object (or table).
18
+ # @param [Variable] worksheet_or_ole_listobject a worksheet or a Win32Ole list object
19
+ # @param [Variable] table_name_or_number a table name or table number
20
+ # @param [Array] position a position of the upper left corner
21
+ # @param [Integer] rows_count number of rows
22
+ # @param [Variable] columns_count_or_names number of columns or array of column names
23
+ # @return [ListObject] a ListObject object
24
+ def initialize(worksheet_or_ole_listobject,
25
+ table_name_or_number = "",
26
+ position = [1,1],
27
+ rows_count = 1,
28
+ columns_count_or_names = 1)
29
+
30
+ if (worksheet_or_ole_listobject.ListRows rescue nil)
31
+ @ole_table = worksheet_or_ole_listobject
32
+ else
33
+ @worksheet = worksheet_or_ole_listobject.to_reo
34
+ @ole_table = @worksheet.ListObjects.Item(table_name_or_number) rescue nil
35
+ end
36
+ unless @ole_table
37
+ columns_count =
38
+ columns_count_or_names.is_a?(Integer) ? columns_count_or_names : columns_count_or_names.length
39
+ column_names = columns_count_or_names.respond_to?(:first) ? columns_count_or_names : []
40
+ begin
41
+ listobjects = @worksheet.ListObjects
42
+ @ole_table = listobjects.Add(XlSrcRange,
43
+ @worksheet.range([position[0]..position[0]+rows_count-1,
44
+ position[1]..position[1]+columns_count-1]).ole_range,
45
+ XlYes)
46
+ @ole_table.Name = table_name_or_number
47
+ @ole_table.HeaderRowRange.Value = [column_names] unless column_names.empty?
48
+ rescue WIN32OLERuntimeError => msg # , Java::OrgRacobCom::ComFailException => msg
49
+ raise TableError, "error #{$!.message}"
50
+ end
51
+ end
52
+
53
+ ole_table = @ole_table
54
+ @row_class = Class.new(ListRow) do
55
+
56
+ @@ole_table = ole_table
57
+
58
+ def initialize(row_number)
59
+ @ole_listrow = @@ole_table.ListRows.Item(row_number)
60
+ end
61
+
62
+ def method_missing(name, *args)
63
+ name_before_last_equal = name.to_s.split('=').first
64
+ column_names = @@ole_table.HeaderRowRange.Value.first
65
+ method_names = column_names.map{|c| c.underscore.gsub(/[^[\w\d]]/, '_')}
66
+ column_name = column_names[method_names.index(name_before_last_equal)]
67
+ if column_name
68
+ ole_cell = @@ole_table.Application.Intersect(
69
+ @ole_listrow.Range, @@ole_table.ListColumns(column_name).Range)
70
+ define_getting_setting_method(ole_cell,name.to_s)
71
+ self.send(name, *args)
72
+ else
73
+ super
74
+ end
75
+ end
76
+
77
+ def define_getting_setting_method(ole_cell,name_str)
78
+ if name_str[-1] != '='
79
+ self.class.define_method(name_str) do
80
+ ole_cell.Value
81
+ end
82
+ else
83
+ self.class.define_method(name_str) do |value|
84
+ ole_cell.Value = value
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ # accesses a table row object
91
+ # @param [Integer] a row number (>= 1)
92
+ # @return [ListRow] a object of dynamically constructed class with superclass ListRow
93
+ def [] row_number
94
+ @row_class.new(row_number)
95
+ end
96
+
97
+ end
98
+
99
+ private
100
+
101
+ def method_missing(name, *args)
102
+ if name.to_s[0,1] =~ /[A-Z]/
103
+ if ::ERRORMESSAGE_JRUBY_BUG
104
+ begin
105
+ @ole_table.send(name, *args)
106
+ rescue Java::OrgRacobCom::ComFailException
107
+ raise VBAMethodMissingError, "unknown VBA property or method #{name.inspect}"
108
+ end
109
+ else
110
+ begin
111
+ @ole_table.send(name, *args)
112
+ rescue NoMethodError
113
+ raise VBAMethodMissingError, "unknown VBA property or method #{name.inspect}"
114
+ end
115
+ end
116
+ else
117
+ super
118
+ end
119
+ end
120
+ end
121
+
122
+ # @private
123
+ class TableError < WorksheetREOError
124
+ end
125
+
126
+ Table = ListObject
127
+ TableRow = ListRow
128
+
129
+ end
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.18.7"
2
+ VERSION = "1.19.3"
3
3
  end
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
34
34
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
35
35
  s.require_paths = ["lib"]
36
+ s.add_runtime_dependency "pry", '>= 0.12.1'
36
37
  s.add_development_dependency "rspec", '>= 2.6.0'
37
38
  s.required_ruby_version = '>= 2.1'
38
39
  end
@@ -20,6 +20,7 @@ module RobustExcelOle
20
20
 
21
21
  before do
22
22
  @dir = create_tmpdir
23
+ @listobject_file = @dir + '/workbook_listobjects.xlsx'
23
24
  @simple_file = @dir + '/workbook.xls'
24
25
  @simple_save_file = @dir + '/workbook_save.xls'
25
26
  @different_file = @dir + '/different_workbook.xls'
@@ -39,6 +40,17 @@ module RobustExcelOle
39
40
 
40
41
  before do
41
42
  @book1 = Workbook.open(@simple_file)
43
+ @book2 = Workbook.open(@listobject_file)
44
+ end
45
+
46
+ it "should type-lift an ListObject" do
47
+ worksheet = @book2.sheet(3)
48
+ ole_table = worksheet.ListObjects.Item(1)
49
+ table = Table.new(ole_table)
50
+ table.Name.should == "table3"
51
+ table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
52
+ table.ListRows.Count.should == 6
53
+ worksheet[3,4].Value.should == "Number"
42
54
  end
43
55
 
44
56
  it "should type-lift an Excel" do
@@ -0,0 +1,143 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), './spec_helper')
4
+
5
+ $VERBOSE = nil
6
+
7
+ include RobustExcelOle
8
+ include General
9
+
10
+ describe ListObject do
11
+
12
+ before(:all) do
13
+ excel = Excel.new(:reuse => true)
14
+ open_books = excel == nil ? 0 : excel.Workbooks.Count
15
+ puts "*** open books *** : #{open_books}" if open_books > 0
16
+ Excel.kill_all
17
+ end
18
+
19
+ before do
20
+ @dir = create_tmpdir
21
+ @listobject_file = @dir + '/workbook_listobjects.xlsx'
22
+ @book = Workbook.open(@listobject_file, :visible => true)
23
+ @sheet = @book.sheet(3)
24
+ end
25
+
26
+ after do
27
+ @book.close(:if_unsaved => :forget)
28
+ Excel.kill_all
29
+ rm_tmp(@dir)
30
+ end
31
+
32
+ describe "creating" do
33
+
34
+ context "with standard" do
35
+
36
+ it "should simply create a new table" do
37
+ table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","Amount"])
38
+ table.Name.should == "table_name"
39
+ table.HeaderRowRange.Value.first.should == ["Person","Amount"]
40
+ table.ListRows.Count.should == 3
41
+ @sheet[1,1].Value.should == "Person"
42
+ end
43
+
44
+ it "should type-lift a Win32ole list object into a RobustExcelOle list object" do
45
+ ole_table = @sheet.ListObjects.Item(1)
46
+ table = Table.new(ole_table)
47
+ table.Name.should == "table3"
48
+ table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
49
+ table.ListRows.Count.should == 6
50
+ @sheet[3,4].Value.should == "Number"
51
+ end
52
+
53
+ it "should type-lift a Win32ole list object into a RobustExcelOle list object with table name" do
54
+ ole_table = @sheet.ListObjects.Item(1)
55
+ table = Table.new(@sheet, "table3")
56
+ table.Name.should == "table3"
57
+ table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
58
+ table.ListRows.Count.should == 6
59
+ @sheet[3,4].Value.should == "Number"
60
+ end
61
+
62
+ it "should type-lift a Win32ole list object into a RobustExcelOle list object with item number" do
63
+ ole_table = @sheet.ListObjects.Item(1)
64
+ table = Table.new(@sheet, 1)
65
+ table.Name.should == "table3"
66
+ table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
67
+ table.ListRows.Count.should == 6
68
+ @sheet[3,4].Value.should == "Number"
69
+ end
70
+
71
+ it "should simply create a new table from a ole-worksheet" do
72
+ table = Table.new(@sheet.ole_worksheet, "table_name", [1,1], 3, ["Person","Amount"])
73
+ table.Name.should == "table_name"
74
+ table.HeaderRowRange.Value.first.should == ["Person","Amount"]
75
+ table.ListRows.Count.should == 3
76
+ @sheet[1,1].Value.should == "Person"
77
+ end
78
+
79
+ it "should type-lift a Win32ole list object into a RobustExcelOle list object with table name" do
80
+ ole_table = @sheet.ListObjects.Item(1)
81
+ table = Table.new(@sheet.ole_worksheet, "table3")
82
+ table.Name.should == "table3"
83
+ table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
84
+ table.ListRows.Count.should == 6
85
+ @sheet[3,4].Value.should == "Number"
86
+ end
87
+
88
+ it "should type-lift a Win32ole list object into a RobustExcelOle list object with item number" do
89
+ ole_table = @sheet.ListObjects.Item(1)
90
+ table = Table.new(@sheet.ole_worksheet, 1)
91
+ table.Name.should == "table3"
92
+ table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
93
+ table.ListRows.Count.should == 6
94
+ @sheet[3,4].Value.should == "Number"
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ describe "getting and setting values" do
102
+
103
+ context "with new table" do
104
+
105
+ before do
106
+ @table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","Amount"])
107
+ @table_row1 = @table[1]
108
+ end
109
+
110
+ it "should set and read values" do
111
+ @table_row1.person.should be nil
112
+ @table_row1.person = "John"
113
+ @table_row1.person.should == "John"
114
+ @sheet[2,1].Value.should == "John"
115
+ @table_row1.amount.should be nil
116
+ @table_row1.amount = 42
117
+ @table_row1.amount.should == 42
118
+ @sheet[2,2].Value.should == 42
119
+ end
120
+ end
121
+
122
+ context "with type-lifted ole list object" do
123
+
124
+ before do
125
+ ole_table = @sheet.ListObjects.Item(1)
126
+ @table = Table.new(ole_table)
127
+ @table_row1 = @table[1]
128
+ end
129
+
130
+ it "should set and read values" do
131
+ @table_row1.number.should == 3
132
+ @table_row1.number = 1
133
+ @table_row1.number.should == 1
134
+ @sheet[4,4].Value.should == 1
135
+ @table_row1.person.should == "Herbert"
136
+ @table_row1.person = "John"
137
+ @table_row1.person.should == "John"
138
+ @sheet[4,5].Value.should == "John"
139
+ end
140
+ end
141
+
142
+ end
143
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robust_excel_ole
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.7
4
+ version: 1.19.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-10 00:00:00.000000000 Z
11
+ date: 2020-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -36,6 +50,7 @@ email:
36
50
  executables:
37
51
  - jreo
38
52
  - reo
53
+ - reo.rb
39
54
  extensions: []
40
55
  extra_rdoc_files:
41
56
  - README.rdoc
@@ -66,6 +81,7 @@ files:
66
81
  - benchmarking/spreadsheet_example.rb
67
82
  - bin/jreo
68
83
  - bin/reo
84
+ - bin/reo.rb
69
85
  - docs/README_excel.rdoc
70
86
  - docs/README_open.rdoc
71
87
  - docs/README_ranges.rdoc
@@ -109,6 +125,7 @@ files:
109
125
  - lib/robust_excel_ole/cygwin.rb
110
126
  - lib/robust_excel_ole/excel.rb
111
127
  - lib/robust_excel_ole/general.rb
128
+ - lib/robust_excel_ole/list_object.rb
112
129
  - lib/robust_excel_ole/range.rb
113
130
  - lib/robust_excel_ole/range_owners.rb
114
131
  - lib/robust_excel_ole/robustexcelole.sublime-project
@@ -117,7 +134,6 @@ files:
117
134
  - lib/robust_excel_ole/version.rb
118
135
  - lib/robust_excel_ole/workbook.rb
119
136
  - lib/robust_excel_ole/worksheet.rb
120
- - lib/rubygems_plugin.rb
121
137
  - lib/spec_helper.rb
122
138
  - reo.bat
123
139
  - robust_excel_ole.gemspec
@@ -141,10 +157,12 @@ files:
141
157
  - spec/data/workbook_connected.xlsm
142
158
  - spec/data/workbook_linked.xlsm
143
159
  - spec/data/workbook_linked_sub.xlsm
160
+ - spec/data/workbook_listobjects.xlsx
144
161
  - spec/excel_spec.rb
145
162
  - spec/general_spec.rb
146
163
  - spec/helpers/create_temporary_dir.rb
147
164
  - spec/helpers/key_sender.rb
165
+ - spec/list_object_spec.rb
148
166
  - spec/range_spec.rb
149
167
  - spec/spec_helper.rb
150
168
  - spec/workbook_spec.rb
@@ -1,3 +0,0 @@
1
- Gem.post_install do
2
- puts "post_install called for gem"
3
- end