class Worksheet
Public Class Methods
# File lib/jruby_excelcom/worksheet.rb, line 4 def initialize(java_ws) @ws = java_ws end
Public Instance Methods
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
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
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
sets content in a range
hash
-
must contain
:range
and:content
, e.g.{:range => 'A1:A3', :content => [1,2,3]}
. Otherwise anArgumentError
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
deletes this worksheet
# File lib/jruby_excelcom/worksheet.rb, line 21 def delete @ws.delete end
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
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
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
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
gets the name of this worksheet
# File lib/jruby_excelcom/worksheet.rb, line 15 def name @ws.getName end
sets the name of this worksheet
# File lib/jruby_excelcom/worksheet.rb, line 9 def name=(name) @ws.setName(name) end
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
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
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
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