class OpenXml::Xlsx::Parts::Stylesheet
Constants
- NUMBER_FORMAT_START_ID
Attributes
borders[R]
fills[R]
fonts[R]
formats[R]
styles[R]
Public Class Methods
new()
click to toggle source
# File lib/openxml/xlsx/parts/stylesheet.rb, line 9 def initialize @formats = [] @fonts = [Font.new("Calibri", 12)] @fills = [PatternFill.new("none"), PatternFill.new("gray125")] @borders = [Border.new] @styles = [Style.new] end
Public Instance Methods
reference_of(options={})
click to toggle source
# File lib/openxml/xlsx/parts/stylesheet.rb, line 17 def reference_of(options={}) case format = options[:format] when NumberFormat options[:format_id] = Xlsx.index!(formats, format) + NUMBER_FORMAT_START_ID when ImpliedNumberFormat options[:format_id] = format.id end options[:font_id] = Xlsx.index!(fonts, options[:font]) if options.key? :font options[:fill_id] = Xlsx.index!(fills, options[:fill]) if options.key? :fill options[:border_id] = Xlsx.index!(borders, options[:border]) if options.key? :border style = Style.new( options.fetch(:format_id, 0), options.fetch(:font_id, 0), options.fetch(:fill_id, 0), options.fetch(:border_id, 0), options.fetch(:alignment, nil)) Xlsx.index!(styles, style) end
to_xml()
click to toggle source
# File lib/openxml/xlsx/parts/stylesheet.rb, line 38 def to_xml build_standalone_xml do |xml| xml.styleSheet(xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main", "xmlns:mc" => "http://schemas.openxmlformats.org/markup-compatibility/2006") do xml.numFmts(count: formats.length) do formats.each_with_index do |format, index| format.to_xml(index + NUMBER_FORMAT_START_ID, xml) end end xml.fonts(count: fonts.length) do fonts.each do |font| font.to_xml(xml) end end xml.fills(count: fills.length) do fills.each do |fill| fill.to_xml(xml) end end xml.borders(count: borders.length) do borders.each do |border| border.to_xml(xml) end end xml.cellXfs(count: styles.length) do styles.each do |style| style.to_xml(xml) end end end end end