axlsx 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/.yardopts +4 -0
  2. data/README.md +7 -4
  3. data/examples/example.rb +6 -4
  4. data/examples/example.rb~ +112 -0
  5. data/lib/schema/dc.xsd~ +118 -0
  6. data/lib/schema/dcterms.xsd~ +331 -0
  7. data/lib/schema/opc-coreProperties.xsd~ +50 -0
  8. metadata +43 -193
  9. data/Gemfile +0 -3
  10. data/Gemfile.lock +0 -29
  11. data/axlsx.gemspec +0 -42
  12. data/doc/Axlsx.html +0 -2718
  13. data/doc/Axlsx/App.html +0 -2640
  14. data/doc/Axlsx/Axis.html +0 -1075
  15. data/doc/Axlsx/Bar3DChart.html +0 -1182
  16. data/doc/Axlsx/BarSeries.html +0 -711
  17. data/doc/Axlsx/Border.html +0 -779
  18. data/doc/Axlsx/BorderPr.html +0 -709
  19. data/doc/Axlsx/CatAxis.html +0 -769
  20. data/doc/Axlsx/CatAxisData.html +0 -397
  21. data/doc/Axlsx/Cell.html +0 -3187
  22. data/doc/Axlsx/CellAlignment.html +0 -1247
  23. data/doc/Axlsx/CellProtection.html +0 -565
  24. data/doc/Axlsx/CellStyle.html +0 -949
  25. data/doc/Axlsx/Chart.html +0 -1692
  26. data/doc/Axlsx/Color.html +0 -670
  27. data/doc/Axlsx/ContentType.html +0 -335
  28. data/doc/Axlsx/Core.html +0 -465
  29. data/doc/Axlsx/DataTypeValidator.html +0 -324
  30. data/doc/Axlsx/Default.html +0 -565
  31. data/doc/Axlsx/Drawing.html +0 -1264
  32. data/doc/Axlsx/Fill.html +0 -460
  33. data/doc/Axlsx/Font.html +0 -1554
  34. data/doc/Axlsx/GradientFill.html +0 -1026
  35. data/doc/Axlsx/GradientStop.html +0 -526
  36. data/doc/Axlsx/GraphicFrame.html +0 -642
  37. data/doc/Axlsx/Line3DChart.html +0 -1004
  38. data/doc/Axlsx/LineSeries.html +0 -605
  39. data/doc/Axlsx/Marker.html +0 -857
  40. data/doc/Axlsx/NumFmt.html +0 -562
  41. data/doc/Axlsx/OneCellAnchor.html +0 -982
  42. data/doc/Axlsx/Override.html +0 -552
  43. data/doc/Axlsx/Package.html +0 -825
  44. data/doc/Axlsx/Parser.html +0 -549
  45. data/doc/Axlsx/PatternFill.html +0 -681
  46. data/doc/Axlsx/Pic.html +0 -1701
  47. data/doc/Axlsx/PictureLocking.html +0 -1159
  48. data/doc/Axlsx/Pie3DChart.html +0 -489
  49. data/doc/Axlsx/PieSeries.html +0 -710
  50. data/doc/Axlsx/RegexValidator.html +0 -268
  51. data/doc/Axlsx/Relationship.html +0 -554
  52. data/doc/Axlsx/Relationships.html +0 -338
  53. data/doc/Axlsx/RestrictionValidator.html +0 -300
  54. data/doc/Axlsx/Row.html +0 -916
  55. data/doc/Axlsx/Scaling.html +0 -742
  56. data/doc/Axlsx/SerAxis.html +0 -641
  57. data/doc/Axlsx/Series.html +0 -813
  58. data/doc/Axlsx/SeriesTitle.html +0 -290
  59. data/doc/Axlsx/Styles.html +0 -1754
  60. data/doc/Axlsx/TableStyle.html +0 -705
  61. data/doc/Axlsx/TableStyleElement.html +0 -677
  62. data/doc/Axlsx/TableStyles.html +0 -594
  63. data/doc/Axlsx/Title.html +0 -543
  64. data/doc/Axlsx/TwoCellAnchor.html +0 -973
  65. data/doc/Axlsx/ValAxis.html +0 -538
  66. data/doc/Axlsx/ValAxisData.html +0 -321
  67. data/doc/Axlsx/View3D.html +0 -973
  68. data/doc/Axlsx/Workbook.html +0 -1630
  69. data/doc/Axlsx/Worksheet.html +0 -2682
  70. data/doc/Axlsx/Xf.html +0 -1780
  71. data/doc/_index.html +0 -649
  72. data/doc/class_list.html +0 -47
  73. data/doc/css/common.css +0 -1
  74. data/doc/css/full_list.css +0 -55
  75. data/doc/css/style.css +0 -322
  76. data/doc/file.LICENSE.html +0 -91
  77. data/doc/file.README.html +0 -338
  78. data/doc/file_list.html +0 -52
  79. data/doc/frames.html +0 -13
  80. data/doc/index.html +0 -338
  81. data/doc/js/app.js +0 -205
  82. data/doc/js/full_list.js +0 -167
  83. data/doc/js/jquery.js +0 -16
  84. data/doc/method_list.html +0 -3502
  85. data/doc/top-level-namespace.html +0 -103
  86. data/lib/axlsx.rb +0 -54
  87. data/lib/axlsx/content_type/content_type.rb +0 -23
  88. data/lib/axlsx/content_type/default.rb +0 -37
  89. data/lib/axlsx/content_type/override.rb +0 -37
  90. data/lib/axlsx/doc_props/app.rb +0 -178
  91. data/lib/axlsx/doc_props/core.rb +0 -34
  92. data/lib/axlsx/drawing/axis.rb +0 -90
  93. data/lib/axlsx/drawing/bar_3D_chart.rb +0 -128
  94. data/lib/axlsx/drawing/bar_series.rb +0 -64
  95. data/lib/axlsx/drawing/cat_axis.rb +0 -63
  96. data/lib/axlsx/drawing/cat_axis_data.rb +0 -35
  97. data/lib/axlsx/drawing/chart.rb +0 -179
  98. data/lib/axlsx/drawing/drawing.rb +0 -137
  99. data/lib/axlsx/drawing/graphic_frame.rb +0 -52
  100. data/lib/axlsx/drawing/line_3D_chart.rb +0 -106
  101. data/lib/axlsx/drawing/line_series.rb +0 -46
  102. data/lib/axlsx/drawing/marker.rb +0 -61
  103. data/lib/axlsx/drawing/one_cell_anchor.rb +0 -89
  104. data/lib/axlsx/drawing/pic.rb +0 -153
  105. data/lib/axlsx/drawing/picture_locking.rb +0 -72
  106. data/lib/axlsx/drawing/pie_3D_chart.rb +0 -41
  107. data/lib/axlsx/drawing/pie_series.rb +0 -56
  108. data/lib/axlsx/drawing/scaling.rb +0 -59
  109. data/lib/axlsx/drawing/ser_axis.rb +0 -45
  110. data/lib/axlsx/drawing/series.rb +0 -71
  111. data/lib/axlsx/drawing/series_title.rb +0 -22
  112. data/lib/axlsx/drawing/title.rb +0 -61
  113. data/lib/axlsx/drawing/two_cell_anchor.rb +0 -76
  114. data/lib/axlsx/drawing/val_axis.rb +0 -34
  115. data/lib/axlsx/drawing/val_axis_data.rb +0 -28
  116. data/lib/axlsx/drawing/view_3D.rb +0 -85
  117. data/lib/axlsx/package.rb +0 -214
  118. data/lib/axlsx/rels/relationship.rb +0 -44
  119. data/lib/axlsx/rels/relationships.rb +0 -25
  120. data/lib/axlsx/stylesheet/border.rb +0 -57
  121. data/lib/axlsx/stylesheet/border_pr.rb +0 -68
  122. data/lib/axlsx/stylesheet/cell_alignment.rb +0 -105
  123. data/lib/axlsx/stylesheet/cell_protection.rb +0 -36
  124. data/lib/axlsx/stylesheet/cell_style.rb +0 -65
  125. data/lib/axlsx/stylesheet/color.rb +0 -69
  126. data/lib/axlsx/stylesheet/fill.rb +0 -32
  127. data/lib/axlsx/stylesheet/font.rb +0 -139
  128. data/lib/axlsx/stylesheet/gradient_fill.rb +0 -76
  129. data/lib/axlsx/stylesheet/gradient_stop.rb +0 -33
  130. data/lib/axlsx/stylesheet/num_fmt.rb +0 -63
  131. data/lib/axlsx/stylesheet/pattern_fill.rb +0 -66
  132. data/lib/axlsx/stylesheet/styles.rb +0 -298
  133. data/lib/axlsx/stylesheet/table_style.rb +0 -47
  134. data/lib/axlsx/stylesheet/table_style_element.rb +0 -71
  135. data/lib/axlsx/stylesheet/table_styles.rb +0 -39
  136. data/lib/axlsx/stylesheet/xf.rb +0 -138
  137. data/lib/axlsx/util/constants.rb +0 -216
  138. data/lib/axlsx/util/parser.rb +0 -43
  139. data/lib/axlsx/util/simple_typed_list.rb +0 -160
  140. data/lib/axlsx/util/validators.rb +0 -132
  141. data/lib/axlsx/version.rb +0 -4
  142. data/lib/axlsx/workbook/workbook.rb +0 -160
  143. data/lib/axlsx/workbook/worksheet/cell.rb +0 -340
  144. data/lib/axlsx/workbook/worksheet/row.rb +0 -107
  145. data/lib/axlsx/workbook/worksheet/worksheet.rb +0 -278
@@ -1,32 +0,0 @@
1
- module Axlsx
2
- # The Fill is a formatting object that manages the background color, and pattern for cells.
3
- # @note The recommended way to manage styles in your workbook is to use Styles#add_style.
4
- # @see Styles#add_style
5
- # @see PatternFill
6
- # @see GradientFill
7
- class Fill
8
-
9
- # The type of fill
10
- # @return [PatternFill, GradientFill]
11
- attr_reader :fill_type
12
-
13
- # Creates a new Fill object
14
- # @param [PatternFill, GradientFill] fill_type
15
- # @raise [ArgumentError] if the fill_type parameter is not a PatternFill or a GradientFill instance
16
- def initialize(fill_type)
17
- self.fill_type = fill_type
18
- end
19
-
20
- # Serializes the fill
21
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
22
- # @return [String]
23
- def to_xml(xml)
24
- xml.fill { @fill_type.to_xml(xml) }
25
- end
26
-
27
- # @see fill_type
28
- def fill_type=(v) DataTypeValidator.validate "Fill.fill_type", [PatternFill, GradientFill], v; @fill_type = v; end
29
-
30
-
31
- end
32
- end
@@ -1,139 +0,0 @@
1
- module Axlsx
2
- # The Font class details a font instance for use in styling cells.
3
- # @note The recommended way to manage fonts, and other styles is Styles#add_style
4
- # @see Styles#add_style
5
- class Font
6
- # The name of the font
7
- # @return [String]
8
- attr_reader :name
9
-
10
- # The charset of the font
11
- # @return [Integer]
12
- # @note
13
- # The following values are defined in the OOXML specification and are OS dependant values
14
- # 0 ANSI_CHARSET
15
- # 1 DEFAULT_CHARSET
16
- # 2 SYMBOL_CHARSET
17
- # 77 MAC_CHARSET
18
- # 128 SHIFTJIS_CHARSET
19
- # 129 HANGUL_CHARSET
20
- # 130 JOHAB_CHARSET
21
- # 134 GB2312_CHARSET
22
- # 136 CHINESEBIG5_CHARSET
23
- # 161 GREEK_CHARSET
24
- # 162 TURKISH_CHARSET
25
- # 163 VIETNAMESE_CHARSET
26
- # 177 HEBREW_CHARSET
27
- # 178 ARABIC_CHARSET
28
- # 186 BALTIC_CHARSET
29
- # 204 RUSSIAN_CHARSET
30
- # 222 THAI_CHARSET
31
- # 238 EASTEUROPE_CHARSET
32
- # 255 OEM_CHARSET
33
- attr_reader :charset
34
-
35
- # The font's family
36
- # @note
37
- # The following are defined OOXML specification
38
- # 0 Not applicable.
39
- # 1 Roman
40
- # 2 Swiss
41
- # 3 Modern
42
- # 4 Script
43
- # 5 Decorative
44
- # 6..14 Reserved for future use
45
- # @return [Integer]
46
- attr_reader :family
47
-
48
- # Indicates if the font should be rendered in *bold*
49
- # @return [Boolean]
50
- attr_reader :b
51
-
52
- # Indicates if the font should be rendered italicized
53
- # @return [Boolean]
54
- attr_reader :i
55
-
56
- # Indicates if the font should be rendered with a strikthrough
57
- # @return [Boolean]
58
- attr_reader :strike
59
-
60
- # Indicates if the font should be rendered with an outline
61
- # @return [Boolean]
62
- attr_reader :outline
63
-
64
- # Indicates if the font should be rendered with a shadow
65
- # @return [Boolean]
66
- attr_reader :shadow
67
-
68
- # Indicates if the font should be condensed
69
- # @return [Boolean]
70
- attr_reader :condense
71
-
72
- # The font's extend property
73
- # @return [Boolean]
74
- attr_reader :extend
75
-
76
- # The color of the font
77
- # @return [Color]
78
- attr_reader :color
79
-
80
- # The size of the font.
81
- # @return [Integer]
82
- attr_reader :sz
83
-
84
- # Creates a new Font
85
- # @option options [String] name
86
- # @option options [Integer] charset
87
- # @option options [Integer] family
88
- # @option options [Integer] family
89
- # @option options [Boolean] b
90
- # @option options [Boolean] i
91
- # @option options [Boolean] strike
92
- # @option options [Boolean] outline
93
- # @option options [Boolean] shadow
94
- # @option options [Boolean] condense
95
- # @option options [Boolean] extend
96
- # @option options [Color] color
97
- # @option options [Integer] sz
98
- def initialize(options={})
99
- options.each do |o|
100
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
101
- end
102
- end
103
- # @see name
104
- def name=(v) Axlsx::validate_string v; @name = v end
105
- # @see charset
106
- def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end
107
- # @see family
108
- def family=(v) Axlsx::validate_unsigned_int v; @family = v end
109
- # @see b
110
- def b=(v) Axlsx::validate_boolean v; @b = v end
111
- # @see i
112
- def i=(v) Axlsx::validate_boolean v; @i = v end
113
- # @see strike
114
- def strike=(v) Axlsx::validate_boolean v; @strike = v end
115
- # @see outline
116
- def outline=(v) Axlsx::validate_boolean v; @outline = v end
117
- # @see shadow
118
- def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
119
- # @see condense
120
- def condense=(v) Axlsx::validate_boolean v; @condense = v end
121
- # @see extend
122
- def extend=(v) Axlsx::validate_boolean v; @extend = v end
123
- # @see color
124
- def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color=v end
125
- # @see sz
126
- def sz=(v) Axlsx::validate_unsigned_int v; @sz=v end
127
-
128
- # Serializes the fill
129
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
130
- # @return [String]
131
- def to_xml(xml)
132
- xml.font {
133
- self.instance_values.each do |k, v|
134
- v.is_a?(Color) ? v.to_xml(xml) : xml.send(k, {:val => v})
135
- end
136
- }
137
- end
138
- end
139
- end
@@ -1,76 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module Axlsx
3
- # A GradientFill defines the color and positioning for gradiant cell fill.
4
- # @see Open Office XML Part 1 §18.8.24
5
- class GradientFill
6
-
7
- # The type of gradient.
8
- # @note
9
- # valid options are
10
- # :linear
11
- # :path
12
- # @return [Symbol]
13
- attr_reader :type
14
-
15
- # Angle of the linear gradient
16
- # @return [Float]
17
- attr_reader :degree
18
-
19
- # Percentage format left
20
- # @return [Float]
21
- attr_reader :left
22
-
23
- # Percentage format right
24
- # @return [Float]
25
- attr_reader :right
26
-
27
- # Percentage format top
28
- # @return [Float]
29
- attr_reader :top
30
-
31
- # Percentage format bottom
32
- # @return [Float]
33
- attr_reader :bottom
34
-
35
- # Collection of stop objects
36
- # @return [SimpleTypedList]
37
- attr_reader :stop
38
-
39
- # Creates a new GradientFill object
40
- # @option options [Symbol] type
41
- # @option options [Float] degree
42
- # @option options [Float] left
43
- # @option options [Float] right
44
- # @option options [Float] top
45
- # @option options [Float] bottom
46
- def initialize(options={})
47
- options[:type] ||= :linear
48
- options.each do |o|
49
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
50
- end
51
- @stop = SimpleTypedList.new GradientStop
52
- end
53
-
54
- # @see type
55
- def type=(v) Axlsx::validate_gradient_type v; @type = v end
56
- # @see degree
57
- def degree=(v) Axlsx::validate_float v; @degree = v end
58
- # @see left
59
- def left=(v) DataTypeValidator.validate "GradientFill.left", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @left = v end
60
- # @see right
61
- def right=(v) DataTypeValidator.validate "GradientFill.right", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @right = v end
62
- # @see top
63
- def top=(v) DataTypeValidator.validate "GradientFill.top", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @top = v end
64
- # @see bottom
65
- def bottom=(v) DataTypeValidator.validate "GradientFill.bottom", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @bottom= v end
66
-
67
- # Serializes the gradientFill
68
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
69
- # @return [String]
70
- def to_xml(xml)
71
- xml.gradientFill(self.instance_values.reject { |k,v| k.to_sym == :stop }) {
72
- @stop.each { |s| s.to_xml(xml) }
73
- }
74
- end
75
- end
76
- end
@@ -1,33 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module Axlsx
3
- # The GradientStop object represents a color point in a gradient.
4
- # @see Open Office XML Part 1 §18.8.24
5
- class GradientStop
6
- # The color for this gradient stop
7
- # @return [Color]
8
- # @see Color
9
- attr_reader :color
10
-
11
- # The position of the color
12
- # @return [Float]
13
- attr_reader :position
14
-
15
- # Creates a new GradientStop object
16
- # @param [Color] color
17
- # @param [Float] position
18
- def initialize(color, position)
19
- self.color = color
20
- self.position = position
21
- end
22
-
23
- # @see color
24
- def color=(v) DataTypeValidator.validate "GradientStop.color", Color, v; @color=v end
25
- # @see position
26
- def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1}; @position = v end
27
-
28
- # Serializes the gradientStop
29
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
30
- # @return [String]
31
- def to_xml(xml) xml.stop(:position => self.position) {self.color.to_xml(xml)} end
32
- end
33
- end
@@ -1,63 +0,0 @@
1
- module Axlsx
2
- # A NumFmt object defines an identifier and formatting code for data in cells.
3
- # @note The recommended way to manage styles is Styles#add_style
4
- class NumFmt
5
- # @return [Integer] An unsinged integer referencing a standard or custom number format.
6
- # @note
7
- # These are the known formats I can dig up. The constant NUM_FMT_PERCENT is 9, and uses the default % formatting. Axlsx also defines a few formats for date and time that are commonly used in asia as NUM_FMT_YYYYMMDD and NUM_FRM_YYYYMMDDHHMMSS.
8
- # 1 0
9
- # 2 0.00
10
- # 3 #,##0
11
- # 4 #,##0.00
12
- # 5 $#,##0_);($#,##0)
13
- # 6 $#,##0_);[Red]($#,##0)
14
- # 7 $#,##0.00_);($#,##0.00)
15
- # 8 $#,##0.00_);[Red]($#,##0.00)
16
- # 9 0%
17
- # 10 0.00%
18
- # 11 0.00E+00
19
- # 12 # ?/?
20
- # 13 # ??/??
21
- # 14 m/d/yyyy
22
- # 15 d-mmm-yy
23
- # 16 d-mmm
24
- # 17 mmm-yy
25
- # 18 h:mm AM/PM
26
- # 19 h:mm:ss AM/PM
27
- # 20 h:mm
28
- # 21 h:mm:ss
29
- # 22 m/d/yyyy h:mm
30
- # 37 #,##0_);(#,##0)
31
- # 38 #,##0_);[Red](#,##0)
32
- # 39 #,##0.00_);(#,##0.00)
33
- # 40 #,##0.00_);[Red](#,##0.00)
34
- # 45 mm:ss
35
- # 46 [h]:mm:ss
36
- # 47 mm:ss.0
37
- # 48 ##0.0E+0
38
- # 49 @
39
- # @see Axlsx
40
- attr_reader :numFmtId
41
-
42
- # @return [String] The formatting to use for this number format.
43
- # @see http://support.microsoft.com/kb/264372
44
- attr_reader :formatCode
45
- def initialize(options={})
46
- @numFmtId = 0
47
- @formatCode = ""
48
- options.each do |o|
49
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
50
- end
51
- end
52
-
53
- # @see numFmtId
54
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
55
- # @see formatCode
56
- def formatCode=(v) Axlsx::validate_string v; @formatCode = v end
57
-
58
- # Creates a numFmt element applying the instance values of this object as attributes.
59
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
60
- def to_xml(xml) xml.numFmt(self.instance_values) end
61
-
62
- end
63
- end
@@ -1,66 +0,0 @@
1
- module Axlsx
2
- # A PatternFill is the pattern and solid fill styling for a cell.
3
- # @note The recommended way to manage styles is with Styles#add_style
4
- # @see Style#add_style
5
- class PatternFill
6
-
7
- # The color to use for the the background in solid fills.
8
- # @return [Color]
9
- attr_reader :fgColor
10
-
11
- # The color to use for the background of the fill when the type is not solid.
12
- # @return [Color]
13
- attr_reader :bgColor
14
-
15
- # The pattern type to use
16
- # @note
17
- # patternType must be one of
18
- # :none
19
- # :solid
20
- # :mediumGray
21
- # :darkGray
22
- # :lightGray
23
- # :darkHorizontal
24
- # :darkVertical
25
- # :darkDown
26
- # :darkUp
27
- # :darkGrid
28
- # :darkTrellis
29
- # :lightHorizontal
30
- # :lightVertical
31
- # :lightDown
32
- # :lightUp
33
- # :lightGrid
34
- # :lightTrellis
35
- # :gray125
36
- # :gray0625
37
- # @see Office Open XML Part 1 18.18.55
38
- attr_reader :patternType
39
-
40
- # Creates a new PatternFill Object
41
- # @option options [Symbol] patternType
42
- # @option options [Color] fgColor
43
- # @option options [Color] bgColor
44
- def initialize(options={})
45
- @patternType = :none
46
- options.each do |o|
47
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
48
- end
49
- end
50
- # @see fgColor
51
- def fgColor=(v) DataTypeValidator.validate "PatternFill.fgColor", Color, v; @fgColor=v end
52
- # @see bgColor
53
- def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor=v end
54
- # @see patternType
55
- def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
56
-
57
- # Serializes the pattern fill
58
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
59
- # @return [String]
60
- def to_xml(xml)
61
- xml.patternFill(:patternType => self.patternType) {
62
- self.instance_values.reject { |k,v| k.to_sym == :patternType }.each { |k,v| xml.send(k, v.instance_values) }
63
- }
64
- end
65
- end
66
- end
@@ -1,298 +0,0 @@
1
- # -*- coding: 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/xf.rb'
18
- require 'axlsx/stylesheet/cell_protection.rb'
19
-
20
- #The Styles class manages worksheet styles
21
- # 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.
22
- # 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.
23
- # @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
24
- # @see Styles#add_style
25
- # @note The recommended way to manage styles is with add_style
26
- class Styles
27
- # numFmts for your styles.
28
- # The default styles, which change based on the system local, are as follows.
29
- # id formatCode
30
- # 0 General
31
- # 1 0
32
- # 2 0.00
33
- # 3 #,##0
34
- # 4 #,##0.00
35
- # 9 0%
36
- # 10 0.00%
37
- # 11 0.00E+00
38
- # 12 # ?/?
39
- # 13 # ??/??
40
- # 14 mm-dd-yy
41
- # 15 d-mmm-yy
42
- # 16 d-mmm
43
- # 17 mmm-yy
44
- # 18 h:mm AM/PM
45
- # 19 h:mm:ss AM/PM
46
- # 20 h:mm
47
- # 21 h:mm:ss
48
- # 22 m/d/yy h:mm
49
- # 37 #,##0 ;(#,##0)
50
- # 38 #,##0 ;[Red](#,##0)
51
- # 39 #,##0.00;(#,##0.00)
52
- # 40 #,##0.00;[Red](#,##0.00)
53
- # 45 mm:ss
54
- # 46 [h]:mm:ss
55
- # 47 mmss.0
56
- # 48 ##0.0E+0
57
- # 49 @
58
- # Axlsx also defines the following constants which you can use in add_style.
59
- # NUM_FMT_PERCENT formats to "0%"
60
- # NUM_FMT_YYYYMMDD formats to "yyyy/mm/dd"
61
- # NUM_FMT_YYYYMMDDHHMMSS formats to "yyyy/mm/dd hh:mm:ss"
62
- # @see Office Open XML Part 1 - 18.8.31 for more information on creating number formats
63
- # @return [SimpleTypedList]
64
- # @note The recommended way to manage styles is with add_style
65
- # @see Styles#add_style
66
- attr_reader :numFmts
67
-
68
- # The collection of fonts used in this workbook
69
- # @return [SimpleTypedList]
70
- # @note The recommended way to manage styles is with add_style
71
- # @see Styles#add_style
72
- attr_reader :fonts
73
-
74
- # The collection of fills used in this workbook
75
- # @return [SimpleTypedList]
76
- # @note The recommended way to manage styles is with add_style
77
- # @see Styles#add_style
78
- attr_reader :fills
79
-
80
- # The collection of borders used in this workbook
81
- # Axlsx predefines THIN_BORDER which can be used to put a border around all of your cells.
82
- # @return [SimpleTypedList]
83
- # @note The recommended way to manage styles is with add_style
84
- # @see Styles#add_style
85
- attr_reader :borders
86
-
87
- # The collection of master formatting records for named cell styles, which means records defined in cellStyles, in the workbook
88
- # @return [SimpleTypedList]
89
- # @note The recommended way to manage styles is with add_style
90
- # @see Styles#add_style
91
- attr_reader :cellStyleXfs
92
-
93
- # The collection of named styles, referencing cellStyleXfs items in the workbook.
94
- # @return [SimpleTypedList]
95
- # @note The recommended way to manage styles is with add_style
96
- # @see Styles#add_style
97
- attr_reader :cellStyles
98
-
99
- # The collection of master formatting records. This is the list that you will actually use in styling a workbook.
100
- # @return [SimpleTypedList]
101
- # @note The recommended way to manage styles is with add_style
102
- # @see Styles#add_style
103
- attr_reader :cellXfs
104
-
105
- # The collection of non-cell formatting records used in the worksheet.
106
- # @return [SimpleTypedList]
107
- # @note The recommended way to manage styles is with add_style
108
- # @see Styles#add_style
109
- attr_reader :dxfs
110
-
111
- # The collection of table styles that will be available to the user in the excel UI
112
- # @return [SimpleTypedList]
113
- # @note The recommended way to manage styles is with add_style
114
- # @see Styles#add_style
115
- attr_reader :tableStyles
116
-
117
- # Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part.
118
- def initialize()
119
- load_default_styles
120
- end
121
-
122
- # Drastically simplifies style creation and management.
123
- # @return [Integer]
124
- # @option options [String] fg_color The text color
125
- # @option options [Integer] sz The text size
126
- # @option options [Boolean] b Indicates if the text should be bold
127
- # @option options [Boolean] i Indicates if the text should be italicised
128
- # @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
129
- # @option options [Boolean] strike Indicates if the text should be rendered with a shadow
130
- # @option options [Integer] charset The character set to use.
131
- # @option options [Integer] family The font family to use.
132
- # @option options [String] name The name of the font to use
133
- # @option options [Integer] num_fmt The number format to apply
134
- # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored.
135
- # @option options [Integer] border The border style to use.
136
- # @option options [String] bg_color The background color to apply to the cell
137
- # @option options [Boolean] hidden Indicates if the cell should be hidden
138
- # @option options [Boolean] locked Indicates if the cell should be locked
139
- # @option options [Hash] alignment A hash defining any of the attributes used in CellAlignment
140
- # @see CellAlignment
141
- #
142
- # @example You Got Style
143
- # require "rubygems" # if that is your preferred way to manage gems!
144
- # require "axlsx"
145
- #
146
- # p = Axlsx::Package.new
147
- # ws = p.workbook.add_worksheet
148
- #
149
- # # black text on a white background at 14pt with thin borders!
150
- # title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=>Axlsx::STYLE_THIN_BORDER
151
- #
152
- # ws.add_row :values => ["Least Popular Pets"]
153
- # ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
154
- # ws.add_row :values => ["Votes", 6, 4, 1], :style=>Axlsx::STYLE_THIN_BORDER
155
- # f = File.open('example_you_got_style.xlsx', 'w')
156
- # p.serialize(f)
157
- #
158
- # @example Styling specifically
159
- # # an example of applying specific styles to specific cells
160
- # require "rubygems" # if that is your preferred way to manage gems!
161
- # require "axlsx"
162
- #
163
- # p = Axlsx::Package.new
164
- # ws = p.workbook.add_worksheet
165
- #
166
- # # define your styles
167
- # title = ws.style.add_style(:bg_color => "FFFF0000",
168
- # :fg_color=>"#FF000000",
169
- # :border=>Axlsx::STYLE_THIN_BORDER,
170
- # :alignment=>{:horizontal => :center})
171
- #
172
- # date_time = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
173
- # :border=>Axlsx::STYLE_THIN_BORDER)
174
- #
175
- # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
176
- # :border=>Axlsx::STYLE_THIN_BORDER)
177
- #
178
- # currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
179
- # :border=>Axlsx::STYLE_THIN_BORDER)
180
- #
181
- # # build your rows
182
- # ws.add_row :values => ["Genreated At:", Time.now], :styles=>[nil, date_time]
183
- # ws.add_row :values => ["Previous Year Quarterly Profits (JPY)"], :style=>title
184
- # ws.add_row :values => ["Quarter", "Profit", "% of Total"], :style=>title
185
- # ws.add_row :values => ["Q1", 4000, 40], :style=>[title, currency, percent]
186
- # ws.add_row :values => ["Q2", 3000, 30], :style=>[title, currency, percent]
187
- # ws.add_row :values => ["Q3", 1000, 10], :style=>[title, currency, percent]
188
- # ws.add_row :values => ["Q4", 2000, 20], :style=>[title, currency, percent]
189
- # f = File.open('example_you_got_style.xlsx', 'w')
190
- # p.serialize(f)
191
- def add_style(options={})
192
-
193
- numFmtId = if options[:format_code]
194
- n = @numFmts.map{ |f| f.numFmtId }.max + 1
195
- numFmts << NumFmt.new(:numFmtId => n, :formatCode=> options[:format_code])
196
- n
197
- else
198
- options[:num_fmt] || 0
199
- end
200
-
201
- borderId = options[:border] || 0
202
- raise ArgumentError, "Invalid borderId" unless borderId < borders.size
203
-
204
- fill = if options[:bg_color]
205
- color = Color.new(:rgb=>options[:bg_color])
206
- pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color)
207
- fills << Fill.new(pattern)
208
- else
209
- 0
210
- end
211
-
212
- fontId = if (options.values_at(:fg_color, :sz, :b, :i, :strike, :outline, :shadow, :charset, :family, :font_name).length)
213
- font = Font.new()
214
- [:b, :i, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
215
- font.color = Color.new(:rgb => options[:fg_color]) unless options[:fg_color].nil?
216
- font.name = options[:font_name] unless options[:font_name].nil?
217
- fonts << font
218
- else
219
- 0
220
- end
221
-
222
- applyProtection = (options[:hidden] || options[:locked]) ? 1 : 0
223
-
224
- xf = Xf.new(:fillId => fill, :fontId=>fontId, :applyFill=>1, :applyFont=>1, :numFmtId=>numFmtId, :borderId=>borderId, :applyProtection=>applyProtection)
225
-
226
- if options[:alignment]
227
- xf.alignment = CellAlignment.new(options[:alignment])
228
- end
229
-
230
- if applyProtection
231
- xf.protection = CellProtection.new(options)
232
- end
233
-
234
- cellXfs << xf
235
- end
236
-
237
- # Serializes the styles document
238
- # @return [String]
239
- def to_xml()
240
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
241
- xml.styleSheet(:xmlns => XML_NS) {
242
- [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
243
- self.instance_values[key.to_s].to_xml(xml)
244
- end
245
- }
246
- end
247
- builder.to_xml
248
- end
249
-
250
- private
251
- # Creates the default set of styles the exel requires to be valid as well as setting up the
252
- # Axlsx::STYLE_THIN_BORDER
253
- def load_default_styles
254
- @numFmts = SimpleTypedList.new NumFmt
255
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode=> "yyyy/mm/dd")
256
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode=> "yyyy/mm/dd hh:mm:ss")
257
-
258
- @numFmts.lock
259
-
260
- @fonts = SimpleTypedList.new Font
261
- @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1, :numFmt=>"0")
262
- @fonts.lock
263
-
264
- @fills = SimpleTypedList.new Fill
265
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:none))
266
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:gray125))
267
- @fills.lock
268
-
269
- @borders = SimpleTypedList.new Border
270
- @borders << Border.new
271
- black_border = Border.new
272
- [:left, :right, :top, :bottom].each do |item|
273
- black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
274
- end
275
- @borders << black_border
276
- @borders.lock
277
-
278
- @cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
279
- @cellStyleXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
280
- @cellStyleXfs.lock
281
-
282
- @cellStyles = SimpleTypedList.new CellStyle
283
- @cellStyles << CellStyle.new(:name =>"Normal", :builtinId =>0, :xfId=>0)
284
- @cellStyles.lock
285
-
286
- @cellXfs = SimpleTypedList.new Xf, "cellXfs"
287
- @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
288
- @cellXfs << Xf.new(:borderId=>1, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
289
- # default date formatting
290
- @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>14, :fontId=>0, :fillId=>0)
291
- @cellXfs.lock
292
-
293
- @dxfs = SimpleTypedList.new(Xf, "dxfs"); @dxfs.lock
294
- @tableStyles = TableStyles.new(:defaultTableStyle => "TableStyleMedium9", :defaultPivotStyle => "PivotStyleLight16"); @tableStyles.lock
295
- end
296
- end
297
- end
298
-