Class: OOXML::Excel

Inherits:
Object
  • Object
show all
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/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.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  @sheets = {}
  @comments = {}
  # @themes = []
  @workbook = nil
  @load_only_sheet = nil
  @styles = nil
  load_xml_contents
end

Instance Attribute Details

#commentsObject (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

#sheet(sheet_name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ooxml_excel/excel.rb', line 20

def sheet(sheet_name)
  sheet_from_workbook = @workbook.sheets.find { |sheet| sheet[:name] == sheet_name}
  raise "No #{sheet_name} in workbook." if sheet_from_workbook.blank?
  sheet = @sheets.fetch(sheet_from_workbook[:relationship_id])

  # shared variables
  sheet.name = sheet_name
  sheet.comments = @comments[sheet_from_workbook[:relationship_id]]
  sheet.styles = @styles
  sheet.defined_names = @workbook.defined_names
  sheet
end

#sheetsObject



16
17
18
# File 'lib/ooxml_excel/excel.rb', line 16

def sheets
  @workbook.sheets.map { |sheet| sheet[:name]}
end