diff options
| author | Stefan Daschek <[email protected]> | 2012-02-27 21:11:36 +0100 |
|---|---|---|
| committer | Stefan Daschek <[email protected]> | 2012-02-27 21:11:53 +0100 |
| commit | cf69408bec13982d6b22cd1c91ec6a52da6c3920 (patch) | |
| tree | 449841b0cad0640ef4e8fab9f5797ee56acb3fe0 /lib | |
| parent | 6440dced8ff2da027fd4f60f434262ec60191573 (diff) | |
| download | caxlsx-cf69408bec13982d6b22cd1c91ec6a52da6c3920.tar.gz caxlsx-cf69408bec13982d6b22cd1c91ec6a52da6c3920.zip | |
Add support for rows with custom height.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/row.rb | 22 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 4 |
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/axlsx/workbook/worksheet/row.rb b/lib/axlsx/workbook/worksheet/row.rb index 9c35a302..e24514bc 100644 --- a/lib/axlsx/workbook/worksheet/row.rb +++ b/lib/axlsx/workbook/worksheet/row.rb @@ -13,12 +13,14 @@ module Axlsx # @return [SimpleTypedList] attr_reader :cells + # The height of this row in points, if set explicitly. + # @return [Float] + attr_reader :height + # TODO 18.3.1.73 # collapsed # customFormat - # customHeight # hidden - # ht (height) # outlineLevel # ph # s (style) @@ -39,12 +41,14 @@ module Axlsx # @option options [Array] values # @option options [Array, Symbol] types # @option options [Array, Integer] style + # @option options [Float] height the row's height (in points) # @see Row#array_to_cells # @see Cell def initialize(worksheet, values=[], options={}) self.worksheet = worksheet @cells = SimpleTypedList.new Cell @worksheet.rows << self + self.height = options.delete(:height) if options[:height] array_to_cells(values, options) end @@ -58,7 +62,9 @@ module Axlsx # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. # @return [String] def to_xml(xml) - xml.row(:r => index+1) { @cells.each { |cell| cell.to_xml(xml) } } + attrs = {:r => index+1} + attrs.merge!(:customHeight => 1, :ht => height) if custom_height? + xml.row(attrs) { |xml| @cells.each { |cell| cell.to_xml(xml) } } end # Adds a singel sell to the row based on the data provided and updates the worksheet's autofit data. @@ -84,6 +90,16 @@ module Axlsx @cells.to_ary end + # @see height + def height=(v); Axlsx::validate_unsigned_numeric(v) unless v.nil?; @height = v end + + # true if the row height has been manually set + # @return [Boolean] + # @see #height + def custom_height? + @height != nil + end + private # assigns the owning worksheet for this row diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 7622aba0..63ff1310 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -205,6 +205,9 @@ module Axlsx # # ws.add_row ['I wish', 'for a fish', 'on my fish wish dish'], :widths=>[:ignore, :auto, 80] # + # @example - specify a fixed height for a row + # ws.add_row ['I wish', 'for a fish', 'on my fish wish dish'], :height => 40 + # # @example - create and use a style for all cells in the row # blue = ws.styles.add_style :color => "#00FF00" # ws.add_row [1, 2, 3], :style=>blue @@ -225,6 +228,7 @@ module Axlsx # @option options [Array, Symbol] types # @option options [Array, Integer] style # @option options [Array] widths each member of the widths array will affect how auto_fit behavies. + # @option options [Float] height the row's height (in points) def add_row(values=[], options={}) Row.new(self, values, options) update_auto_fit_data @rows.last.cells, options.delete(:widths) || [] |
