axlsx 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/README.md +21 -3
  2. data/doc/Axlsx.html +150 -6
  3. data/doc/Axlsx/App.html +1 -1
  4. data/doc/Axlsx/Axis.html +1 -1
  5. data/doc/Axlsx/Bar3DChart.html +1 -1
  6. data/doc/Axlsx/BarSeries.html +1 -1
  7. data/doc/Axlsx/Border.html +1 -1
  8. data/doc/Axlsx/BorderPr.html +1 -1
  9. data/doc/Axlsx/CatAxis.html +1 -1
  10. data/doc/Axlsx/CatAxisData.html +7 -5
  11. data/doc/Axlsx/Cell.html +1 -1
  12. data/doc/Axlsx/CellAlignment.html +1 -1
  13. data/doc/Axlsx/CellProtection.html +1 -1
  14. data/doc/Axlsx/CellStyle.html +1 -1
  15. data/doc/Axlsx/Chart.html +16 -16
  16. data/doc/Axlsx/Color.html +1 -1
  17. data/doc/Axlsx/ContentType.html +1 -1
  18. data/doc/Axlsx/Core.html +1 -1
  19. data/doc/Axlsx/DataTypeValidator.html +1 -1
  20. data/doc/Axlsx/Default.html +1 -1
  21. data/doc/Axlsx/Drawing.html +243 -65
  22. data/doc/Axlsx/Fill.html +1 -1
  23. data/doc/Axlsx/Font.html +1 -1
  24. data/doc/Axlsx/GradientFill.html +1 -1
  25. data/doc/Axlsx/GradientStop.html +1 -1
  26. data/doc/Axlsx/GraphicFrame.html +21 -21
  27. data/doc/Axlsx/Line3DChart.html +1 -1
  28. data/doc/Axlsx/LineSeries.html +6 -8
  29. data/doc/Axlsx/Marker.html +1 -1
  30. data/doc/Axlsx/NumFmt.html +1 -1
  31. data/doc/Axlsx/OneCellAnchor.html +988 -0
  32. data/doc/Axlsx/Override.html +1 -1
  33. data/doc/Axlsx/Package.html +127 -75
  34. data/doc/Axlsx/PatternFill.html +1 -1
  35. data/doc/Axlsx/Pic.html +1532 -0
  36. data/doc/Axlsx/Pie3DChart.html +5 -7
  37. data/doc/Axlsx/PieSeries.html +1 -1
  38. data/doc/Axlsx/RegexValidator.html +1 -1
  39. data/doc/Axlsx/Relationship.html +6 -6
  40. data/doc/Axlsx/Relationships.html +1 -1
  41. data/doc/Axlsx/RestrictionValidator.html +1 -1
  42. data/doc/Axlsx/Row.html +1 -1
  43. data/doc/Axlsx/Scaling.html +1 -1
  44. data/doc/Axlsx/SerAxis.html +1 -1
  45. data/doc/Axlsx/Series.html +1 -1
  46. data/doc/Axlsx/SeriesTitle.html +1 -1
  47. data/doc/Axlsx/SimpleTypedList.html +1 -1
  48. data/doc/Axlsx/Styles.html +1 -1
  49. data/doc/Axlsx/TableStyle.html +1 -1
  50. data/doc/Axlsx/TableStyleElement.html +1 -1
  51. data/doc/Axlsx/TableStyles.html +1 -1
  52. data/doc/Axlsx/Title.html +1 -1
  53. data/doc/Axlsx/TwoCellAnchor.html +165 -61
  54. data/doc/Axlsx/ValAxis.html +1 -1
  55. data/doc/Axlsx/ValAxisData.html +1 -1
  56. data/doc/Axlsx/View3D.html +1 -1
  57. data/doc/Axlsx/Workbook.html +151 -47
  58. data/doc/Axlsx/Worksheet.html +172 -35
  59. data/doc/Axlsx/Xf.html +1 -1
  60. data/doc/_index.html +15 -1
  61. data/doc/class_list.html +1 -1
  62. data/doc/file.README.html +29 -4
  63. data/doc/index.html +29 -4
  64. data/doc/method_list.html +571 -363
  65. data/doc/top-level-namespace.html +1 -1
  66. data/examples/example.rb +13 -0
  67. data/examples/image1.gif +0 -0
  68. data/examples/image1.jpeg +0 -0
  69. data/examples/image1.jpg +0 -0
  70. data/examples/image1.png +0 -0
  71. data/lib/axlsx/drawing/bar_series.rb +0 -1
  72. data/lib/axlsx/drawing/cat_axis_data.rb +1 -0
  73. data/lib/axlsx/drawing/chart.rb +0 -1
  74. data/lib/axlsx/drawing/drawing.rb +31 -7
  75. data/lib/axlsx/drawing/graphic_frame.rb +0 -2
  76. data/lib/axlsx/drawing/line_series.rb +0 -1
  77. data/lib/axlsx/drawing/one_cell_anchor.rb +89 -0
  78. data/lib/axlsx/drawing/pic.rb +158 -0
  79. data/lib/axlsx/drawing/pie_3D_chart.rb +0 -1
  80. data/lib/axlsx/drawing/two_cell_anchor.rb +17 -4
  81. data/lib/axlsx/package.rb +31 -5
  82. data/lib/axlsx/rels/relationship.rb +1 -2
  83. data/lib/axlsx/util/constants.rb +24 -0
  84. data/lib/axlsx/util/validators.rb +2 -2
  85. data/lib/axlsx/version.rb +1 -1
  86. data/lib/axlsx/workbook/workbook.rb +8 -0
  87. data/lib/axlsx/workbook/worksheet/worksheet.rb +10 -1
  88. data/test/drawing/tc_drawing.rb +10 -1
  89. data/test/drawing/tc_one_cell_anchor.rb +67 -0
  90. data/test/drawing/tc_pic.rb +71 -0
  91. data/test/tc_package.rb +0 -2
  92. metadata +13 -118
  93. data/examples/#example.rb# +0 -87
  94. data/examples/example.rb~ +0 -79
  95. data/examples/multi_chart.xlsx +0 -0
  96. data/lib/axlsx.rb~ +0 -67
  97. data/lib/axlsx/content_type/content_type.rb~ +0 -20
  98. data/lib/axlsx/content_type/default.rb~ +0 -32
  99. data/lib/axlsx/content_type/override.rb~ +0 -30
  100. data/lib/axlsx/doc_props/app.rb~ +0 -127
  101. data/lib/axlsx/doc_props/core.rb~ +0 -25
  102. data/lib/axlsx/drawing/#bar_series.rb# +0 -62
  103. data/lib/axlsx/drawing/axis.rb~ +0 -0
  104. data/lib/axlsx/drawing/bar_3D_chart.rb~ +0 -64
  105. data/lib/axlsx/drawing/bar_series.rb~ +0 -92
  106. data/lib/axlsx/drawing/cat_axis.rb~ +0 -32
  107. data/lib/axlsx/drawing/cat_axis_data.rb~ +0 -28
  108. data/lib/axlsx/drawing/chart.rb~ +0 -0
  109. data/lib/axlsx/drawing/drawing.rb~ +0 -102
  110. data/lib/axlsx/drawing/graphic_frame.rb~ +0 -40
  111. data/lib/axlsx/drawing/line_3D_chart.rb~ +0 -138
  112. data/lib/axlsx/drawing/line_series.rb~ +0 -91
  113. data/lib/axlsx/drawing/marker.rb~ +0 -50
  114. data/lib/axlsx/drawing/pie_3D_chart.rb~ +0 -132
  115. data/lib/axlsx/drawing/pie_series.rb~ +0 -0
  116. data/lib/axlsx/drawing/scaling.rb~ +0 -0
  117. data/lib/axlsx/drawing/ser_axis.rb~ +0 -48
  118. data/lib/axlsx/drawing/series.rb~ +0 -114
  119. data/lib/axlsx/drawing/series_title.rb~ +0 -18
  120. data/lib/axlsx/drawing/title.rb~ +0 -69
  121. data/lib/axlsx/drawing/two_cell_anchor.rb~ +0 -70
  122. data/lib/axlsx/drawing/val_axis.rb~ +0 -34
  123. data/lib/axlsx/drawing/val_axis_data.rb~ +0 -29
  124. data/lib/axlsx/drawing/view_3D.rb~ +0 -21
  125. data/lib/axlsx/package.rb~ +0 -181
  126. data/lib/axlsx/rels/relationship.rb~ +0 -18
  127. data/lib/axlsx/rels/relationships.rb~ +0 -23
  128. data/lib/axlsx/stylesheet/border.rb~ +0 -24
  129. data/lib/axlsx/stylesheet/border_pr.rb~ +0 -64
  130. data/lib/axlsx/stylesheet/cell_alignment.rb~ +0 -93
  131. data/lib/axlsx/stylesheet/cell_protection.rb~ +0 -16
  132. data/lib/axlsx/stylesheet/cell_style.rb~ +0 -61
  133. data/lib/axlsx/stylesheet/color.rb~ +0 -56
  134. data/lib/axlsx/stylesheet/fill.rb~ +0 -31
  135. data/lib/axlsx/stylesheet/font.rb~ +0 -33
  136. data/lib/axlsx/stylesheet/gradient_fill.rb~ +0 -70
  137. data/lib/axlsx/stylesheet/gradient_stop.rb~ +0 -15
  138. data/lib/axlsx/stylesheet/num_fmt.rb~ +0 -60
  139. data/lib/axlsx/stylesheet/pattern_fill.rb~ +0 -63
  140. data/lib/axlsx/stylesheet/styles.rb~ +0 -279
  141. data/lib/axlsx/stylesheet/table_style.rb~ +0 -43
  142. data/lib/axlsx/stylesheet/table_style_element.rb~ +0 -66
  143. data/lib/axlsx/stylesheet/table_styles.rb~ +0 -36
  144. data/lib/axlsx/stylesheet/xf.rb~ +0 -37
  145. data/lib/axlsx/util/constants.rb~ +0 -187
  146. data/lib/axlsx/util/monkey_patches_for_true_zip_stream.rb~ +0 -61
  147. data/lib/axlsx/util/simple_typed_list.rb~ +0 -79
  148. data/lib/axlsx/util/validators.rb~ +0 -132
  149. data/lib/axlsx/util/xml_escape.rb~ +0 -6
  150. data/lib/axlsx/workbook/workbook.rb~ +0 -130
  151. data/lib/axlsx/workbook/worksheet/cell.rb~ +0 -185
  152. data/lib/axlsx/workbook/worksheet/row.rb~ +0 -92
  153. data/lib/axlsx/workbook/worksheet/worksheet.rb~ +0 -194
  154. data/test/content_type/tc_content_type.rb~ +0 -81
  155. data/test/content_type/tc_default.rb~ +0 -40
  156. data/test/content_type/tc_override.rb~ +0 -40
  157. data/test/doc_props/tc_app.rb~ +0 -19
  158. data/test/drawing/tc_axis.rb~ +0 -0
  159. data/test/drawing/tc_bar_3D_chart.rb~ +0 -66
  160. data/test/drawing/tc_bar_series.rb~ +0 -31
  161. data/test/drawing/tc_cat_axis.rb~ +0 -39
  162. data/test/drawing/tc_cat_axis_data.rb~ +0 -32
  163. data/test/drawing/tc_chart.rb~ +0 -59
  164. data/test/drawing/tc_graphic_frame.rb~ +0 -21
  165. data/test/drawing/tc_line_3d_chart.rb~ +0 -48
  166. data/test/drawing/tc_line_series.rb~ +0 -34
  167. data/test/drawing/tc_marker.rb~ +0 -26
  168. data/test/drawing/tc_pie_3D_chart.rb~ +0 -33
  169. data/test/drawing/tc_pie_series.rb~ +0 -26
  170. data/test/drawing/tc_scaling.rb~ +0 -45
  171. data/test/drawing/tc_ser_axis.rb~ +0 -20
  172. data/test/drawing/tc_series.rb~ +0 -31
  173. data/test/drawing/tc_series_title.rb~ +0 -34
  174. data/test/drawing/tc_title.rb~ +0 -34
  175. data/test/drawing/tc_two_cell_anchor.rb~ +0 -37
  176. data/test/drawing/tc_val_axis.rb~ +0 -32
  177. data/test/drawing/tc_val_axis_data.rb~ +0 -18
  178. data/test/drawing/tc_view_3D.rb~ +0 -37
  179. data/test/rels/tc_relationship.rb~ +0 -39
  180. data/test/rels/tc_relationships.rb~ +0 -37
  181. data/test/stylesheet/tc_border.rb~ +0 -31
  182. data/test/stylesheet/tc_border_pr.rb~ +0 -31
  183. data/test/stylesheet/tc_cell_alignment.rb~ +0 -38
  184. data/test/stylesheet/tc_cell_protection.rb~ +0 -77
  185. data/test/stylesheet/tc_cell_style.rb~ +0 -30
  186. data/test/stylesheet/tc_color.rb~ +0 -38
  187. data/test/stylesheet/tc_fill.rb~ +0 -19
  188. data/test/stylesheet/tc_font.rb~ +0 -19
  189. data/test/stylesheet/tc_gradient_fill.rb~ +0 -114
  190. data/test/stylesheet/tc_gradient_stop.rb~ +0 -65
  191. data/test/stylesheet/tc_num_fmt.rb~ +0 -32
  192. data/test/stylesheet/tc_pattern_fill.rb~ +0 -31
  193. data/test/stylesheet/tc_table_style.rb~ +0 -38
  194. data/test/stylesheet/tc_table_style_element.rb~ +0 -37
  195. data/test/stylesheet/tc_table_styles.rb~ +0 -37
  196. data/test/stylesheet/tc_xf.rb~ +0 -30
  197. data/test/tc_app.rb~ +0 -19
  198. data/test/tc_border_pr.rb~ +0 -21
  199. data/test/tc_package.rb~ +0 -64
  200. data/test/tc_pie_3D_chart.rb~ +0 -66
  201. data/test/tc_relationships.rb~ +0 -37
  202. data/test/tc_series.rb~ +0 -31
  203. data/test/tc_styles.rb~ +0 -64
  204. data/test/tc_validators.rb~ +0 -77
  205. data/test/tc_worksheet.rb~ +0 -85
  206. data/test/workbook/worksheet/tc_row.rb~ +0 -30
  207. data/test/workbook/worksheet/tc_worksheet.rb~ +0 -85
@@ -1,15 +0,0 @@
1
- module Axlsx
2
- class GradientStop
3
- attr_accessor :color, :position
4
- def initialize(options={})
5
- raise ArugumentError, "postion is required" unless options[:position]
6
- raise ArugumentError, "color is required" unless options[:color]
7
- options.each do |o|
8
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
9
- end
10
- end
11
- def color=(v) raise ArgumentError, "#{v.inspect} is not a Axlsx::Color" unless v.is_a? Axlsx::Color; @color=v end
12
- def position=(v) Axlsx::validate_float v; @position = v end
13
- def to_xml(xml) xml.stop(:position => self.position) {self.color.to_xml(xml)} end
14
- end
15
- end
@@ -1,60 +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_accessor :numFmtId
41
-
42
- # @return [String] The formatting to use for this number format.
43
- # @see http://support.microsoft.com/kb/264372
44
- attr_accessor :formatCode
45
- def initialize(options={})
46
- raise ArgumentError, "numFmtId:Integer, formatCode:String required. #{options.inspect}" unless options[:numFmtId] && options[:formatCode]
47
- options.each do |o|
48
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
49
- end
50
- end
51
-
52
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
53
- def formatCode=(v) Axlsx::validate_string v; @formatCode = v end
54
-
55
- # Creates a numFmt element applying the instance values of this object as attributes.
56
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
57
- def to_xml(xml) xml.numFmt(self.instance_values) end
58
-
59
- end
60
- end
@@ -1,63 +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_accessor :fgColor
10
-
11
- # The color to use for the background of the fill when the type is not solid.
12
- # @return [Color]
13
- attr_accessor :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_accessor :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
- options.each do |o|
46
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
47
- end
48
- end
49
-
50
- def fgColor=(v) DataTypeValidator.validate "PatternFill.fgColor", Color, v; @fgColor=v end
51
- def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor=v end
52
- def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
53
-
54
- # Serializes the pattern fill
55
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
56
- # @return [String]
57
- def to_xml(xml)
58
- xml.patternFill(:patternType => self.patternType) {
59
- self.instance_values.reject { |k,v| k.to_sym == :patternType }.each { |k,v| xml.send(k, v.instance_values) }
60
- }
61
- end
62
- end
63
- end
@@ -1,279 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module Axlsx
3
- #The Styles class manages worksheet styles
4
- # 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.
5
- # 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.
6
- # @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
7
- # @see Styles#add_style
8
- # @note The recommended way to manage styles is with add_style
9
- class Styles
10
- # numFmts for your styles.
11
- # The default styles, which change based on the system local, are as follows.
12
- # id formatCode
13
- # 0 General
14
- # 1 0
15
- # 2 0.00
16
- # 3 #,##0
17
- # 4 #,##0.00
18
- # 9 0%
19
- # 10 0.00%
20
- # 11 0.00E+00
21
- # 12 # ?/?
22
- # 13 # ??/??
23
- # 14 mm-dd-yy
24
- # 15 d-mmm-yy
25
- # 16 d-mmm
26
- # 17 mmm-yy
27
- # 18 h:mm AM/PM
28
- # 19 h:mm:ss AM/PM
29
- # 20 h:mm
30
- # 21 h:mm:ss
31
- # 22 m/d/yy h:mm
32
- # 37 #,##0 ;(#,##0)
33
- # 38 #,##0 ;[Red](#,##0)
34
- # 39 #,##0.00;(#,##0.00)
35
- # 40 #,##0.00;[Red](#,##0.00)
36
- # 45 mm:ss
37
- # 46 [h]:mm:ss
38
- # 47 mmss.0
39
- # 48 ##0.0E+0
40
- # 49 @
41
- # Axlsx also defines the following constants which you can use in add_style.
42
- # NUM_FMT_PERCENT formats to "0%"
43
- # NUM_FMT_YYYYMMDD formats to "yyyy/mm/dd"
44
- # NUM_FMT_YYYYMMDDHHMMSS formats to "yyyy/mm/dd hh:mm:ss"
45
- # @see Office Open XML Part 1 - 18.8.31 for more information on creating number formats
46
- # @return [SimpleTypedList]
47
- # @note The recommended way to manage styles is with add_style
48
- # @see Styles#add_style
49
- attr_reader :numFmts
50
-
51
- # The collection of fonts used in this workbook
52
- # @return [SimpleTypedList]
53
- # @note The recommended way to manage styles is with add_style
54
- # @see Styles#add_style
55
- attr_reader :fonts
56
-
57
- # The collection of fills used in this workbook
58
- # @return [SimpleTypedList]
59
- # @note The recommended way to manage styles is with add_style
60
- # @see Styles#add_style
61
- attr_reader :fills
62
-
63
- # The collection of borders used in this workbook
64
- # Axlsx predefines THIN_BORDER which can be used to put a border around all of your cells.
65
- # @return [SimpleTypedList]
66
- # @note The recommended way to manage styles is with add_style
67
- # @see Styles#add_style
68
- attr_reader :borders
69
-
70
- # The collection of master formatting records for named cell styles, which means records defined in cellStyles, in the workbook
71
- # @return [SimpleTypedList]
72
- # @note The recommended way to manage styles is with add_style
73
- # @see Styles#add_style
74
- attr_reader :cellStyleXfs
75
-
76
- # The collection of named styles, referencing cellStyleXfs items in the workbook.
77
- # @return [SimpleTypedList]
78
- # @note The recommended way to manage styles is with add_style
79
- # @see Styles#add_style
80
- attr_reader :cellStyles
81
-
82
- # The collection of master formatting records. This is the list that you will actually use in styling a workbook.
83
- # @return [SimpleTypedList]
84
- # @note The recommended way to manage styles is with add_style
85
- # @see Styles#add_style
86
- attr_reader :cellXfs
87
-
88
- # The collection of non-cell formatting records used in the worksheet.
89
- # @return [SimpleTypedList]
90
- # @note The recommended way to manage styles is with add_style
91
- # @see Styles#add_style
92
- attr_reader :dxfs
93
-
94
- # The collection of table styles that will be available to the user in the excel UI
95
- # @return [SimpleTypedList]
96
- # @note The recommended way to manage styles is with add_style
97
- # @see Styles#add_style
98
- attr_reader :tableStyles
99
-
100
- # Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part.
101
- def initialize()
102
- load_default_styles
103
- end
104
-
105
- # Drastically simplifies style creation and management.
106
- # @return [Integer]
107
- # @option options [String] fg_color The text color
108
- # @option options [Integer] sz The text size
109
- # @option options [Boolean] b Indicates if the text should be bold
110
- # @option options [Boolean] i Indicates if the text should be italicised
111
- # @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
112
- # @option options [Boolean] strike Indicates if the text should be rendered with a shadow
113
- # @option options [Integer] charset The character set to use.
114
- # @option options [Integer] family The font family to use.
115
- # @option options [String] name The name of the font to use
116
- # @option options [Integer] num_fmt The number format to apply
117
- # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored.
118
- # @option options [Integer] border The border style to use.
119
- # @option options [String] bg_color The background color to apply to the cell
120
- # @option options [Boolean] hidden Indicates if the cell should be hidden
121
- # @option options [Boolean] locked Indicates if the cell should be locked
122
- # @option options [Hash] alignment A hash defining any of the attributes used in CellAlignment
123
- # @see CellAlignment
124
- #
125
- # @example You Got Style
126
- # require "rubygems" # if that is your preferred way to manage gems!
127
- # require "axlsx"
128
- #
129
- # p = Axlsx::Package.new
130
- # ws = p.workbook.add_worksheet
131
- #
132
- # # black text on a white background at 14pt with thin borders!
133
- # title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=>Axlsx::STYLE_THIN_BORDER
134
- #
135
- # ws.add_row :values => ["Least Popular Pets"]
136
- # ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
137
- # ws.add_row :values => ["Votes", 6, 4, 1], :style=>Axlsx::STYLE_THIN_BORDER
138
- # f = File.open('example_you_got_style.xlsx', 'w')
139
- # p.serialize(f)
140
- #
141
- # @example Styling specifically
142
- # # an example of applying specific styles to specific cells
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
- # # define your styles
150
- # title = ws.style.add_style(:bg_color => "FFFF0000",
151
- # :fg_color=>"#FF000000",
152
- # :border=>Axlsx::STYLE_THIN_BORDER,
153
- # :alignment=>{:horizontal => :center})
154
- #
155
- # date_time = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
156
- # :border=>Axlsx::STYLE_THIN_BORDER)
157
- #
158
- # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
159
- # :border=>Axlsx::STYLE_THIN_BORDER)
160
- #
161
- # currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
162
- # :border=>Axlsx::STYLE_THIN_BORDER)
163
- #
164
- # # build your rows
165
- # ws.add_row :values => ["Genreated At:", Time.now], :styles=>[nil, date_time]
166
- # ws.add_row :values => ["Previous Year Quarterly Profits (JPY)"], :style=>title
167
- # ws.add_row :values => ["Quarter", "Profit", "% of Total"], :style=>title
168
- # ws.add_row :values => ["Q1", 4000, 40], :style=>[title, currency, percent]
169
- # ws.add_row :values => ["Q2", 3000, 30], :style=>[title, currency, percent]
170
- # ws.add_row :values => ["Q3", 1000, 10], :style=>[title, currency, percent]
171
- # ws.add_row :values => ["Q4", 2000, 20], :style=>[title, currency, percent]
172
- # f = File.open('example_you_got_style.xlsx', 'w')
173
- # p.serialize(f)
174
- def add_style(options={})
175
-
176
- numFmtId = if options[:format_code]
177
- n = @numFmts.map{ |f| f.numFmtId }.max + 1
178
- numFmts << NumFmt.new(:numFmtId => n, :formatCode=> options[:format_code])
179
- n
180
- else
181
- options[:num_fmt] || 0
182
- end
183
-
184
- borderId = options[:border] || 0
185
- raise ArgumentError, "Invalid borderId" unless borderId < borders.size
186
-
187
- fill = if options[:bg_color]
188
- color = Color.new(:rgb=>options[:bg_color])
189
- pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color)
190
- fills << Fill.new(pattern)
191
- else
192
- 0
193
- end
194
-
195
- fontId = if (options.values_at(:fg_color, :sz, :b, :i, :strike, :outline, :shadow, :charset, :family, :font_name).length)
196
- font = Font.new()
197
- [:b, :i, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
198
- font.color = Color.new(:rgb => options[:fg_color]) unless options[:fg_color].nil?
199
- font.name = options[:font_name] unless options[:font_name].nil?
200
- fonts << font
201
- else
202
- 0
203
- end
204
-
205
- applyProtection = (options[:hidden] || options[:locked]) ? 1 : 0
206
-
207
- xf = Xf.new(:fillId => fill, :fontId=>fontId, :applyFill=>1, :applyFont=>1, :numFmtId=>numFmtId, :borderId=>borderId, :applyProtection=>applyProtection)
208
-
209
- if options[:alignment]
210
- xf.alignment = CellAlignment.new(options[:alignment])
211
- end
212
-
213
- if applyProtection
214
- xf.protection = CellProtection.new(options)
215
- end
216
-
217
- cellXfs << xf
218
- end
219
-
220
- # Serializes the styles document
221
- # @return [String]
222
- def to_xml()
223
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
224
- xml.styleSheet(:xmlns => XML_NS) {
225
- [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :dxfs, :tableStyles].each do |key|
226
- self.instance_values[key.to_s].to_xml(xml)
227
- end
228
- }
229
- end
230
- builder.to_xml
231
- end
232
-
233
- private
234
- # Creates the default set of styles the exel requires to be valid as well as setting up the
235
- # Axlsx::STYLE_THIN_BORDER
236
- def load_default_styles
237
- @numFmts = SimpleTypedList.new NumFmt
238
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode=> "yyyy/mm/dd")
239
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode=> "yyyy/mm/dd hh:mm:ss")
240
-
241
- @numFmts.lock
242
-
243
- @fonts = SimpleTypedList.new Font
244
- @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
245
- @fonts.lock
246
-
247
- @fills = SimpleTypedList.new Fill
248
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:none))
249
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:gray125))
250
- @fills.lock
251
-
252
- @borders = SimpleTypedList.new Border
253
- @borders << Border.new
254
- black_border = Border.new
255
- [:left, :right, :top, :bottom].each do |item|
256
- black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
257
- end
258
- @borders << black_border
259
- @borders.lock
260
-
261
- @cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
262
- @cellStyleXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
263
- @cellStyleXfs.lock
264
-
265
- @cellStyles = SimpleTypedList.new CellStyle
266
- @cellStyles << CellStyle.new(:name =>"標準", :builtinId =>0, :xfId=>0)
267
- @cellStyles.lock
268
-
269
- @cellXfs = SimpleTypedList.new Xf, "cellXfs"
270
- @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
271
- @cellXfs << Xf.new(:borderId=>1, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
272
- @cellXfs.lock
273
-
274
- @dxfs = SimpleTypedList.new(Xf, "dxfs"); @dxfs.lock
275
- @tableStyles = TableStyles.new(:defaultTableStyle => "TableStyleMedium9", :defaultPivotStyle => "PivotStyleLight16"); @tableStyles.lock
276
- end
277
- end
278
- end
279
-
@@ -1,43 +0,0 @@
1
- module Axlsx
2
- # A single table style definition and is a collection for tableStyleElements
3
- # @note Table are not supported in this version and only the defaults required for a valid workbook are created.
4
- class TableStyle < SimpleTypedList
5
-
6
- # The name of this table style
7
- # @return [string]
8
- attr_accessor :name
9
-
10
- # indicates if this style should be applied to pivot tables
11
- # @return [Boolean]
12
- attr_accessor :pivot
13
-
14
- # indicates if this style should be applied to tables
15
- # @return [Boolean]
16
- attr_accessor :table
17
-
18
- # creates a new TableStyle object
19
- # @raise [ArgumentError] if name option is not provided.
20
- # @param [String] name
21
- # @option options [Boolean] pivot
22
- # @option options [Boolean] table
23
- def initialize(name, options={})
24
- options.each do |o|
25
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
26
- end
27
- super TableStyleElement
28
- end
29
-
30
- def name=(v) Axlsx::validate_string v; @name=v end
31
- def pivot=(v) Axlsx::validate_boolean v; @pivot=v end
32
- def table=(v) Axlsx::validate_boolean v; @table=v end
33
-
34
- # Serializes the table style
35
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
36
- # @return [String]
37
- def to_xml(xml)
38
- attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k }
39
- attr[:count] = self.size
40
- xml.tableStyle(attr) { self.each { |table_style_el| table_style_el.to_xml(xml) } }
41
- end
42
- end
43
- end