axlsx 1.0.16 → 1.1.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 (173) hide show
  1. data/.yardopts +1 -0
  2. data/CHANGELOG.md +18 -3
  3. data/README.md +189 -55
  4. data/examples/example.csv +1000 -0
  5. data/examples/example.rb +264 -142
  6. data/examples/example.xlsx +0 -0
  7. data/examples/example_streamed.xlsx +0 -0
  8. data/examples/no-use_autowidth.xlsx +0 -0
  9. data/examples/shared_strings_example.xlsx +0 -0
  10. data/lib/axlsx/content_type/content_type.rb +13 -12
  11. data/lib/axlsx/content_type/default.rb +10 -6
  12. data/lib/axlsx/content_type/override.rb +13 -8
  13. data/lib/axlsx/doc_props/app.rb +38 -41
  14. data/lib/axlsx/doc_props/core.rb +13 -17
  15. data/lib/axlsx/drawing/axis.rb +39 -19
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +34 -32
  17. data/lib/axlsx/drawing/bar_series.rb +14 -14
  18. data/lib/axlsx/drawing/cat_axis.rb +16 -14
  19. data/lib/axlsx/drawing/cat_axis_data.rb +17 -18
  20. data/lib/axlsx/drawing/chart.rb +40 -41
  21. data/lib/axlsx/drawing/drawing.rb +16 -12
  22. data/lib/axlsx/drawing/graphic_frame.rb +22 -21
  23. data/lib/axlsx/drawing/hyperlink.rb +13 -12
  24. data/lib/axlsx/drawing/line_3D_chart.rb +31 -28
  25. data/lib/axlsx/drawing/line_series.rb +12 -11
  26. data/lib/axlsx/drawing/marker.rb +11 -8
  27. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  28. data/lib/axlsx/drawing/one_cell_anchor.rb +18 -16
  29. data/lib/axlsx/drawing/pic.rb +26 -38
  30. data/lib/axlsx/drawing/picture_locking.rb +22 -18
  31. data/lib/axlsx/drawing/pie_3D_chart.rb +11 -8
  32. data/lib/axlsx/drawing/pie_series.rb +16 -12
  33. data/lib/axlsx/drawing/scaling.rb +11 -10
  34. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  35. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  36. data/lib/axlsx/drawing/ser_axis.rb +11 -10
  37. data/lib/axlsx/drawing/series.rb +16 -15
  38. data/lib/axlsx/drawing/series_title.rb +15 -14
  39. data/lib/axlsx/drawing/title.rb +27 -26
  40. data/lib/axlsx/drawing/two_cell_anchor.rb +19 -20
  41. data/lib/axlsx/drawing/val_axis.rb +9 -7
  42. data/lib/axlsx/drawing/val_axis_data.rb +18 -17
  43. data/lib/axlsx/drawing/view_3D.rb +23 -20
  44. data/lib/axlsx/package.rb +116 -51
  45. data/lib/axlsx/rels/relationship.rb +12 -8
  46. data/lib/axlsx/rels/relationships.rb +8 -1
  47. data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
  48. data/lib/axlsx/stylesheet/border.rb +28 -23
  49. data/lib/axlsx/stylesheet/border_pr.rb +17 -15
  50. data/lib/axlsx/stylesheet/cell_alignment.rb +24 -21
  51. data/lib/axlsx/stylesheet/cell_protection.rb +11 -7
  52. data/lib/axlsx/stylesheet/cell_style.rb +9 -5
  53. data/lib/axlsx/stylesheet/color.rb +21 -14
  54. data/lib/axlsx/stylesheet/fill.rb +8 -5
  55. data/lib/axlsx/stylesheet/font.rb +22 -14
  56. data/lib/axlsx/stylesheet/gradient_fill.rb +20 -17
  57. data/lib/axlsx/stylesheet/gradient_stop.rb +10 -6
  58. data/lib/axlsx/stylesheet/num_fmt.rb +13 -6
  59. data/lib/axlsx/stylesheet/pattern_fill.rb +26 -10
  60. data/lib/axlsx/stylesheet/styles.rb +53 -41
  61. data/lib/axlsx/stylesheet/table_style.rb +10 -4
  62. data/lib/axlsx/stylesheet/table_style_element.rb +11 -7
  63. data/lib/axlsx/stylesheet/table_styles.rb +12 -8
  64. data/lib/axlsx/stylesheet/xf.rb +30 -25
  65. data/lib/axlsx/util/cbf.rb +1 -0
  66. data/lib/axlsx/util/constants.rb +27 -14
  67. data/lib/axlsx/util/ms_off_crypto.rb +1 -1
  68. data/lib/axlsx/util/parser.rb +1 -0
  69. data/lib/axlsx/util/simple_typed_list.rb +20 -10
  70. data/lib/axlsx/util/storage.rb +1 -0
  71. data/lib/axlsx/util/validators.rb +23 -7
  72. data/lib/axlsx/version.rb +2 -1
  73. data/lib/axlsx/workbook/shared_strings_table.rb +69 -0
  74. data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
  75. data/lib/axlsx/workbook/workbook.rb +81 -35
  76. data/lib/axlsx/workbook/worksheet/cell.rb +172 -117
  77. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  78. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  79. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  80. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  81. data/lib/axlsx/workbook/worksheet/row.rb +53 -21
  82. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  83. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  84. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  85. data/lib/axlsx/workbook/worksheet/worksheet.rb +269 -121
  86. data/lib/axlsx.rb +41 -14
  87. data/lib/schema/dc.xsd +5 -5
  88. data/lib/schema/dcmitype.xsd +5 -3
  89. data/lib/schema/dcterms.xsd +15 -15
  90. data/lib/schema/opc-coreProperties.xsd +6 -2
  91. data/lib/schema/xml.xsd +7 -8
  92. data/test/#benchmark.txt# +7 -0
  93. data/test/#tc_helper.rb# +3 -0
  94. data/test/benchmark.rb +81 -0
  95. data/test/benchmark.rb~ +0 -0
  96. data/test/benchmark.txt +6 -0
  97. data/test/benchmark.txt~ +6 -0
  98. data/test/content_type/tc_content_type.rb +31 -31
  99. data/test/content_type/tc_default.rb +9 -22
  100. data/test/content_type/tc_override.rb +8 -21
  101. data/test/doc_props/tc_app.rb +2 -8
  102. data/test/doc_props/tc_core.rb +6 -7
  103. data/test/drawing/tc_axis.rb +7 -3
  104. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  105. data/test/drawing/tc_bar_series.rb +4 -5
  106. data/test/drawing/tc_cat_axis.rb +2 -3
  107. data/test/drawing/tc_cat_axis_data.rb +2 -3
  108. data/test/drawing/tc_chart.rb +13 -14
  109. data/test/drawing/tc_drawing.rb +7 -8
  110. data/test/drawing/tc_graphic_frame.rb +3 -4
  111. data/test/drawing/tc_hyperlink.rb +2 -3
  112. data/test/drawing/tc_line_3d_chart.rb +5 -6
  113. data/test/drawing/tc_line_series.rb +3 -4
  114. data/test/drawing/tc_marker.rb +3 -4
  115. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  116. data/test/drawing/tc_pic.rb +8 -9
  117. data/test/drawing/tc_picture_locking.rb +2 -3
  118. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  119. data/test/drawing/tc_pie_series.rb +4 -5
  120. data/test/drawing/tc_scaling.rb +3 -4
  121. data/test/drawing/tc_scatter_chart.rb +43 -0
  122. data/test/drawing/tc_scatter_series.rb +20 -0
  123. data/test/drawing/tc_ser_axis.rb +2 -3
  124. data/test/drawing/tc_series.rb +4 -5
  125. data/test/drawing/tc_series_title.rb +4 -5
  126. data/test/drawing/tc_title.rb +4 -5
  127. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  128. data/test/drawing/tc_val_axis.rb +2 -3
  129. data/test/drawing/tc_val_axis_data.rb +2 -3
  130. data/test/drawing/tc_view_3D.rb +6 -7
  131. data/test/example.csv +1000 -0
  132. data/test/example.xlsx +0 -0
  133. data/test/example_streamed.xlsx +0 -0
  134. data/test/profile.rb +33 -0
  135. data/test/rels/tc_relationship.rb +5 -6
  136. data/test/rels/tc_relationships.rb +4 -5
  137. data/test/stylesheet/tc_border.rb +3 -4
  138. data/test/stylesheet/tc_border_pr.rb +3 -4
  139. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  140. data/test/stylesheet/tc_cell_protection.rb +2 -3
  141. data/test/stylesheet/tc_cell_style.rb +2 -3
  142. data/test/stylesheet/tc_color.rb +2 -3
  143. data/test/stylesheet/tc_fill.rb +1 -2
  144. data/test/stylesheet/tc_font.rb +12 -5
  145. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  146. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  147. data/test/stylesheet/tc_num_fmt.rb +1 -2
  148. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  149. data/test/stylesheet/tc_styles.rb +16 -6
  150. data/test/stylesheet/tc_table_style.rb +2 -3
  151. data/test/stylesheet/tc_table_style_element.rb +2 -3
  152. data/test/stylesheet/tc_table_styles.rb +3 -4
  153. data/test/stylesheet/tc_xf.rb +16 -17
  154. data/test/tc_axlsx.rb +39 -0
  155. data/test/tc_axlsx.rb~ +0 -0
  156. data/test/tc_helper.rb +3 -0
  157. data/test/tc_helper.rb~ +3 -0
  158. data/test/tc_package.rb +43 -9
  159. data/test/util/tc_simple_typed_list.rb +8 -9
  160. data/test/util/tc_validators.rb +7 -8
  161. data/test/workbook/tc_shared_strings_table.rb +38 -0
  162. data/test/workbook/tc_workbook.rb +32 -6
  163. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  164. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  165. data/test/workbook/worksheet/tc_cell.rb +70 -13
  166. data/test/workbook/worksheet/tc_col.rb +59 -0
  167. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  168. data/test/workbook/worksheet/tc_date_time_converter.rb +126 -0
  169. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  170. data/test/workbook/worksheet/tc_row.rb +54 -4
  171. data/test/workbook/worksheet/tc_worksheet.rb +191 -31
  172. metadata +162 -109
  173. data/test/drawing/tc_hyperlink.rb~ +0 -71
@@ -1,39 +1,39 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # This class details a border used in Office Open XML spreadsheet styles.
3
4
  class Border
4
5
 
5
- # @return [Boolean] The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell.
6
+ # @return [Boolean] The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell.
6
7
  attr_reader :diagonalUp
7
-
8
+
8
9
  # @return [Boolean] The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell.
9
10
  attr_reader :diagonalDown
10
11
 
11
12
  # @return [Boolean] The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells.
12
13
  attr_reader :outline
13
14
 
14
- # @return [SimpleTypedList] A list of BorderPr objects for this border.
15
+ # @return [SimpleTypedList] A list of BorderPr objects for this border.
15
16
  attr_reader :prs
16
17
 
17
18
  # Creates a new Border object
18
19
  # @option options [Boolean] diagonalUp
19
20
  # @option options [Boolean] diagonalDown
20
21
  # @option options [Boolean] outline
21
- # @example Making a border
22
- # p = Package.new
23
- # red_border = Border.new
24
- # [:left, :right, :top, :bottom].each do |item|
25
- # red_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FFFF0000")) #
26
- # end
27
- # # this sets red_border to be the index for the created border.
28
- # red_border = p.workbook.styles.@borders << red_border
29
- # #used in row creation as follows. This will add a red border to each of the cells in the row.
30
- # p.workbook.add_worksheet.rows << :values=>[1,2,3] :style=>red_border
22
+ # @example - Making a border
23
+ # p = Axlsx::Package.new
24
+ # red_border = p.workbook.styles.add_style :border => { :style => :thin, :color => "FFFF0000" }
25
+ # ws = p.workbook.add_worksheet
26
+ # ws.add_row [1,2,3], :style => red_border
27
+ # p.serialize('red_border.xlsx')
28
+ #
29
+ # @note The recommended way to manage borders is with Style#add_style
30
+ # @see Style#add_style
31
31
  def initialize(options={})
32
32
  @prs = SimpleTypedList.new BorderPr
33
33
  options.each do |o|
34
34
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
35
35
  end
36
- end
36
+ end
37
37
 
38
38
  # @see diagonalUp
39
39
  def diagonalUp=(v) Axlsx::validate_boolean v; @diagonalUp = v end
@@ -42,16 +42,21 @@ module Axlsx
42
42
  # @see outline
43
43
  def outline=(v) Axlsx::validate_boolean v; @outline = v end
44
44
 
45
- # Serializes the border element
46
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
47
- def to_xml(xml)
48
- xml.border(self.instance_values.select{ |k,v| [:diagonalUp, :diagonalDown, :outline].include? k }) {
49
- [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal].each do |k|
50
- @prs.select { |pr| pr.name == k }.each do |part|
51
- part.to_xml(xml)
52
- end
45
+ # Serializes the object
46
+ # @param [String] str
47
+ # @return [String]
48
+ def to_xml_string(str = '')
49
+ str << '<border '
50
+ h = self.instance_values.select{ |k,v| [:diagonalUp, :diagonalDown, :outline].include? k }
51
+ str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
52
+ str << '>'
53
+ [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal].each do |k|
54
+ @prs.select { |pr| pr.name == k }.each do |part|
55
+ part.to_xml_string(str)
53
56
  end
54
- }
57
+ end
58
+ str << '</border>'
55
59
  end
60
+
56
61
  end
57
62
  end
@@ -1,21 +1,22 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
- # A border part.
3
+ # A border part.
3
4
  class BorderPr
4
-
5
+
5
6
  # @return [Color] The color of this border part.
6
7
  attr_reader :color
7
8
 
8
- # @return [Symbol] The syle of this border part.
9
- # @note
9
+ # @return [Symbol] The syle of this border part.
10
+ # @note
10
11
  # The following are allowed
11
- # :none
12
+ # :none
12
13
  # :thin
13
14
  # :medium
14
15
  # :dashed
15
16
  # :dotted
16
17
  # :thick
17
18
  # :double
18
- # :hair
19
+ # :hair
19
20
  # :mediumDashed
20
21
  # :dashDot
21
22
  # :mediumDashDot
@@ -25,7 +26,7 @@ module Axlsx
25
26
  attr_reader :style
26
27
 
27
28
  # @return [Symbol] The name of this border part
28
- # @note
29
+ # @note
29
30
  # The following are allowed
30
31
  # :start
31
32
  # :end
@@ -37,7 +38,7 @@ module Axlsx
37
38
  # :vertical
38
39
  # :horizontal
39
40
  attr_reader :name
40
-
41
+
41
42
  # Creates a new Border Part Object
42
43
  # @option options [Color] color
43
44
  # @option options [Symbol] name
@@ -52,17 +53,18 @@ module Axlsx
52
53
  # @see name
53
54
  def name=(v) RestrictionValidator.validate "BorderPr.name", [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal], v; @name = v end
54
55
  # @see color
55
- def color=(v) DataTypeValidator.validate(:color, Color, v); @color = v end
56
+ def color=(v) DataTypeValidator.validate(:color, Color, v); @color = v end
56
57
  # @see style
57
58
  def style=(v) RestrictionValidator.validate "BorderPr.style", [:none, :thin, :medium, :dashed, :dotted, :thick, :double, :hair, :mediumDashed, :dashDot, :mediumDashDot, :dashDotDot, :mediumDashDotDot, :slantDashDot], v; @style = v end
58
59
 
59
- # Serializes the border part
60
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
60
+ # Serializes the object
61
+ # @param [String] str
61
62
  # @return [String]
62
- def to_xml(xml)
63
- xml.send(@name, :style => @style) {
64
- @color.to_xml(xml) if @color.is_a? Color
65
- }
63
+ def to_xml_string(str = '')
64
+ str << '<' << @name.to_s << ' style="' << @style.to_s << '">'
65
+ @color.to_xml_string(str) if @color.is_a?(Color)
66
+ str << '</' << @name.to_s << '>'
66
67
  end
68
+
67
69
  end
68
70
  end
@@ -1,10 +1,11 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # CellAlignment stores information about the cell alignment of a style Xf Object.
3
- # @note Using Styles#add_style is the recommended way to manage cell alignment.
4
+ # @note Using Styles#add_style is the recommended way to manage cell alignment.
4
5
  # @see Styles#add_style
5
6
  class CellAlignment
6
7
  # The horizontal alignment of the cell.
7
- # @note
8
+ # @note
8
9
  # The horizontal cell alignement style must be one of
9
10
  # :general
10
11
  # :left
@@ -35,7 +36,7 @@ module Axlsx
35
36
  # Indicate if the text of the cell should wrap
36
37
  # @return [Boolean]
37
38
  attr_reader :wrapText
38
-
39
+
39
40
  # The amount of indent
40
41
  # @return [Integer]
41
42
  attr_reader :indent
@@ -53,12 +54,12 @@ module Axlsx
53
54
  attr_reader :shrinkToFit
54
55
 
55
56
  # The reading order of the text
56
- # 0 Context Dependent
57
+ # 0 Context Dependent
57
58
  # 1 Left-to-Right
58
59
  # 2 Right-to-Left
59
60
  # @return [Integer]
60
61
  attr_reader :readingOrder
61
-
62
+
62
63
  # Create a new cell_alignment object
63
64
  # @option options [Symbol] horizontal
64
65
  # @option options [Symbol] vertical
@@ -73,33 +74,35 @@ module Axlsx
73
74
  options.each do |o|
74
75
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
75
76
  end
76
- end
77
-
77
+ end
78
+
78
79
  # @see horizontal
79
- def horizontal=(v) Axlsx::validate_horizontal_alignment v; @horizontal = v end
80
+ def horizontal=(v) Axlsx::validate_horizontal_alignment v; @horizontal = v end
80
81
  # @see vertical
81
- def vertical=(v) Axlsx::validate_vertical_alignment v; @vertical = v end
82
+ def vertical=(v) Axlsx::validate_vertical_alignment v; @vertical = v end
82
83
  # @see textRotation
83
- def textRotation=(v) Axlsx::validate_unsigned_int v; @textRotation = v end
84
+ def textRotation=(v) Axlsx::validate_unsigned_int v; @textRotation = v end
84
85
  # @see wrapText
85
- def wrapText=(v) Axlsx::validate_boolean v; @wrapText = v end
86
+ def wrapText=(v) Axlsx::validate_boolean v; @wrapText = v end
86
87
  # @see indent
87
- def indent=(v) Axlsx::validate_unsigned_int v; @indent = v end
88
+ def indent=(v) Axlsx::validate_unsigned_int v; @indent = v end
88
89
  # @see relativeIndent
89
- def relativeIndent=(v) Axlsx::validate_int v; @relativeIndent = v end
90
+ def relativeIndent=(v) Axlsx::validate_int v; @relativeIndent = v end
90
91
  # @see justifyLastLine
91
- def justifyLastLine=(v) Axlsx::validate_boolean v; @justifyLastLine = v end
92
+ def justifyLastLine=(v) Axlsx::validate_boolean v; @justifyLastLine = v end
92
93
  # @see shrinkToFit
93
- def shrinkToFit=(v) Axlsx::validate_boolean v; @shrinkToFit = v end
94
+ def shrinkToFit=(v) Axlsx::validate_boolean v; @shrinkToFit = v end
94
95
  # @see readingOrder
95
- def readingOrder=(v) Axlsx::validate_unsigned_int v; @readingOrder = v end
96
+ def readingOrder=(v) Axlsx::validate_unsigned_int v; @readingOrder = v end
96
97
 
97
- # Serializes the cell alignment
98
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
98
+ # Serializes the object
99
+ # @param [String] str
99
100
  # @return [String]
100
- def to_xml(xml)
101
- xml.alignment(self.instance_values)
101
+ def to_xml_string(str = '')
102
+ str << '<alignment '
103
+ str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
104
+ str << '/>'
102
105
  end
103
-
106
+
104
107
  end
105
108
  end
@@ -1,9 +1,10 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # CellProtection stores information about locking or hiding cells in spreadsheet.
3
4
  # @note Using Styles#add_style is the recommended way to manage cell protection.
4
5
  # @see Styles#add_style
5
6
  class CellProtection
6
-
7
+
7
8
  # specifies locking for cells that have the style containing this protection
8
9
  # @return [Boolean]
9
10
  attr_reader :hidden
@@ -22,15 +23,18 @@ module Axlsx
22
23
  end
23
24
 
24
25
  # @see hidden
25
- def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
26
+ def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
26
27
  # @see locked
27
- def locked=(v) Axlsx::validate_boolean v; @locked = v end
28
+ def locked=(v) Axlsx::validate_boolean v; @locked = v end
28
29
 
29
- # Serializes the cell protection
30
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
30
+ # Serializes the object
31
+ # @param [String] str
31
32
  # @return [String]
32
- def to_xml(xml)
33
- xml.protection(self.instance_values)
33
+ def to_xml_string(str = '')
34
+ str << '<protection '
35
+ str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
36
+ str << '/>'
34
37
  end
38
+
35
39
  end
36
40
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # CellStyle defines named styles that reference defined formatting records and can be used in your worksheet.
3
4
  # @note Using Styles#add_style is the recommended way to manage cell styling.
@@ -6,7 +7,7 @@ module Axlsx
6
7
  # The name of this cell style
7
8
  # @return [String]
8
9
  attr_reader :name
9
-
10
+
10
11
  # The formatting record id this named style utilizes
11
12
  # @return [Integer]
12
13
  # @see Axlsx::Xf
@@ -54,12 +55,15 @@ module Axlsx
54
55
  # @see customBuiltin
55
56
  def customBuiltin=(v) Axlsx::validate_boolean v; @customBuiltin = v end
56
57
 
57
- # Serializes the cell style
58
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
58
+ # Serializes the object
59
+ # @param [String] str
59
60
  # @return [String]
60
- def to_xml(xml)
61
- xml.cellStyle(self.instance_values)
61
+ def to_xml_string(str = '')
62
+ str << '<cellStyle '
63
+ str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
64
+ str << '/>'
62
65
  end
66
+
63
67
  end
64
68
 
65
69
  end
@@ -1,12 +1,13 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # The color class represents a color used for borders, fills an fonts
3
4
  class Color
4
5
  # Determines if the color is system color dependant
5
6
  # @return [Boolean]
6
7
  attr_reader :auto
7
-
8
- # The color as defined in rgb terms.
9
- # @note
8
+
9
+ # The color as defined in rgb terms.
10
+ # @note
10
11
  # rgb colors need to conform to ST_UnsignedIntHex. That basically means put 'FF' before you color
11
12
  # When assigning the rgb value the behavior is much like CSS selectors and can use shorthand versions as follows:
12
13
  # If you provide a two character value it will be repeated for each r, g, b assignment
@@ -24,16 +25,16 @@ module Axlsx
24
25
  # no support for theme just yet
25
26
  # @return [Integer]
26
27
  #attr_reader :theme
27
-
28
+
28
29
  # The tint value.
29
30
  # @note valid values are between -1.0 and 1.0
30
31
  # @return [Float]
31
32
  attr_reader :tint
32
-
33
+
33
34
  # Creates a new Color object
34
35
  # @option options [Boolean] auto
35
36
  # @option options [String] rgb
36
- # @option options [Float] tint
37
+ # @option options [Float] tint
37
38
  def initialize(options={})
38
39
  @rgb = "FF000000"
39
40
  options.each do |o|
@@ -41,7 +42,7 @@ module Axlsx
41
42
  end
42
43
  end
43
44
  # @see auto
44
- def auto=(v) Axlsx::validate_boolean v; @auto = v end
45
+ def auto=(v) Axlsx::validate_boolean v; @auto = v end
45
46
  # @see color
46
47
  def rgb=(v)
47
48
  Axlsx::validate_string(v)
@@ -55,15 +56,21 @@ module Axlsx
55
56
  def tint=(v) Axlsx::validate_float v; @tint = v end
56
57
 
57
58
  # This version does not support themes
58
- # def theme=(v) Axlsx::validate_unsigned_integer v; @theme = v end
59
-
60
- # Indexed colors are for backward compatability which I am choosing not to support
61
- # def indexed=(v) Axlsx::validate_unsigned_integer v; @indexed = v end
59
+ # def theme=(v) Axlsx::validate_unsigned_integer v; @theme = v end
62
60
 
61
+ # Indexed colors are for backward compatability which I am choosing not to support
62
+ # def indexed=(v) Axlsx::validate_unsigned_integer v; @indexed = v end
63
63
 
64
- # Serializes the color
65
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
64
+ # Serializes the object
65
+ # @param [String] str
66
66
  # @return [String]
67
- def to_xml(xml) xml.color(self.instance_values) end
67
+ def to_xml_string(str = '')
68
+ str << "<color "
69
+ self.instance_values.each do |key, value|
70
+ str << key.to_s << '="' << value.to_s << '" '
71
+ end
72
+ str << "/>"
73
+ end
74
+
68
75
  end
69
76
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # The Fill is a formatting object that manages the background color, and pattern for cells.
3
4
  # @note The recommended way to manage styles in your workbook is to use Styles#add_style.
@@ -11,17 +12,19 @@ module Axlsx
11
12
  attr_reader :fill_type
12
13
 
13
14
  # Creates a new Fill object
14
- # @param [PatternFill, GradientFill] fill_type
15
+ # @param [PatternFill, GradientFill] fill_type
15
16
  # @raise [ArgumentError] if the fill_type parameter is not a PatternFill or a GradientFill instance
16
17
  def initialize(fill_type)
17
18
  self.fill_type = fill_type
18
19
  end
19
20
 
20
- # Serializes the fill
21
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
21
+ # Serializes the object
22
+ # @param [String] str
22
23
  # @return [String]
23
- def to_xml(xml)
24
- xml.fill { @fill_type.to_xml(xml) }
24
+ def to_xml_string(str = '')
25
+ str << '<fill>'
26
+ @fill_type.to_xml_string(str)
27
+ str << '</fill>'
25
28
  end
26
29
 
27
30
  # @see fill_type
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # The Font class details a font instance for use in styling cells.
3
4
  # @note The recommended way to manage fonts, and other styles is Styles#add_style
@@ -6,7 +7,7 @@ module Axlsx
6
7
  # The name of the font
7
8
  # @return [String]
8
9
  attr_reader :name
9
-
10
+
10
11
  # The charset of the font
11
12
  # @return [Integer]
12
13
  # @note
@@ -31,9 +32,9 @@ module Axlsx
31
32
  # 238 EASTEUROPE_CHARSET
32
33
  # 255 OEM_CHARSET
33
34
  attr_reader :charset
34
-
35
+
35
36
  # The font's family
36
- # @note
37
+ # @note
37
38
  # The following are defined OOXML specification
38
39
  # 0 Not applicable.
39
40
  # 1 Roman
@@ -53,6 +54,10 @@ module Axlsx
53
54
  # @return [Boolean]
54
55
  attr_reader :i
55
56
 
57
+ # Indicates if the font should be rendered underlined
58
+ # @return [Boolean]
59
+ attr_reader :u
60
+
56
61
  # Indicates if the font should be rendered with a strikthrough
57
62
  # @return [Boolean]
58
63
  attr_reader :strike
@@ -88,6 +93,7 @@ module Axlsx
88
93
  # @option options [Integer] family
89
94
  # @option options [Boolean] b
90
95
  # @option options [Boolean] i
96
+ # @option options [Boolean] u
91
97
  # @option options [Boolean] strike
92
98
  # @option options [Boolean] outline
93
99
  # @option options [Boolean] shadow
@@ -101,21 +107,23 @@ module Axlsx
101
107
  end
102
108
  end
103
109
  # @see name
104
- def name=(v) Axlsx::validate_string v; @name = v end
110
+ def name=(v) Axlsx::validate_string v; @name = v end
105
111
  # @see charset
106
112
  def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end
107
113
  # @see family
108
114
  def family=(v) Axlsx::validate_unsigned_int v; @family = v end
109
115
  # @see b
110
- def b=(v) Axlsx::validate_boolean v; @b = v end
116
+ def b=(v) Axlsx::validate_boolean v; @b = v end
111
117
  # @see i
112
118
  def i=(v) Axlsx::validate_boolean v; @i = v end
119
+ # @see u
120
+ def u=(v) Axlsx::validate_boolean v; @u = v end
113
121
  # @see strike
114
122
  def strike=(v) Axlsx::validate_boolean v; @strike = v end
115
123
  # @see outline
116
124
  def outline=(v) Axlsx::validate_boolean v; @outline = v end
117
125
  # @see shadow
118
- def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
126
+ def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
119
127
  # @see condense
120
128
  def condense=(v) Axlsx::validate_boolean v; @condense = v end
121
129
  # @see extend
@@ -125,15 +133,15 @@ module Axlsx
125
133
  # @see sz
126
134
  def sz=(v) Axlsx::validate_unsigned_int v; @sz=v end
127
135
 
128
- # Serializes the fill
129
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
136
+ # Serializes the object
137
+ # @param [String] str
130
138
  # @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
- }
139
+ def to_xml_string(str = '')
140
+ str << '<font>'
141
+ instance_values.each do |k, v|
142
+ v.is_a?(Color) ? v.to_xml_string(str) : (str << '<' << k.to_s << ' val="' << v.to_s << '"/>')
143
+ end
144
+ str << '</font>'
137
145
  end
138
146
  end
139
147
  end
@@ -1,11 +1,11 @@
1
- # -*- coding: utf-8 -*-
1
+ # encoding: UTF-8
2
2
  module Axlsx
3
3
  # A GradientFill defines the color and positioning for gradiant cell fill.
4
- # @see Open Office XML Part 1 §18.8.24
4
+ # @see Open Office XML Part 1 §18.8.24
5
5
  class GradientFill
6
6
 
7
7
  # The type of gradient.
8
- # @note
8
+ # @note
9
9
  # valid options are
10
10
  # :linear
11
11
  # :path
@@ -26,7 +26,7 @@ module Axlsx
26
26
 
27
27
  # Percentage format top
28
28
  # @return [Float]
29
- attr_reader :top
29
+ attr_reader :top
30
30
 
31
31
  # Percentage format bottom
32
32
  # @return [Float]
@@ -35,7 +35,7 @@ module Axlsx
35
35
  # Collection of stop objects
36
36
  # @return [SimpleTypedList]
37
37
  attr_reader :stop
38
-
38
+
39
39
  # Creates a new GradientFill object
40
40
  # @option options [Symbol] type
41
41
  # @option options [Float] degree
@@ -52,25 +52,28 @@ module Axlsx
52
52
  end
53
53
 
54
54
  # @see type
55
- def type=(v) Axlsx::validate_gradient_type v; @type = v end
55
+ def type=(v) Axlsx::validate_gradient_type v; @type = v end
56
56
  # @see degree
57
- def degree=(v) Axlsx::validate_float v; @degree = v end
57
+ def degree=(v) Axlsx::validate_float v; @degree = v end
58
58
  # @see left
59
- def left=(v) DataTypeValidator.validate "GradientFill.left", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @left = v end
59
+ def left=(v) DataTypeValidator.validate "GradientFill.left", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @left = v end
60
60
  # @see right
61
- def right=(v) DataTypeValidator.validate "GradientFill.right", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @right = v end
61
+ def right=(v) DataTypeValidator.validate "GradientFill.right", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @right = v end
62
62
  # @see top
63
- def top=(v) DataTypeValidator.validate "GradientFill.top", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @top = v end
63
+ def top=(v) DataTypeValidator.validate "GradientFill.top", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @top = v end
64
64
  # @see bottom
65
- def bottom=(v) DataTypeValidator.validate "GradientFill.bottom", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @bottom= v end
65
+ def bottom=(v) DataTypeValidator.validate "GradientFill.bottom", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @bottom= v end
66
66
 
67
- # Serializes the gradientFill
68
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
67
+ # Serializes the object
68
+ # @param [String] str
69
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
- }
70
+ def to_xml_string(str = '')
71
+ str << '<gradientFill'
72
+ h = self.instance_values.reject { |k,v| k.to_sym == :stop }
73
+ str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
74
+ str << '>'
75
+ @stop.each { |s| s.to_xml_string(str) }
76
+ str << '</gradientFill>'
74
77
  end
75
78
  end
76
79
  end
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # encoding: UTF-8
2
2
  module Axlsx
3
3
  # The GradientStop object represents a color point in a gradient.
4
- # @see Open Office XML Part 1 §18.8.24
4
+ # @see Open Office XML Part 1 §18.8.24
5
5
  class GradientStop
6
6
  # The color for this gradient stop
7
7
  # @return [Color]
@@ -23,11 +23,15 @@ module Axlsx
23
23
  # @see color
24
24
  def color=(v) DataTypeValidator.validate "GradientStop.color", Color, v; @color=v end
25
25
  # @see position
26
- def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1}; @position = v end
26
+ def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1}; @position = v end
27
27
 
28
- # Serializes the gradientStop
29
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
28
+ # Serializes the object
29
+ # @param [String] str
30
30
  # @return [String]
31
- def to_xml(xml) xml.stop(:position => self.position) {self.color.to_xml(xml)} end
31
+ def to_xml_string(str = '')
32
+ str << '<stop position="' << position.to_s << '">'
33
+ self.color.to_xml_string(str)
34
+ str << '</stop>'
35
+ end
32
36
  end
33
37
  end
@@ -1,10 +1,11 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
- # A NumFmt object defines an identifier and formatting code for data in cells.
3
+ # A NumFmt object defines an identifier and formatting code for data in cells.
3
4
  # @note The recommended way to manage styles is Styles#add_style
4
5
  class NumFmt
5
6
  # @return [Integer] An unsinged integer referencing a standard or custom number format.
6
7
  # @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
+ # 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
9
  # 1 0
9
10
  # 2 0.00
10
11
  # 3 #,##0
@@ -39,7 +40,7 @@ module Axlsx
39
40
  # @see Axlsx
40
41
  attr_reader :numFmtId
41
42
 
42
- # @return [String] The formatting to use for this number format.
43
+ # @return [String] The formatting to use for this number format.
43
44
  # @see http://support.microsoft.com/kb/264372
44
45
  attr_reader :formatCode
45
46
  def initialize(options={})
@@ -55,9 +56,15 @@ module Axlsx
55
56
  # @see formatCode
56
57
  def formatCode=(v) Axlsx::validate_string v; @formatCode = v end
57
58
 
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
59
+
60
+ # Serializes the object
61
+ # @param [String] str
62
+ # @return [String]
63
+ def to_xml_string(str = '')
64
+ str << '<numFmt '
65
+ str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
66
+ str << '/>'
67
+ end
61
68
 
62
69
  end
63
70
  end