Class: Axlsx::OneCellAnchor

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/drawing/one_cell_anchor.rb

Overview

Note:

The recommended way to manage drawings, images and charts is Worksheet#add_chart or Worksheet#add_image.

This class details a single cell anchor for drawings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drawing, options = {}) ⇒ OneCellAnchor

Creates a new OneCellAnchor object and an Pic associated with it.

Parameters:

  • drawing (Drawing)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • start_at (Array)

    the col, row to start at

  • width (Integer)
  • height (Integer)
  • image_src (String)

    the file location of the image you will render

  • name (String)

    the name attribute for the rendered image

  • descr (String)

    the description of the image rendered



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 39

def initialize(drawing, options={})
  @drawing = drawing
  @width = 0
  @height = 0
  drawing.anchors << self      
  @from = Marker.new
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
  @object = Pic.new(self, options)
end

Instance Attribute Details

#drawingDrawing (readonly)

The drawing that holds this anchor

Returns:



18
19
20
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 18

def drawing
  @drawing
end

#fromMarker (readonly)

A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively

Returns:



10
11
12
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 10

def from
  @from
end

#heightInteger

the height of the graphic object in pixels this is converted to EMU at a 92 ppi resolution

Returns:

  • (Integer)


28
29
30
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 28

def height
  @height
end

#objectPic (readonly)

The object this anchor hosts

Returns:



14
15
16
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 14

def object
  @object
end

#widthInteger

the width of the graphic object in pixels. this is converted to EMU at a 92 ppi resolution

Returns:

  • (Integer)


23
24
25
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 23

def width
  @width
end

Instance Method Details

#indexInteger

The index of this anchor in the drawing

Returns:

  • (Integer)


59
60
61
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 59

def index
  @drawing.anchors.index(self)
end

#to_xml(xml) ⇒ String

Serializes the anchor

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

Returns:

  • (String)


66
67
68
69
70
71
72
73
74
75
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 66

def to_xml(xml)
  xml.send('xdr:oneCellAnchor') {
    xml.send('xdr:from') {
      from.to_xml(xml)
    }
    xml.send('xdr:ext', ext)
    @object.to_xml(xml)
    xml.send('xdr:clientData')
  }
end