Class: OOXML::Excel::Styles
- Inherits:
-
Object
- Object
- OOXML::Excel::Styles
- Defined in:
- lib/ooxml_excel/styles.rb,
lib/ooxml_excel/styles.rb,
lib/ooxml_excel/styles.rb,
lib/ooxml_excel/styles.rb
Defined Under Namespace
Classes: CellStyleXfs, Fill, Font
Instance Attribute Summary collapse
-
#cell_style_xfs ⇒ Object
Returns the value of attribute cell_style_xfs.
-
#fills ⇒ Object
Returns the value of attribute fills.
-
#fonts ⇒ Object
Returns the value of attribute fonts.
Class Method Summary collapse
Instance Method Summary collapse
- #by_id(id) ⇒ Object
- #fills_by_index(fill_index) ⇒ Object
- #fonts_by_index(font_index) ⇒ Object
-
#initialize(**attrs) ⇒ Styles
constructor
A new instance of Styles.
Constructor Details
#initialize(**attrs) ⇒ Styles
5 6 7 |
# File 'lib/ooxml_excel/styles.rb', line 5 def initialize(**attrs) attrs.each { |property, value| send("#{property}=", value)} end |
Instance Attribute Details
#cell_style_xfs ⇒ Object
Returns the value of attribute cell_style_xfs.
4 5 6 |
# File 'lib/ooxml_excel/styles.rb', line 4 def cell_style_xfs @cell_style_xfs end |
#fills ⇒ Object
Returns the value of attribute fills.
4 5 6 |
# File 'lib/ooxml_excel/styles.rb', line 4 def fills @fills end |
#fonts ⇒ Object
Returns the value of attribute fonts.
4 5 6 |
# File 'lib/ooxml_excel/styles.rb', line 4 def fonts @fonts end |
Class Method Details
.load_from_stream(xml_stream) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ooxml_excel/styles.rb', line 25 def self.load_from_stream(xml_stream) style_doc = Nokogiri.XML(xml_stream).remove_namespaces! fonts = style_doc.xpath('//fonts/font') fills = style_doc.xpath('//fills/fill') # This element contains the master formatting records (xf) which # define the formatting applied to cells in this workbook. # link: https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.cellformats(v=office.14).aspx cell_style_xfs = style_doc.xpath('//cellXfs/xf') self.new( fonts: fonts.map { |font_node| Excel::Styles::Font.load_from_node(font_node)}, fills: fills.map { |fill_node| Excel::Styles::Fill.load_from_node(fill_node)}, cell_style_xfs: cell_style_xfs.map { |cell_style_xfs_node| Excel::Styles::CellStyleXfs.load_from_node(cell_style_xfs_node)} ) end |
Instance Method Details
#by_id(id) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/ooxml_excel/styles.rb', line 9 def by_id(id) cell_style = cell_style_xfs.fetch(id) { font: fonts_by_index(cell_style.font_id), fill: fills_by_index(cell_style.fill_id) } end |
#fills_by_index(fill_index) ⇒ Object
21 22 23 |
# File 'lib/ooxml_excel/styles.rb', line 21 def fills_by_index(fill_index) @fills[fill_index] end |
#fonts_by_index(font_index) ⇒ Object
17 18 19 |
# File 'lib/ooxml_excel/styles.rb', line 17 def fonts_by_index(font_index) @fonts[font_index] end |