class Worksheet

Public Class Methods

new(java_ws) click to toggle source
# File lib/jruby_excelcom/worksheet.rb, line 4
def initialize(java_ws)
  @ws = java_ws
end

Public Instance Methods

border_color(range) click to toggle source

gets the border color of cells in range. Throws a NullpointerException if range contains multiple colors

# File lib/jruby_excelcom/worksheet.rb, line 128
def border_color(range)
  @ws.getBorderColor(range)
end
Also aliased as: getBorderColor
border_color=(hash) click to toggle source

sets border color of cells in range

hash

must contain :range and :color

# File lib/jruby_excelcom/worksheet.rb, line 121
def border_color=(hash)
  raise ArgumentError, 'cannot set border color, argument is not a hash' unless hash.is_a? Hash
  raise ArgumentError, 'cannot set border color, hash does not contain :range or :color key' if hash[:range].nil? or hash[:color].nil?
  set_border_color hash[:range], hash[:color]
end
content(range = 'UsedRange') click to toggle source

returns the content in range as a matrix, a vector or a single value, depending on range's dimensions

range

range with content to get, default value is UsedRange

# File lib/jruby_excelcom/worksheet.rb, line 27
def content(range = 'UsedRange')
  c = @ws.getContent(range).to_a.each{ |row| row.to_a }
  columns = c.size
  rows = columns > 0 ? c[0].size : 0
  if columns == 1 and rows == 1 # range is one cell
    c[0][0].is_a?(Java::JavaUtil::Date) ? Time.at(c[0][0].getTime/1000) : c[0][0]
  elsif (columns > 1 and rows == 1) or (columns == 1 and rows > 1) # range is one column or row
      c.flatten.map!{|cell| cell.is_a?(Java::JavaUtil::Date) ? Time.at(cell.getTime/1000) : cell }
  else # range is a matrix
    c.map!{|row| row.map!{|cell| cell.is_a?(Java::JavaUtil::Date) ? Time.at(cell.getTime/1000) : cell }}
  end
end
Also aliased as: getContent
content=(hash) click to toggle source

sets content in a range

hash

must contain :range and :content, e.g. {:range => 'A1:A3', :content => [1,2,3]}. Otherwise an ArgumentError is raised

# File lib/jruby_excelcom/worksheet.rb, line 61
def content=(hash)
  raise ArgumentError, 'cannot set content, argument is not a hash' unless hash.is_a? Hash
  raise ArgumentError, 'cannot set content, hash does not contain :range or :content key' if hash[:range].nil? or hash[:content].nil?
  set_content hash[:range], hash[:content]
end
delete() click to toggle source

deletes this worksheet

# File lib/jruby_excelcom/worksheet.rb, line 21
def delete
  @ws.delete
end
fill_color(range) click to toggle source

gets the fill color of cells in range. Throws a NullpointerException if range contains multiple colors

# File lib/jruby_excelcom/worksheet.rb, line 84
def fill_color(range)
  @ws.getFillColor(range)
end
Also aliased as: getFillColor
fill_color=(hash) click to toggle source

fills cells in range with color

hash

must contain :range and :color

# File lib/jruby_excelcom/worksheet.rb, line 77
def fill_color=(hash)
  raise ArgumentError, 'cannot set fill color, argument is not a hash' unless hash.is_a? Hash
  raise ArgumentError, 'cannot set fill color, hash does not contain :range or :color key' if hash[:range].nil? or hash[:color].nil?
  set_fill_color hash[:range], hash[:color]
end
font_color(range) click to toggle source

gets the font color of cells in range. Throws a NullpointerException if range contains multiple colors

# File lib/jruby_excelcom/worksheet.rb, line 106
def font_color(range)
  @ws.getFontColor(range)
end
Also aliased as: getFontColor
font_color=(hash) click to toggle source

sets font color of cells in range

hash

must contain :range and :color

# File lib/jruby_excelcom/worksheet.rb, line 99
def font_color=(hash)
  raise ArgumentError, 'cannot set font color, argument is not a hash' unless hash.is_a? Hash
  raise ArgumentError, 'cannot set font color, hash does not contain :range or :color key' if hash[:range].nil? or hash[:color].nil?
  set_font_color hash[:range], hash[:color]
end
getBorderColor(range)
Alias for: border_color
getContent(range = 'UsedRange')
Alias for: content
getFillColor(range)
Alias for: fill_color
getFontColor(range)
Alias for: font_color
getName()
Alias for: name
name() click to toggle source

gets the name of this worksheet

# File lib/jruby_excelcom/worksheet.rb, line 15
def name
  @ws.getName
end
Also aliased as: getName
name=(name) click to toggle source

sets the name of this worksheet

# File lib/jruby_excelcom/worksheet.rb, line 9
def name=(name)
  @ws.setName(name)
end
Also aliased as: setName
setBorderColor(range, color)
Alias for: set_border_color
setContent(range, content)
Alias for: set_content
setFillColor(range, color)
Alias for: set_fill_color
setFontColor(range, color)
Alias for: set_font_color
setName(name)
Alias for: name=
set_border_color(range, color) click to toggle source

sets border color of cells in range

range

range to be colorized

color

color to be used, must be an ExcelColor, e.g. ExcelColor::RED

# File lib/jruby_excelcom/worksheet.rb, line 114
def set_border_color(range, color)
  @ws.setBorderColor(range, color)
end
Also aliased as: setBorderColor
set_content(range, content) click to toggle source

sets content in a range

range

range in worksheet, e.g. 'A1:B3'

content

may be a matrix, a vector or a single value. If it's a matrix or vector, its dimensions must be equal to range's dimensions

# File lib/jruby_excelcom/worksheet.rb, line 44
def set_content(range, content)
  if content.is_a?(Array)
    if content[0].is_a?(Array) # content is a matrix
      @ws.java_send :setContent, [java.lang.String, java.lang.Object[][]], range, content
    elsif JavaExcelcom::Util::getRangeSize(range)[0] == 1 # content is a row
      @ws.java_send :setContent, [java.lang.String, java.lang.Object[][]], range, [content]
    else # content is a column
      @ws.java_send :setContent, [java.lang.String, java.lang.Object[][]], range, content.map{|cell| [cell] }
    end
  else # content is a single value
    @ws.java_send :setContent, [java.lang.String, java.lang.Object], range, content
  end
end
Also aliased as: setContent
set_fill_color(range, color) click to toggle source

fills cells in range with color

range

range to be colorized

color

color to be used, must be an ExcelColor, e.g. ExcelColor::RED

# File lib/jruby_excelcom/worksheet.rb, line 70
def set_fill_color(range, color)
  @ws.setFillColor(range, color)
end
Also aliased as: setFillColor
set_font_color(range, color) click to toggle source

sets font color of cells in range

range

range to be colorized

color

color to be used, must be an ExcelColor, e.g. ExcelColor::RED

# File lib/jruby_excelcom/worksheet.rb, line 92
def set_font_color(range, color)
  @ws.setFontColor(range, color)
end
Also aliased as: setFontColor