Module: RubyExcel
- Defined in:
- lib/rubyexcel.rb,
lib/rubyexcel/data.rb,
lib/rubyexcel/sheet.rb,
lib/rubyexcel/address.rb,
lib/rubyexcel/element.rb,
lib/rubyexcel/section.rb,
lib/rubyexcel/excel_tools.rb,
lib/rubyexcel/rubyexcel_components.rb
Overview
Namespace for all RubyExcel Classes and Modules
Defined Under Namespace
Modules: Address Classes: Cell, Column, Data, Element, Range, Row, Section, Sheet, Workbook
Class Method Summary collapse
-
.borders(range, weight = 1, inner = false) ⇒ WIN32OLE::Range
Add borders to an Excel Range.
-
.documents_path ⇒ String
Find the Windows “Documents” or “My Documents” path, or return the present working directory if it can’t be found.
-
.import(*args) ⇒ Object
Shortcut to import a WIN32OLE Workbook or Sheet.
-
.method_missing(method, *args, &block) ⇒ Object
Don’t require Windows-specific libraries unless the relevant methods are called.
-
.sample_data ⇒ Object
Example data to use in tests / demos.
-
.sample_hash ⇒ Object
Example hash to demonstrate imports.
-
.sample_sheet ⇒ Object
Shortcut to create a Sheet with example data.
Class Method Details
.borders(range, weight = 1, inner = false) ⇒ WIN32OLE::Range
Add borders to an Excel Range
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rubyexcel/excel_tools.rb', line 19 def self.borders( range, weight=1, inner=false ) range.ole_respond_to?( :borders ) or fail ArgumentError, 'First Argument must be WIN32OLE Range' [0,1,2,3].include?( weight ) or fail ArgumentError, "Invalid line weight #{ weight }. Must be from 0 to 3" defined?( ExcelConstants::XlEdgeLeft ) or WIN32OLE.const_load( range.application, ExcelConstants ) consts = [ ExcelConstants::XlEdgeLeft, ExcelConstants::XlEdgeTop, ExcelConstants::XlEdgeBottom, ExcelConstants::XlEdgeRight, ExcelConstants::XlInsideVertical, ExcelConstants::XlInsideHorizontal ] inner or consts.pop(2) weight = [ 0, ExcelConstants::XlThin, ExcelConstants::XlMedium, ExcelConstants::XlThick ][ weight ] consts.each { |const| weight.zero? ? range.Borders( const ).linestyle = ExcelConstants::XlNone : range.Borders( const ).weight = weight } range end |
.documents_path ⇒ String
Find the Windows “Documents” or “My Documents” path, or return the present working directory if it can’t be found.
36 37 38 |
# File 'lib/rubyexcel/excel_tools.rb', line 36 def self.documents_path Win32::Registry::HKEY_CURRENT_USER.open( 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders' )['Personal'] rescue Dir.pwd.gsub('/','\\') end |
.import(*args) ⇒ Object
Shortcut to import a WIN32OLE Workbook or Sheet
67 68 69 |
# File 'lib/rubyexcel/rubyexcel_components.rb', line 67 def self.import( *args ) Workbook.new.import( *args ) end |
.method_missing(method, *args, &block) ⇒ Object
Don’t require Windows-specific libraries unless the relevant methods are called
33 34 35 36 37 38 39 40 |
# File 'lib/rubyexcel.rb', line 33 def self.method_missing( method, *args, &block ) if method == :documents_path require_relative 'rubyexcel/excel_tools.rb' send( method, *args, &block ) else super end end |
.sample_data ⇒ Object
Example data to use in tests / demos
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rubyexcel/rubyexcel_components.rb', line 14 def self.sample_data [ [ 'Part', 'Ref1', 'Ref2', 'Qty', 'Cost' ], [ 'Type1', 'QT1', '231', 1, 35.15 ], [ 'Type2', 'QT3', '123', 1, 40 ], [ 'Type3', 'XT1', '321', 3, 0.1 ], [ 'Type1', 'XY2', '132', 1, 30.00 ], [ 'Type4', 'XT3', '312', 2, 3 ], [ 'Type2', 'QY2', '213', 1, 99.99 ], [ 'Type1', 'QT4', '123', 2, 104 ] ] end |
.sample_hash ⇒ Object
Example hash to demonstrate imports
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubyexcel/rubyexcel_components.rb', line 32 def self.sample_hash { Part1: { Type1: { SubType1: 1, SubType2: 2, SubType3: 3 }, Type2: { SubType1: 4, SubType2: 5, SubType3: 6 } }, Part2: { Type1: { SubType1: 1, SubType2: 2, SubType3: 3 }, Type2: { SubType1: 4, SubType2: 5, SubType3: 6 } } } end |
.sample_sheet ⇒ Object
Shortcut to create a Sheet with example data
59 60 61 |
# File 'lib/rubyexcel/rubyexcel_components.rb', line 59 def self.sample_sheet Workbook.new.load RubyExcel.sample_data end |