summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/util/validators.rb8
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb14
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index 9accd3db..ce810e54 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -53,6 +53,14 @@ module Axlsx
DataTypeValidator.validate(:unsigned_int, [Fixnum, Integer], v, lambda { |arg| arg.respond_to?(:>=) && arg >= 0 })
end
+ # Requires that the value is a Fixnum Integer or Float and is greater or equal to 0
+ # @param [Any] v The value validated
+ # @raise [ArgumentError] raised if the value is not a Fixnum or Integer value greater or equal to 0
+ # @return [Boolean] true if the data is valid
+ def self.validate_unsigned_numeric(v)
+ DataTypeValidator.validate("Invalid column width", [Fixnum, Integer, Float], v, lambda { |arg| arg.respond_to?(:>=) && arg >= 0 })
+ end
+
# Requires that the value is a Fixnum or Integer
# @param [Any] v The value validated
def self.validate_int(v)
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 11a2292e..aa701c9f 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -217,7 +217,19 @@ module Axlsx
end
end
end
-
+
+ # lets you specify a fixed width for any valid column in the worksheet.
+ # 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|
+ 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
+ end
+ end
+
# Adds a chart to this worksheets drawing. This is the recommended way to create charts for your worksheet. This method wraps the complexity of dealing with ooxml drawing, anchors, markers graphic frames chart objects and all the other dirty details.
# @param [Class] chart_type
# @option options [Array] start_at