Class: OpenXml::Xlsx::Parts::Stylesheet
- Inherits:
-
Part
- Object
- Part
- OpenXml::Xlsx::Parts::Stylesheet
- Includes:
- Elements
- Defined in:
- lib/openxml/xlsx/parts/stylesheet.rb
Instance Attribute Summary collapse
-
#borders ⇒ Object
readonly
Returns the value of attribute borders.
-
#fills ⇒ Object
readonly
Returns the value of attribute fills.
-
#fonts ⇒ Object
readonly
Returns the value of attribute fonts.
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
Instance Method Summary collapse
-
#initialize ⇒ Stylesheet
constructor
A new instance of Stylesheet.
- #reference_of(options = {}) ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize ⇒ Stylesheet
Returns a new instance of Stylesheet.
9 10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#borders ⇒ Object (readonly)
Returns the value of attribute borders.
7 8 9 |
# File 'lib/openxml/xlsx/parts/stylesheet.rb', line 7 def borders @borders end |
#fills ⇒ Object (readonly)
Returns the value of attribute fills.
7 8 9 |
# File 'lib/openxml/xlsx/parts/stylesheet.rb', line 7 def fills @fills end |
#fonts ⇒ Object (readonly)
Returns the value of attribute fonts.
7 8 9 |
# File 'lib/openxml/xlsx/parts/stylesheet.rb', line 7 def fonts @fonts end |
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
7 8 9 |
# File 'lib/openxml/xlsx/parts/stylesheet.rb', line 7 def formats @formats end |
#styles ⇒ Object (readonly)
Returns the value of attribute styles.
7 8 9 |
# File 'lib/openxml/xlsx/parts/stylesheet.rb', line 7 def styles @styles end |
Instance Method Details
#reference_of(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/openxml/xlsx/parts/stylesheet.rb', line 17 def reference_of(={}) case format = [:format] when NumberFormat [:format_id] = Xlsx.index!(formats, format) + NUMBER_FORMAT_START_ID when ImpliedNumberFormat [:format_id] = format.id end [:font_id] = Xlsx.index!(fonts, [:font]) if .key? :font [:fill_id] = Xlsx.index!(fills, [:fill]) if .key? :fill [:border_id] = Xlsx.index!(borders, [:border]) if .key? :border style = Style.new( .fetch(:format_id, 0), .fetch(:font_id, 0), .fetch(:fill_id, 0), .fetch(:border_id, 0), .fetch(:alignment, nil)) Xlsx.index!(styles, style) end |
#to_xml ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# 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 |