summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-02-14 08:33:39 +0900
committerRandy Morgan <[email protected]>2012-02-14 08:33:39 +0900
commit8bcc77953262fd934bd4b84daf53d946c576193b (patch)
tree4179fefc544b92aeaee97a031dd083a52423aac8
parent80459ca70930ee8522b8547669bbbe7aef5a12a4 (diff)
downloadcaxlsx-8bcc77953262fd934bd4b84daf53d946c576193b.tar.gz
caxlsx-8bcc77953262fd934bd4b84daf53d946c576193b.zip
changing column_widths to accept *args instead of a declared array.
-rw-r--r--README.md8
-rw-r--r--examples/example.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/row.rb14
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb11
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb8
5 files changed, 30 insertions, 13 deletions
diff --git a/README.md b/README.md
index 23fe446a..a0aafa0a 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Axlsx: Office Open XML Spreadsheet Generation
**Latest Version**: 1.0.17
**Ruby Version**: 1.8.7, 1.9.2, 1.9.3
-**Release Date**: February 13th 2012
+**Release Date**: February 14th 2012
Synopsis
--------
@@ -262,7 +262,7 @@ To install Axlsx, use the following command:
wb.add_worksheet(:name => "custom column widths") do |sheet|
sheet.add_row ["I use auto_fit and am very wide", "I use a custom width and am narrow"]
- sheet.column_widths [nil, 3]
+ sheet.column_widths nil, 3
end
##Validate and Serialize
@@ -294,11 +294,11 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
#Changelog
---------
-- ** February.13.12**: 1.0.17 release
+- ** February.14.12**: 1.0.17 release
https://github.com/randym/axlsx/compare/1.0.16...1.0.17
- Added in support for serializing to StringIO
- Added in support for using shared strings table. This makes most of the features in axlsx interoperable with iWorks Numbers
- - Added in support for fixed column widths via worksheet.auto_fit_data[index][:fixed] = Int||Float
+ - Added in support for fixed column_widths
- Removed unneded depenencies on activesupport and i18n
- ** February.2.12**: 1.0.16 release
diff --git a/examples/example.rb b/examples/example.rb
index 552a5fc9..b06f0544 100644
--- a/examples/example.rb
+++ b/examples/example.rb
@@ -191,7 +191,7 @@
wb.add_worksheet(:name => "custom column widths") do |sheet|
sheet.add_row ["I use autowidth and am very wide", "I use a custom width and am narrow"]
- sheet.column_widths [nil, 3]
+ sheet.column_widths nil, 3
end
##Validate and Serialize
diff --git a/lib/axlsx/workbook/worksheet/row.rb b/lib/axlsx/workbook/worksheet/row.rb
index 61bd4d8f..9c35a302 100644
--- a/lib/axlsx/workbook/worksheet/row.rb
+++ b/lib/axlsx/workbook/worksheet/row.rb
@@ -13,6 +13,20 @@ module Axlsx
# @return [SimpleTypedList]
attr_reader :cells
+ # TODO 18.3.1.73
+ # collapsed
+ # customFormat
+ # customHeight
+ # hidden
+ # ht (height)
+ # outlineLevel
+ # ph
+ # s (style)
+ # spans
+ # thickTop
+ # thickBottom
+
+
# Creates a new row. New Cell objects are created based on the values, types and style options.
# A new cell is created for each item in the values array. style and types options are applied as follows:
# If the types option is defined and is a symbol it is applied to all the cells created.
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index aa701c9f..16aeffa1 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -218,12 +218,15 @@ module Axlsx
end
end
- # lets you specify a fixed width for any valid column in the worksheet.
+ # This is a helper method that Lets you specify a fixed width for multiple columns in a worksheet in one go.
# Axlsx is sparse, so if you have not set data for a column, you cannot set the width.
# Setting a fixed column width to nil will revert the behaviour back to calculating the width for you.
- # @option options [Array] a array of column widths. Use nil memebers do default to the auto-fit behaviour. Values should be nil or an unsigned Integer, Float or Fixnum
- def column_widths(options=[])
- options.each_with_index do |value, index|
+ # @example This would set the first and third column widhts but leave the second column in autofit state.
+ # ws.column_widths 7.2, nil, 3
+ # @note For updating only a single column it is probably easier to just set ws.auto_fit_data[col_index][:fixed] directly
+ # @param [Integer|Float|Fixnum|nil] values
+ def column_widths(*args)
+ args.each_with_index do |value, index|
raise ArgumentError, "Invalid column specification" unless index < @auto_fit_data.size
Axlsx::validate_unsigned_numeric(value) unless value == nil
@auto_fit_data[index][:fixed] = value
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index a6f9b304..e50490d0 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -153,11 +153,11 @@ class TestWorksheet < Test::Unit::TestCase
def test_set_column_width
@ws.add_row ["chasing windmills", "penut"]
assert_equal(@ws.auto_fit_data[0][:fixed], nil, 'no fixed by default')
- @ws.column_widths [nil, 0.5]
+ @ws.column_widths nil, 0.5
assert_equal(@ws.auto_fit_data[1][:fixed], 0.5, 'eat my width')
- assert_raise(ArgumentError, 'reject invalid columns') { @ws.column_widths [2, 7, nil] }
- assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths [2, 7, -1] }
- assert_raise(ArgumentError, 'only accept Integer, Float or Fixnum') { @ws.column_widths [2, 7, "-1"] }
+ assert_raise(ArgumentError, 'reject invalid columns') { @ws.column_widths 2, 7, nil }
+ assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths 2, 7, -1 }
+ assert_raise(ArgumentError, 'only accept Integer, Float or Fixnum') { @ws.column_widths 2, 7, "-1" }
end