caxlsx 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +9 -9
- data/.yardopts_guide +18 -18
- data/CHANGELOG.md +385 -354
- data/LICENSE +21 -21
- data/README.md +165 -168
- data/Rakefile +29 -29
- data/examples/generate.rb +15 -15
- data/lib/axlsx/content_type/abstract_content_type.rb +32 -32
- data/lib/axlsx/content_type/content_type.rb +26 -26
- data/lib/axlsx/content_type/default.rb +25 -25
- data/lib/axlsx/content_type/override.rb +25 -25
- data/lib/axlsx/doc_props/app.rb +235 -235
- data/lib/axlsx/doc_props/core.rb +39 -39
- data/lib/axlsx/drawing/area_chart.rb +99 -99
- data/lib/axlsx/drawing/area_series.rb +110 -110
- data/lib/axlsx/drawing/ax_data_source.rb +26 -26
- data/lib/axlsx/drawing/axes.rb +61 -61
- data/lib/axlsx/drawing/axis.rb +190 -190
- data/lib/axlsx/drawing/bar_3D_chart.rb +148 -148
- data/lib/axlsx/drawing/bar_chart.rb +138 -138
- data/lib/axlsx/drawing/bar_series.rb +97 -97
- data/lib/axlsx/drawing/bubble_chart.rb +59 -59
- data/lib/axlsx/drawing/bubble_series.rb +63 -63
- data/lib/axlsx/drawing/cat_axis.rb +85 -85
- data/lib/axlsx/drawing/chart.rb +299 -276
- data/lib/axlsx/drawing/d_lbls.rb +91 -90
- data/lib/axlsx/drawing/drawing.rb +167 -167
- data/lib/axlsx/drawing/graphic_frame.rb +54 -54
- data/lib/axlsx/drawing/hyperlink.rb +100 -100
- data/lib/axlsx/drawing/line_3D_chart.rb +68 -68
- data/lib/axlsx/drawing/line_chart.rb +99 -99
- data/lib/axlsx/drawing/line_series.rb +110 -110
- data/lib/axlsx/drawing/marker.rb +84 -84
- data/lib/axlsx/drawing/num_data.rb +52 -52
- data/lib/axlsx/drawing/num_data_source.rb +62 -62
- data/lib/axlsx/drawing/num_val.rb +34 -34
- data/lib/axlsx/drawing/one_cell_anchor.rb +99 -99
- data/lib/axlsx/drawing/pic.rb +211 -211
- data/lib/axlsx/drawing/picture_locking.rb +42 -42
- data/lib/axlsx/drawing/pie_3D_chart.rb +47 -47
- data/lib/axlsx/drawing/pie_series.rb +74 -74
- data/lib/axlsx/drawing/scaling.rb +60 -60
- data/lib/axlsx/drawing/scatter_chart.rb +74 -74
- data/lib/axlsx/drawing/scatter_series.rb +129 -129
- data/lib/axlsx/drawing/ser_axis.rb +45 -45
- data/lib/axlsx/drawing/series.rb +69 -69
- data/lib/axlsx/drawing/series_title.rb +25 -25
- data/lib/axlsx/drawing/str_data.rb +42 -42
- data/lib/axlsx/drawing/str_val.rb +34 -34
- data/lib/axlsx/drawing/title.rb +107 -97
- data/lib/axlsx/drawing/two_cell_anchor.rb +97 -97
- data/lib/axlsx/drawing/val_axis.rb +37 -37
- data/lib/axlsx/drawing/view_3D.rb +115 -115
- data/lib/axlsx/drawing/vml_drawing.rb +42 -42
- data/lib/axlsx/drawing/vml_shape.rb +66 -66
- data/lib/axlsx/package.rb +398 -388
- data/lib/axlsx/rels/relationship.rb +130 -130
- data/lib/axlsx/rels/relationships.rb +32 -32
- data/lib/axlsx/stylesheet/border.rb +73 -73
- data/lib/axlsx/stylesheet/border_pr.rb +71 -71
- data/lib/axlsx/stylesheet/cell_alignment.rb +132 -132
- data/lib/axlsx/stylesheet/cell_protection.rb +41 -41
- data/lib/axlsx/stylesheet/cell_style.rb +72 -72
- data/lib/axlsx/stylesheet/color.rb +76 -76
- data/lib/axlsx/stylesheet/dxf.rb +79 -79
- data/lib/axlsx/stylesheet/fill.rb +35 -35
- data/lib/axlsx/stylesheet/font.rb +156 -156
- data/lib/axlsx/stylesheet/gradient_fill.rb +103 -103
- data/lib/axlsx/stylesheet/gradient_stop.rb +37 -37
- data/lib/axlsx/stylesheet/num_fmt.rb +86 -86
- data/lib/axlsx/stylesheet/pattern_fill.rb +73 -73
- data/lib/axlsx/stylesheet/styles.rb +535 -494
- data/lib/axlsx/stylesheet/table_style.rb +54 -54
- data/lib/axlsx/stylesheet/table_style_element.rb +77 -77
- data/lib/axlsx/stylesheet/table_styles.rb +46 -46
- data/lib/axlsx/stylesheet/xf.rb +147 -147
- data/lib/axlsx/util/accessors.rb +64 -64
- data/lib/axlsx/util/constants.rb +416 -410
- data/lib/axlsx/util/mime_type_utils.rb +11 -11
- data/lib/axlsx/util/options_parser.rb +16 -16
- data/lib/axlsx/util/serialized_attributes.rb +89 -89
- data/lib/axlsx/util/simple_typed_list.rb +179 -179
- data/lib/axlsx/util/storage.rb +146 -146
- data/lib/axlsx/util/validators.rb +312 -312
- data/lib/axlsx/util/zip_command.rb +73 -73
- data/lib/axlsx/version.rb +5 -5
- data/lib/axlsx/workbook/defined_name.rb +128 -128
- data/lib/axlsx/workbook/defined_names.rb +21 -21
- data/lib/axlsx/workbook/shared_strings_table.rb +77 -77
- data/lib/axlsx/workbook/workbook.rb +425 -395
- data/lib/axlsx/workbook/workbook_view.rb +80 -80
- data/lib/axlsx/workbook/workbook_views.rb +22 -22
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -77
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -94
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +244 -244
- data/lib/axlsx/workbook/worksheet/border_creator.rb +76 -0
- data/lib/axlsx/workbook/worksheet/break.rb +35 -35
- data/lib/axlsx/workbook/worksheet/cell.rb +532 -506
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +164 -164
- data/lib/axlsx/workbook/worksheet/cfvo.rb +60 -60
- data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -18
- data/lib/axlsx/workbook/worksheet/col.rb +145 -145
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -35
- data/lib/axlsx/workbook/worksheet/color_scale.rb +110 -110
- data/lib/axlsx/workbook/worksheet/cols.rb +23 -23
- data/lib/axlsx/workbook/worksheet/comment.rb +91 -91
- data/lib/axlsx/workbook/worksheet/comments.rb +82 -82
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -82
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +220 -220
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -25
- data/lib/axlsx/workbook/worksheet/data_bar.rb +129 -129
- data/lib/axlsx/workbook/worksheet/data_validation.rb +267 -246
- data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -28
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +30 -30
- data/lib/axlsx/workbook/worksheet/dimension.rb +64 -64
- data/lib/axlsx/workbook/worksheet/header_footer.rb +52 -52
- data/lib/axlsx/workbook/worksheet/icon_set.rb +81 -81
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +37 -37
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -33
- data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -97
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -44
- data/lib/axlsx/workbook/worksheet/page_setup.rb +240 -240
- data/lib/axlsx/workbook/worksheet/pane.rb +139 -139
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +335 -296
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -66
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -24
- data/lib/axlsx/workbook/worksheet/print_options.rb +39 -39
- data/lib/axlsx/workbook/worksheet/protected_range.rb +47 -47
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +37 -37
- data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -55
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -250
- data/lib/axlsx/workbook/worksheet/row.rb +164 -164
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -33
- data/lib/axlsx/workbook/worksheet/selection.rb +101 -101
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -29
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +27 -27
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +87 -87
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +118 -118
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +213 -213
- data/lib/axlsx/workbook/worksheet/table.rb +102 -102
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +49 -49
- data/lib/axlsx/workbook/worksheet/tables.rb +34 -34
- data/lib/axlsx/workbook/worksheet/worksheet.rb +829 -786
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +58 -58
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +58 -58
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -74
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -38
- data/lib/axlsx.rb +204 -185
- data/lib/caxlsx.rb +2 -2
- data/lib/schema/dc.xsd +118 -118
- data/lib/schema/dcmitype.xsd +51 -51
- data/lib/schema/dcterms.xsd +331 -331
- data/lib/schema/dml-chartDrawing.xsd +146 -146
- data/lib/schema/dml-compatibility.xsd +14 -14
- data/lib/schema/dml-lockedCanvas.xsd +11 -11
- data/lib/schema/dml-main.xsd +3048 -3048
- data/lib/schema/dml-picture.xsd +23 -23
- data/lib/schema/dml-spreadsheetDrawing.xsd +185 -185
- data/lib/schema/dml-wordprocessingDrawing.xsd +185 -185
- data/lib/schema/shared-additionalCharacteristics.xsd +28 -28
- data/lib/schema/shared-bibliography.xsd +144 -144
- data/lib/schema/shared-commonSimpleTypes.xsd +166 -166
- data/lib/schema/shared-customXmlDataProperties.xsd +25 -25
- data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -18
- data/lib/schema/shared-documentPropertiesCustom.xsd +59 -59
- data/lib/schema/shared-documentPropertiesExtended.xsd +56 -56
- data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -195
- data/lib/schema/shared-relationshipReference.xsd +25 -25
- data/lib/schema/vml-main.xsd +569 -569
- data/lib/schema/vml-officeDrawing.xsd +509 -509
- data/lib/schema/vml-presentationDrawing.xsd +12 -12
- data/lib/schema/vml-spreadsheetDrawing.xsd +108 -108
- data/lib/schema/vml-wordprocessingDrawing.xsd +96 -96
- data/lib/schema/xml.xsd +116 -116
- metadata +5 -252
- data/test/benchmark.rb +0 -72
- data/test/content_type/tc_content_type.rb +0 -76
- data/test/content_type/tc_default.rb +0 -16
- data/test/content_type/tc_override.rb +0 -14
- data/test/doc_props/tc_app.rb +0 -43
- data/test/doc_props/tc_core.rb +0 -42
- data/test/drawing/tc_area_chart.rb +0 -39
- data/test/drawing/tc_area_series.rb +0 -71
- data/test/drawing/tc_axes.rb +0 -8
- data/test/drawing/tc_axis.rb +0 -112
- data/test/drawing/tc_bar_3D_chart.rb +0 -86
- data/test/drawing/tc_bar_chart.rb +0 -86
- data/test/drawing/tc_bar_series.rb +0 -46
- data/test/drawing/tc_bubble_chart.rb +0 -44
- data/test/drawing/tc_bubble_series.rb +0 -21
- data/test/drawing/tc_cat_axis.rb +0 -31
- data/test/drawing/tc_cat_axis_data.rb +0 -27
- data/test/drawing/tc_chart.rb +0 -123
- data/test/drawing/tc_d_lbls.rb +0 -57
- data/test/drawing/tc_data_source.rb +0 -23
- data/test/drawing/tc_drawing.rb +0 -80
- data/test/drawing/tc_graphic_frame.rb +0 -27
- data/test/drawing/tc_hyperlink.rb +0 -64
- data/test/drawing/tc_line_3d_chart.rb +0 -47
- data/test/drawing/tc_line_chart.rb +0 -39
- data/test/drawing/tc_line_series.rb +0 -71
- data/test/drawing/tc_marker.rb +0 -44
- data/test/drawing/tc_named_axis_data.rb +0 -27
- data/test/drawing/tc_num_data.rb +0 -31
- data/test/drawing/tc_num_val.rb +0 -29
- data/test/drawing/tc_one_cell_anchor.rb +0 -66
- data/test/drawing/tc_pic.rb +0 -103
- data/test/drawing/tc_picture_locking.rb +0 -72
- data/test/drawing/tc_pie_3D_chart.rb +0 -28
- data/test/drawing/tc_pie_series.rb +0 -33
- data/test/drawing/tc_scaling.rb +0 -36
- data/test/drawing/tc_scatter_chart.rb +0 -48
- data/test/drawing/tc_scatter_series.rb +0 -74
- data/test/drawing/tc_ser_axis.rb +0 -31
- data/test/drawing/tc_series.rb +0 -23
- data/test/drawing/tc_series_title.rb +0 -54
- data/test/drawing/tc_str_data.rb +0 -18
- data/test/drawing/tc_str_val.rb +0 -30
- data/test/drawing/tc_title.rb +0 -70
- data/test/drawing/tc_two_cell_anchor.rb +0 -36
- data/test/drawing/tc_val_axis.rb +0 -24
- data/test/drawing/tc_view_3D.rb +0 -54
- data/test/drawing/tc_vml_drawing.rb +0 -25
- data/test/drawing/tc_vml_shape.rb +0 -106
- data/test/fixtures/image1.gif +0 -0
- data/test/fixtures/image1.jpeg +0 -0
- data/test/fixtures/image1.jpg +0 -0
- data/test/fixtures/image1.png +0 -0
- data/test/fixtures/image1_fake.jpg +0 -0
- data/test/profile.rb +0 -24
- data/test/rels/tc_relationship.rb +0 -52
- data/test/rels/tc_relationships.rb +0 -37
- data/test/stylesheet/tc_border.rb +0 -37
- data/test/stylesheet/tc_border_pr.rb +0 -32
- data/test/stylesheet/tc_cell_alignment.rb +0 -81
- data/test/stylesheet/tc_cell_protection.rb +0 -29
- data/test/stylesheet/tc_cell_style.rb +0 -57
- data/test/stylesheet/tc_color.rb +0 -43
- data/test/stylesheet/tc_dxf.rb +0 -81
- data/test/stylesheet/tc_fill.rb +0 -18
- data/test/stylesheet/tc_font.rb +0 -133
- data/test/stylesheet/tc_gradient_fill.rb +0 -72
- data/test/stylesheet/tc_gradient_stop.rb +0 -31
- data/test/stylesheet/tc_num_fmt.rb +0 -30
- data/test/stylesheet/tc_pattern_fill.rb +0 -43
- data/test/stylesheet/tc_styles.rb +0 -309
- data/test/stylesheet/tc_table_style.rb +0 -44
- data/test/stylesheet/tc_table_style_element.rb +0 -45
- data/test/stylesheet/tc_table_styles.rb +0 -29
- data/test/stylesheet/tc_xf.rb +0 -120
- data/test/tc_axlsx.rb +0 -109
- data/test/tc_helper.rb +0 -10
- data/test/tc_package.rb +0 -317
- data/test/util/tc_mime_type_utils.rb +0 -13
- data/test/util/tc_serialized_attributes.rb +0 -19
- data/test/util/tc_simple_typed_list.rb +0 -77
- data/test/util/tc_validators.rb +0 -210
- data/test/workbook/tc_defined_name.rb +0 -49
- data/test/workbook/tc_shared_strings_table.rb +0 -59
- data/test/workbook/tc_workbook.rb +0 -165
- data/test/workbook/tc_workbook_view.rb +0 -50
- data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +0 -38
- data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +0 -76
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +0 -50
- data/test/workbook/worksheet/tc_break.rb +0 -49
- data/test/workbook/worksheet/tc_cell.rb +0 -465
- data/test/workbook/worksheet/tc_cfvo.rb +0 -31
- data/test/workbook/worksheet/tc_col.rb +0 -93
- data/test/workbook/worksheet/tc_color_scale.rb +0 -58
- data/test/workbook/worksheet/tc_comment.rb +0 -72
- data/test/workbook/worksheet/tc_comments.rb +0 -57
- data/test/workbook/worksheet/tc_conditional_formatting.rb +0 -224
- data/test/workbook/worksheet/tc_data_bar.rb +0 -46
- data/test/workbook/worksheet/tc_data_validation.rb +0 -265
- data/test/workbook/worksheet/tc_date_time_converter.rb +0 -124
- data/test/workbook/worksheet/tc_header_footer.rb +0 -151
- data/test/workbook/worksheet/tc_icon_set.rb +0 -45
- data/test/workbook/worksheet/tc_outline_pr.rb +0 -19
- data/test/workbook/worksheet/tc_page_margins.rb +0 -97
- data/test/workbook/worksheet/tc_page_set_up_pr.rb +0 -15
- data/test/workbook/worksheet/tc_page_setup.rb +0 -143
- data/test/workbook/worksheet/tc_pane.rb +0 -54
- data/test/workbook/worksheet/tc_pivot_table.rb +0 -180
- data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +0 -62
- data/test/workbook/worksheet/tc_print_options.rb +0 -72
- data/test/workbook/worksheet/tc_protected_range.rb +0 -17
- data/test/workbook/worksheet/tc_rich_text.rb +0 -44
- data/test/workbook/worksheet/tc_rich_text_run.rb +0 -173
- data/test/workbook/worksheet/tc_row.rb +0 -160
- data/test/workbook/worksheet/tc_selection.rb +0 -55
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +0 -18
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +0 -88
- data/test/workbook/worksheet/tc_sheet_pr.rb +0 -49
- data/test/workbook/worksheet/tc_sheet_protection.rb +0 -117
- data/test/workbook/worksheet/tc_sheet_view.rb +0 -214
- data/test/workbook/worksheet/tc_table.rb +0 -77
- data/test/workbook/worksheet/tc_table_style_info.rb +0 -53
- data/test/workbook/worksheet/tc_worksheet.rb +0 -632
- data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +0 -55
@@ -1,494 +1,535 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module Axlsx
|
3
|
-
require 'axlsx/stylesheet/border.rb'
|
4
|
-
require 'axlsx/stylesheet/border_pr.rb'
|
5
|
-
require 'axlsx/stylesheet/cell_alignment.rb'
|
6
|
-
require 'axlsx/stylesheet/cell_style.rb'
|
7
|
-
require 'axlsx/stylesheet/color.rb'
|
8
|
-
require 'axlsx/stylesheet/fill.rb'
|
9
|
-
require 'axlsx/stylesheet/font.rb'
|
10
|
-
require 'axlsx/stylesheet/gradient_fill.rb'
|
11
|
-
require 'axlsx/stylesheet/gradient_stop.rb'
|
12
|
-
require 'axlsx/stylesheet/num_fmt.rb'
|
13
|
-
require 'axlsx/stylesheet/pattern_fill.rb'
|
14
|
-
require 'axlsx/stylesheet/table_style.rb'
|
15
|
-
require 'axlsx/stylesheet/table_styles.rb'
|
16
|
-
require 'axlsx/stylesheet/table_style_element.rb'
|
17
|
-
require 'axlsx/stylesheet/dxf.rb'
|
18
|
-
require 'axlsx/stylesheet/xf.rb'
|
19
|
-
require 'axlsx/stylesheet/cell_protection.rb'
|
20
|
-
|
21
|
-
#The Styles class manages worksheet styles
|
22
|
-
# In addition to creating the require style objects for a valid xlsx package, this class provides the key mechanism for adding styles to your workbook, and safely applying them to the cells of your worksheet.
|
23
|
-
# All portions of the stylesheet are implemented here exception colors, which specify legacy and modified pallete colors, and exLst, whic is used as a future feature data storage area.
|
24
|
-
# @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
|
25
|
-
# @see Styles#add_style
|
26
|
-
# @note The recommended way to manage styles is with add_style
|
27
|
-
class Styles
|
28
|
-
# numFmts for your styles.
|
29
|
-
# The default styles, which change based on the system local, are as follows.
|
30
|
-
# id formatCode
|
31
|
-
# 0 General
|
32
|
-
# 1 0
|
33
|
-
# 2 0.00
|
34
|
-
# 3 #,##0
|
35
|
-
# 4 #,##0.00
|
36
|
-
# 9 0%
|
37
|
-
# 10 0.00%
|
38
|
-
# 11 0.00E+00
|
39
|
-
# 12 # ?/?
|
40
|
-
# 13 # ??/??
|
41
|
-
# 14 mm-dd-yy
|
42
|
-
# 15 d-mmm-yy
|
43
|
-
# 16 d-mmm
|
44
|
-
# 17 mmm-yy
|
45
|
-
# 18 h:mm AM/PM
|
46
|
-
# 19 h:mm:ss AM/PM
|
47
|
-
# 20 h:mm
|
48
|
-
# 21 h:mm:ss
|
49
|
-
# 22 m/d/yy h:mm
|
50
|
-
# 37 #,##0 ;(#,##0)
|
51
|
-
# 38 #,##0 ;[Red](#,##0)
|
52
|
-
# 39 #,##0.00;(#,##0.00)
|
53
|
-
# 40 #,##0.00;[Red](#,##0.00)
|
54
|
-
# 45 mm:ss
|
55
|
-
# 46 [h]:mm:ss
|
56
|
-
# 47 mmss.0
|
57
|
-
# 48 ##0.0E+0
|
58
|
-
# 49 @
|
59
|
-
# Axlsx also defines the following constants which you can use in add_style.
|
60
|
-
# NUM_FMT_PERCENT formats to "0%"
|
61
|
-
# NUM_FMT_YYYYMMDD formats to "yyyy/mm/dd"
|
62
|
-
# NUM_FMT_YYYYMMDDHHMMSS formats to "yyyy/mm/dd hh:mm:ss"
|
63
|
-
# @see Office Open XML Part 1 - 18.8.31 for more information on creating number formats
|
64
|
-
# @return [SimpleTypedList]
|
65
|
-
# @note The recommended way to manage styles is with add_style
|
66
|
-
# @see Styles#add_style
|
67
|
-
attr_reader :numFmts
|
68
|
-
|
69
|
-
# The collection of fonts used in this workbook
|
70
|
-
# @return [SimpleTypedList]
|
71
|
-
# @note The recommended way to manage styles is with add_style
|
72
|
-
# @see Styles#add_style
|
73
|
-
attr_reader :fonts
|
74
|
-
|
75
|
-
# The collection of fills used in this workbook
|
76
|
-
# @return [SimpleTypedList]
|
77
|
-
# @note The recommended way to manage styles is with add_style
|
78
|
-
# @see Styles#add_style
|
79
|
-
attr_reader :fills
|
80
|
-
|
81
|
-
# The collection of borders used in this workbook
|
82
|
-
# Axlsx predefines THIN_BORDER which can be used to put a border around all of your cells.
|
83
|
-
# @return [SimpleTypedList]
|
84
|
-
# @note The recommended way to manage styles is with add_style
|
85
|
-
# @see Styles#add_style
|
86
|
-
attr_reader :borders
|
87
|
-
|
88
|
-
# The collection of master formatting records for named cell styles, which means records defined in cellStyles, in the workbook
|
89
|
-
# @return [SimpleTypedList]
|
90
|
-
# @note The recommended way to manage styles is with add_style
|
91
|
-
# @see Styles#add_style
|
92
|
-
attr_reader :cellStyleXfs
|
93
|
-
|
94
|
-
# The collection of named styles, referencing cellStyleXfs items in the workbook.
|
95
|
-
# @return [SimpleTypedList]
|
96
|
-
# @note The recommended way to manage styles is with add_style
|
97
|
-
# @see Styles#add_style
|
98
|
-
attr_reader :cellStyles
|
99
|
-
|
100
|
-
# The collection of master formatting records. This is the list that you will actually use in styling a workbook.
|
101
|
-
# @return [SimpleTypedList]
|
102
|
-
# @note The recommended way to manage styles is with add_style
|
103
|
-
# @see Styles#add_style
|
104
|
-
attr_reader :cellXfs
|
105
|
-
|
106
|
-
# The collection of non-cell formatting records used in the worksheet.
|
107
|
-
# @return [SimpleTypedList]
|
108
|
-
# @note The recommended way to manage styles is with add_style
|
109
|
-
# @see Styles#add_style
|
110
|
-
attr_reader :dxfs
|
111
|
-
|
112
|
-
# The collection of table styles that will be available to the user in the excel UI
|
113
|
-
# @return [SimpleTypedList]
|
114
|
-
# @note The recommended way to manage styles is with add_style
|
115
|
-
# @see Styles#add_style
|
116
|
-
attr_reader :tableStyles
|
117
|
-
|
118
|
-
# Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part.
|
119
|
-
def initialize()
|
120
|
-
load_default_styles
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
#
|
128
|
-
# @
|
129
|
-
# @option options [
|
130
|
-
# @option options [
|
131
|
-
# @option options [Boolean]
|
132
|
-
# @option options [
|
133
|
-
# @option options [
|
134
|
-
# @option options [
|
135
|
-
# @option options [
|
136
|
-
# @option options [
|
137
|
-
# @option options [Integer
|
138
|
-
#
|
139
|
-
# @option options [
|
140
|
-
# @option options [
|
141
|
-
# @option options [
|
142
|
-
#
|
143
|
-
# @option options [
|
144
|
-
# @
|
145
|
-
#
|
146
|
-
# @
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
#
|
158
|
-
# ws.
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
# ws.add_row ["
|
191
|
-
# ws.add_row ["
|
192
|
-
# ws.add_row ["
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
#
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
# ws.add_row ["
|
215
|
-
# ws.add_row ["
|
216
|
-
# ws.add_row ["
|
217
|
-
#
|
218
|
-
# ws.
|
219
|
-
#
|
220
|
-
#
|
221
|
-
#
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
#
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
#
|
307
|
-
# @note noop if
|
308
|
-
# @option options [
|
309
|
-
#
|
310
|
-
#
|
311
|
-
#
|
312
|
-
#
|
313
|
-
#
|
314
|
-
#
|
315
|
-
# @
|
316
|
-
#
|
317
|
-
#
|
318
|
-
# @
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
if
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
options[
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Axlsx
|
3
|
+
require 'axlsx/stylesheet/border.rb'
|
4
|
+
require 'axlsx/stylesheet/border_pr.rb'
|
5
|
+
require 'axlsx/stylesheet/cell_alignment.rb'
|
6
|
+
require 'axlsx/stylesheet/cell_style.rb'
|
7
|
+
require 'axlsx/stylesheet/color.rb'
|
8
|
+
require 'axlsx/stylesheet/fill.rb'
|
9
|
+
require 'axlsx/stylesheet/font.rb'
|
10
|
+
require 'axlsx/stylesheet/gradient_fill.rb'
|
11
|
+
require 'axlsx/stylesheet/gradient_stop.rb'
|
12
|
+
require 'axlsx/stylesheet/num_fmt.rb'
|
13
|
+
require 'axlsx/stylesheet/pattern_fill.rb'
|
14
|
+
require 'axlsx/stylesheet/table_style.rb'
|
15
|
+
require 'axlsx/stylesheet/table_styles.rb'
|
16
|
+
require 'axlsx/stylesheet/table_style_element.rb'
|
17
|
+
require 'axlsx/stylesheet/dxf.rb'
|
18
|
+
require 'axlsx/stylesheet/xf.rb'
|
19
|
+
require 'axlsx/stylesheet/cell_protection.rb'
|
20
|
+
|
21
|
+
#The Styles class manages worksheet styles
|
22
|
+
# In addition to creating the require style objects for a valid xlsx package, this class provides the key mechanism for adding styles to your workbook, and safely applying them to the cells of your worksheet.
|
23
|
+
# All portions of the stylesheet are implemented here exception colors, which specify legacy and modified pallete colors, and exLst, whic is used as a future feature data storage area.
|
24
|
+
# @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
|
25
|
+
# @see Styles#add_style
|
26
|
+
# @note The recommended way to manage styles is with add_style
|
27
|
+
class Styles
|
28
|
+
# numFmts for your styles.
|
29
|
+
# The default styles, which change based on the system local, are as follows.
|
30
|
+
# id formatCode
|
31
|
+
# 0 General
|
32
|
+
# 1 0
|
33
|
+
# 2 0.00
|
34
|
+
# 3 #,##0
|
35
|
+
# 4 #,##0.00
|
36
|
+
# 9 0%
|
37
|
+
# 10 0.00%
|
38
|
+
# 11 0.00E+00
|
39
|
+
# 12 # ?/?
|
40
|
+
# 13 # ??/??
|
41
|
+
# 14 mm-dd-yy
|
42
|
+
# 15 d-mmm-yy
|
43
|
+
# 16 d-mmm
|
44
|
+
# 17 mmm-yy
|
45
|
+
# 18 h:mm AM/PM
|
46
|
+
# 19 h:mm:ss AM/PM
|
47
|
+
# 20 h:mm
|
48
|
+
# 21 h:mm:ss
|
49
|
+
# 22 m/d/yy h:mm
|
50
|
+
# 37 #,##0 ;(#,##0)
|
51
|
+
# 38 #,##0 ;[Red](#,##0)
|
52
|
+
# 39 #,##0.00;(#,##0.00)
|
53
|
+
# 40 #,##0.00;[Red](#,##0.00)
|
54
|
+
# 45 mm:ss
|
55
|
+
# 46 [h]:mm:ss
|
56
|
+
# 47 mmss.0
|
57
|
+
# 48 ##0.0E+0
|
58
|
+
# 49 @
|
59
|
+
# Axlsx also defines the following constants which you can use in add_style.
|
60
|
+
# NUM_FMT_PERCENT formats to "0%"
|
61
|
+
# NUM_FMT_YYYYMMDD formats to "yyyy/mm/dd"
|
62
|
+
# NUM_FMT_YYYYMMDDHHMMSS formats to "yyyy/mm/dd hh:mm:ss"
|
63
|
+
# @see Office Open XML Part 1 - 18.8.31 for more information on creating number formats
|
64
|
+
# @return [SimpleTypedList]
|
65
|
+
# @note The recommended way to manage styles is with add_style
|
66
|
+
# @see Styles#add_style
|
67
|
+
attr_reader :numFmts
|
68
|
+
|
69
|
+
# The collection of fonts used in this workbook
|
70
|
+
# @return [SimpleTypedList]
|
71
|
+
# @note The recommended way to manage styles is with add_style
|
72
|
+
# @see Styles#add_style
|
73
|
+
attr_reader :fonts
|
74
|
+
|
75
|
+
# The collection of fills used in this workbook
|
76
|
+
# @return [SimpleTypedList]
|
77
|
+
# @note The recommended way to manage styles is with add_style
|
78
|
+
# @see Styles#add_style
|
79
|
+
attr_reader :fills
|
80
|
+
|
81
|
+
# The collection of borders used in this workbook
|
82
|
+
# Axlsx predefines THIN_BORDER which can be used to put a border around all of your cells.
|
83
|
+
# @return [SimpleTypedList]
|
84
|
+
# @note The recommended way to manage styles is with add_style
|
85
|
+
# @see Styles#add_style
|
86
|
+
attr_reader :borders
|
87
|
+
|
88
|
+
# The collection of master formatting records for named cell styles, which means records defined in cellStyles, in the workbook
|
89
|
+
# @return [SimpleTypedList]
|
90
|
+
# @note The recommended way to manage styles is with add_style
|
91
|
+
# @see Styles#add_style
|
92
|
+
attr_reader :cellStyleXfs
|
93
|
+
|
94
|
+
# The collection of named styles, referencing cellStyleXfs items in the workbook.
|
95
|
+
# @return [SimpleTypedList]
|
96
|
+
# @note The recommended way to manage styles is with add_style
|
97
|
+
# @see Styles#add_style
|
98
|
+
attr_reader :cellStyles
|
99
|
+
|
100
|
+
# The collection of master formatting records. This is the list that you will actually use in styling a workbook.
|
101
|
+
# @return [SimpleTypedList]
|
102
|
+
# @note The recommended way to manage styles is with add_style
|
103
|
+
# @see Styles#add_style
|
104
|
+
attr_reader :cellXfs
|
105
|
+
|
106
|
+
# The collection of non-cell formatting records used in the worksheet.
|
107
|
+
# @return [SimpleTypedList]
|
108
|
+
# @note The recommended way to manage styles is with add_style
|
109
|
+
# @see Styles#add_style
|
110
|
+
attr_reader :dxfs
|
111
|
+
|
112
|
+
# The collection of table styles that will be available to the user in the excel UI
|
113
|
+
# @return [SimpleTypedList]
|
114
|
+
# @note The recommended way to manage styles is with add_style
|
115
|
+
# @see Styles#add_style
|
116
|
+
attr_reader :tableStyles
|
117
|
+
|
118
|
+
# Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part.
|
119
|
+
def initialize()
|
120
|
+
load_default_styles
|
121
|
+
end
|
122
|
+
|
123
|
+
def style_index
|
124
|
+
@style_index ||= {}
|
125
|
+
end
|
126
|
+
|
127
|
+
# Drastically simplifies style creation and management.
|
128
|
+
# @return [Integer]
|
129
|
+
# @option options [String] fg_color The text color
|
130
|
+
# @option options [Integer] sz The text size
|
131
|
+
# @option options [Boolean] b Indicates if the text should be bold
|
132
|
+
# @option options [Boolean] i Indicates if the text should be italicised
|
133
|
+
# @option options [Boolean] u Indicates if the text should be underlined
|
134
|
+
# @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
|
135
|
+
# @option options [Boolean] shadow Indicates if the text should be rendered with a shadow
|
136
|
+
# @option options [Integer] charset The character set to use.
|
137
|
+
# @option options [Integer] family The font family to use.
|
138
|
+
# @option options [String] font_name The name of the font to use
|
139
|
+
# @option options [Integer] num_fmt The number format to apply
|
140
|
+
# @option options [String] format_code The formatting to apply.
|
141
|
+
# @option options [Integer|Hash] border The border style to use.
|
142
|
+
# borders support style, color and edges options @see parse_border_options
|
143
|
+
# @option options [String] bg_color The background color to apply to the cell
|
144
|
+
# @option options [Boolean] hidden Indicates if the cell should be hidden
|
145
|
+
# @option options [Boolean] locked Indicates if the cell should be locked
|
146
|
+
# @option options [Symbol] type What type of style is this. Options are [:dxf, :xf]. :xf is default
|
147
|
+
# @option options [Hash] alignment A hash defining any of the attributes used in CellAlignment
|
148
|
+
# @see CellAlignment
|
149
|
+
#
|
150
|
+
# @example You Got Style
|
151
|
+
# require "rubygems" # if that is your preferred way to manage gems!
|
152
|
+
# require "axlsx"
|
153
|
+
#
|
154
|
+
# p = Axlsx::Package.new
|
155
|
+
# ws = p.workbook.add_worksheet
|
156
|
+
#
|
157
|
+
# # black text on a white background at 14pt with thin borders!
|
158
|
+
# title = ws.styles.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
|
159
|
+
#
|
160
|
+
# ws.add_row ["Least Popular Pets"]
|
161
|
+
# ws.add_row ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
|
162
|
+
# ws.add_row ["Votes", 6, 4, 1], :style=>Axlsx::STYLE_THIN_BORDER
|
163
|
+
# f = File.open('example_you_got_style.xlsx', 'wb')
|
164
|
+
# p.serialize(f)
|
165
|
+
#
|
166
|
+
# @example Styling specifically
|
167
|
+
# # an example of applying specific styles to specific cells
|
168
|
+
# require "rubygems" # if that is your preferred way to manage gems!
|
169
|
+
# require "axlsx"
|
170
|
+
#
|
171
|
+
# p = Axlsx::Package.new
|
172
|
+
# ws = p.workbook.add_worksheet
|
173
|
+
#
|
174
|
+
# # define your styles
|
175
|
+
# title = ws.styles.add_style(:bg_color => "FFFF0000",
|
176
|
+
# :fg_color=>"#FF000000",
|
177
|
+
# :border=>Axlsx::STYLE_THIN_BORDER,
|
178
|
+
# :alignment=>{:horizontal => :center})
|
179
|
+
#
|
180
|
+
# date_time = ws.styles.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
|
181
|
+
# :border=>Axlsx::STYLE_THIN_BORDER)
|
182
|
+
#
|
183
|
+
# percent = ws.styles.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
|
184
|
+
# :border=>Axlsx::STYLE_THIN_BORDER)
|
185
|
+
#
|
186
|
+
# currency = ws.styles.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
|
187
|
+
# :border=>Axlsx::STYLE_THIN_BORDER)
|
188
|
+
#
|
189
|
+
# # build your rows
|
190
|
+
# ws.add_row ["Generated At:", Time.now], :styles=>[nil, date_time]
|
191
|
+
# ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
|
192
|
+
# ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
|
193
|
+
# ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
|
194
|
+
# ws.add_row ["Q2", 3000, 30], :style=>[title, currency, percent]
|
195
|
+
# ws.add_row ["Q3", 1000, 10], :style=>[title, currency, percent]
|
196
|
+
# ws.add_row ["Q4", 2000, 20], :style=>[title, currency, percent]
|
197
|
+
# f = File.open('example_you_got_style.xlsx', 'wb')
|
198
|
+
# p.serialize(f)
|
199
|
+
#
|
200
|
+
# @example Differential styling
|
201
|
+
# # Differential styles apply on top of cell styles. Used in Conditional Formatting. Must specify :type => :dxf, and you can't use :num_fmt.
|
202
|
+
# require "rubygems" # if that is your preferred way to manage gems!
|
203
|
+
# require "axlsx"
|
204
|
+
#
|
205
|
+
# p = Axlsx::Package.new
|
206
|
+
# wb = p.workbook
|
207
|
+
# ws = wb.add_worksheet
|
208
|
+
#
|
209
|
+
# # define your styles
|
210
|
+
# profitable = wb.styles.add_style(:bg_color => "FFFF0000",
|
211
|
+
# :fg_color=>"#FF000000",
|
212
|
+
# :type => :dxf)
|
213
|
+
#
|
214
|
+
# ws.add_row ["Genreated At:", Time.now], :styles=>[nil, date_time]
|
215
|
+
# ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
|
216
|
+
# ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
|
217
|
+
# ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
|
218
|
+
# ws.add_row ["Q2", 3000, 30], :style=>[title, currency, percent]
|
219
|
+
# ws.add_row ["Q3", 1000, 10], :style=>[title, currency, percent]
|
220
|
+
# ws.add_row ["Q4", 2000, 20], :style=>[title, currency, percent]
|
221
|
+
#
|
222
|
+
# ws.add_conditional_formatting("A1:A7", { :type => :cellIs, :operator => :greaterThan, :formula => "2000", :dxfId => profitable, :priority => 1 })
|
223
|
+
# f = File.open('example_differential_styling', 'wb')
|
224
|
+
# p.serialize(f)
|
225
|
+
#
|
226
|
+
# An index for cell styles where keys are styles codes as per Axlsx::Style and values are Cell#raw_style
|
227
|
+
# The reason for the backward key/value ordering is that style lookup must be most efficient, while `add_style` can be less efficient
|
228
|
+
def add_style(options={})
|
229
|
+
# Default to :xf
|
230
|
+
options[:type] ||= :xf
|
231
|
+
|
232
|
+
raise ArgumentError, "Type must be one of [:xf, :dxf]" unless [:xf, :dxf].include?(options[:type] )
|
233
|
+
|
234
|
+
if options[:border].is_a?(Hash) && options[:border][:edges] == :all
|
235
|
+
options[:border][:edges] = Axlsx::Border::EDGES
|
236
|
+
end
|
237
|
+
|
238
|
+
if options[:type] == :xf
|
239
|
+
# Check to see if style in cache already
|
240
|
+
|
241
|
+
font_defaults = {name: @fonts.first.name, sz: @fonts.first.sz, family: @fonts.first.family}
|
242
|
+
|
243
|
+
raw_style = {type: :xf}.merge(font_defaults).merge(options)
|
244
|
+
|
245
|
+
if raw_style[:format_code]
|
246
|
+
raw_style.delete(:num_fmt)
|
247
|
+
end
|
248
|
+
|
249
|
+
xf_index = style_index.key(raw_style)
|
250
|
+
|
251
|
+
if xf_index
|
252
|
+
return xf_index
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
fill = parse_fill_options options
|
257
|
+
font = parse_font_options options
|
258
|
+
numFmt = parse_num_fmt_options options
|
259
|
+
border = parse_border_options options
|
260
|
+
alignment = parse_alignment_options options
|
261
|
+
protection = parse_protection_options options
|
262
|
+
|
263
|
+
case options[:type]
|
264
|
+
when :dxf
|
265
|
+
style = Dxf.new :fill => fill, :font => font, :numFmt => numFmt, :border => border, :alignment => alignment, :protection => protection
|
266
|
+
else
|
267
|
+
style = Xf.new :fillId=>fill || 0, :fontId=>font || 0, :numFmtId=>numFmt || 0, :borderId=>border || 0, :alignment => alignment, :protection => protection, :applyFill=>!fill.nil?, :applyFont=>!font.nil?, :applyNumberFormat =>!numFmt.nil?, :applyBorder=>!border.nil?, :applyAlignment => !alignment.nil?, :applyProtection => !protection.nil?
|
268
|
+
end
|
269
|
+
|
270
|
+
if options[:type] == :xf
|
271
|
+
xf_index = (cellXfs << style)
|
272
|
+
|
273
|
+
# Add styles to style_index cache for re-use
|
274
|
+
style_index[xf_index] = raw_style
|
275
|
+
|
276
|
+
return xf_index
|
277
|
+
else
|
278
|
+
dxf_index = (dxfs << style)
|
279
|
+
|
280
|
+
return dxf_index
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
# parses add_style options for protection styles
|
285
|
+
# noop if options hash does not include :hide or :locked key
|
286
|
+
|
287
|
+
# @option options [Boolean] hide boolean value defining cell protection attribute for hiding.
|
288
|
+
# @option options [Boolean] locked boolean value defining cell protection attribute for locking.
|
289
|
+
# @return [CellProtection]
|
290
|
+
def parse_protection_options(options={})
|
291
|
+
return if (options.keys & [:hidden, :locked]).empty?
|
292
|
+
CellProtection.new(options)
|
293
|
+
end
|
294
|
+
|
295
|
+
# parses add_style options for alignment
|
296
|
+
# noop if options hash does not include :alignment key
|
297
|
+
# @option options [Hash] alignment A hash of options to prive the CellAlignment intializer
|
298
|
+
# @return [CellAlignment]
|
299
|
+
# @see CellAlignment
|
300
|
+
def parse_alignment_options(options={})
|
301
|
+
return unless options[:alignment]
|
302
|
+
CellAlignment.new options[:alignment]
|
303
|
+
end
|
304
|
+
|
305
|
+
# parses add_style options for fonts. If the options hash contains :type => :dxf we return a new Font object.
|
306
|
+
# if not, we return the index of the newly created font object in the styles.fonts collection.
|
307
|
+
# @note noop if none of the options described here are set on the options parameter.
|
308
|
+
# @option options [Symbol] type The type of style object we are working with (dxf or xf)
|
309
|
+
# @option options [String] fg_color The text color
|
310
|
+
# @option options [Integer] sz The text size
|
311
|
+
# @option options [Boolean] b Indicates if the text should be bold
|
312
|
+
# @option options [Boolean] i Indicates if the text should be italicised
|
313
|
+
# @option options [Boolean] u Indicates if the text should be underlined
|
314
|
+
# @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
|
315
|
+
# @option options [Boolean] outline Indicates if the text should be rendered with a shadow
|
316
|
+
# @option options [Integer] charset The character set to use.
|
317
|
+
# @option options [Integer] family The font family to use.
|
318
|
+
# @option options [String] font_name The name of the font to use
|
319
|
+
# @return [Font|Integer]
|
320
|
+
def parse_font_options(options={})
|
321
|
+
return if (options.keys & [:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name]).empty?
|
322
|
+
Axlsx.instance_values_for(fonts.first).each do |key, value|
|
323
|
+
# Thanks for that 1.8.7 - cant do a simple merge...
|
324
|
+
options[key.to_sym] = value unless options.keys.include?(key.to_sym)
|
325
|
+
end
|
326
|
+
font = Font.new(options)
|
327
|
+
font.color = Color.new(:rgb => options[:fg_color]) if options[:fg_color]
|
328
|
+
font.name = options[:font_name] if options[:font_name]
|
329
|
+
options[:type] == :dxf ? font : fonts << font
|
330
|
+
end
|
331
|
+
|
332
|
+
# parses add_style options for fills. If the options hash contains :type => :dxf we return a Fill object. If not, we return the index of the fill after being added to the fills collection.
|
333
|
+
# @note noop if :bg_color is not specified in options
|
334
|
+
# @option options [String] bg_color The rgb color to apply to the fill
|
335
|
+
# @return [Fill|Integer]
|
336
|
+
def parse_fill_options(options={})
|
337
|
+
return unless options[:bg_color]
|
338
|
+
color = Color.new(:rgb=>options[:bg_color])
|
339
|
+
dxf = options[:type] == :dxf
|
340
|
+
color_key = dxf ? :bgColor : :fgColor
|
341
|
+
pattern = PatternFill.new(:patternType =>:solid, color_key=>color)
|
342
|
+
fill = Fill.new(pattern)
|
343
|
+
dxf ? fill : fills << fill
|
344
|
+
end
|
345
|
+
|
346
|
+
# parses Style#add_style options for borders.
|
347
|
+
# @note noop if :border is not specified in options
|
348
|
+
# @option options [Hash|Integer] A border style definition hash or the index of an existing border.
|
349
|
+
# Border style definition hashes must include :style and :color key-value entries and
|
350
|
+
# may include an :edges entry that references an array of symbols identifying which border edges
|
351
|
+
# you wish to apply the style or any other valid Border initializer options.
|
352
|
+
# If the :edges entity is not provided the style is applied to all edges of cells that reference this style.
|
353
|
+
# Also available :border_top, :border_right, :border_bottom and :border_left options with :style and/or :color
|
354
|
+
# key-value entries, which override :border values.
|
355
|
+
# @example
|
356
|
+
# #apply a thick red border to the top and bottom
|
357
|
+
# { :border => { :style => :thick, :color => "FFFF0000", :edges => [:top, :bottom] }
|
358
|
+
# @return [Border|Integer]
|
359
|
+
def parse_border_options(options={})
|
360
|
+
if options[:border].nil? && Border::EDGES.all?{|x| options["border_#{x}".to_sym].nil? }
|
361
|
+
return nil
|
362
|
+
end
|
363
|
+
|
364
|
+
if options[:border].is_a?(Integer)
|
365
|
+
if options[:border] >= borders.size
|
366
|
+
raise ArgumentError, (ERR_INVALID_BORDER_ID % options[:border])
|
367
|
+
end
|
368
|
+
|
369
|
+
if options[:type] == :dxf
|
370
|
+
return borders[options[:border]].clone
|
371
|
+
else
|
372
|
+
return options[:border]
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
validate_border_hash = ->(val){
|
377
|
+
if !(val.keys.include?(:style) && val.keys.include?(:color))
|
378
|
+
raise ArgumentError, (ERR_INVALID_BORDER_OPTIONS % options[:border])
|
379
|
+
end
|
380
|
+
}
|
381
|
+
|
382
|
+
borders_array = []
|
383
|
+
|
384
|
+
if options[:border].nil?
|
385
|
+
base_border_opts = {}
|
386
|
+
else
|
387
|
+
if options[:border].is_a?(Array)
|
388
|
+
borders_array += options[:border]
|
389
|
+
|
390
|
+
base_border_opts = {}
|
391
|
+
|
392
|
+
options[:border].each do |b_opts|
|
393
|
+
if b_opts[:edges].nil?
|
394
|
+
base_border_opts = base_border_opts.merge(b_opts)
|
395
|
+
end
|
396
|
+
end
|
397
|
+
else
|
398
|
+
borders_array << options[:border]
|
399
|
+
|
400
|
+
base_border_opts = options[:border]
|
401
|
+
|
402
|
+
validate_border_hash.call(base_border_opts)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
Border::EDGES.each do |edge|
|
407
|
+
val = options["border_#{edge}".to_sym]
|
408
|
+
|
409
|
+
if val
|
410
|
+
borders_array << val.merge(edges: [edge])
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
border = Border.new(base_border_opts)
|
415
|
+
|
416
|
+
Border::EDGES.each do |edge|
|
417
|
+
edge_b_opts = base_border_opts
|
418
|
+
|
419
|
+
skip_edge = true
|
420
|
+
|
421
|
+
borders_array.each do |b_opts|
|
422
|
+
if b_opts[:edges] && b_opts[:edges].include?(edge)
|
423
|
+
edge_b_opts = edge_b_opts.merge(b_opts)
|
424
|
+
skip_edge = false
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
if options["border_#{edge}".to_sym]
|
429
|
+
edge_b_opts = edge_b_opts.merge(options["border_#{edge}".to_sym])
|
430
|
+
skip_edge = false
|
431
|
+
end
|
432
|
+
|
433
|
+
if skip_edge && base_border_opts[:edges]
|
434
|
+
next
|
435
|
+
end
|
436
|
+
|
437
|
+
if !edge_b_opts.empty?
|
438
|
+
if base_border_opts.empty?
|
439
|
+
validate_border_hash.call(edge_b_opts)
|
440
|
+
end
|
441
|
+
|
442
|
+
border.prs << BorderPr.new({
|
443
|
+
:name => edge,
|
444
|
+
:style => edge_b_opts[:style],
|
445
|
+
:color => Color.new(:rgb => edge_b_opts[:color]) },
|
446
|
+
)
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
if options[:type] == :dxf
|
451
|
+
return border
|
452
|
+
else
|
453
|
+
return borders << border
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
# Parses Style#add_style options for number formatting.
|
458
|
+
# noop if neither :format_code or :num_format options are set.
|
459
|
+
# @option options [Hash] A hash describing the :format_code and/or :num_fmt integer for the style.
|
460
|
+
# @return [NumFmt|Integer]
|
461
|
+
def parse_num_fmt_options(options={})
|
462
|
+
return if (options.keys & [:format_code, :num_fmt]).empty?
|
463
|
+
|
464
|
+
#When the user provides format_code - we always need to create a new numFmt object
|
465
|
+
#When the type is :dxf we always need to create a new numFmt object
|
466
|
+
if options[:format_code] || options[:type] == :dxf
|
467
|
+
#If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
|
468
|
+
options[:num_fmt] ||= (@numFmts.map{ |num_fmt| num_fmt.numFmtId }.max + 1) if options[:type] != :dxf
|
469
|
+
numFmt = NumFmt.new(:numFmtId => options[:num_fmt] || 0, :formatCode=> options[:format_code].to_s)
|
470
|
+
options[:type] == :dxf ? numFmt : (numFmts << numFmt; numFmt.numFmtId)
|
471
|
+
else
|
472
|
+
options[:num_fmt]
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
# Serializes the object
|
477
|
+
# @param [String] str
|
478
|
+
# @return [String]
|
479
|
+
def to_xml_string(str = '')
|
480
|
+
str << ('<styleSheet xmlns="' << XML_NS << '">')
|
481
|
+
instance_vals = Axlsx.instance_values_for(self)
|
482
|
+
[:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
|
483
|
+
instance_vals[key.to_s].to_xml_string(str) unless instance_vals[key.to_s].nil?
|
484
|
+
end
|
485
|
+
str << '</styleSheet>'
|
486
|
+
end
|
487
|
+
|
488
|
+
private
|
489
|
+
# Creates the default set of styles the exel requires to be valid as well as setting up the
|
490
|
+
# Axlsx::STYLE_THIN_BORDER
|
491
|
+
def load_default_styles
|
492
|
+
@numFmts = SimpleTypedList.new NumFmt, 'numFmts'
|
493
|
+
@numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode=> "yyyy/mm/dd")
|
494
|
+
@numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode=> "yyyy/mm/dd hh:mm:ss")
|
495
|
+
|
496
|
+
@numFmts.lock
|
497
|
+
|
498
|
+
@fonts = SimpleTypedList.new Font, 'fonts'
|
499
|
+
@fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
|
500
|
+
@fonts.lock
|
501
|
+
|
502
|
+
@fills = SimpleTypedList.new Fill, 'fills'
|
503
|
+
@fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:none))
|
504
|
+
@fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:gray125))
|
505
|
+
@fills.lock
|
506
|
+
|
507
|
+
@borders = SimpleTypedList.new Border, 'borders'
|
508
|
+
@borders << Border.new
|
509
|
+
black_border = Border.new
|
510
|
+
[:left, :right, :top, :bottom].each do |item|
|
511
|
+
black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
|
512
|
+
end
|
513
|
+
@borders << black_border
|
514
|
+
@borders.lock
|
515
|
+
|
516
|
+
@cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
|
517
|
+
@cellStyleXfs << Xf.new(:borderId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
|
518
|
+
@cellStyleXfs.lock
|
519
|
+
|
520
|
+
@cellStyles = SimpleTypedList.new CellStyle, 'cellStyles'
|
521
|
+
@cellStyles << CellStyle.new(:name =>"Normal", :builtinId =>0, :xfId=>0)
|
522
|
+
@cellStyles.lock
|
523
|
+
|
524
|
+
@cellXfs = SimpleTypedList.new Xf, "cellXfs"
|
525
|
+
@cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
|
526
|
+
@cellXfs << Xf.new(:borderId=>1, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
|
527
|
+
# default date formatting
|
528
|
+
@cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>14, :fontId=>0, :fillId=>0, :applyNumberFormat=>1)
|
529
|
+
@cellXfs.lock
|
530
|
+
|
531
|
+
@dxfs = SimpleTypedList.new(Dxf, "dxfs"); @dxfs.lock
|
532
|
+
@tableStyles = TableStyles.new(:defaultTableStyle => "TableStyleMedium9", :defaultPivotStyle => "PivotStyleLight16"); @tableStyles.lock
|
533
|
+
end
|
534
|
+
end
|
535
|
+
end
|