Class: OOXML::Excel
- Inherits:
-
Object
- Object
- OOXML::Excel
- Includes:
- Helper::List
- Defined in:
- lib/ooxml_excel/excel.rb,
lib/ooxml_excel/sheet.rb,
lib/ooxml_excel/sheet.rb,
lib/ooxml_excel/sheet.rb,
lib/ooxml_excel/sheet.rb,
lib/ooxml_excel/sheet.rb,
lib/ooxml_excel/styles.rb,
lib/ooxml_excel/styles.rb,
lib/ooxml_excel/styles.rb,
lib/ooxml_excel/styles.rb,
lib/ooxml_excel/styles.rb,
lib/ooxml_excel/version.rb,
lib/ooxml_excel/comments.rb,
lib/ooxml_excel/workbook.rb
Defined Under Namespace
Classes: Comments, Sheet, Styles, Workbook
Constant Summary collapse
- VERSION =
"0.0.3.4.2"
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
Instance Method Summary collapse
- #[](text) ⇒ Object
-
#initialize(spreadsheet, load_only_sheet: nil) ⇒ Excel
constructor
A new instance of Excel.
- #named_range(name) ⇒ Object
- #sheet(sheet_name) ⇒ Object
- #sheets ⇒ Object
Methods included from Helper::List
#list_value_formula, #list_values, #list_values_from_formula
Constructor Details
#initialize(spreadsheet, load_only_sheet: nil) ⇒ Excel
Returns a new instance of Excel.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/ooxml_excel/excel.rb', line 5 def initialize(spreadsheet, load_only_sheet:nil) @spreadsheet = spreadsheet @workbook = nil @sheets = {} @comments = {} # @themes = [] @load_only_sheet = nil @styles = nil load_xml_contents end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
4 5 6 |
# File 'lib/ooxml_excel/excel.rb', line 4 def comments @comments end |
Instance Method Details
#[](text) ⇒ Object
34 35 36 37 38 |
# File 'lib/ooxml_excel/excel.rb', line 34 def [](text) # immediately treat as cell range if an exclamation point is detected # otherwise, normally load a sheet text.include?('!') ? load_list_values(text) : sheet(text) end |
#named_range(name) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/ooxml_excel/excel.rb', line 40 def named_range(name) # "Hidden11390550_39"=>"Hidden!$B$734:$B$735" # ooxml.named_range('Hidden11390550_107') # a typical named range would be be # yes_no => 'Lists'!$A$1:$A$6 defined_name = @workbook.defined_names[name] load_list_values(defined_name) if defined_name.present? end |
#sheet(sheet_name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ooxml_excel/excel.rb', line 20 def sheet(sheet_name) sheet_index = @workbook.sheets.index { |sheet| sheet[:name] == sheet_name} raise "No #{sheet_name} in workbook." if sheet_index.blank? sheet = @sheets.fetch((sheet_index+1).to_s) # shared variables sheet.name = sheet_name sheet.comments = @comments[(sheet_index+1).to_s] sheet.styles = @styles sheet.defined_names = @workbook.defined_names sheet end |
#sheets ⇒ Object
16 17 18 |
# File 'lib/ooxml_excel/excel.rb', line 16 def sheets @workbook.sheets.map { |sheet| sheet[:name]} end |