Class: RobustExcelOle::Workbook
- Inherits:
-
RangeOwners
- Object
- Base
- VbaObjects
- RangeOwners
- RobustExcelOle::Workbook
- Defined in:
- lib/robust_excel_ole/workbook.rb
Overview
This class essentially wraps a Win32Ole Workbook object. You can apply all VBA methods (starting with a capital letter) that you would apply for a Workbook object. See docs.microsoft.com/en-us/office/vba/api/excel.workbook#methods
Defined Under Namespace
Classes: AlreadyManaged
Constant Summary collapse
- CORE_DEFAULT_OPEN_OPTS =
{ default: {excel: :current}, force: {}, update_links: :never }.freeze
- DEFAULT_OPEN_OPTS =
{ if_unsaved: :raise, if_obstructed: :raise, if_absent: :raise, if_exists: :raise }.merge(CORE_DEFAULT_OPEN_OPTS).freeze
- ABBREVIATIONS =
[ [:default,:d], [:force, :f], [:excel, :e], [:visible, :v], [:if_obstructed, :if_blocked] ].freeze
Instance Attribute Summary collapse
-
#excel ⇒ Object
readonly
Returns the value of attribute excel.
-
#ole_workbook ⇒ Object
readonly
Returns the value of attribute ole_workbook.
-
#stored_filename ⇒ Object
readonly
Returns the value of attribute stored_filename.
Class Method Summary collapse
-
.close(file, opts = {if_unsaved: :raise}) ⇒ Object
closes a given file if it is open.
-
.create(filename, opts = { }) ⇒ Object
creates, i.e., opens a new, empty workbook, and saves it under a given filename.
- .for_modifying(arg, opts = { }, &block) ⇒ Object
- .for_reading(arg, opts = { }, &block) ⇒ Object
-
.new(file_or_workbook, opts = { }) ⇒ Workbook
opens a workbook.
- .process_options(opts, proc_opts = {use_defaults: true}) ⇒ Object
-
.save(file) ⇒ Object
saves a given file if it is open.
-
.save_as(file, new_file, opts = { }) ⇒ Object
saves a given file under a new name if it is open.
- .set_was_open(hash, value) ⇒ Object
- .translate(opts) ⇒ Object
-
.unobtrusively(file_or_workbook, opts = { }, &block) ⇒ Workbook
allows to read or modify a workbook such that its state remains unchanged state comprises: open, saved, writable, visible, calculation mode, check compatibility.
Instance Method Summary collapse
-
#==(other_book) ⇒ Boolean
True, if the full workbook names and excel Instances are identical, false otherwise.
-
#[](name) ⇒ Object
returns the value of a range.
-
#[]=(name, value) ⇒ Object
sets the value of a range.
-
#add_or_copy_sheet(sheet = nil, opts = { }) ⇒ Worksheet
copies a sheet to another position if a sheet is given, or adds an empty sheet default: copied or empty sheet is appended, i.e.
-
#add_sheet(sheet = nil, opts = { }) ⇒ Object
for compatibility to older versions.
-
#alive? ⇒ Boolean
returns true, if the workbook reacts to methods, false otherwise.
- #calculation ⇒ Object
-
#close(opts = {if_unsaved: :raise}) ⇒ Object
closes the workbook, if it is alive options: :if_unsaved if the workbook is unsaved :raise -> raises an exception :save -> saves the workbook before it is closed :forget -> closes the workbook :keep_open -> keep the workbook open :alert or :excel -> gives control to excel.
-
#copy_sheet(sheet, opts = { }) ⇒ Object
for compatibility to older versions.
-
#each ⇒ Enumerator
Traversing all worksheet objects.
- #each_with_index(offset = 0) ⇒ Object
-
#filename ⇒ Object
returns the full file name of the workbook.
- #first_sheet ⇒ Object
-
#focus ⇒ Object
brings workbook to foreground, makes it available for heyboard inputs, makes the Excel instance visible.
- #for_modifying(opts = { }, &block) ⇒ Object
- #for_reading(opts = { }, &block) ⇒ Object
-
#for_this_workbook(opts) ⇒ Object
sets options.
-
#initialize(file_or_workbook, opts) ⇒ Workbook
constructor
creates a new Workbook object, if a file name is given Promotes the win32ole workbook to a Workbook object, if a win32ole-workbook is given.
- #last_sheet ⇒ Object
-
#range(name_or_worksheet, name_or_address = :__not_provided, address2 = :__not_provided) ⇒ Range
creates a range from a given defined name or from a given worksheet and address.
-
#retain_saved ⇒ Object
keeps the saved-status unchanged.
- #set_was_open(hash, value) ⇒ Object
-
#sheet(name) ⇒ Object
returns a sheet, if a sheet name or a number is given.
- #unobtrusively(opts = { }, &block) ⇒ Object
-
#visible ⇒ Object
returns true, if the workbook is visible, false otherwise.
-
#visible=(visible_value) ⇒ Object
makes both the Excel instance and the window of the workbook visible, or the window invisible does not do anything if geben visible_value is nil.
-
#window_visible ⇒ Object
returns true, if the window of the workbook is set to visible, false otherwise.
-
#window_visible=(visible_value) ⇒ Object
makes the window of the workbook visible or invisible.
- #worksheets_count ⇒ Object
Methods inherited from RangeOwners
#add_name, #delete_name, #name2range, #names, #namevalue_global, #rename_name, #set_namevalue_global
Methods inherited from VbaObjects
Constructor Details
#initialize(file_or_workbook, opts) ⇒ Workbook
creates a new Workbook object, if a file name is given Promotes the win32ole workbook to a Workbook object, if a win32ole-workbook is given
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/robust_excel_ole/workbook.rb', line 157 def initialize(file_or_workbook, opts) if file_or_workbook.is_a? WIN32OLE @ole_workbook = file_or_workbook ole_excel = begin @ole_workbook.Application rescue WIN32OLERuntimeError raise ExcelREOError, "could not determine the Excel instance\n#{$!.message}" end @excel = excel_class.new(ole_excel) filename = @ole_workbook.Fullname.tr('\\','/') else filename = file_or_workbook ensure_workbook(filename, opts) end (filename, opts) store_myself if block_given? begin yield self ensure close end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object (private)
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 |
# File 'lib/robust_excel_ole/workbook.rb', line 1103 def method_missing(name, *args) super unless name.to_s[0,1] =~ /[A-Z]/ raise ObjectNotAlive, 'method missing: workbook not alive' unless alive? if ::ERRORMESSAGE_JRUBY_BUG begin @ole_workbook.send(name, *args) rescue Java::OrgRacobCom::ComFailException raise VBAMethodMissingError, "unknown VBA property or method #{name.inspect}" end else begin @ole_workbook.send(name, *args) rescue NoMethodError raise VBAMethodMissingError, "unknown VBA property or method #{name.inspect}" end end end |
Instance Attribute Details
#excel ⇒ Object (readonly)
Returns the value of attribute excel
17 18 19 |
# File 'lib/robust_excel_ole/workbook.rb', line 17 def excel @excel end |
#ole_workbook ⇒ Object (readonly)
Returns the value of attribute ole_workbook
16 17 18 |
# File 'lib/robust_excel_ole/workbook.rb', line 16 def ole_workbook @ole_workbook end |
#stored_filename ⇒ Object (readonly)
Returns the value of attribute stored_filename
18 19 20 |
# File 'lib/robust_excel_ole/workbook.rb', line 18 def stored_filename @stored_filename end |
Class Method Details
.close(file, opts = {if_unsaved: :raise}) ⇒ Object
closes a given file if it is open
791 792 793 794 795 796 797 798 |
# File 'lib/robust_excel_ole/workbook.rb', line 791 def self.close(file, opts = {if_unsaved: :raise}) book = begin bookstore.fetch(file) rescue nil end book.close(opts) if book && book.alive? end |
.create(filename, opts = { }) ⇒ Object
creates, i.e., opens a new, empty workbook, and saves it under a given filename
501 502 503 |
# File 'lib/robust_excel_ole/workbook.rb', line 501 def self.create(filename, opts = { }) open(filename, if_absent: :create) end |
.for_modifying(arg, opts = { }, &block) ⇒ Object
575 576 577 |
# File 'lib/robust_excel_ole/workbook.rb', line 575 def self.(arg, opts = { }, &block) unobtrusively(arg, {writable: true}.merge(opts), &block) end |
.for_reading(arg, opts = { }, &block) ⇒ Object
571 572 573 |
# File 'lib/robust_excel_ole/workbook.rb', line 571 def self.for_reading(arg, opts = { }, &block) unobtrusively(arg, {writable: false}.merge(opts), &block) end |
.new(file_or_workbook, opts = { }) ⇒ Workbook
opens a workbook. options: :default : if the workbook was already open before, then use (unchange) its properties,
otherwise, i.e. if the workbook cannot be reopened, use the properties stated in :default
:force : no matter whether the workbook was already open before, use the properties stated in :force :default and :force contain: :excel
:excel :current (or :active or :reuse)
-> connects to a running (the first opened) Excel instance,
excluding the hidden Excel instance, if it exists,
otherwise opens in a new Excel instance.
:new -> opens in a new Excel instance
<excel-instance> -> opens in the given Excel instance
:visible true, false, or nil (default)
alternatives: :default_excel, :force_excel, :visible, :d, :f, :e, :v
:if_unsaved if an unsaved workbook with the same name is open, then
:raise -> raises an exception
:forget -> close the unsaved workbook, open the new workbook
:accept -> lets the unsaved workbook open
:alert or :excel -> gives control to Excel
:new_excel -> opens the new workbook in a new Excel instance
:if_obstructed if a workbook with the same name in a different path is open, then or :raise -> raises an exception :if_blocked :forget -> closes the old workbook, open the new workbook
:save -> saves the old workbook, close it, open the new workbook
:close_if_saved -> closes the old workbook and open the new workbook, if the old workbook is saved,
otherwise raises an exception.
:new_excel -> opens the new workbook in a new Excel instance
:if_absent :raise -> raises an exception , if the file does not exists
:create -> creates a new Excel file, if it does not exists
:read_only true -> opens in read-only mode :visible true -> makes the workbook visible :check_compatibility true -> check compatibility when saving :update_links true -> user is being asked how to update links, false -> links are never updated
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/robust_excel_ole/workbook.rb', line 90 def self.new(file_or_workbook, opts = { }) (opts) case file_or_workbook when NilClass raise FileNameNotGiven, "filename is nil" when WIN32OLE begin file_or_workbook.send(:LinkSources) file = file_or_workbook.Fullname.tr('\\','/') rescue raise TypeREOError, "given win32ol object is not a workbook" end when Workbook file = file_or_workbook.Fullname.tr('\\','/') when String file = file_or_workbook raise FileNotFound, "file #{General.absolute_path(file).inspect} is a directory" if File.directory?(file) when ->(n){ n.respond_to? :to_path } file = file_or_workbook.to_path raise FileNotFound, "file #{General.absolute_path(file).inspect} is a directory" if File.directory?(file) else raise TypeREOError, "given object is neither a filename, a Win32ole, nor a Workbook object" end # try to fetch the workbook from the bookstore set_was_open opts, file_or_workbook.is_a?(WIN32OLE) book = nil if opts[:force][:excel] != :new # if readonly is true, then prefer a book that is given in force_excel if this option is set forced_excel = begin (opts[:force][:excel].nil? || opts[:force][:excel] == :current) ? (excel_class.new(reuse: true) if !::CONNECT_JRUBY_BUG) : opts[:force][:excel].to_reo.excel rescue NoMethodError raise TypeREOError, "provided Excel option value is neither an Excel object nor a valid option" end begin book = if File.exists?(file) bookstore.fetch(file, prefer_writable: !(opts[:read_only]), prefer_excel: (opts[:read_only] ? forced_excel : nil)) end rescue raise #trace "#{$!.message}" end if book set_was_open opts, book.alive? # drop the fetched workbook if it shall be opened in another Excel instance # or the workbook is an unsaved workbook that should not be accepted if (opts[:force][:excel].nil? || opts[:force][:excel] == :current || forced_excel == book.excel) && !(book.alive? && !book.saved && (opts[:if_unsaved] != :accept)) opts[:force][:excel] = book.excel if book.excel && book.excel.alive? book.ensure_workbook(file,opts) book.send :apply_options, file, opts return book end end end super(file_or_workbook, opts) end |
.process_options(opts, proc_opts = {use_defaults: true}) ⇒ Object
192 193 194 195 196 197 |
# File 'lib/robust_excel_ole/workbook.rb', line 192 def self.(opts, proc_opts = {use_defaults: true}) translate(opts) default_opts = (proc_opts[:use_defaults] ? DEFAULT_OPEN_OPTS : CORE_DEFAULT_OPEN_OPTS).dup translate(default_opts) opts.merge!(default_opts) { |key, v1, v2| !v2.is_a?(Hash) ? v1 : v2.merge(v1 || {}) } end |
.save(file) ⇒ Object
saves a given file if it is open
801 802 803 804 |
# File 'lib/robust_excel_ole/workbook.rb', line 801 def self.save(file) book = bookstore.fetch(file) rescue nil book.save if book && book.alive? end |
.save_as(file, new_file, opts = { }) ⇒ Object
saves a given file under a new name if it is open
807 808 809 810 811 812 813 814 |
# File 'lib/robust_excel_ole/workbook.rb', line 807 def self.save_as(file, new_file, opts = { }) book = begin bookstore.fetch(file) rescue nil end book.save_as(new_file, opts) if book && book.alive? end |
.set_was_open(hash, value) ⇒ Object
184 185 186 |
# File 'lib/robust_excel_ole/workbook.rb', line 184 def self.set_was_open(hash, value) hash[:was_open] = value if hash.has_key?(:was_open) end |
.translate(opts) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/robust_excel_ole/workbook.rb', line 199 def self.translate(opts) erg = {} opts.each do |key,value| new_key = key ABBREVIATIONS.each { |long,short| new_key = long if key == short } if value.is_a?(Hash) erg[new_key] = {} value.each do |k,v| new_k = k ABBREVIATIONS.each { |l,s| new_k = l if k == s } erg[new_key][new_k] = v end else erg[new_key] = value end end opts.merge!(erg) opts[:default] ||= {} opts[:force] ||= {} force_list = [:visible, :excel] opts.each { |key,value| opts[:force][key] = value if force_list.include?(key) } opts[:default][:excel] = opts[:default_excel] unless opts[:default_excel].nil? opts[:force][:excel] = opts[:force_excel] unless opts[:force_excel].nil? opts[:default][:excel] = :current if opts[:default][:excel] == :reuse || opts[:default][:excel] == :active opts[:force][:excel] = :current if opts[:force][:excel] == :reuse || opts[:force][:excel] == :active end |
.unobtrusively(file_or_workbook, opts = { }, &block) ⇒ Workbook
allows to read or modify a workbook such that its state remains unchanged state comprises: open, saved, writable, visible, calculation mode, check compatibility
590 591 592 593 |
# File 'lib/robust_excel_ole/workbook.rb', line 590 def self.unobtrusively(file_or_workbook, opts = { }, &block) file = (file_or_workbook.is_a? WIN32OLE) ? file_or_workbook.Fullname.tr('\\','/') : file_or_workbook unobtrusively_opening(file, opts, nil, &block) end |
Instance Method Details
#==(other_book) ⇒ Boolean
Returns true, if the full workbook names and excel Instances are identical, false otherwise.
1028 1029 1030 1031 1032 |
# File 'lib/robust_excel_ole/workbook.rb', line 1028 def == other_book other_book.is_a?(Workbook) && @excel == other_book.excel && self.filename == other_book.filename end |
#[](name) ⇒ Object
returns the value of a range
941 942 943 |
# File 'lib/robust_excel_ole/workbook.rb', line 941 def [] name namevalue_global(name) end |
#[]=(name, value) ⇒ Object
sets the value of a range
948 949 950 |
# File 'lib/robust_excel_ole/workbook.rb', line 948 def []= (name, value) set_namevalue_global(name, value) end |
#add_or_copy_sheet(sheet = nil, opts = { }) ⇒ Worksheet
copies a sheet to another position if a sheet is given, or adds an empty sheet default: copied or empty sheet is appended, i.e. added behind the last sheet
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 |
# File 'lib/robust_excel_ole/workbook.rb', line 856 def add_or_copy_sheet(sheet = nil, opts = { }) if sheet.is_a? Hash opts = sheet sheet = nil end begin sheet = sheet.to_reo unless sheet.nil? new_sheet_name = opts.delete(:as) last_sheet_local = last_sheet after_or_before, base_sheet = opts.to_a.first || [:after, last_sheet_local] base_sheet_ole = base_sheet.to_reo.ole_worksheet if !::COPYSHEETS_JRUBY_BUG add_or_copy_sheet_simple(sheet, { after_or_before.to_s => base_sheet_ole }) else if after_or_before == :before add_or_copy_sheet_simple(sheet, base_sheet_ole) else if base_sheet.name != last_sheet_local.name add_or_copy_sheet_simple(sheet, base_sheet.Next) else add_or_copy_sheet_simple(sheet, base_sheet_ole) base_sheet.Move(ole_workbook.Worksheets.Item(ole_workbook.Worksheets.Count-1)) ole_workbook.Worksheets.Item(ole_workbook.Worksheets.Count).Activate end end end rescue # WIN32OLERuntimeError, NameNotFound, Java::OrgRacobCom::ComFailException raise WorksheetREOError, "could not add given worksheet #{sheet.inspect}\n#{$!.message}" end new_sheet = worksheet_class.new(ole_workbook.Activesheet) new_sheet.name = new_sheet_name if new_sheet_name new_sheet end |
#add_sheet(sheet = nil, opts = { }) ⇒ Object
for compatibility to older versions
903 904 905 |
# File 'lib/robust_excel_ole/workbook.rb', line 903 def add_sheet(sheet = nil, opts = { }) add_or_copy_sheet(sheet, opts) end |
#alive? ⇒ Boolean
returns true, if the workbook reacts to methods, false otherwise
968 969 970 971 972 973 974 |
# File 'lib/robust_excel_ole/workbook.rb', line 968 def alive? @ole_workbook.Name true rescue @ole_workbook = nil # dead object won't be alive again false end |
#calculation ⇒ Object
991 992 993 |
# File 'lib/robust_excel_ole/workbook.rb', line 991 def calculation @excel.properties[:calculation] if @ole_workbook end |
#close(opts = {if_unsaved: :raise}) ⇒ Object
closes the workbook, if it is alive options:
:if_unsaved if the workbook is unsaved
:raise -> raises an exception
:save -> saves the workbook before it is closed
:forget -> closes the workbook
:keep_open -> keep the workbook open
:alert or :excel -> gives control to excel
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/robust_excel_ole/workbook.rb', line 517 def close(opts = {if_unsaved: :raise}) return close_workbook unless (alive? && !@ole_workbook.Saved && writable) case opts[:if_unsaved] when :raise raise WorkbookNotSaved, "workbook is unsaved: #{File.basename(self.stored_filename).inspect}" + "\nHint: Use option :save or :forget to close the workbook with or without saving" when :save save close_workbook when :forget @excel.with_displayalerts(false) { close_workbook } when :keep_open # nothing when :alert, :excel @excel.with_displayalerts(true) { close_workbook } else raise OptionInvalid, ":if_unsaved: invalid option: #{opts[:if_unsaved].inspect}" + "\nHint: Valid values are :raise, :save, :keep_open, :alert, :excel" end end |
#copy_sheet(sheet, opts = { }) ⇒ Object
for compatibility to older versions
908 909 910 |
# File 'lib/robust_excel_ole/workbook.rb', line 908 def copy_sheet(sheet, opts = { }) add_or_copy_sheet(sheet, opts) end |
#each ⇒ Enumerator
Returns traversing all worksheet objects.
830 831 832 833 834 835 836 837 838 |
# File 'lib/robust_excel_ole/workbook.rb', line 830 def each if block_given? @ole_workbook.Worksheets.lazy.each do |ole_worksheet| yield worksheet_class.new(ole_worksheet) end else to_enum(:each).lazy end end |
#each_with_index(offset = 0) ⇒ Object
840 841 842 843 844 845 846 |
# File 'lib/robust_excel_ole/workbook.rb', line 840 def each_with_index(offset = 0) i = offset @ole_workbook.Worksheets.lazy.each do |sheet| yield worksheet_class.new(sheet), i i += 1 end end |
#filename ⇒ Object
returns the full file name of the workbook
977 978 979 |
# File 'lib/robust_excel_ole/workbook.rb', line 977 def filename General.canonize(@ole_workbook.Fullname.tr('\\','/')) rescue nil end |
#first_sheet ⇒ Object
916 917 918 |
# File 'lib/robust_excel_ole/workbook.rb', line 916 def first_sheet worksheet_class.new(@ole_workbook.Worksheets.Item(1)) end |
#focus ⇒ Object
brings workbook to foreground, makes it available for heyboard inputs, makes the Excel instance visible
961 962 963 964 965 |
# File 'lib/robust_excel_ole/workbook.rb', line 961 def focus self.visible = true @excel.focus @ole_workbook.Activate end |
#for_modifying(opts = { }, &block) ⇒ Object
567 568 569 |
# File 'lib/robust_excel_ole/workbook.rb', line 567 def (opts = { }, &block) unobtrusively({writable: true}.merge(opts), &block) end |
#for_reading(opts = { }, &block) ⇒ Object
563 564 565 |
# File 'lib/robust_excel_ole/workbook.rb', line 563 def for_reading(opts = { }, &block) unobtrusively({writable: false}.merge(opts), &block) end |
#for_this_workbook(opts) ⇒ Object
sets options
954 955 956 957 958 |
# File 'lib/robust_excel_ole/workbook.rb', line 954 def for_this_workbook(opts) return unless alive? self.class.(opts, use_defaults: false) self.send :apply_options, @stored_filename, opts end |
#last_sheet ⇒ Object
912 913 914 |
# File 'lib/robust_excel_ole/workbook.rb', line 912 def last_sheet worksheet_class.new(@ole_workbook.Worksheets.Item(@ole_workbook.Worksheets.Count)) end |
#range(name_or_worksheet, name_or_address = :__not_provided, address2 = :__not_provided) ⇒ Range
creates a range from a given defined name or from a given worksheet and address
924 925 926 927 928 929 930 931 932 933 934 935 936 |
# File 'lib/robust_excel_ole/workbook.rb', line 924 def range(name_or_worksheet, name_or_address = :__not_provided, address2 = :__not_provided) if name_or_worksheet.respond_to?(:gsub) name = name_or_worksheet RobustExcelOle::Range.new(get_name_object(name).RefersToRange) else begin worksheet = name_or_worksheet.to_reo worksheet.range(name_or_address, address2) rescue raise RangeNotCreated, "argument error: a defined name or a worksheet and an address must be provided" end end end |
#retain_saved ⇒ Object
keeps the saved-status unchanged
554 555 556 557 558 559 560 561 |
# File 'lib/robust_excel_ole/workbook.rb', line 554 def retain_saved saved = self.Saved begin yield self ensure self.Saved = saved end end |
#set_was_open(hash, value) ⇒ Object
188 189 190 |
# File 'lib/robust_excel_ole/workbook.rb', line 188 def set_was_open(hash, value) self.class.set_was_open(hash, value) end |
#sheet(name) ⇒ Object
returns a sheet, if a sheet name or a number is given
819 820 821 822 823 |
# File 'lib/robust_excel_ole/workbook.rb', line 819 def sheet(name) worksheet_class.new(@ole_workbook.Worksheets.Item(name)) rescue WIN32OLERuntimeError, Java::OrgRacobCom::ComFailException => msg raise NameNotFound, "could not return a sheet with name #{name.inspect}" end |
#unobtrusively(opts = { }, &block) ⇒ Object
595 596 597 598 |
# File 'lib/robust_excel_ole/workbook.rb', line 595 def unobtrusively(opts = { }, &block) file = @stored_filename self.class.unobtrusively_opening(file, opts, alive?, &block) end |
#visible ⇒ Object
returns true, if the workbook is visible, false otherwise
1001 1002 1003 |
# File 'lib/robust_excel_ole/workbook.rb', line 1001 def visible @excel.Visible && @ole_workbook.Windows(@ole_workbook.Name).Visible end |
#visible=(visible_value) ⇒ Object
makes both the Excel instance and the window of the workbook visible, or the window invisible does not do anything if geben visible_value is nil
1008 1009 1010 1011 1012 |
# File 'lib/robust_excel_ole/workbook.rb', line 1008 def visible= visible_value return if visible_value.nil? @excel.visible = true if visible_value self.window_visible = @excel.Visible ? visible_value : true end |
#window_visible ⇒ Object
returns true, if the window of the workbook is set to visible, false otherwise
1015 1016 1017 |
# File 'lib/robust_excel_ole/workbook.rb', line 1015 def window_visible @ole_workbook.Windows(@ole_workbook.Name).Visible end |
#window_visible=(visible_value) ⇒ Object
makes the window of the workbook visible or invisible
1021 1022 1023 1024 1025 |
# File 'lib/robust_excel_ole/workbook.rb', line 1021 def window_visible= visible_value retain_saved do @ole_workbook.Windows(@ole_workbook.Name).Visible = visible_value if @ole_workbook.Windows.Count > 0 end end |
#worksheets_count ⇒ Object
825 826 827 |
# File 'lib/robust_excel_ole/workbook.rb', line 825 def worksheets_count @ole_workbook.Worksheets.Count end |