Class: RubyXL::Stylesheet

Inherits:
OOXMLTopLevelObject show all
Defined in:
lib/rubyXL/objects/stylesheet.rb

Overview

Constant Summary collapse

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

Constants inherited from OOXMLTopLevelObject

OOXMLTopLevelObject::ROOT, OOXMLTopLevelObject::SAVE_ORDER

Instance Attribute Summary

Attributes inherited from OOXMLTopLevelObject

#root

Attributes included from OOXMLObjectInstanceMethods

#local_namespaces

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OOXMLTopLevelObject

#add_to_zip, #file_index, parse_file, set_namespaces

Methods included from OOXMLObjectInstanceMethods

#==, #before_write_xml, included, #index_in_collection, #write_xml

Constructor Details

#initialize(*args) ⇒ Stylesheet

Returns a new instance of Stylesheet.



180
181
182
183
# File 'lib/rubyXL/objects/stylesheet.rb', line 180

def initialize(*args)
  super
  @format_hash = nil
end

Class Method Details

.defaultObject



189
190
191
192
193
194
195
196
# File 'lib/rubyXL/objects/stylesheet.rb', line 189

def self.default
  self.new(:fonts          => RubyXL::Fonts.default,
           :fills          => RubyXL::Fills.default,
           :borders        => RubyXL::Borders.default,
           :cell_xfs       => RubyXL::CellXFs.default,
           :cell_styles    => RubyXL::CellStyles.default,
           :cell_style_xfs => RubyXL::CellStyleXFs.default)
end

Instance Method Details

#get_number_format_by_id(format_id) ⇒ Object



198
199
200
201
202
203
204
205
206
207
# File 'lib/rubyXL/objects/stylesheet.rb', line 198

def get_number_format_by_id(format_id)
  @format_hash ||= {}

  if @format_hash[format_id].nil? then
    @format_hash[format_id] = NumberFormats::DEFAULT_NUMBER_FORMATS.find_by_format_id(format_id) ||
                                (number_formats && number_formats.find_by_format_id(format_id))
  end

  @format_hash[format_id]
end

#register_number_format(format_code) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/rubyXL/objects/stylesheet.rb', line 209

def register_number_format(format_code)
  self.number_formats ||= RubyXL::NumberFormats.new

  max_fmt_id = 163

  (NumberFormats::DEFAULT_NUMBER_FORMATS + number_formats).each { |fmt|
    return fmt.num_fmt_id if fmt.format_code == format_code
    max_fmt_id = fmt.num_fmt_id if fmt.num_fmt_id > max_fmt_id
  }

  max_fmt_id += 1
  number_formats << RubyXL::NumberFormat.new(:num_fmt_id => max_fmt_id, :format_code => format_code)

  return max_fmt_id
end

#xlsx_pathObject



185
186
187
# File 'lib/rubyXL/objects/stylesheet.rb', line 185

def xlsx_path
  ROOT.join('xl', 'styles.xml')
end