axlsx 2.1.0.pre → 3.0.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +17 -20
- data/Rakefile +0 -1
- data/examples/conditional_formatting/example_conditional_formatting.rb +15 -0
- data/examples/example.rb +31 -1
- data/lib/axlsx.rb +9 -4
- data/lib/axlsx/drawing/area_chart.rb +99 -0
- data/lib/axlsx/drawing/area_series.rb +110 -0
- data/lib/axlsx/drawing/bar_chart.rb +143 -0
- data/lib/axlsx/drawing/chart.rb +8 -1
- data/lib/axlsx/drawing/d_lbls.rb +3 -3
- data/lib/axlsx/drawing/drawing.rb +3 -0
- data/lib/axlsx/drawing/line_series.rb +18 -1
- data/lib/axlsx/drawing/num_val.rb +3 -1
- data/lib/axlsx/drawing/one_cell_anchor.rb +2 -1
- data/lib/axlsx/drawing/pic.rb +24 -17
- data/lib/axlsx/drawing/scaling.rb +2 -2
- data/lib/axlsx/drawing/scatter_series.rb +16 -2
- data/lib/axlsx/drawing/str_val.rb +3 -1
- data/lib/axlsx/drawing/title.rb +19 -1
- data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
- data/lib/axlsx/drawing/view_3D.rb +2 -2
- data/lib/axlsx/package.rb +7 -16
- data/lib/axlsx/rels/relationships.rb +5 -2
- data/lib/axlsx/stylesheet/num_fmt.rb +9 -0
- data/lib/axlsx/stylesheet/styles.rb +1 -1
- data/lib/axlsx/util/constants.rb +8 -5
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/simple_typed_list.rb +1 -1
- data/lib/axlsx/util/validators.rb +14 -9
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/workbook.rb +19 -1
- data/lib/axlsx/workbook/workbook_view.rb +5 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +26 -19
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +15 -5
- data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -0
- data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +2 -0
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +36 -13
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +4 -1
- data/lib/axlsx/workbook/worksheet/rich_text.rb +23 -3
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +28 -32
- data/lib/axlsx/workbook/worksheet/row.rb +7 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
- data/lib/axlsx/workbook/worksheet/tables.rb +3 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +8 -51
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
- data/test/axlsx.qcachegrind +2226 -0
- data/test/drawing/tc_area_chart.rb +39 -0
- data/test/drawing/tc_area_series.rb +71 -0
- data/test/drawing/tc_bar_chart.rb +71 -0
- data/test/drawing/tc_chart.rb +23 -10
- data/test/drawing/tc_drawing.rb +2 -2
- data/test/drawing/tc_line_series.rb +38 -5
- data/test/drawing/tc_pic.rb +11 -19
- data/test/drawing/tc_scatter_series.rb +16 -5
- data/test/drawing/tc_str_val.rb +9 -0
- data/test/drawing/tc_title.rb +5 -0
- data/test/stylesheet/tc_styles.rb +2 -2
- data/test/tc_axlsx.rb +31 -0
- data/test/tc_helper.rb +3 -1
- data/test/tc_package.rb +12 -0
- data/test/util/tc_mime_type_utils.rb +13 -0
- data/test/util/tc_simple_typed_list.rb +1 -1
- data/test/util/tc_validators.rb +34 -10
- data/test/workbook/tc_shared_strings_table.rb +16 -1
- data/test/workbook/tc_workbook.rb +22 -1
- data/test/workbook/worksheet/tc_cell.rb +53 -11
- data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
- data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
- data/test/workbook/worksheet/tc_rich_text_run.rb +11 -11
- data/test/workbook/worksheet/tc_row.rb +5 -0
- data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
- data/test/workbook/worksheet/tc_table.rb +2 -3
- data/test/workbook/worksheet/tc_worksheet.rb +53 -38
- metadata +72 -20
- data/examples/IMAGE1UP.JPEG +0 -0
- data/lib/axlsx/util/string.rb +0 -7
@@ -10,14 +10,17 @@ require 'axlsx/rels/relationship.rb'
|
|
10
10
|
def initialize
|
11
11
|
super Relationship
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
# The relationship instance for the given source object, or nil if none exists.
|
15
15
|
# @see Relationship#source_obj
|
16
16
|
# @return [Relationship]
|
17
17
|
def for(source_obj)
|
18
18
|
find{ |rel| rel.source_obj == source_obj }
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
|
+
# serialize relationships
|
22
|
+
# @param [String] str
|
23
|
+
# @return [String]
|
21
24
|
def to_xml_string(str = '')
|
22
25
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
23
26
|
str << ('<Relationships xmlns="' << RELS_R << '">')
|
@@ -73,5 +73,14 @@ module Axlsx
|
|
73
73
|
serialized_tag('numFmt', str)
|
74
74
|
end
|
75
75
|
|
76
|
+
# Override to avoid removing underscores
|
77
|
+
def serialized_attributes(str = '', additional_attributes = {})
|
78
|
+
attributes = declared_attributes.merge! additional_attributes
|
79
|
+
attributes.each do |key, value|
|
80
|
+
str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.booleanize(value)}\" "
|
81
|
+
end
|
82
|
+
str
|
83
|
+
end
|
84
|
+
|
76
85
|
end
|
77
86
|
end
|
@@ -128,7 +128,7 @@ module Axlsx
|
|
128
128
|
# @option options [Boolean] i Indicates if the text should be italicised
|
129
129
|
# @option options [Boolean] u Indicates if the text should be underlined
|
130
130
|
# @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
|
131
|
-
# @option options [Boolean]
|
131
|
+
# @option options [Boolean] shadow Indicates if the text should be rendered with a shadow
|
132
132
|
# @option options [Integer] charset The character set to use.
|
133
133
|
# @option options [Integer] family The font family to use.
|
134
134
|
# @option options [String] font_name The name of the font to use
|
data/lib/axlsx/util/constants.rb
CHANGED
@@ -67,7 +67,7 @@ module Axlsx
|
|
67
67
|
APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties".freeze
|
68
68
|
|
69
69
|
# core rels namespace
|
70
|
-
CORE_R = "http://schemas.openxmlformats.org/
|
70
|
+
CORE_R = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties".freeze
|
71
71
|
|
72
72
|
# digital signature rels namespace
|
73
73
|
DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature".freeze
|
@@ -385,13 +385,16 @@ module Axlsx
|
|
385
385
|
# @see http://www.codetable.net/asciikeycodes
|
386
386
|
pattern = "\x0-\x08\x0B\x0C\x0E-\x1F"
|
387
387
|
pattern = pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
|
388
|
-
|
388
|
+
|
389
389
|
# The regular expression used to remove control characters from worksheets
|
390
390
|
CONTROL_CHARS = pattern.freeze
|
391
|
-
|
391
|
+
|
392
|
+
# ISO 8601 date recognition
|
392
393
|
ISO_8601_REGEX = /\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?\Z/.freeze
|
393
|
-
|
394
|
+
|
395
|
+
# FLOAT recognition
|
394
396
|
FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/.freeze
|
395
|
-
|
397
|
+
|
398
|
+
# Numeric recognition
|
396
399
|
NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze
|
397
400
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# This module defines some utils related with mime type detection
|
3
|
+
module MimeTypeUtils
|
4
|
+
# Detect a file mime type
|
5
|
+
# @param [String] v File path
|
6
|
+
# @return [String] File mime type
|
7
|
+
def self.get_mime_type(v)
|
8
|
+
MimeMagic.by_magic(File.open(v)).to_s
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -56,13 +56,13 @@ module Axlsx
|
|
56
56
|
raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v)
|
57
57
|
end
|
58
58
|
v_class = v.is_a?(Class) ? v : v.class
|
59
|
-
Array(types).each do |t|
|
59
|
+
Array(types).each do |t|
|
60
60
|
return if v_class <= t
|
61
61
|
end
|
62
62
|
raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
|
67
67
|
# Requires that the value can be converted to an integer
|
68
68
|
# @para, [Any] v the value to validate
|
@@ -78,18 +78,19 @@ module Axlsx
|
|
78
78
|
def self.validate_angle(v)
|
79
79
|
raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v.to_i >= -5400000 && v.to_i <= 5400000)
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
|
+
# Validates an unsigned intger
|
82
83
|
UINT_VALIDATOR = lambda { |arg| arg.respond_to?(:>=) && arg >= 0 }
|
83
|
-
|
84
|
-
# Requires that the value is a
|
84
|
+
|
85
|
+
# Requires that the value is a Integer and is greater or equal to 0
|
85
86
|
# @param [Any] v The value validated
|
86
|
-
# @raise [ArgumentError] raised if the value is not a
|
87
|
+
# @raise [ArgumentError] raised if the value is not a Integer value greater or equal to 0
|
87
88
|
# @return [Boolean] true if the data is valid
|
88
89
|
def self.validate_unsigned_int(v)
|
89
90
|
DataTypeValidator.validate(:unsigned_int, Integer, v, UINT_VALIDATOR)
|
90
91
|
end
|
91
92
|
|
92
|
-
# Requires that the value is a
|
93
|
+
# Requires that the value is a Integer or Float and is greater or equal to 0
|
93
94
|
# @param [Any] v The value validated
|
94
95
|
# @raise [ArgumentError] raised if the value is not a Fixnun, Integer, Float value greater or equal to 0
|
95
96
|
# @return [Boolean] true if the data is valid
|
@@ -104,7 +105,7 @@ module Axlsx
|
|
104
105
|
end
|
105
106
|
|
106
107
|
# Requires that the value is a form that can be evaluated as a boolean in an xml document.
|
107
|
-
# The value must be an instance of
|
108
|
+
# The value must be an instance of String, Integer, Symbol, TrueClass or FalseClass and
|
108
109
|
# it must be one of 0, 1, "true", "false", :true, :false, true, false, "0", or "1"
|
109
110
|
# @param [Any] v The value validated
|
110
111
|
def self.validate_boolean(v)
|
@@ -148,7 +149,7 @@ module Axlsx
|
|
148
149
|
RestrictionValidator.validate "cell run style u", [:none, :single, :double, :singleAccounting, :doubleAccounting], v
|
149
150
|
end
|
150
151
|
|
151
|
-
# validates cell style family which must be between 1 and 5
|
152
|
+
# validates cell style family which must be between 1 and 5
|
152
153
|
def self.validate_family(v)
|
153
154
|
RestrictionValidator.validate "cell run style family", 1..5, v
|
154
155
|
end
|
@@ -304,4 +305,8 @@ module Axlsx
|
|
304
305
|
RestrictionValidator.validate :visibility, [:visible, :hidden, :very_hidden], v
|
305
306
|
end
|
306
307
|
|
308
|
+
# Requires that the value is one of :default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x
|
309
|
+
def self.validate_marker_symbol(v)
|
310
|
+
RestrictionValidator.validate :marker_symbol, [:default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x], v
|
311
|
+
end
|
307
312
|
end
|
data/lib/axlsx/version.rb
CHANGED
@@ -11,6 +11,7 @@ require 'axlsx/workbook/worksheet/cell_serializer.rb'
|
|
11
11
|
require 'axlsx/workbook/worksheet/cell.rb'
|
12
12
|
require 'axlsx/workbook/worksheet/page_margins.rb'
|
13
13
|
require 'axlsx/workbook/worksheet/page_set_up_pr.rb'
|
14
|
+
require 'axlsx/workbook/worksheet/outline_pr.rb'
|
14
15
|
require 'axlsx/workbook/worksheet/page_setup.rb'
|
15
16
|
require 'axlsx/workbook/worksheet/header_footer.rb'
|
16
17
|
require 'axlsx/workbook/worksheet/print_options.rb'
|
@@ -96,6 +97,15 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
96
97
|
@use_shared_strings = v
|
97
98
|
end
|
98
99
|
|
100
|
+
# If true reverse the order in which the workbook is serialized
|
101
|
+
# @return [Boolean]
|
102
|
+
attr_reader :is_reversed
|
103
|
+
|
104
|
+
def is_reversed=(v)
|
105
|
+
Axlsx::validate_boolean(v)
|
106
|
+
@is_reversed = v
|
107
|
+
end
|
108
|
+
|
99
109
|
|
100
110
|
# A collection of worksheets associated with this workbook.
|
101
111
|
# @note The recommended way to manage worksheets is add_worksheet
|
@@ -270,6 +280,10 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
270
280
|
worksheet
|
271
281
|
end
|
272
282
|
|
283
|
+
# Adds a new WorkbookView
|
284
|
+
# @return WorkbookViews
|
285
|
+
# @option options [Hash] options passed into the added WorkbookView
|
286
|
+
# @see WorkbookView#initialize
|
273
287
|
def add_view(options={})
|
274
288
|
views << WorkbookView.new(options)
|
275
289
|
end
|
@@ -344,7 +358,11 @@ require 'axlsx/workbook/worksheet/selection.rb'
|
|
344
358
|
str << ('<workbookPr date1904="' << @@date1904.to_s << '"/>')
|
345
359
|
views.to_xml_string(str)
|
346
360
|
str << '<sheets>'
|
347
|
-
|
361
|
+
if is_reversed
|
362
|
+
worksheets.reverse_each { |sheet| sheet.to_sheet_node_xml_string(str) }
|
363
|
+
else
|
364
|
+
worksheets.each { |sheet| sheet.to_sheet_node_xml_string(str) }
|
365
|
+
end
|
348
366
|
str << '</sheets>'
|
349
367
|
defined_names.to_xml_string(str)
|
350
368
|
unless pivot_tables.empty?
|
@@ -33,7 +33,7 @@ module Axlsx
|
|
33
33
|
|
34
34
|
|
35
35
|
# Creates a new BookView object
|
36
|
-
# @
|
36
|
+
# @param [Hash] options A hash of key/value pairs that will be mapped to this instances attributes.
|
37
37
|
# @option [Symbol] visibility Specifies visible state of the workbook window. The default value for this attribute is :visible.
|
38
38
|
# @option [Boolean] minimized Specifies a boolean value that indicates whether the workbook window is minimized.
|
39
39
|
# @option [Boolean] show_horizontal_scroll Specifies a boolean value that indicates whether to display the horizontal scroll bar in the user interface.
|
@@ -41,7 +41,7 @@ module Axlsx
|
|
41
41
|
# @option [Boolean] show_sheet_tabs Specifies a boolean value that indicates whether to display the sheet tabs in the user interface.
|
42
42
|
# @option [Integer] tab_ratio Specifies ratio between the workbook tabs bar and the horizontal scroll bar.
|
43
43
|
# @option [Integer] first_sheet Specifies the index to the first sheet in this book view.
|
44
|
-
# @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view.
|
44
|
+
# @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view.
|
45
45
|
# @option [Integer] x_window Specifies the X coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
|
46
46
|
# @option [Integer] y_window Specifies the Y coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
|
47
47
|
# @option [Integer] window_width Specifies the width of the workbook window. The unit of measurement for this value is twips.
|
@@ -68,7 +68,9 @@ module Axlsx
|
|
68
68
|
:show_sheet_tabs, :auto_filter_date_grouping
|
69
69
|
|
70
70
|
|
71
|
-
|
71
|
+
# Serialize the WorkbookView
|
72
|
+
# @param [String] str
|
73
|
+
# @return [String]
|
72
74
|
def to_xml_string(str = '')
|
73
75
|
str << '<workbookView '
|
74
76
|
serialized_attributes str
|
@@ -37,14 +37,14 @@ module Axlsx
|
|
37
37
|
# to get less GC cycles
|
38
38
|
type = options.delete(:type) || cell_type_from_value(value)
|
39
39
|
self.type = type unless type == :string
|
40
|
-
|
40
|
+
|
41
41
|
|
42
42
|
val = options.delete(:style)
|
43
43
|
self.style = val unless val.nil? || val == 0
|
44
44
|
val = options.delete(:formula_value)
|
45
45
|
self.formula_value = val unless val.nil?
|
46
|
-
|
47
|
-
parse_options(options)
|
46
|
+
|
47
|
+
parse_options(options)
|
48
48
|
|
49
49
|
self.value = value
|
50
50
|
value.cell = self if contains_rich_text?
|
@@ -64,9 +64,10 @@ module Axlsx
|
|
64
64
|
:family, :b, :i, :strike, :outline,
|
65
65
|
:shadow, :condense, :extend, :u,
|
66
66
|
:vertAlign, :sz, :color, :scheme].freeze
|
67
|
-
|
67
|
+
|
68
|
+
# An array of valid cell types
|
68
69
|
CELL_TYPES = [:date, :time, :float, :integer, :richtext,
|
69
|
-
:string, :boolean, :iso_8601].freeze
|
70
|
+
:string, :boolean, :iso_8601, :text].freeze
|
70
71
|
|
71
72
|
# The index of the cellXfs item to be applied to this cell.
|
72
73
|
# @return [Integer]
|
@@ -79,7 +80,7 @@ module Axlsx
|
|
79
80
|
# @return [Row]
|
80
81
|
attr_reader :row
|
81
82
|
|
82
|
-
# The cell's data type.
|
83
|
+
# The cell's data type.
|
83
84
|
# Changing the type for a cell will recast the value into that type. If no type option is specified in the constructor, the type is
|
84
85
|
# automatically determed.
|
85
86
|
# @see Cell#cell_type_from_value
|
@@ -93,7 +94,7 @@ module Axlsx
|
|
93
94
|
def type
|
94
95
|
defined?(@type) ? @type : :string
|
95
96
|
end
|
96
|
-
|
97
|
+
|
97
98
|
# @see type
|
98
99
|
def type=(v)
|
99
100
|
RestrictionValidator.validate :cell_type, CELL_TYPES, v
|
@@ -104,7 +105,7 @@ module Axlsx
|
|
104
105
|
# The value of this cell.
|
105
106
|
# @return [String, Integer, Float, Time, Boolean] casted value based on cell's type attribute.
|
106
107
|
attr_reader :value
|
107
|
-
|
108
|
+
|
108
109
|
# @see value
|
109
110
|
def value=(v)
|
110
111
|
#TODO: consider doing value based type determination first?
|
@@ -115,15 +116,15 @@ module Axlsx
|
|
115
116
|
# @return [Boolean]
|
116
117
|
def is_text_run?
|
117
118
|
defined?(@is_text_run) && @is_text_run && !contains_rich_text?
|
118
|
-
end
|
119
|
-
|
119
|
+
end
|
120
|
+
|
120
121
|
def contains_rich_text?
|
121
122
|
type == :richtext
|
122
123
|
end
|
123
|
-
|
124
|
+
|
124
125
|
# Indicates if the cell is good for shared string table
|
125
126
|
def plain_string?
|
126
|
-
type == :string && # String typed
|
127
|
+
(type == :string || type == :text) && # String typed
|
127
128
|
!is_text_run? && # No inline styles
|
128
129
|
!@value.nil? && # Not nil
|
129
130
|
!@value.empty? && # Not empty
|
@@ -347,7 +348,9 @@ module Axlsx
|
|
347
348
|
|
348
349
|
# returns the name of the cell
|
349
350
|
attr_reader :name
|
350
|
-
|
351
|
+
|
352
|
+
# Attempts to determine the correct width for this cell's content
|
353
|
+
# @return [Float]
|
351
354
|
def autowidth
|
352
355
|
return if is_formula? || value.nil?
|
353
356
|
if contains_rich_text?
|
@@ -363,12 +366,12 @@ module Axlsx
|
|
363
366
|
string_width(value, font_size)
|
364
367
|
end
|
365
368
|
end
|
366
|
-
|
369
|
+
|
367
370
|
# Returns the sanatized value
|
368
371
|
# TODO find a better way to do this as it accounts for 30% of
|
369
372
|
# processing time in benchmarking...
|
370
373
|
def clean_value
|
371
|
-
if type == :string && !Axlsx::trust_input
|
374
|
+
if (type == :string || type == :text) && !Axlsx::trust_input
|
372
375
|
Axlsx::sanitize(::CGI.escapeHTML(@value.to_s))
|
373
376
|
else
|
374
377
|
@value.to_s
|
@@ -376,17 +379,17 @@ module Axlsx
|
|
376
379
|
end
|
377
380
|
|
378
381
|
private
|
379
|
-
|
382
|
+
|
380
383
|
def styles
|
381
384
|
row.worksheet.styles
|
382
385
|
end
|
383
|
-
|
386
|
+
|
384
387
|
# Returns the width of a string according to the current style
|
385
388
|
# This is still not perfect...
|
386
389
|
# - scaling is not linear as font sizes increase
|
387
390
|
def string_width(string, font_size)
|
388
391
|
font_scale = font_size / 10.0
|
389
|
-
(string.to_s.count(Worksheet::THIN_CHARS) + 3.0) *
|
392
|
+
(string.to_s.count(Worksheet::THIN_CHARS) + 3.0) * font_scale
|
390
393
|
end
|
391
394
|
|
392
395
|
# we scale the font size if bold style is applied to either the style font or
|
@@ -452,7 +455,11 @@ module Axlsx
|
|
452
455
|
v
|
453
456
|
when :time
|
454
457
|
self.style = STYLE_DATE if self.style == 0
|
455
|
-
v.
|
458
|
+
if !v.is_a?(Time) && v.respond_to?(:to_time)
|
459
|
+
v.to_time
|
460
|
+
else
|
461
|
+
v
|
462
|
+
end
|
456
463
|
when :float
|
457
464
|
v.to_f
|
458
465
|
when :integer
|
@@ -14,7 +14,7 @@ module Axlsx
|
|
14
14
|
method = cell.type
|
15
15
|
self.send(method, cell, str)
|
16
16
|
str << '</c>'
|
17
|
-
end
|
17
|
+
end
|
18
18
|
|
19
19
|
# builds an xml text run based on this cells attributes.
|
20
20
|
# @param [String] str The string instance this run will be concated to.
|
@@ -22,7 +22,7 @@ module Axlsx
|
|
22
22
|
def run_xml_string(cell, str = '')
|
23
23
|
if cell.is_text_run?
|
24
24
|
valid = RichTextRun::INLINE_STYLES - [:value, :type]
|
25
|
-
data = Hash[cell.instance_values.map{ |k, v| [k.to_sym, v] }]
|
25
|
+
data = Hash[cell.instance_values.map{ |k, v| [k.to_sym, v] }]
|
26
26
|
data = data.select { |key, value| valid.include?(key) && !value.nil? }
|
27
27
|
RichText.new(cell.value.to_s, data).to_xml_string(str)
|
28
28
|
elsif cell.contains_rich_text?
|
@@ -124,7 +124,7 @@ module Axlsx
|
|
124
124
|
inline_string_serialization cell, str
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
# Serializes cells that are of the type richtext
|
129
129
|
# @param [Cell] cell The cell that is being serialized
|
130
130
|
# @param [String] str The string the serialized content will be appended to.
|
@@ -137,6 +137,18 @@ module Axlsx
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
# Serializes cells that are of the type text
|
141
|
+
# @param [Cell] cell The cell that is being serialized
|
142
|
+
# @param [String] str The string the serialized content will be appended to.
|
143
|
+
# @return [String]
|
144
|
+
def text(cell, str)
|
145
|
+
if cell.ssti.nil?
|
146
|
+
inline_string_serialization cell, str
|
147
|
+
else
|
148
|
+
value_serialization 's', cell.ssti, str
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
140
152
|
private
|
141
153
|
|
142
154
|
def numeric(cell, str = '')
|
@@ -147,8 +159,6 @@ module Axlsx
|
|
147
159
|
str << ('t="' << serialization_type.to_s << '"') if serialization_type
|
148
160
|
str << ('><v>' << serialization_value.to_s << '</v>')
|
149
161
|
end
|
150
|
-
|
151
|
-
|
152
162
|
end
|
153
163
|
end
|
154
164
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Axlsx
|
2
2
|
|
3
|
-
# The cols class manages the col object used to manage column widths.
|
3
|
+
# The cols class manages the col object used to manage column widths.
|
4
4
|
# This is where the magic happens with autowidth
|
5
5
|
class Cols < SimpleTypedList
|
6
6
|
|
@@ -10,11 +10,14 @@ module Axlsx
|
|
10
10
|
@worksheet = worksheet
|
11
11
|
end
|
12
12
|
|
13
|
+
# Serialize the Cols object
|
14
|
+
# @param [String] str
|
15
|
+
# @return [String]
|
13
16
|
def to_xml_string(str = '')
|
14
17
|
return if empty?
|
15
18
|
str << '<cols>'
|
16
19
|
each { |item| item.to_xml_string(str) }
|
17
|
-
str << '</cols>'
|
20
|
+
str << '</cols>'
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|