Class: RubyXL::Workbook

Inherits:
OOXMLTopLevelObject show all
Includes:
LegacyWorkbook, RelationshipSupport
Defined in:
lib/rubyXL/objects/workbook.rb

Overview

Constant Summary collapse

CONTENT_TYPE =
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'
REL_TYPE =
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument'

Constants included from LegacyWorkbook

LegacyWorkbook::APPLICATION, LegacyWorkbook::APPVERSION, LegacyWorkbook::SHEET_NAME_TEMPLATE

Instance Attribute Summary collapse

Attributes included from LegacyWorkbook

#worksheets

Attributes included from RelationshipSupport

#generic_storage, #relationship_container

Instance Method Summary collapse

Methods included from LegacyWorkbook

#[], #add_worksheet, #borders, #cell_xfs, #date_to_num, #each, #fills, #fonts, #get_fill_color, #initialize, #modify_alignment, #modify_border, #modify_fill, #modify_text_wrap, #num_to_date, #register_new_fill, #register_new_font, #register_new_xf, #write

Methods included from RelationshipSupport

#collect_related_objects, #load_relationships, #store_relationship

Methods inherited from OOXMLTopLevelObject

#add_to_zip, #file_index, parse_file, save_order, set_namespaces

Methods included from OOXMLObjectClassMethods

#define_attribute, #define_child_node, #define_element_name, #obtain_class_variable, #parse, #set_countable

Methods included from OOXMLObjectInstanceMethods

#dup, #index_in_collection, #initialize, #write_xml

Instance Attribute Details

#calculation_chainObject

Returns the value of attribute calculation_chain.



323
324
325
# File 'lib/rubyXL/objects/workbook.rb', line 323

def calculation_chain
  @calculation_chain
end

#rootObject

Returns the value of attribute root.



322
323
324
# File 'lib/rubyXL/objects/workbook.rb', line 322

def root
  @root
end

#shared_strings_containerObject

Returns the value of attribute shared_strings_container.



323
324
325
# File 'lib/rubyXL/objects/workbook.rb', line 323

def shared_strings_container
  @shared_strings_container
end

#stylesheetObject

Returns the value of attribute stylesheet.



323
324
325
# File 'lib/rubyXL/objects/workbook.rb', line 323

def stylesheet
  @stylesheet
end

#themeObject

Returns the value of attribute theme.



323
324
325
# File 'lib/rubyXL/objects/workbook.rb', line 323

def theme
  @theme
end

Instance Method Details

#applicationObject



379
380
381
# File 'lib/rubyXL/objects/workbook.rb', line 379

def application
  root.document_properties.application && self.document_properties.application.value
end

#application=(v) ⇒ Object



383
384
385
386
# File 'lib/rubyXL/objects/workbook.rb', line 383

def application=(v)
  root.document_properties.application ||= StringNode.new
  root.document_properties.application.value = v
end

#appversionObject



388
389
390
# File 'lib/rubyXL/objects/workbook.rb', line 388

def appversion
  root.document_properties.app_version && root.document_properties.app_version.value
end

#appversion=(v) ⇒ Object



392
393
394
395
# File 'lib/rubyXL/objects/workbook.rb', line 392

def appversion=(v)
  root.document_properties.app_version ||= StringNode.new
  root.document_properties.app_version.value = v
end

#attach_relationship(rid, rf) ⇒ Object



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/rubyXL/objects/workbook.rb', line 345

def attach_relationship(rid, rf)
  case rf
  when RubyXL::SharedStringsTable       then self.shared_strings_container = rf
  when RubyXL::Stylesheet               then self.stylesheet = rf
  when RubyXL::Theme                    then self.theme = rf
  when RubyXL::CalculationChain         then self.calculation_chain = rf
  when RubyXL::ExternalLinksFile        then store_relationship(rf) # TODO
  when RubyXL::PivotCacheDefinitionFile then store_relationship(rf) # TODO
  when RubyXL::CustomXMLFile            then store_relationship(rf) # TODO
  when RubyXL::MacrosFile               then store_relationship(rf) # TODO
  when RubyXL::SlicerCacheFile          then store_relationship(rf) # TODO
  when RubyXL::Worksheet, RubyXL::Chartsheet then nil # These will be handled in the next loop
  else store_relationship(rf, :unknown)
  end
end

#before_write_xmlObject



325
326
327
328
329
330
331
332
333
334
335
# File 'lib/rubyXL/objects/workbook.rb', line 325

def before_write_xml
  self.sheets = RubyXL::Sheets.new

  worksheets.each_with_index { |sheet, i|
    rel = relationship_container.find_by_target(sheet.xlsx_path.gsub(/\Axl\//, ''))
    sheets << RubyXL::Sheet.new(:name => sheet.sheet_name[0..30], # Max sheet name length is 31 char
                                :sheet_id => sheet.sheet_id || (i + 1),
                                :state => sheet.state, :r_id => rel.id)
  }
  true
end

#companyObject



370
371
372
# File 'lib/rubyXL/objects/workbook.rb', line 370

def company
  self.document_properties.company && self.document_properties.company.value
end

#company=(v) ⇒ Object



374
375
376
377
# File 'lib/rubyXL/objects/workbook.rb', line 374

def company=(v)
  root.document_properties.company ||= StringNode.new
  root.document_properties.company.value = v
end

#created_atObject



413
414
415
# File 'lib/rubyXL/objects/workbook.rb', line 413

def created_at
  root.core_properties.created_at
end

#created_at=(v) ⇒ Object



417
418
419
# File 'lib/rubyXL/objects/workbook.rb', line 417

def created_at=(v)
  root.core_properties.created_at = v
end

#creatorObject



397
398
399
# File 'lib/rubyXL/objects/workbook.rb', line 397

def creator
  root.core_properties.creator
end

#creator=(v) ⇒ Object



401
402
403
# File 'lib/rubyXL/objects/workbook.rb', line 401

def creator=(v)
  root.core_properties.creator = v
end

#date1904Object



361
362
363
# File 'lib/rubyXL/objects/workbook.rb', line 361

def date1904
  workbook_properties && workbook_properties.date1904
end

#date1904=(v) ⇒ Object



365
366
367
368
# File 'lib/rubyXL/objects/workbook.rb', line 365

def date1904=(v)
  self.workbook_properties ||= RubyXL::WorkbookProperties.new
  workbook_properties.date1904 = v
end

#modified_atObject



421
422
423
# File 'lib/rubyXL/objects/workbook.rb', line 421

def modified_at
  root.core_properties.modified_at
end

#modified_at=(v) ⇒ Object



425
426
427
# File 'lib/rubyXL/objects/workbook.rb', line 425

def modified_at=(v)
  root.core_properties.modified_at = v
end

#modifierObject



405
406
407
# File 'lib/rubyXL/objects/workbook.rb', line 405

def modifier
  root.core_properties.modifier
end

#modifier=(v) ⇒ Object



409
410
411
# File 'lib/rubyXL/objects/workbook.rb', line 409

def modifier=(v)
  root.core_properties.modifier = v
end


337
338
339
# File 'lib/rubyXL/objects/workbook.rb', line 337

def related_objects
  [ calculation_chain, stylesheet, theme, shared_strings_container ] + @worksheets
end

#relationship_file_classObject



341
342
343
# File 'lib/rubyXL/objects/workbook.rb', line 341

def relationship_file_class
  RubyXL::WorkbookRelationships
end

#xlsx_pathObject



429
430
431
# File 'lib/rubyXL/objects/workbook.rb', line 429

def xlsx_path
  File.join('xl', 'workbook.xml')
end