Class: Axlsx::OneCellAnchor

Inherits:
Object
  • Object
show all
Includes:
OptionsParser
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)

Methods included from OptionsParser

#parse_options

Constructor Details

- (OneCellAnchor) initialize(drawing, options = {})

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

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



19
20
21
22
23
24
25
26
27
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 19

def initialize(drawing, options={})
  @drawing = drawing
  @width = 0
  @height = 0
  drawing.anchors << self
  @from = Marker.new
  parse_options options
  @object = Pic.new(self, options)
end

Instance Attribute Details

- (Drawing) drawing (readonly)

The drawing that holds this anchor



39
40
41
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 39

def drawing
  @drawing
end

- (Marker) from (readonly)

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



31
32
33
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 31

def from
  @from
end

- (Integer) height

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



49
50
51
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 49

def height
  @height
end

- (Pic) object (readonly)

The object this anchor hosts



35
36
37
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 35

def object
  @object
end

- (Integer) width

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



44
45
46
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 44

def width
  @width
end

Instance Method Details

- (Integer) index

The index of this anchor in the drawing



68
69
70
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 68

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

- (Object) start_at(x, y = 0)

sets the starting position for the anchor. You can provide a String like "A1", an array like [0,0] or a cell object for the x parameter. We just 'figure it out' for you.



56
57
58
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 56

def start_at(x, y=0)
  from.coord x, y
end

- (String) to_xml_string(str = '')

Serializes the object



75
76
77
78
79
80
81
82
83
84
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 75

def to_xml_string(str = '')
  str << '<xdr:oneCellAnchor>'
  str << '<xdr:from>'
  from.to_xml_string(str)
  str << '</xdr:from>'
  str << ('<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>')
  @object.to_xml_string(str)
  str << '<xdr:clientData/>'
  str << '</xdr:oneCellAnchor>'
end