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.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -11
  3. data/README.md +43 -16
  4. data/Rakefile +5 -11
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
  7. data/lib/axlsx/content_type/content_type.rb +8 -10
  8. data/lib/axlsx/content_type/default.rb +7 -6
  9. data/lib/axlsx/content_type/override.rb +6 -5
  10. data/lib/axlsx/doc_props/app.rb +96 -32
  11. data/lib/axlsx/doc_props/core.rb +9 -12
  12. data/lib/axlsx/drawing/area_chart.rb +16 -17
  13. data/lib/axlsx/drawing/area_series.rb +23 -18
  14. data/lib/axlsx/drawing/ax_data_source.rb +4 -7
  15. data/lib/axlsx/drawing/axes.rb +11 -10
  16. data/lib/axlsx/drawing/axis.rb +83 -36
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
  18. data/lib/axlsx/drawing/bar_chart.rb +29 -20
  19. data/lib/axlsx/drawing/bar_series.rb +23 -18
  20. data/lib/axlsx/drawing/bubble_chart.rb +9 -10
  21. data/lib/axlsx/drawing/bubble_series.rb +11 -12
  22. data/lib/axlsx/drawing/cat_axis.rb +38 -28
  23. data/lib/axlsx/drawing/chart.rb +52 -30
  24. data/lib/axlsx/drawing/d_lbls.rb +36 -32
  25. data/lib/axlsx/drawing/drawing.rb +61 -62
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  27. data/lib/axlsx/drawing/hyperlink.rb +22 -14
  28. data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
  29. data/lib/axlsx/drawing/line_chart.rb +16 -17
  30. data/lib/axlsx/drawing/line_series.rb +23 -18
  31. data/lib/axlsx/drawing/marker.rb +29 -16
  32. data/lib/axlsx/drawing/num_data.rb +13 -16
  33. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  34. data/lib/axlsx/drawing/num_val.rb +10 -11
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
  36. data/lib/axlsx/drawing/pic.rb +68 -24
  37. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +26 -17
  41. data/lib/axlsx/drawing/scaling.rb +26 -13
  42. data/lib/axlsx/drawing/scatter_chart.rb +10 -11
  43. data/lib/axlsx/drawing/scatter_series.rb +17 -18
  44. data/lib/axlsx/drawing/ser_axis.rb +22 -19
  45. data/lib/axlsx/drawing/series.rb +14 -8
  46. data/lib/axlsx/drawing/series_title.rb +6 -6
  47. data/lib/axlsx/drawing/str_data.rb +10 -13
  48. data/lib/axlsx/drawing/str_val.rb +8 -9
  49. data/lib/axlsx/drawing/title.rb +23 -27
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +9 -9
  51. data/lib/axlsx/drawing/val_axis.rb +7 -8
  52. data/lib/axlsx/drawing/view_3D.rb +38 -30
  53. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  54. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  55. data/lib/axlsx/package.rb +134 -99
  56. data/lib/axlsx/rels/relationship.rb +42 -30
  57. data/lib/axlsx/rels/relationships.rb +9 -10
  58. data/lib/axlsx/stylesheet/border.rb +16 -8
  59. data/lib/axlsx/stylesheet/border_pr.rb +24 -12
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
  61. data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
  62. data/lib/axlsx/stylesheet/cell_style.rb +36 -15
  63. data/lib/axlsx/stylesheet/color.rb +23 -14
  64. data/lib/axlsx/stylesheet/dxf.rb +36 -15
  65. data/lib/axlsx/stylesheet/fill.rb +7 -6
  66. data/lib/axlsx/stylesheet/font.rb +71 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
  69. data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
  71. data/lib/axlsx/stylesheet/styles.rb +167 -118
  72. data/lib/axlsx/stylesheet/table_style.rb +20 -10
  73. data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
  74. data/lib/axlsx/stylesheet/table_styles.rb +16 -11
  75. data/lib/axlsx/stylesheet/theme.rb +163 -0
  76. data/lib/axlsx/stylesheet/xf.rb +78 -25
  77. data/lib/axlsx/util/accessors.rb +13 -11
  78. data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
  79. data/lib/axlsx/util/constants.rb +133 -110
  80. data/lib/axlsx/util/mime_type_utils.rb +75 -5
  81. data/lib/axlsx/util/options_parser.rb +4 -3
  82. data/lib/axlsx/util/serialized_attributes.rb +47 -23
  83. data/lib/axlsx/util/simple_typed_list.rb +77 -64
  84. data/lib/axlsx/util/storage.rb +38 -41
  85. data/lib/axlsx/util/uri_utils.rb +70 -0
  86. data/lib/axlsx/util/validators.rb +111 -48
  87. data/lib/axlsx/util/zip_command.rb +10 -12
  88. data/lib/axlsx/version.rb +3 -2
  89. data/lib/axlsx/workbook/defined_name.rb +13 -9
  90. data/lib/axlsx/workbook/defined_names.rb +5 -4
  91. data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
  92. data/lib/axlsx/workbook/workbook.rb +152 -120
  93. data/lib/axlsx/workbook/workbook_view.rb +9 -12
  94. data/lib/axlsx/workbook/workbook_views.rb +5 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
  96. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
  97. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
  98. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
  100. data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
  101. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  102. data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
  103. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
  104. data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
  105. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  106. data/lib/axlsx/workbook/worksheet/col.rb +32 -19
  107. data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
  108. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  109. data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
  110. data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
  111. data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
  112. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
  113. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
  114. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  116. data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
  117. data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
  118. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  119. data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
  120. data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
  121. data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
  122. data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
  123. data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
  125. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
  126. data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
  127. data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
  128. data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
  129. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  130. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
  131. data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
  132. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  133. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
  134. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  135. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
  136. data/lib/axlsx/workbook/worksheet/row.rb +34 -23
  137. data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
  138. data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
  139. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -7
  140. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  141. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  142. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +12 -8
  143. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
  144. data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
  145. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  146. data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
  147. data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
  148. data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
  149. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
  150. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  151. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
  152. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
  153. data/lib/axlsx.rb +120 -60
  154. data/lib/caxlsx.rb +3 -2
  155. metadata +42 -75
@@ -1,18 +1,18 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # TableStyles represents a collection of style definitions for table styles and pivot table styles.
4
5
  # @note Support for custom table styles does not exist in this version. Many of the classes required are defined in preparation for future release. Please do not attempt to add custom table styles.
5
6
  class TableStyles < SimpleTypedList
6
-
7
7
  include Axlsx::SerializedAttributes
8
8
 
9
9
  # Creates a new TableStyles object that is a container for TableStyle objects
10
10
  # @option options [String] defaultTableStyle
11
11
  # @option options [String] defaultPivotStyle
12
- def initialize(options={})
12
+ def initialize(options = {})
13
13
  @defaultTableStyle = options[:defaultTableStyle] || "TableStyleMedium9"
14
14
  @defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
15
- super TableStyle
15
+ super(TableStyle)
16
16
  end
17
17
 
18
18
  serializable_attributes :defaultTableStyle, :defaultPivotStyle
@@ -25,22 +25,27 @@ module Axlsx
25
25
  # @return [String]
26
26
  attr_reader :defaultPivotStyle
27
27
 
28
- # @see defaultTableStyle
29
- def defaultTableStyle=(v) Axlsx::validate_string(v); @defaultTableStyle = v; end
28
+ # @see defaultTableStyle
29
+ def defaultTableStyle=(v)
30
+ Axlsx.validate_string(v)
31
+ @defaultTableStyle = v
32
+ end
33
+
30
34
  # @see defaultPivotStyle
31
- def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end
35
+ def defaultPivotStyle=(v)
36
+ Axlsx.validate_string(v)
37
+ @defaultPivotStyle = v
38
+ end
32
39
 
33
40
  # Serializes the object
34
41
  # @param [String] str
35
42
  # @return [String]
36
- def to_xml_string(str = '')
43
+ def to_xml_string(str = +'')
37
44
  str << '<tableStyles '
38
- serialized_attributes str, {:count => self.size }
45
+ serialized_attributes str, { count: size }
39
46
  str << '>'
40
47
  each { |table_style| table_style.to_xml_string(str) }
41
48
  str << '</tableStyles>'
42
49
  end
43
-
44
50
  end
45
-
46
51
  end
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Axlsx
4
+ # Theme represents the theme part of the package and is responsible for
5
+ # generating the default Office theme that is required for encryption compatibility
6
+ class Theme
7
+ # The part name of this theme
8
+ # @return [String]
9
+ def pn
10
+ THEME_PN
11
+ end
12
+
13
+ # Serializes the default theme to XML
14
+ # @param [String] str
15
+ # @return [String]
16
+ def to_xml_string(str = +'')
17
+ str << <<~XML.delete("\n")
18
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
19
+ <a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme">
20
+ <a:themeElements>
21
+ <a:clrScheme name="Office">
22
+ <a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1>
23
+ <a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1>
24
+ <a:dk2><a:srgbClr val="1F497D"/></a:dk2>
25
+ <a:lt2><a:srgbClr val="EEECE1"/></a:lt2>
26
+ <a:accent1><a:srgbClr val="4F81BD"/></a:accent1>
27
+ <a:accent2><a:srgbClr val="C0504D"/></a:accent2>
28
+ <a:accent3><a:srgbClr val="9BBB59"/></a:accent3>
29
+ <a:accent4><a:srgbClr val="8064A2"/></a:accent4>
30
+ <a:accent5><a:srgbClr val="4BACC6"/></a:accent5>
31
+ <a:accent6><a:srgbClr val="F79646"/></a:accent6>
32
+ <a:hlink><a:srgbClr val="0000FF"/></a:hlink>
33
+ <a:folHlink><a:srgbClr val="800080"/></a:folHlink>
34
+ </a:clrScheme>
35
+
36
+ <a:fontScheme name="Office">
37
+ <a:majorFont>
38
+ <a:latin typeface="Cambria"/>
39
+ <a:ea typeface=""/>
40
+ <a:cs typeface=""/>
41
+ </a:majorFont>
42
+ <a:minorFont>
43
+ <a:latin typeface="Calibri"/>
44
+ <a:ea typeface=""/>
45
+ <a:cs typeface=""/>
46
+ </a:minorFont>
47
+ </a:fontScheme>
48
+
49
+ <a:fmtScheme name="Office">
50
+ <a:fillStyleLst>
51
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
52
+ <a:gradFill rotWithShape="1">
53
+ <a:gsLst>
54
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
55
+ <a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
56
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
57
+ </a:gsLst>
58
+ <a:lin ang="16200000" scaled="1"/>
59
+ </a:gradFill>
60
+ <a:gradFill rotWithShape="1">
61
+ <a:gsLst>
62
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="100000"/><a:shade val="100000"/><a:satMod val="130000"/></a:schemeClr></a:gs>
63
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="50000"/><a:shade val="100000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
64
+ </a:gsLst>
65
+ <a:lin ang="16200000" scaled="false"/>
66
+ </a:gradFill>
67
+ </a:fillStyleLst>
68
+
69
+ <a:lnStyleLst>
70
+ <a:ln w="9525" cap="flat" cmpd="sng" algn="ctr">
71
+ <a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill>
72
+ <a:prstDash val="solid"/>
73
+ </a:ln>
74
+ <a:ln w="25400" cap="flat" cmpd="sng" algn="ctr">
75
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
76
+ <a:prstDash val="solid"/>
77
+ </a:ln>
78
+ <a:ln w="38100" cap="flat" cmpd="sng" algn="ctr">
79
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
80
+ <a:prstDash val="solid"/>
81
+ </a:ln>
82
+ </a:lnStyleLst>
83
+
84
+ <a:effectStyleLst>
85
+ <a:effectStyle>
86
+ <a:effectLst>
87
+ <a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="false">
88
+ <a:srgbClr val="000000"><a:alpha val="38000"/></a:srgbClr>
89
+ </a:outerShdw>
90
+ </a:effectLst>
91
+ </a:effectStyle>
92
+ <a:effectStyle>
93
+ <a:effectLst>
94
+ <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="false">
95
+ <a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr>
96
+ </a:outerShdw>
97
+ </a:effectLst>
98
+ </a:effectStyle>
99
+ <a:effectStyle>
100
+ <a:effectLst>
101
+ <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="false">
102
+ <a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr>
103
+ </a:outerShdw>
104
+ </a:effectLst>
105
+ <a:scene3d>
106
+ <a:camera prst="orthographicFront"><a:rot lat="0" lon="0" rev="0"/></a:camera>
107
+ <a:lightRig rig="threePt" dir="t"><a:rot lat="0" lon="0" rev="1200000"/></a:lightRig>
108
+ </a:scene3d>
109
+ <a:sp3d><a:bevelT w="63500" h="25400"/></a:sp3d>
110
+ </a:effectStyle>
111
+ </a:effectStyleLst>
112
+
113
+ <a:bgFillStyleLst>
114
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
115
+ <a:gradFill rotWithShape="1">
116
+ <a:gsLst>
117
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
118
+ <a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
119
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs>
120
+ </a:gsLst>
121
+ <a:path path="circle"><a:fillToRect l="50000" t="-80000" r="50000" b="180000"/></a:path>
122
+ </a:gradFill>
123
+ <a:gradFill rotWithShape="1">
124
+ <a:gsLst>
125
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
126
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs>
127
+ </a:gsLst>
128
+ <a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path>
129
+ </a:gradFill>
130
+ </a:bgFillStyleLst>
131
+ </a:fmtScheme>
132
+ </a:themeElements>
133
+
134
+ <a:objectDefaults>
135
+ <a:spDef>
136
+ <a:spPr/>
137
+ <a:bodyPr/>
138
+ <a:lstStyle/>
139
+ <a:style>
140
+ <a:lnRef idx="1"><a:schemeClr val="accent1"/></a:lnRef>
141
+ <a:fillRef idx="3"><a:schemeClr val="accent1"/></a:fillRef>
142
+ <a:effectRef idx="2"><a:schemeClr val="accent1"/></a:effectRef>
143
+ <a:fontRef idx="minor"><a:schemeClr val="lt1"/></a:fontRef>
144
+ </a:style>
145
+ </a:spDef>
146
+ <a:lnDef>
147
+ <a:spPr/>
148
+ <a:bodyPr/>
149
+ <a:lstStyle/>
150
+ <a:style>
151
+ <a:lnRef idx="2"><a:schemeClr val="accent1"/></a:lnRef>
152
+ <a:fillRef idx="0"><a:schemeClr val="accent1"/></a:fillRef>
153
+ <a:effectRef idx="1"><a:schemeClr val="accent1"/></a:effectRef>
154
+ <a:fontRef idx="minor"><a:schemeClr val="tx1"/></a:fontRef>
155
+ </a:style>
156
+ </a:lnDef>
157
+ </a:objectDefaults>
158
+ <a:extraClrSchemeLst/>
159
+ </a:theme>
160
+ XML
161
+ end
162
+ end
163
+ end
@@ -1,12 +1,14 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # The Xf class defines a formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
4
5
  # @see Styles#add_style
5
6
  class Xf
6
- #does not support extList (ExtensionList)
7
+ # does not support extList (ExtensionList)
7
8
 
8
9
  include Axlsx::SerializedAttributes
9
10
  include Axlsx::OptionsParser
11
+
10
12
  # Creates a new Xf object
11
13
  # @option options [Integer] numFmtId
12
14
  # @option options [Integer] fontId
@@ -23,7 +25,7 @@ module Axlsx
23
25
  # @option options [Boolean] applyProtection
24
26
  # @option options [CellAlignment] alignment
25
27
  # @option options [CellProtection] protection
26
- def initialize(options={})
28
+ def initialize(options = {})
27
29
  parse_options options
28
30
  end
29
31
 
@@ -61,7 +63,7 @@ module Axlsx
61
63
  # @return [Integer]
62
64
  attr_reader :xfId
63
65
 
64
- # indecates if text should be prefixed by a single quote in the cell
66
+ # indicates if text should be prefixed by a single quote in the cell
65
67
  # @return [Boolean]
66
68
  attr_reader :quotePrefix
67
69
 
@@ -93,55 +95,106 @@ module Axlsx
93
95
  # @return [Boolean]
94
96
  attr_reader :applyProtection
95
97
 
96
- # @see Xf#alignment
97
- def alignment=(v) DataTypeValidator.validate "Xf.alignment", CellAlignment, v; @alignment = v end
98
+ # @see Xf#alignment
99
+ def alignment=(v)
100
+ DataTypeValidator.validate "Xf.alignment", CellAlignment, v
101
+ @alignment = v
102
+ end
98
103
 
99
104
  # @see protection
100
- def protection=(v) DataTypeValidator.validate "Xf.protection", CellProtection, v; @protection = v end
105
+ def protection=(v)
106
+ DataTypeValidator.validate "Xf.protection", CellProtection, v
107
+ @protection = v
108
+ end
101
109
 
102
110
  # @see numFmtId
103
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
111
+ def numFmtId=(v)
112
+ Axlsx.validate_unsigned_int v
113
+ @numFmtId = v
114
+ end
104
115
 
105
116
  # @see fontId
106
- def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
117
+ def fontId=(v)
118
+ Axlsx.validate_unsigned_int v
119
+ @fontId = v
120
+ end
121
+
107
122
  # @see fillId
108
- def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
123
+ def fillId=(v)
124
+ Axlsx.validate_unsigned_int v
125
+ @fillId = v
126
+ end
127
+
109
128
  # @see borderId
110
- def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
129
+ def borderId=(v)
130
+ Axlsx.validate_unsigned_int v
131
+ @borderId = v
132
+ end
133
+
111
134
  # @see xfId
112
- def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
135
+ def xfId=(v)
136
+ Axlsx.validate_unsigned_int v
137
+ @xfId = v
138
+ end
139
+
113
140
  # @see quotePrefix
114
- def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
141
+ def quotePrefix=(v)
142
+ Axlsx.validate_boolean v
143
+ @quotePrefix = v
144
+ end
145
+
115
146
  # @see pivotButton
116
- def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
147
+ def pivotButton=(v)
148
+ Axlsx.validate_boolean v
149
+ @pivotButton = v
150
+ end
151
+
117
152
  # @see applyNumberFormat
118
- def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
153
+ def applyNumberFormat=(v)
154
+ Axlsx.validate_boolean v
155
+ @applyNumberFormat = v
156
+ end
157
+
119
158
  # @see applyFont
120
- def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
159
+ def applyFont=(v)
160
+ Axlsx.validate_boolean v
161
+ @applyFont = v
162
+ end
163
+
121
164
  # @see applyFill
122
- def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
165
+ def applyFill=(v)
166
+ Axlsx.validate_boolean v
167
+ @applyFill = v
168
+ end
123
169
 
124
170
  # @see applyBorder
125
- def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
171
+ def applyBorder=(v)
172
+ Axlsx.validate_boolean v
173
+ @applyBorder = v
174
+ end
126
175
 
127
176
  # @see applyAlignment
128
- def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
177
+ def applyAlignment=(v)
178
+ Axlsx.validate_boolean v
179
+ @applyAlignment = v
180
+ end
129
181
 
130
182
  # @see applyProtection
131
- def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
183
+ def applyProtection=(v)
184
+ Axlsx.validate_boolean v
185
+ @applyProtection = v
186
+ end
132
187
 
133
188
  # Serializes the object
134
189
  # @param [String] str
135
190
  # @return [String]
136
- def to_xml_string(str = '')
191
+ def to_xml_string(str = +'')
137
192
  str << '<xf '
138
193
  serialized_attributes str
139
194
  str << '>'
140
- alignment.to_xml_string(str) if self.alignment
141
- protection.to_xml_string(str) if self.protection
195
+ alignment.to_xml_string(str) if alignment
196
+ protection.to_xml_string(str) if protection
142
197
  str << '</xf>'
143
198
  end
144
-
145
-
146
199
  end
147
200
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # This module defines some of the more common validating attribute
3
5
  # accessors that we use in Axlsx
@@ -14,7 +16,6 @@ module Axlsx
14
16
 
15
17
  # Defines the class level xxx_attr_accessor methods
16
18
  module ClassMethods
17
-
18
19
  # Creates one or more string validated attr_accessors
19
20
  # @param [Array] symbols An array of symbols representing the
20
21
  # names of the attributes you will add to your class.
@@ -22,8 +23,7 @@ module Axlsx
22
23
  validated_attr_accessor(symbols, :validate_string)
23
24
  end
24
25
 
25
-
26
- # Creates one or more usigned integer attr_accessors
26
+ # Creates one or more unsigned integer attr_accessors
27
27
  # @param [Array] symbols An array of symbols representing the
28
28
  # names of the attributes you will add to your class
29
29
  def unsigned_int_attr_accessor(*symbols)
@@ -44,21 +44,23 @@ module Axlsx
44
44
  validated_attr_accessor(symbols, :validate_boolean)
45
45
  end
46
46
 
47
- # Template for defining validated write accessors
48
- SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end".freeze
49
-
50
47
  # Creates the reader and writer access methods
51
- # @param [Array] symbols The names of the attributes to create
52
- # @param [String] validator The axlsx validation method to use when
48
+ # @param [Array<Symbol, String>] symbols The names of the attributes to create
49
+ # @param [Symbol|String] validator The axlsx validation method to use when
53
50
  # validating assignation.
54
- # @see lib/axlsx/util/validators.rb
51
+ # @see lib/axlsx/util/validators.rb
55
52
  def validated_attr_accessor(symbols, validator)
56
53
  symbols.each do |symbol|
57
54
  attr_reader symbol
58
- module_eval(SETTER % [symbol, validator, symbol], __FILE__, __LINE__)
55
+
56
+ module_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
57
+ def #{symbol}=(value) # def name=(value)
58
+ Axlsx.#{validator} value # Axlsx.validate_string value
59
+ @#{symbol} = value # @name = value
60
+ end # end
61
+ RUBY_EVAL
59
62
  end
60
63
  end
61
64
  end
62
65
  end
63
66
  end
64
-
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Axlsx
4
+ # The BufferedZipOutputStream buffers the output in order to avoid appending many small strings directly to the
5
+ # the `Zip::OutputStream`.
6
+ #
7
+ # The methods provided here mimic `Zip::OutputStream` so that this class can be used a drop-in replacement.
8
+ class BufferedZipOutputStream
9
+ # The 4_096 was chosen somewhat arbitrary, however, it was difficult to see any obvious improvement with larger
10
+ # buffer sizes.
11
+ BUFFER_SIZE = 4_096
12
+ # The suppress_extra_fields method was introduced in rubyzip 3.2
13
+ # Between rubyzip 3.0 and 3.2, it automatically writes zip64 support to the xlsx files
14
+ # See: https://github.com/caxlsx/caxlsx/issues/481
15
+ SUPPRESS_ZIP64 = Zip::OutputStream.method(:open).parameters.any? { |_, key| key == :suppress_extra_fields } ? { suppress_extra_fields: :zip64 } : {}
16
+
17
+ def initialize(zos)
18
+ @zos = zos
19
+ @buffer = String.new(capacity: BUFFER_SIZE * 2)
20
+ end
21
+
22
+ # Create a temporary directory for writing files to.
23
+ #
24
+ # The directory and its contents are removed at the end of the block.
25
+ def self.open(file_name, encrypter = nil)
26
+ Zip::OutputStream.open(file_name, encrypter: encrypter, **SUPPRESS_ZIP64) do |zos|
27
+ bzos = new(zos)
28
+ yield(bzos)
29
+ ensure
30
+ bzos.flush if bzos
31
+ end
32
+ end
33
+
34
+ def self.write_buffer(io = ::StringIO.new, encrypter = nil)
35
+ Zip::OutputStream.write_buffer(io, encrypter: encrypter, **SUPPRESS_ZIP64) do |zos|
36
+ bzos = new(zos)
37
+ yield(bzos)
38
+ ensure
39
+ bzos.flush if bzos
40
+ end
41
+ end
42
+
43
+ # Closes the current entry and opens a new for writing.
44
+ def put_next_entry(entry)
45
+ flush
46
+ @zos.put_next_entry(entry)
47
+ end
48
+
49
+ # Write to a buffer that will be written to the current entry
50
+ def write(content)
51
+ @buffer << content.to_s
52
+ flush if @buffer.size > BUFFER_SIZE
53
+ self
54
+ end
55
+ alias << write
56
+
57
+ def flush
58
+ return if @buffer.empty?
59
+
60
+ @zos << @buffer
61
+ @buffer.clear
62
+ end
63
+ end
64
+ end