class Axlsx::OneCellAnchor

This class details a single cell anchor for drawings. @note The recommended way to manage drawings, images and charts is Worksheet#add_chart or Worksheet#add_image. @see Worksheet#add_chart @see Worksheet#add_image

Attributes

drawing[R]

The drawing that holds this anchor @return [Drawing]

from[R]

A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively @return [Marker]

height[R]

the height of the graphic object in pixels this is converted to EMU at a 92 ppi resolution @return [Integer]

object[R]

The object this anchor hosts @return [Pic]

width[R]

the width of the graphic object in pixels. this is converted to EMU at a 92 ppi resolution @return [Integer]

Public Class Methods

new(drawing, options={}) click to toggle source

Creates a new OneCellAnchor object and an Pic associated with it. @param [Drawing] drawing @option options [Array] start_at the col, row to start at @option options [Integer] width @option options [Integer] height @option options [String] image_src the file location of the image you will render @option options [String] name the name attribute for the rendered image @option options [String] descr the description of the image rendered

# 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

Public Instance Methods

height=(v) click to toggle source

@see height

# File lib/axlsx/drawing/one_cell_anchor.rb, line 61
def height=(v) Axlsx::validate_unsigned_int(v); @height = v; end
index() click to toggle source

The index of this anchor in the drawing @return [Integer]

# File lib/axlsx/drawing/one_cell_anchor.rb, line 68
def index
  @drawing.anchors.index(self)
end
start_at(x, y=0) click to toggle source

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. @param [Array, String, Cell, Integer] x Accepts many inputs for defining the starting position of the cell. @param [Integer] y When x is an integer, this value is used for the row index at which the anchor starts.

# 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 = '') click to toggle source

Serializes the object @param [String] str @return [String]

# 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
width=(v) click to toggle source

@see width

# File lib/axlsx/drawing/one_cell_anchor.rb, line 64
def width=(v) Axlsx::validate_unsigned_int(v); @width = v; end

Private Instance Methods

ext() click to toggle source

converts the pixel width and height to EMU units and returns a hash of !{:cx=>, :cy=> @return [Hash]

# File lib/axlsx/drawing/one_cell_anchor.rb, line 91
def ext
  cy = @height * 914400 / 96
  cx = @width * 914400 / 96
  {:cy=>cy, :cx=>cx}
end