Class: OpenXML::SpreadsheetML::Workbook
- Inherits:
-
Object
- Object
- OpenXML::SpreadsheetML::Workbook
- Defined in:
- lib/xlsx/parser.rb,
lib/xlsx/workbook.rb
Instance Attribute Summary collapse
-
#calc_chain ⇒ Object
Returns the value of attribute calc_chain.
-
#sheets ⇒ Object
Returns the value of attribute sheets.
-
#styles ⇒ Object
Returns the value of attribute styles.
-
#theme ⇒ Object
Returns the value of attribute theme.
-
#xml_maps ⇒ Object
Returns the value of attribute xml_maps.
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(xlsx_path) {|_self| ... } ⇒ Workbook
constructor
A new instance of Workbook.
- #merge_shared_strings(shared_strings_reference) ⇒ Object
- #merge_sheets(sheets) ⇒ Object
Constructor Details
#initialize(xlsx_path) {|_self| ... } ⇒ Workbook
Returns a new instance of Workbook.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/xlsx/parser.rb', line 4 def initialize xlsx_path @sheets = [] @shared_strings = nil Zip::File.open(xlsx_path) do |zf| zf.each do |entry| content = entry.get_input_stream.read case entry.name when %r{^xl/workbook\.xml$}i workbook_parser content when %r{^xl/sharedStrings\.xml$}i shared_strings_parser content when %r{^xl/worksheets/sheet\d*\.xml$}i sheet_parser content end end end merge_sheets(@sheet_names) if @sheet_names merge_shared_strings(@shared_strings) if @shared_strings yield(self) if block_given? end |
Instance Attribute Details
#calc_chain ⇒ Object
Returns the value of attribute calc_chain.
4 5 6 |
# File 'lib/xlsx/workbook.rb', line 4 def calc_chain @calc_chain end |
#sheets ⇒ Object
Returns the value of attribute sheets.
4 5 6 |
# File 'lib/xlsx/workbook.rb', line 4 def sheets @sheets end |
#styles ⇒ Object
Returns the value of attribute styles.
4 5 6 |
# File 'lib/xlsx/workbook.rb', line 4 def styles @styles end |
#theme ⇒ Object
Returns the value of attribute theme.
4 5 6 |
# File 'lib/xlsx/workbook.rb', line 4 def theme @theme end |
#xml_maps ⇒ Object
Returns the value of attribute xml_maps.
4 5 6 |
# File 'lib/xlsx/workbook.rb', line 4 def xml_maps @xml_maps end |
Instance Method Details
#[](index) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/xlsx/workbook.rb', line 6 def [] index self.sheets.each do |sheet| return sheet if sheet.name == index end nil end |
#merge_shared_strings(shared_strings_reference) ⇒ Object
22 23 24 25 26 |
# File 'lib/xlsx/workbook.rb', line 22 def merge_shared_strings shared_strings_reference sheets.each do |sheet| sheet.merge_shared_strings shared_strings_reference end end |
#merge_sheets(sheets) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/xlsx/workbook.rb', line 13 def merge_sheets sheets new_sheets = [] self.sheets.zip(sheets) do |x, y| new_sheets << x + y end sheets = new_sheets self end |