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
# 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

#drawingDrawing (readonly)

The drawing that holds this anchor

Returns:



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

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:



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

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)


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

def height
  @height
end

#objectPic (readonly)

The object this anchor hosts

Returns:



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

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)


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

def width
  @width
end

Instance Method Details

#indexInteger

The index of this anchor in the drawing

Returns:

  • (Integer)


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

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.



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

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)


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