caxlsx 3.3.0 → 4.5.0
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 +87 -11
- data/README.md +43 -16
- data/Rakefile +5 -11
- data/examples/generate.rb +3 -1
- data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
- data/lib/axlsx/content_type/content_type.rb +8 -10
- data/lib/axlsx/content_type/default.rb +7 -6
- data/lib/axlsx/content_type/override.rb +6 -5
- data/lib/axlsx/doc_props/app.rb +96 -32
- data/lib/axlsx/doc_props/core.rb +9 -12
- data/lib/axlsx/drawing/area_chart.rb +16 -17
- data/lib/axlsx/drawing/area_series.rb +23 -18
- data/lib/axlsx/drawing/ax_data_source.rb +4 -7
- data/lib/axlsx/drawing/axes.rb +11 -10
- data/lib/axlsx/drawing/axis.rb +83 -36
- data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
- data/lib/axlsx/drawing/bar_chart.rb +29 -20
- data/lib/axlsx/drawing/bar_series.rb +23 -18
- data/lib/axlsx/drawing/bubble_chart.rb +9 -10
- data/lib/axlsx/drawing/bubble_series.rb +11 -12
- data/lib/axlsx/drawing/cat_axis.rb +38 -28
- data/lib/axlsx/drawing/chart.rb +52 -30
- data/lib/axlsx/drawing/d_lbls.rb +36 -32
- data/lib/axlsx/drawing/drawing.rb +61 -62
- data/lib/axlsx/drawing/graphic_frame.rb +6 -7
- data/lib/axlsx/drawing/hyperlink.rb +22 -14
- data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
- data/lib/axlsx/drawing/line_chart.rb +16 -17
- data/lib/axlsx/drawing/line_series.rb +23 -18
- data/lib/axlsx/drawing/marker.rb +29 -16
- data/lib/axlsx/drawing/num_data.rb +13 -16
- data/lib/axlsx/drawing/num_data_source.rb +11 -13
- data/lib/axlsx/drawing/num_val.rb +10 -11
- data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
- data/lib/axlsx/drawing/pic.rb +68 -24
- data/lib/axlsx/drawing/picture_locking.rb +6 -7
- data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
- data/lib/axlsx/drawing/pie_chart.rb +36 -0
- data/lib/axlsx/drawing/pie_series.rb +26 -17
- data/lib/axlsx/drawing/scaling.rb +26 -13
- data/lib/axlsx/drawing/scatter_chart.rb +10 -11
- data/lib/axlsx/drawing/scatter_series.rb +17 -18
- data/lib/axlsx/drawing/ser_axis.rb +22 -19
- data/lib/axlsx/drawing/series.rb +14 -8
- data/lib/axlsx/drawing/series_title.rb +6 -6
- data/lib/axlsx/drawing/str_data.rb +10 -13
- data/lib/axlsx/drawing/str_val.rb +8 -9
- data/lib/axlsx/drawing/title.rb +23 -27
- data/lib/axlsx/drawing/two_cell_anchor.rb +9 -9
- data/lib/axlsx/drawing/val_axis.rb +7 -8
- data/lib/axlsx/drawing/view_3D.rb +38 -30
- data/lib/axlsx/drawing/vml_drawing.rb +19 -20
- data/lib/axlsx/drawing/vml_shape.rb +25 -26
- data/lib/axlsx/package.rb +134 -99
- data/lib/axlsx/rels/relationship.rb +42 -30
- data/lib/axlsx/rels/relationships.rb +9 -10
- data/lib/axlsx/stylesheet/border.rb +16 -8
- data/lib/axlsx/stylesheet/border_pr.rb +24 -12
- data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
- data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
- data/lib/axlsx/stylesheet/cell_style.rb +36 -15
- data/lib/axlsx/stylesheet/color.rb +23 -14
- data/lib/axlsx/stylesheet/dxf.rb +36 -15
- data/lib/axlsx/stylesheet/fill.rb +7 -6
- data/lib/axlsx/stylesheet/font.rb +71 -22
- data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
- data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
- data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
- data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
- data/lib/axlsx/stylesheet/styles.rb +167 -118
- data/lib/axlsx/stylesheet/table_style.rb +20 -10
- data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
- data/lib/axlsx/stylesheet/table_styles.rb +16 -11
- data/lib/axlsx/stylesheet/theme.rb +163 -0
- data/lib/axlsx/stylesheet/xf.rb +78 -25
- data/lib/axlsx/util/accessors.rb +13 -11
- data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
- data/lib/axlsx/util/constants.rb +133 -110
- data/lib/axlsx/util/mime_type_utils.rb +75 -5
- data/lib/axlsx/util/options_parser.rb +4 -3
- data/lib/axlsx/util/serialized_attributes.rb +47 -23
- data/lib/axlsx/util/simple_typed_list.rb +77 -64
- data/lib/axlsx/util/storage.rb +38 -41
- data/lib/axlsx/util/uri_utils.rb +70 -0
- data/lib/axlsx/util/validators.rb +111 -48
- data/lib/axlsx/util/zip_command.rb +10 -12
- data/lib/axlsx/version.rb +3 -2
- data/lib/axlsx/workbook/defined_name.rb +13 -9
- data/lib/axlsx/workbook/defined_names.rb +5 -4
- data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
- data/lib/axlsx/workbook/workbook.rb +152 -120
- data/lib/axlsx/workbook/workbook_view.rb +9 -12
- data/lib/axlsx/workbook/workbook_views.rb +5 -5
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
- data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
- data/lib/axlsx/workbook/worksheet/break.rb +4 -5
- data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
- data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
- data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
- data/lib/axlsx/workbook/worksheet/col.rb +32 -19
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
- data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
- data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
- data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
- data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
- data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
- data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
- data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
- data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
- data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
- data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
- data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
- data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
- data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
- data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
- data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
- data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
- data/lib/axlsx/workbook/worksheet/row.rb +34 -23
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
- data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -7
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +12 -8
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
- data/lib/axlsx/workbook/worksheet/table.rb +13 -13
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
- data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
- data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
- data/lib/axlsx.rb +120 -60
- data/lib/caxlsx.rb +3 -2
- metadata +42 -75
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# The SheetPr class manages serialization of a worksheet's sheetPr element.
|
|
4
5
|
class SheetPr
|
|
5
6
|
include Axlsx::OptionsParser
|
|
@@ -17,7 +18,7 @@ module Axlsx
|
|
|
17
18
|
:sync_ref
|
|
18
19
|
|
|
19
20
|
# These attributes are all boolean so I'm doing a bit of a hand
|
|
20
|
-
# waving magic show to set up the
|
|
21
|
+
# waving magic show to set up the attribute accessors
|
|
21
22
|
boolean_attr_accessor :sync_horizontal,
|
|
22
23
|
:sync_vertical,
|
|
23
24
|
:transition_evaluation,
|
|
@@ -30,8 +31,9 @@ module Axlsx
|
|
|
30
31
|
|
|
31
32
|
# Creates a new SheetPr object
|
|
32
33
|
# @param [Worksheet] worksheet The worksheet that owns this SheetPr object
|
|
33
|
-
def initialize(worksheet, options={})
|
|
34
|
+
def initialize(worksheet, options = {})
|
|
34
35
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
|
36
|
+
|
|
35
37
|
@worksheet = worksheet
|
|
36
38
|
@outline_pr = nil
|
|
37
39
|
parse_options options
|
|
@@ -48,9 +50,11 @@ module Axlsx
|
|
|
48
50
|
# Serialize the object
|
|
49
51
|
# @param [String] str serialized output will be appended to this object if provided.
|
|
50
52
|
# @return [String]
|
|
51
|
-
def to_xml_string(str = '')
|
|
53
|
+
def to_xml_string(str = +'')
|
|
52
54
|
update_properties
|
|
53
|
-
str <<
|
|
55
|
+
str << '<sheetPr '
|
|
56
|
+
serialized_attributes(str)
|
|
57
|
+
str << '>'
|
|
54
58
|
tab_color.to_xml_string(str, 'tabColor') if tab_color
|
|
55
59
|
outline_pr.to_xml_string(str) if @outline_pr
|
|
56
60
|
page_setup_pr.to_xml_string(str)
|
|
@@ -62,7 +66,7 @@ module Axlsx
|
|
|
62
66
|
def page_setup_pr
|
|
63
67
|
@page_setup_pr ||= PageSetUpPr.new
|
|
64
68
|
end
|
|
65
|
-
|
|
69
|
+
|
|
66
70
|
# The OutlinePr for this sheet pr object
|
|
67
71
|
# @return [OutlinePr]
|
|
68
72
|
def outline_pr
|
|
@@ -71,14 +75,14 @@ module Axlsx
|
|
|
71
75
|
|
|
72
76
|
# @see tab_color
|
|
73
77
|
def tab_color=(v)
|
|
74
|
-
@tab_color
|
|
78
|
+
@tab_color = Color.new(rgb: v)
|
|
75
79
|
end
|
|
76
80
|
|
|
77
81
|
private
|
|
78
82
|
|
|
79
83
|
def update_properties
|
|
80
84
|
page_setup_pr.fit_to_page = worksheet.fit_to_page?
|
|
81
|
-
|
|
85
|
+
unless worksheet.auto_filter.columns.empty?
|
|
82
86
|
self.filter_mode = 1
|
|
83
87
|
self.enable_format_conditions_calculation = 1
|
|
84
88
|
end
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
#
|
|
2
|
-
module Axlsx
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
3
|
+
module Axlsx
|
|
4
4
|
# The SheetProtection object manages worksheet protection options per sheet.
|
|
5
5
|
class SheetProtection
|
|
6
|
-
|
|
7
6
|
include Axlsx::OptionsParser
|
|
8
7
|
include Axlsx::SerializedAttributes
|
|
9
8
|
include Axlsx::Accessors
|
|
@@ -26,7 +25,7 @@ module Axlsx
|
|
|
26
25
|
# @option options [Boolean] pivot_tables @see SheetProtection#pivot_tables
|
|
27
26
|
# @option options [Boolean] select_unlocked_cells @see SheetProtection#select_unlocked_cells
|
|
28
27
|
# @option options [String] password. The password required for unlocking. @see SheetProtection#password=
|
|
29
|
-
def initialize(options={})
|
|
28
|
+
def initialize(options = {})
|
|
30
29
|
@objects = @scenarios = @select_locked_cells = @select_unlocked_cells = false
|
|
31
30
|
@sheet = @format_cells = @format_rows = @format_columns = @insert_columns = @insert_rows = @insert_hyperlinks = @delete_columns = @delete_rows = @sort = @auto_filter = @pivot_tables = true
|
|
32
31
|
@password = nil
|
|
@@ -34,12 +33,12 @@ module Axlsx
|
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
boolean_attr_accessor :sheet, :objects, :scenarios, :format_cells, :format_columns, :format_rows,
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
:insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns, :delete_rows,
|
|
37
|
+
:select_locked_cells, :sort, :auto_filter, :pivot_tables, :select_unlocked_cells
|
|
39
38
|
|
|
40
39
|
serializable_attributes :sheet, :objects, :scenarios, :format_cells, :format_columns, :format_rows,
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
:insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns, :delete_rows,
|
|
41
|
+
:select_locked_cells, :sort, :auto_filter, :pivot_tables, :select_unlocked_cells, :salt, :password
|
|
43
42
|
|
|
44
43
|
# Specifies the salt which was prepended to the user-supplied password before it was hashed using the hashing algorithm
|
|
45
44
|
# @return [String]
|
|
@@ -50,9 +49,9 @@ module Axlsx
|
|
|
50
49
|
# default nil
|
|
51
50
|
attr_reader :password
|
|
52
51
|
|
|
53
|
-
# This block is intended to implement the salt_value, hash_value and spin count as per the ECMA-376 standard.
|
|
54
|
-
# However, it does not seem to actually work in EXCEL - instead they are using their old retro algorithm shown below
|
|
55
|
-
# defined in the transitional portion of the speck. I am leaving this code in in the hope that someday Ill be able to
|
|
52
|
+
# This block is intended to implement the salt_value, hash_value and spin count as per the ECMA-376 standard.
|
|
53
|
+
# However, it does not seem to actually work in EXCEL - instead they are using their old retro algorithm shown below
|
|
54
|
+
# defined in the transitional portion of the speck. I am leaving this code in in the hope that someday Ill be able to
|
|
56
55
|
# figure out why it does not work, and if Excel even supports it.
|
|
57
56
|
# def propper_password=(v)
|
|
58
57
|
# @algorithm_name = v == nil ? nil : 'SHA-1'
|
|
@@ -68,48 +67,50 @@ module Axlsx
|
|
|
68
67
|
|
|
69
68
|
# encodes password for protection locking
|
|
70
69
|
def password=(v)
|
|
71
|
-
return if v
|
|
70
|
+
return if v.nil?
|
|
71
|
+
|
|
72
72
|
@password = create_password_hash(v)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
# Serialize the object
|
|
76
76
|
# @param [String] str
|
|
77
77
|
# @return [String]
|
|
78
|
-
def to_xml_string(str = '')
|
|
78
|
+
def to_xml_string(str = +'')
|
|
79
79
|
serialized_tag('sheetProtection', str)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
private
|
|
83
|
+
|
|
83
84
|
# Creates a password hash for a given password
|
|
84
85
|
# @return [String]
|
|
85
86
|
def create_password_hash(password)
|
|
86
87
|
encoded_password = encode_password(password)
|
|
87
88
|
|
|
88
89
|
password_as_hex = [encoded_password].pack("v")
|
|
89
|
-
password_as_string = password_as_hex.
|
|
90
|
+
password_as_string = password_as_hex.unpack1("H*").upcase
|
|
90
91
|
|
|
91
92
|
password_as_string[2..3] + password_as_string[0..1]
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
# Encodes a given password
|
|
95
96
|
# Based on the algorithm provided by Daniel Rentz of OpenOffice.
|
|
96
|
-
#
|
|
97
|
+
# https://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
|
|
97
98
|
# @return [String]
|
|
98
99
|
def encode_password(password)
|
|
99
100
|
i = 0
|
|
100
|
-
chars = password.
|
|
101
|
+
chars = password.chars
|
|
101
102
|
count = chars.size
|
|
102
103
|
|
|
103
104
|
chars.collect! do |char|
|
|
104
105
|
i += 1
|
|
105
|
-
char = char.
|
|
106
|
+
char = char.unpack1('c') << i # ord << i
|
|
106
107
|
low_15 = char & 0x7fff
|
|
107
|
-
high_15 = char & 0x7fff << 15
|
|
108
|
-
high_15
|
|
109
|
-
|
|
108
|
+
high_15 = char & (0x7fff << 15)
|
|
109
|
+
high_15 >>= 15
|
|
110
|
+
low_15 | high_15
|
|
110
111
|
end
|
|
111
112
|
|
|
112
|
-
encoded_password
|
|
113
|
+
encoded_password = 0x0000
|
|
113
114
|
chars.each { |c| encoded_password ^= c }
|
|
114
115
|
encoded_password ^= count
|
|
115
116
|
encoded_password ^= 0xCE4B
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
module Axlsx
|
|
3
4
|
# View options for a worksheet.
|
|
4
5
|
#
|
|
5
6
|
# @note The recommended way to manage the sheet view is via Worksheet#sheet_view
|
|
6
7
|
# @see Worksheet#sheet_view
|
|
7
8
|
class SheetView
|
|
8
|
-
|
|
9
9
|
include Axlsx::OptionsParser
|
|
10
10
|
include Axlsx::Accessors
|
|
11
11
|
include Axlsx::SerializedAttributes
|
|
@@ -30,11 +30,11 @@ module Axlsx
|
|
|
30
30
|
# @option options [Integer] zoom_scale_normal Zoom Scale Normal View
|
|
31
31
|
# @option options [Integer] zoom_scale_page_layout_view Zoom Scale Page Layout View
|
|
32
32
|
# @option options [Integer] zoom_scale_sheet_layout_view Zoom Scale Page Break Preview
|
|
33
|
-
def initialize(options={})
|
|
34
|
-
#defaults
|
|
33
|
+
def initialize(options = {})
|
|
34
|
+
# defaults
|
|
35
35
|
@color_id = @top_left_cell = @pane = nil
|
|
36
|
-
@right_to_left = @show_formulas = @
|
|
37
|
-
@default_grid_color = @show_grid_lines = @show_row_col_headers = @show_ruler = @show_zeros = true
|
|
36
|
+
@right_to_left = @show_formulas = @show_white_space = @tab_selected = @window_protection = false
|
|
37
|
+
@default_grid_color = @show_grid_lines = @show_row_col_headers = @show_ruler = @show_zeros = @show_outline_symbols = true
|
|
38
38
|
@zoom_scale = 100
|
|
39
39
|
@zoom_scale_normal = @zoom_scale_page_layout_view = @zoom_scale_sheet_layout_view = @workbook_view_id = 0
|
|
40
40
|
@selections = {}
|
|
@@ -42,16 +42,15 @@ module Axlsx
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
boolean_attr_accessor :default_grid_color, :right_to_left, :show_formulas, :show_grid_lines,
|
|
45
|
-
|
|
45
|
+
:show_row_col_headers, :show_ruler, :show_white_space, :show_zeros, :tab_selected, :window_protection, :show_outline_symbols
|
|
46
46
|
|
|
47
47
|
serializable_attributes :default_grid_color, :right_to_left, :show_formulas, :show_grid_lines,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
:show_row_col_headers, :show_ruler, :show_white_space, :show_zeros, :tab_selected, :window_protection, :show_outline_symbols,
|
|
49
|
+
:zoom_scale_sheet_layout_view, :zoom_scale_page_layout_view, :zoom_scale_normal, :workbook_view_id,
|
|
50
|
+
:view, :top_left_cell, :color_id, :zoom_scale
|
|
52
51
|
|
|
53
52
|
# instance values that must be serialized as their own elements - e.g. not attributes.
|
|
54
|
-
CHILD_ELEMENTS = [
|
|
53
|
+
CHILD_ELEMENTS = [:pane, :selections].freeze
|
|
55
54
|
|
|
56
55
|
# The pane object for the sheet view
|
|
57
56
|
# @return [Pane]
|
|
@@ -66,11 +65,11 @@ module Axlsx
|
|
|
66
65
|
# @return [Hash]
|
|
67
66
|
attr_reader :selections
|
|
68
67
|
|
|
69
|
-
#
|
|
68
|
+
#
|
|
70
69
|
# Color Id
|
|
71
70
|
# Index to the color value for row/column
|
|
72
|
-
# text headings and gridlines. This is an
|
|
73
|
-
# 'index color value' (ICV) rather than
|
|
71
|
+
# text headings and gridlines. This is an
|
|
72
|
+
# 'index color value' (ICV) rather than
|
|
74
73
|
# rgb value.
|
|
75
74
|
# @see type
|
|
76
75
|
# @return [Integer]
|
|
@@ -78,18 +77,17 @@ module Axlsx
|
|
|
78
77
|
attr_reader :color_id
|
|
79
78
|
|
|
80
79
|
# Top Left Visible Cell
|
|
81
|
-
# Location of the top left visible cell Location
|
|
80
|
+
# Location of the top left visible cell Location
|
|
82
81
|
# of the top left visible cell in the bottom right
|
|
83
82
|
# pane (when in Left-to-Right mode).
|
|
84
83
|
# @see type
|
|
85
84
|
# @return [String]
|
|
86
85
|
# default nil
|
|
87
86
|
attr_reader :top_left_cell
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
|
|
90
88
|
# View Type
|
|
91
89
|
# Indicates the view type.
|
|
92
|
-
# Options are
|
|
90
|
+
# Options are
|
|
93
91
|
# * normal: Normal view
|
|
94
92
|
# * page_break_preview: Page break preview
|
|
95
93
|
# * page_layout: Page Layout View
|
|
@@ -99,62 +97,59 @@ module Axlsx
|
|
|
99
97
|
attr_reader :view
|
|
100
98
|
|
|
101
99
|
# Workbook View Index
|
|
102
|
-
# Zero-based index of this workbook view, pointing
|
|
100
|
+
# Zero-based index of this workbook view, pointing
|
|
103
101
|
# to a workbookView element in the bookViews collection.
|
|
104
102
|
# @see type
|
|
105
|
-
# @return [Integer]
|
|
103
|
+
# @return [Integer]
|
|
106
104
|
# default 0
|
|
107
105
|
attr_reader :workbook_view_id
|
|
108
106
|
|
|
109
107
|
# Zoom Scale
|
|
110
|
-
# Window zoom magnification for current view
|
|
108
|
+
# Window zoom magnification for current view
|
|
111
109
|
# representing percent values. This attribute
|
|
112
|
-
# is restricted to values ranging from 10 to 400.
|
|
110
|
+
# is restricted to values ranging from 10 to 400.
|
|
113
111
|
# Horizontal & Vertical scale together.
|
|
114
|
-
# Current view can be Normal, Page Layout, or
|
|
112
|
+
# Current view can be Normal, Page Layout, or
|
|
115
113
|
# Page Break Preview.
|
|
116
114
|
# @see type
|
|
117
|
-
# @return [Integer]
|
|
115
|
+
# @return [Integer]
|
|
118
116
|
# default 100
|
|
119
117
|
attr_reader :zoom_scale
|
|
120
118
|
|
|
121
|
-
|
|
122
119
|
# Zoom Scale Normal View
|
|
123
|
-
# Zoom magnification to use when in normal view,
|
|
124
|
-
# representing percent values. This attribute is
|
|
125
|
-
# restricted to values ranging from 10 to 400.
|
|
120
|
+
# Zoom magnification to use when in normal view,
|
|
121
|
+
# representing percent values. This attribute is
|
|
122
|
+
# restricted to values ranging from 10 to 400.
|
|
126
123
|
# Horizontal & Vertical scale together.
|
|
127
|
-
# Applies for worksheets only; zero implies the
|
|
124
|
+
# Applies for worksheets only; zero implies the
|
|
128
125
|
# automatic setting.
|
|
129
126
|
# @see type
|
|
130
|
-
# @return [Integer]
|
|
127
|
+
# @return [Integer]
|
|
131
128
|
# default 0
|
|
132
129
|
attr_reader :zoom_scale_normal
|
|
133
130
|
|
|
134
|
-
|
|
135
131
|
# Zoom Scale Page Layout View
|
|
136
|
-
# Zoom magnification to use when in page layout
|
|
137
|
-
# view, representing percent values. This attribute
|
|
138
|
-
# is restricted to values ranging from 10 to 400.
|
|
132
|
+
# Zoom magnification to use when in page layout
|
|
133
|
+
# view, representing percent values. This attribute
|
|
134
|
+
# is restricted to values ranging from 10 to 400.
|
|
139
135
|
# Horizontal & Vertical scale together.
|
|
140
|
-
# Applies for worksheets only; zero implies
|
|
136
|
+
# Applies for worksheets only; zero implies
|
|
141
137
|
# the automatic setting.
|
|
142
138
|
# @see type
|
|
143
|
-
# @return [Integer]
|
|
139
|
+
# @return [Integer]
|
|
144
140
|
# default 0
|
|
145
141
|
attr_reader :zoom_scale_page_layout_view
|
|
146
142
|
|
|
147
|
-
|
|
148
143
|
# Zoom Scale Page Break Preview
|
|
149
|
-
# Zoom magnification to use when in page break
|
|
150
|
-
# preview, representing percent values. This
|
|
151
|
-
# attribute is restricted to values ranging
|
|
144
|
+
# Zoom magnification to use when in page break
|
|
145
|
+
# preview, representing percent values. This
|
|
146
|
+
# attribute is restricted to values ranging
|
|
152
147
|
# from 10 to 400. Horizontal & Vertical scale
|
|
153
148
|
# together.
|
|
154
|
-
# Applies for worksheet only; zero implies
|
|
149
|
+
# Applies for worksheet only; zero implies
|
|
155
150
|
# the automatic setting.
|
|
156
151
|
# @see type
|
|
157
|
-
# @return [Integer]
|
|
152
|
+
# @return [Integer]
|
|
158
153
|
# default 0
|
|
159
154
|
attr_reader :zoom_scale_sheet_layout_view
|
|
160
155
|
|
|
@@ -163,47 +158,68 @@ module Axlsx
|
|
|
163
158
|
# param [Hash] options
|
|
164
159
|
# return [Selection]
|
|
165
160
|
def add_selection(pane, options = {})
|
|
166
|
-
@selections[pane] = Selection.new(options.merge(:
|
|
161
|
+
@selections[pane] = Selection.new(options.merge(pane: pane))
|
|
167
162
|
end
|
|
168
163
|
|
|
169
164
|
# @see color_id
|
|
170
|
-
def color_id=(v)
|
|
165
|
+
def color_id=(v)
|
|
166
|
+
Axlsx.validate_unsigned_int(v)
|
|
167
|
+
@color_id = v
|
|
168
|
+
end
|
|
171
169
|
|
|
172
170
|
# @see top_left_cell
|
|
173
171
|
def top_left_cell=(v)
|
|
174
|
-
cell = (v.
|
|
175
|
-
Axlsx
|
|
172
|
+
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
|
|
173
|
+
Axlsx.validate_string(cell)
|
|
176
174
|
@top_left_cell = cell
|
|
177
175
|
end
|
|
178
176
|
|
|
179
177
|
# @see view
|
|
180
|
-
def view=(v)
|
|
178
|
+
def view=(v)
|
|
179
|
+
Axlsx.validate_sheet_view_type(v)
|
|
180
|
+
@view = v
|
|
181
|
+
end
|
|
181
182
|
|
|
182
183
|
# @see workbook_view_id
|
|
183
|
-
def workbook_view_id=(v)
|
|
184
|
+
def workbook_view_id=(v)
|
|
185
|
+
Axlsx.validate_unsigned_int(v)
|
|
186
|
+
@workbook_view_id = v
|
|
187
|
+
end
|
|
184
188
|
|
|
185
189
|
# @see zoom_scale
|
|
186
|
-
def zoom_scale=(v)
|
|
190
|
+
def zoom_scale=(v)
|
|
191
|
+
Axlsx.validate_scale_0_10_400(v)
|
|
192
|
+
@zoom_scale = v
|
|
193
|
+
end
|
|
187
194
|
|
|
188
195
|
# @see zoom_scale_normal
|
|
189
|
-
def zoom_scale_normal=(v)
|
|
196
|
+
def zoom_scale_normal=(v)
|
|
197
|
+
Axlsx.validate_scale_0_10_400(v)
|
|
198
|
+
@zoom_scale_normal = v
|
|
199
|
+
end
|
|
190
200
|
|
|
191
201
|
# @see zoom_scale_page_layout_view
|
|
192
|
-
def zoom_scale_page_layout_view=(v)
|
|
202
|
+
def zoom_scale_page_layout_view=(v)
|
|
203
|
+
Axlsx.validate_scale_0_10_400(v)
|
|
204
|
+
@zoom_scale_page_layout_view = v
|
|
205
|
+
end
|
|
193
206
|
|
|
194
207
|
# @see zoom_scale_sheet_layout_view
|
|
195
|
-
def zoom_scale_sheet_layout_view=(v)
|
|
208
|
+
def zoom_scale_sheet_layout_view=(v)
|
|
209
|
+
Axlsx.validate_scale_0_10_400(v)
|
|
210
|
+
@zoom_scale_sheet_layout_view = v
|
|
211
|
+
end
|
|
196
212
|
|
|
197
213
|
# Serializes the data validation
|
|
198
214
|
# @param [String] str
|
|
199
215
|
# @return [String]
|
|
200
|
-
def to_xml_string(str = '')
|
|
216
|
+
def to_xml_string(str = +'')
|
|
201
217
|
str << '<sheetViews>'
|
|
202
218
|
str << '<sheetView '
|
|
203
219
|
serialized_attributes str
|
|
204
220
|
str << '>'
|
|
205
221
|
@pane.to_xml_string(str) if @pane
|
|
206
|
-
@selections.
|
|
222
|
+
@selections.each_value do |selection|
|
|
207
223
|
selection.to_xml_string(str)
|
|
208
224
|
end
|
|
209
225
|
str << '</sheetView>'
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
module Axlsx
|
|
3
4
|
# Table
|
|
4
5
|
# @note Worksheet#add_table is the recommended way to create tables for your worksheets.
|
|
5
6
|
# @see README for examples
|
|
6
7
|
class Table
|
|
7
|
-
|
|
8
8
|
include Axlsx::OptionsParser
|
|
9
9
|
|
|
10
10
|
# Creates a new Table object
|
|
@@ -12,13 +12,13 @@ module Axlsx
|
|
|
12
12
|
# @param [Worksheet] sheet The sheet containing the table data.
|
|
13
13
|
# @option options [Cell, String] name
|
|
14
14
|
# @option options [TableStyle] style
|
|
15
|
-
def initialize(ref, sheet, options={})
|
|
15
|
+
def initialize(ref, sheet, options = {})
|
|
16
16
|
@ref = ref
|
|
17
17
|
@sheet = sheet
|
|
18
18
|
@style = nil
|
|
19
19
|
@sheet.workbook.tables << self
|
|
20
20
|
@table_style_info = TableStyleInfo.new(options[:style_info]) if options[:style_info]
|
|
21
|
-
@name = "Table#{index+1}"
|
|
21
|
+
@name = "Table#{index + 1}"
|
|
22
22
|
parse_options options
|
|
23
23
|
yield self if block_given?
|
|
24
24
|
end
|
|
@@ -44,7 +44,7 @@ module Axlsx
|
|
|
44
44
|
# The part name for this table
|
|
45
45
|
# @return [String]
|
|
46
46
|
def pn
|
|
47
|
-
|
|
47
|
+
format(TABLE_PN, index + 1)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
# The relationship id for this table.
|
|
@@ -64,7 +64,7 @@ module Axlsx
|
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
# TableStyleInfo for the table.
|
|
67
|
+
# TableStyleInfo for the table.
|
|
68
68
|
# initialization can be fed via the :style_info option
|
|
69
69
|
def table_style_info
|
|
70
70
|
@table_style_info ||= TableStyleInfo.new
|
|
@@ -73,14 +73,14 @@ module Axlsx
|
|
|
73
73
|
# Serializes the object
|
|
74
74
|
# @param [String] str
|
|
75
75
|
# @return [String]
|
|
76
|
-
def to_xml_string(str = '')
|
|
76
|
+
def to_xml_string(str = +'')
|
|
77
77
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
|
78
|
-
str <<
|
|
79
|
-
str <<
|
|
80
|
-
str <<
|
|
81
|
-
str <<
|
|
82
|
-
header_cells.each_with_index do |cell,index|
|
|
83
|
-
str <<
|
|
78
|
+
str << '<table xmlns="' << XML_NS << '" id="' << (index + 1).to_s << '" name="' << @name << '" displayName="' << @name.gsub(/\s/, '_') << '" '
|
|
79
|
+
str << 'ref="' << @ref << '" totalsRowShown="0">'
|
|
80
|
+
str << '<autoFilter ref="' << @ref << '"/>'
|
|
81
|
+
str << '<tableColumns count="' << header_cells.length.to_s << '">'
|
|
82
|
+
header_cells.each_with_index do |cell, index|
|
|
83
|
+
str << '<tableColumn id ="' << (index + 1).to_s << '" name="' << cell.clean_value << '"/>'
|
|
84
84
|
end
|
|
85
85
|
str << '</tableColumns>'
|
|
86
86
|
table_style_info.to_xml_string(str)
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# The table style info class manages style attributes for defined tables in
|
|
4
5
|
# a worksheet
|
|
5
6
|
class TableStyleInfo
|
|
6
7
|
include Axlsx::OptionsParser
|
|
7
8
|
include Axlsx::SerializedAttributes
|
|
8
9
|
include Axlsx::Accessors
|
|
10
|
+
|
|
9
11
|
# creates a new TableStyleInfo instance
|
|
10
12
|
# @param [Hash] options
|
|
11
13
|
# @option [Boolean] show_first_column indicates if the first column should
|
|
@@ -15,7 +17,7 @@ module Axlsx
|
|
|
15
17
|
# @option [Boolean] show_column_stripes indicates if column stripes should
|
|
16
18
|
# be shown
|
|
17
19
|
# @option [Boolean] show_row_stripes indicates if row stripes should be shown
|
|
18
|
-
# @option [String] name The name of the style to apply to your table.
|
|
20
|
+
# @option [String] name The name of the style to apply to your table.
|
|
19
21
|
# Only predefined styles are currently supported.
|
|
20
22
|
# @see Annex G. (normative) Predefined SpreadsheetML Style Definitions in part 1 of the specification.
|
|
21
23
|
def initialize(options = {})
|
|
@@ -27,22 +29,22 @@ module Axlsx
|
|
|
27
29
|
# boolean attributes for this object
|
|
28
30
|
boolean_attr_accessor :show_first_column, :show_last_column, :show_row_stripes, :show_column_stripes
|
|
29
31
|
serializable_attributes :show_first_column, :show_last_column, :show_row_stripes, :show_column_stripes,
|
|
30
|
-
|
|
32
|
+
:name
|
|
31
33
|
|
|
32
34
|
# Initialize all the values to false as Excel requires them to
|
|
33
35
|
# explicitly be disabled or all will show.
|
|
34
36
|
def initialize_defaults
|
|
35
37
|
%w(show_first_column show_last_column show_row_stripes show_column_stripes).each do |attr|
|
|
36
|
-
|
|
38
|
+
send(:"#{attr}=", 0)
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
# The name of the table style.
|
|
41
43
|
attr_accessor :name
|
|
42
44
|
|
|
43
|
-
#
|
|
45
|
+
# serializes this object to an xml string
|
|
44
46
|
# @param [String] str the string to contact this objects serialization to.
|
|
45
|
-
def to_xml_string(str = '')
|
|
47
|
+
def to_xml_string(str = +'')
|
|
46
48
|
serialized_tag('tableStyleInfo', str)
|
|
47
49
|
end
|
|
48
50
|
end
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# A simple, self serializing class for storing tables
|
|
4
5
|
class Tables < SimpleTypedList
|
|
5
|
-
|
|
6
6
|
# creates a new Tables object
|
|
7
7
|
def initialize(worksheet)
|
|
8
8
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
super(Table)
|
|
10
11
|
@worksheet = worksheet
|
|
11
12
|
end
|
|
12
13
|
|
|
@@ -17,18 +18,19 @@ module Axlsx
|
|
|
17
18
|
# returns the relationships required by this collection
|
|
18
19
|
def relationships
|
|
19
20
|
return [] if empty?
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
map { |table| Relationship.new(table, TABLE_R, "../#{table.pn}") }
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
# renders the tables xml
|
|
24
26
|
# @param [String] str
|
|
25
27
|
# @return [String]
|
|
26
|
-
def to_xml_string(str =
|
|
28
|
+
def to_xml_string(str = +'')
|
|
27
29
|
return if empty?
|
|
30
|
+
|
|
28
31
|
str << "<tableParts count='#{size}'>"
|
|
29
32
|
each { |table| str << "<tablePart r:id='#{table.rId}'/>" }
|
|
30
33
|
str << '</tableParts>'
|
|
31
34
|
end
|
|
32
35
|
end
|
|
33
|
-
|
|
34
36
|
end
|