Class: Writexlsx::Package::App

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/write_xlsx/package/app.rb

Constant Summary

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, #dash_types, delete_files, #fill_properties, #float_to_str, #layout_properties, #line_fill_properties, #line_properties, #palette_color, #pixels_to_points, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initialize(workbook) ⇒ App


11
12
13
14
15
16
17
# File 'lib/write_xlsx/package/app.rb', line 11

def initialize(workbook)
  @writer = Package::XMLWriterSimple.new
  @workbook      = workbook
  @part_names    = []
  @heading_pairs = []
  @properties    = {}
end

Instance Method Details

#add_chartsheet_heading_pairsObject


50
51
52
# File 'lib/write_xlsx/package/app.rb', line 50

def add_chartsheet_heading_pairs
  add_heading_pair(['Charts', @workbook.chartsheet_count])
end

#add_chartsheet_part_namesObject


60
61
62
63
64
# File 'lib/write_xlsx/package/app.rb', line 60

def add_chartsheet_part_names
  @workbook.worksheets.
    select { |sheet| sheet.is_chartsheet? }.
    each   { |sheet| add_part_name(sheet.name) }
end

#add_heading_pair(heading_pair) ⇒ Object


82
83
84
85
86
# File 'lib/write_xlsx/package/app.rb', line 82

def add_heading_pair(heading_pair)
  return if heading_pair[1] == 0

  @heading_pairs.push(['lpstr', heading_pair[0]], ['i4', heading_pair[1]])
end

#add_named_range_heading_pairsObject


70
71
72
73
74
75
76
# File 'lib/write_xlsx/package/app.rb', line 70

def add_named_range_heading_pairs
  range_count = @workbook.named_ranges.size

  if range_count != 0
    add_heading_pair([ 'Named Ranges', range_count ])
  end
end

#add_named_ranges_partsObject


78
79
80
# File 'lib/write_xlsx/package/app.rb', line 78

def add_named_ranges_parts
  @workbook.named_ranges.each { |named_range| add_part_name(named_range) }
end

#add_part_name(part_name) ⇒ Object


66
67
68
# File 'lib/write_xlsx/package/app.rb', line 66

def add_part_name(part_name)
  @part_names.push(part_name)
end

#add_worksheet_heading_pairsObject


41
42
43
44
45
46
47
48
# File 'lib/write_xlsx/package/app.rb', line 41

def add_worksheet_heading_pairs
  add_heading_pair(
    [
      'Worksheets',
      @workbook.worksheets.reject {|s| s.is_chartsheet?}.count
    ]
  )
end

#add_worksheet_part_namesObject


54
55
56
57
58
# File 'lib/write_xlsx/package/app.rb', line 54

def add_worksheet_part_names
  @workbook.worksheets.
    reject { |sheet| sheet.is_chartsheet? }.
    each   { |sheet| add_part_name(sheet.name) }
end

#assemble_xml_fileObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/write_xlsx/package/app.rb', line 23

def assemble_xml_file
  write_xml_declaration do
    write_properties do
      write_application
      write_doc_security
      write_scale_crop
      write_heading_pairs
      write_titles_of_parts
      write_manager
      write_company
      write_links_up_to_date
      write_shared_doc
      write_hyperlinks_changed
      write_app_version
    end
  end
end

#set_properties(properties) ⇒ Object

Set the document properties.


91
92
93
# File 'lib/write_xlsx/package/app.rb', line 91

def set_properties(properties)
  @properties = properties
end

#set_xml_writer(filename) ⇒ Object


19
20
21
# File 'lib/write_xlsx/package/app.rb', line 19

def set_xml_writer(filename)
  @writer.set_xml_writer(filename)
end