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

#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



19
20
21
22
23
24
25
26
27
28
# 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
  start_at(*options[:start_at]) if options[:start_at]
  @object = Pic.new(self, options)
end

Instance Attribute Details

#drawingDrawing (readonly)

The drawing that holds this anchor

Returns:



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

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:



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

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)


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

def height
  @height
end

#objectPic (readonly)

The object this anchor hosts

Returns:



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

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)


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

def width
  @width
end

Instance Method Details

#indexInteger

The index of this anchor in the drawing

Returns:

  • (Integer)


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

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

#start_at(x, y = 0) ⇒ Object

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.

Parameters:

  • x (Array, String, Cell, Integer)

    Accepts many inputs for defining the starting position of the cell.

  • y (Integer) (defaults to: 0)

    When x is an integer, this value is used for the row index at which the anchor starts.



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

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

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


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

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