axlsx 1.1.6 → 1.2.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 +5 -2
  2. data/CHANGELOG.md +39 -0
  3. data/README.md +97 -46
  4. data/Rakefile +3 -2
  5. data/examples/basic_charts.rb +54 -0
  6. data/examples/chart_colors.rb +18 -3
  7. data/examples/example.rb +118 -42
  8. data/examples/example.xlsx +0 -0
  9. data/examples/example_streamed.xlsx +0 -0
  10. data/examples/extractive.pdf +0 -0
  11. data/examples/no-use_autowidth.xlsx +0 -0
  12. data/examples/scraping_html.rb +91 -0
  13. data/examples/shared_strings_example.xlsx +0 -0
  14. data/examples/sheet_view.rb +34 -0
  15. data/lib/axlsx/content_type/content_type.rb +2 -0
  16. data/lib/axlsx/content_type/default.rb +21 -12
  17. data/lib/axlsx/content_type/override.rb +22 -11
  18. data/lib/axlsx/doc_props/app.rb +36 -32
  19. data/lib/axlsx/doc_props/core.rb +9 -5
  20. data/lib/axlsx/drawing/ax_data_source.rb +7 -6
  21. data/lib/axlsx/drawing/axis.rb +64 -25
  22. data/lib/axlsx/drawing/bar_3D_chart.rb +49 -45
  23. data/lib/axlsx/drawing/bar_series.rb +1 -0
  24. data/lib/axlsx/drawing/cat_axis.rb +43 -39
  25. data/lib/axlsx/drawing/chart.rb +65 -54
  26. data/lib/axlsx/drawing/d_lbls.rb +100 -0
  27. data/lib/axlsx/drawing/drawing.rb +7 -5
  28. data/lib/axlsx/drawing/graphic_frame.rb +2 -2
  29. data/lib/axlsx/drawing/line_3D_chart.rb +3 -10
  30. data/lib/axlsx/drawing/num_data.rb +2 -2
  31. data/lib/axlsx/drawing/num_data_source.rb +1 -1
  32. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -7
  33. data/lib/axlsx/drawing/scatter_chart.rb +2 -8
  34. data/lib/axlsx/drawing/title.rb +21 -9
  35. data/lib/axlsx/drawing/two_cell_anchor.rb +41 -9
  36. data/lib/axlsx/drawing/view_3D.rb +41 -31
  37. data/lib/axlsx/drawing/vml_drawing.rb +1 -1
  38. data/lib/axlsx/package.rb +20 -16
  39. data/lib/axlsx/rels/relationship.rb +3 -3
  40. data/lib/axlsx/stylesheet/styles.rb +1 -1
  41. data/lib/axlsx/util/constants.rb +4 -0
  42. data/lib/axlsx/util/simple_typed_list.rb +15 -8
  43. data/lib/axlsx/util/validators.rb +28 -4
  44. data/lib/axlsx/version.rb +2 -7
  45. data/lib/axlsx/workbook/defined_name.rb +174 -0
  46. data/lib/axlsx/workbook/defined_names.rb +21 -0
  47. data/lib/axlsx/workbook/workbook.rb +46 -17
  48. data/lib/axlsx/workbook/worksheet/auto_filter.rb +34 -0
  49. data/lib/axlsx/workbook/worksheet/cell.rb +28 -1
  50. data/lib/axlsx/workbook/worksheet/col.rb +15 -0
  51. data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
  52. data/lib/axlsx/workbook/worksheet/comments.rb +8 -0
  53. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
  54. data/lib/axlsx/workbook/worksheet/data_bar.rb +1 -1
  55. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
  56. data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
  57. data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
  58. data/lib/axlsx/workbook/worksheet/page_setup.rb +10 -1
  59. data/lib/axlsx/workbook/worksheet/pane.rb +144 -0
  60. data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -0
  61. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
  62. data/lib/axlsx/workbook/worksheet/row.rb +1 -1
  63. data/lib/axlsx/workbook/worksheet/selection.rb +111 -0
  64. data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
  65. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +24 -0
  66. data/lib/axlsx/workbook/worksheet/sheet_view.rb +379 -0
  67. data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
  68. data/lib/axlsx/workbook/worksheet/worksheet.rb +315 -291
  69. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
  70. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
  71. data/lib/axlsx.rb +24 -16
  72. data/test/content_type/tc_content_type.rb +1 -6
  73. data/test/doc_props/tc_core.rb +1 -1
  74. data/test/drawing/tc_axis.rb +27 -2
  75. data/test/drawing/tc_bar_3D_chart.rb +12 -12
  76. data/test/drawing/tc_bar_series.rb +1 -2
  77. data/test/drawing/tc_cat_axis.rb +3 -3
  78. data/test/drawing/tc_chart.rb +8 -6
  79. data/test/drawing/tc_d_lbls.rb +47 -0
  80. data/test/drawing/tc_drawing.rb +5 -4
  81. data/test/drawing/tc_line_series.rb +1 -1
  82. data/test/drawing/tc_num_data.rb +5 -1
  83. data/test/drawing/tc_pie_3D_chart.rb +4 -8
  84. data/test/drawing/tc_pie_series.rb +1 -1
  85. data/test/drawing/tc_scatter_series.rb +1 -1
  86. data/test/drawing/tc_series.rb +1 -1
  87. data/test/drawing/tc_title.rb +16 -0
  88. data/test/drawing/tc_view_3D.rb +18 -18
  89. data/test/tc_package.rb +41 -4
  90. data/test/util/tc_validators.rb +68 -11
  91. data/test/workbook/tc_defined_name.rb +41 -0
  92. data/test/workbook/tc_workbook.rb +5 -3
  93. data/test/workbook/worksheet/table/tc_table.rb +0 -8
  94. data/test/workbook/worksheet/tc_cell.rb +2 -4
  95. data/test/workbook/worksheet/tc_page_setup.rb +20 -3
  96. data/test/workbook/worksheet/tc_pane.rb +94 -0
  97. data/test/workbook/worksheet/tc_protected_range.rb +17 -0
  98. data/test/workbook/worksheet/tc_row.rb +2 -2
  99. data/test/workbook/worksheet/tc_selection.rb +94 -0
  100. data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
  101. data/test/workbook/worksheet/tc_worksheet.rb +53 -41
  102. metadata +104 -97
  103. data/examples/chart_colors.xlsx +0 -0
  104. data/examples/conditional_formatting/getting_barred.xlsx +0 -0
  105. data/examples/doc/_index.html +0 -84
  106. data/examples/doc/class_list.html +0 -47
  107. data/examples/doc/css/common.css +0 -1
  108. data/examples/doc/css/full_list.css +0 -55
  109. data/examples/doc/css/style.css +0 -322
  110. data/examples/doc/file_list.html +0 -46
  111. data/examples/doc/frames.html +0 -13
  112. data/examples/doc/index.html +0 -84
  113. data/examples/doc/js/app.js +0 -205
  114. data/examples/doc/js/full_list.js +0 -173
  115. data/examples/doc/js/jquery.js +0 -16
  116. data/examples/doc/method_list.html +0 -46
  117. data/examples/doc/top-level-namespace.html +0 -95
  118. data/examples/examples_saved.xlsx +0 -0
  119. data/examples/fish.xlsx +0 -0
  120. data/examples/pareto.rb +0 -28
  121. data/examples/pareto.xlsx +0 -0
  122. data/examples/pie_chart.rb +0 -16
  123. data/examples/pie_chart.xlsx +0 -0
  124. data/examples/pie_chart_saved.xlsx +0 -0
  125. data/examples/sheet_protection.xlsx +0 -0
  126. data/examples/two_cell_anchor_image.xlsx +0 -0
  127. data/examples/~$pie_chart_saved.xlsx +0 -0
  128. data/lib/axlsx/drawing/ax_data_source.rb~ +0 -55
  129. data/lib/axlsx/drawing/data_source.rb~ +0 -51
  130. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  131. data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
  132. data/lib/axlsx/drawing/num_data.rb~ +0 -51
  133. data/lib/axlsx/drawing/num_data_source.rb~ +0 -54
  134. data/lib/axlsx/drawing/num_val.rb~ +0 -40
  135. data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
  136. data/lib/axlsx/drawing/ref.rb~ +0 -41
  137. data/lib/axlsx/drawing/str_data.rb~ +0 -58
  138. data/lib/axlsx/drawing/str_val.rb~ +0 -35
  139. data/lib/axlsx/drawing/vml_drawing.rb~ +0 -6
  140. data/lib/axlsx/drawing/vml_shape.rb~ +0 -61
  141. data/lib/axlsx/util/cbf.rb +0 -333
  142. data/lib/axlsx/util/cfb.rb~ +0 -201
  143. data/lib/axlsx/util/font_tables.rb~ +0 -0
  144. data/lib/axlsx/util/ms_off_crypto.rb +0 -189
  145. data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
  146. data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
  147. data/lib/axlsx/util/parser.rb~ +0 -6
  148. data/lib/axlsx/util/storage.rb~ +0 -0
  149. data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
  150. data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
  151. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  152. data/lib/axlsx/workbook/worksheet/color_scale.rb~ +0 -46
  153. data/lib/axlsx/workbook/worksheet/comment.rb~ +0 -91
  154. data/lib/axlsx/workbook/worksheet/comments.rb~ +0 -86
  155. data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
  156. data/lib/axlsx/workbook/worksheet/icon_set.rb~ +0 -95
  157. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  158. data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
  159. data/lib/schema/dc.xsd~ +0 -118
  160. data/lib/schema/dcterms.xsd~ +0 -331
  161. data/lib/schema/opc-coreProperties.xsd~ +0 -50
  162. data/test/drawing/tc_data_source.rb~ +0 -30
  163. data/test/drawing/tc_num_data.rb~ +0 -35
  164. data/test/drawing/tc_num_val.rb~ +0 -29
  165. data/test/drawing/tc_str_data.rb~ +0 -30
  166. data/test/drawing/tc_str_val.rb~ +0 -26
  167. data/test/drawing/tc_vml_drawing.rb~ +0 -0
  168. data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
  169. data/test/workbook/worksheet/tc_cfvo.rb~ +0 -20
  170. data/test/workbook/worksheet/tc_col.rb~ +0 -10
  171. data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
  172. data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
  173. data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
@@ -25,8 +25,8 @@ module Axlsx
25
25
  def data=(values=[])
26
26
  @tag_name = values.first.is_a?(Cell) ? :numCache : :numLit
27
27
  values.each do |value|
28
- v = value.is_a?(Cell) ? value.value : value
29
- @pt << NumVal.new(:v => v)
28
+ value = value.is_formula? ? 0 : value.value if value.is_a?(Cell)
29
+ @pt << NumVal.new(:v => value)
30
30
  end
31
31
  end
32
32
 
@@ -36,7 +36,7 @@ module Axlsx
36
36
  end
37
37
 
38
38
  # sets the tag name for this data source
39
- # @param [Symbol] One of the allowed_tag_names
39
+ # @param [Symbol] v One of the allowed_tag_names
40
40
  def tag_name=(v)
41
41
  Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
42
42
  @tag_name = v
@@ -13,19 +13,20 @@ module Axlsx
13
13
  # @option options [Cell, String] title
14
14
  # @option options [Boolean] show_legend
15
15
  # @option options [Symbol] grouping
16
- # @option options [String] gapDepth
17
- # @option options [Integer] rotX
18
- # @option options [String] hPercent
19
- # @option options [Integer] rotY
20
- # @option options [String] depthPercent
21
- # @option options [Boolean] rAngAx
16
+ # @option options [String] gap_depth
17
+ # @option options [Integer] rot_x
18
+ # @option options [String] h_percent
19
+ # @option options [Integer] rot_y
20
+ # @option options [String] depth_percent
21
+ # @option options [Boolean] r_ang_ax
22
22
  # @option options [Integer] perspective
23
23
  # @see Chart
24
24
  # @see View3D
25
25
  def initialize(frame, options={})
26
26
  super(frame, options)
27
27
  @series_type = PieSeries
28
- @view3D = View3D.new({:rotX=>30, :perspective=>30}.merge(options))
28
+ @view_3D = View3D.new({:rot_x =>30, :perspective=>30}.merge(options))
29
+ @d_lbls = nil
29
30
  end
30
31
 
31
32
  # Serializes the object
@@ -33,9 +34,11 @@ module Axlsx
33
34
  # @return [String]
34
35
  def to_xml_string(str = '')
35
36
  super(str) do |str_inner|
37
+
36
38
  str_inner << '<c:pie3DChart>'
37
39
  str_inner << '<c:varyColors val="1"/>'
38
40
  @series.each { |ser| ser.to_xml_string(str_inner) }
41
+ d_lbls.to_xml_string(str) if @d_lbls
39
42
  str_inner << '</c:pie3DChart>'
40
43
  end
41
44
  end
@@ -29,6 +29,7 @@ module Axlsx
29
29
  @yValAxis = ValAxis.new(@yValAxId, @xValAxId)
30
30
  super(frame, options)
31
31
  @series_type = ScatterSeries
32
+ @d_lbls = nil
32
33
  options.each do |o|
33
34
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
34
35
  end
@@ -49,14 +50,7 @@ module Axlsx
49
50
  str_inner << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
50
51
  str_inner << '<c:varyColors val="1"/>'
51
52
  @series.each { |ser| ser.to_xml_string(str_inner) }
52
- str_inner << '<c:dLbls>'
53
- str_inner << '<c:showLegendKey val="0"/>'
54
- str_inner << '<c:showVal val="0"/>'
55
- str_inner << '<c:showCatName val="0"/>'
56
- str_inner << '<c:showSerName val="0"/>'
57
- str_inner << '<c:showPercent val="0"/>'
58
- str_inner << '<c:showBubbleSize val="0"/>'
59
- str_inner << '</c:dLbls>'
53
+ d_lbls.to_xml_string(str) if @d_lbls
60
54
  str_inner << '<c:axId val="' << @xValAxId.to_s << '"/>'
61
55
  str_inner << '<c:axId val="' << @yValAxId.to_s << '"/>'
62
56
  str_inner << '</c:scatterChart>'
@@ -46,15 +46,27 @@ module Axlsx
46
46
  str << '<c:title>'
47
47
  unless @text.empty?
48
48
  str << '<c:tx>'
49
- str << '<c:strRef>'
50
- str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
51
- str << '<c:strCache>'
52
- str << '<c:ptCount val="1"/>'
53
- str << '<c:pt idx="0">'
54
- str << '<c:v>' << @text << '</c:v>'
55
- str << '</c:pt>'
56
- str << '</c:strCache>'
57
- str << '</c:strRef>'
49
+ if @cell.is_a?(Cell)
50
+ str << '<c:strRef>'
51
+ str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
52
+ str << '<c:strCache>'
53
+ str << '<c:ptCount val="1"/>'
54
+ str << '<c:pt idx="0">'
55
+ str << '<c:v>' << @text << '</c:v>'
56
+ str << '</c:pt>'
57
+ str << '</c:strCache>'
58
+ str << '</c:strRef>'
59
+ else
60
+ str << '<c:rich>'
61
+ str << '<a:bodyPr/>'
62
+ str << '<a:lstStyle/>'
63
+ str << '<a:p>'
64
+ str << '<a:r>'
65
+ str << '<a:t>' << @text.to_s << '</a:t>'
66
+ str << '</a:r>'
67
+ str << '</a:p>'
68
+ str << '</c:rich>'
69
+ end
58
70
  str << '</c:tx>'
59
71
  end
60
72
  str << '<c:layout/>'
@@ -25,23 +25,33 @@ module Axlsx
25
25
  # @return [Drawing]
26
26
  attr_reader :drawing
27
27
 
28
-
29
- # Creates a new TwoCellAnchor object and sets up a reference to the from and to markers in the
30
- # graphic_frame's chart. That means that you can do stuff like
31
- # c = worksheet.add_chart Axlsx::Chart
28
+ # Creates a new TwoCellAnchor object
32
29
  # c.start_at 5, 9
33
- # @note the chart_type parameter will be replaced with object in v. 2.0.0
34
30
  # @param [Drawing] drawing
35
- # @param [Class] chart_type This is passed to the graphic frame for instantiation. must be Chart or a subclass of Chart
36
- # @param object The object this anchor holds.
37
- # @option options [Array] start_at the col, row to start at THIS IS DOCUMENTED BUT NOT IMPLEMENTED HERE!
38
- # @option options [Array] end_at the col, row to end at
31
+ # @option options [Array] :start_at the col, row to start at THIS IS DOCUMENTED BUT NOT IMPLEMENTED HERE!
32
+ # @option options [Array] :end_at the col, row to end at
39
33
  def initialize(drawing, options={})
40
34
  @drawing = drawing
41
35
  drawing.anchors << self
42
36
  @from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
43
37
  end
44
38
 
39
+ # sets the col, row attributes for the from marker.
40
+ # @note The recommended way to set the start position for graphical
41
+ # objects is directly thru the object.
42
+ # @see Chart#start_at
43
+ def start_at(x, y)
44
+ set_marker_coords(x, y, from)
45
+ end
46
+
47
+ # sets the col, row attributes for the to marker
48
+ # @note the recommended way to set the to position for graphical
49
+ # objects is directly thru the object
50
+ # @see Char#end_at
51
+ def end_at(x, y)
52
+ set_marker_coords(x, y, to)
53
+ end
54
+
45
55
  # Creates a graphic frame and chart object associated with this anchor
46
56
  # @return [Chart]
47
57
  def add_chart(chart_type, options)
@@ -75,6 +85,28 @@ module Axlsx
75
85
  str << '<xdr:clientData/>'
76
86
  str << '</xdr:twoCellAnchor>'
77
87
  end
88
+ private
89
+
90
+ # parses coordinates and sets up a marker's row/col propery
91
+ def set_marker_coords(x, y, marker)
92
+ marker.col, marker.row = *parse_coord_args(x, y)
93
+ end
94
+
95
+ # handles multiple inputs for setting the position of a marker
96
+ # @see Chart#start_at
97
+ def parse_coord_args(x, y=0)
98
+ if x.is_a?(String)
99
+ x, y = *Axlsx::name_to_indices(x)
100
+ end
101
+ if x.is_a?(Cell)
102
+ x, y = *x.pos
103
+ end
104
+ if x.is_a?(Array)
105
+ x, y = *x
106
+ end
107
+ [x, y]
108
+ end
109
+
78
110
 
79
111
  end
80
112
  end
@@ -12,63 +12,73 @@ module Axlsx
12
12
  # x rotation for the chart
13
13
  # must be between -90 and 90
14
14
  # @return [Integer]
15
- attr_reader :rotX
16
-
15
+ attr_reader :rot_x
16
+ alias :rotX :rot_x
17
+
17
18
  # height of chart as % of chart
18
19
  # must be between 5% and 500%
19
20
  # @return [String]
20
- attr_reader :hPercent
21
+ attr_reader :h_percent
22
+ alias :hPercent :h_percent
21
23
 
22
24
  # y rotation for the chart
23
25
  # must be between 0 and 360
24
26
  # @return [Integer]
25
- attr_reader :rotY
26
-
27
+ attr_reader :rot_y
28
+ alias :rotY :rot_y
29
+
27
30
  # depth or chart as % of chart width
28
31
  # must be between 20% and 2000%
29
32
  # @return [String]
30
- attr_reader :depthPercent
33
+ attr_reader :depth_percent
34
+ alias :depthPercent :depth_percent
31
35
 
32
36
  # Chart axis are at right angles
33
37
  # @return [Boolean]
34
- attr_reader :rAngAx
38
+ attr_reader :r_ang_ax
39
+ alias :rAngAx :r_ang_ax
35
40
 
36
41
  # field of view angle
37
42
  # @return [Integer]
38
43
  attr_reader :perspective
39
44
 
40
45
  # Creates a new View3D for charts
41
- # @option options [Integer] rotX
42
- # @option options [String] hPercent
43
- # @option options [Integer] rotY
44
- # @option options [String] depthPercent
45
- # @option options [Boolean] rAngAx
46
+ # @option options [Integer] rot_x
47
+ # @option options [String] h_percent
48
+ # @option options [Integer] rot_y
49
+ # @option options [String] depth_percent
50
+ # @option options [Boolean] r_ang_ax
46
51
  # @option options [Integer] perspective
47
52
  def initialize(options={})
48
- @rotX, @hPercent, @rotY, @depthPercent, @rAngAx, @perspective = nil, nil, nil, nil, nil, nil
53
+ @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
49
54
  options.each do |o|
50
55
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
51
56
  end
52
57
  end
53
58
 
54
- # @see rotX
55
- def rotX=(v) DataTypeValidator.validate "#{self.class}.rotX", [Integer, Fixnum], v, lambda {|arg| arg >= -90 && arg <= 90 }; @rotX = v; end
59
+ # @see rot_x
60
+ def rot_x=(v) DataTypeValidator.validate "#{self.class}.rot_x", [Integer, Fixnum], v, lambda {|arg| arg >= -90 && arg <= 90 }; @rot_x = v; end
61
+ alias :rotX= :rot_x=
56
62
 
57
- # @see hPercent
58
- def hPercent=(v)
59
- RegexValidator.validate "#{self.class}.hPercent", H_PERCENT_REGEX, v
60
- @hPercent = v
63
+ # @see h_percent
64
+ def h_percent=(v)
65
+ RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
66
+ @h_percent = v
61
67
  end
68
+ alias :hPercent= :h_percent=
62
69
 
63
- # @see rotY
64
- def rotY=(v) DataTypeValidator.validate "#{self.class}.rotY", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 360 }; @rotY = v; end
65
-
66
- # @see depthPercent
67
- def depthPercent=(v) RegexValidator.validate "#{self.class}.depthPercent", DEPTH_PERCENT_REGEX, v; @depthPercent = v; end
70
+ # @see rot_y
71
+ def rot_y=(v) DataTypeValidator.validate "#{self.class}.rot_y", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 360 }; @rot_y = v; end
72
+ alias :rotY= :rot_y=
68
73
 
69
- # @see rAngAx
70
- def rAngAx=(v) Axlsx::validate_boolean(v); @rAngAx = v; end
74
+ # @see depth_percent
75
+ def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
76
+ alias :depthPercent= :depth_percent=
71
77
 
78
+ # @see r_ang_ax
79
+ def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
80
+ alias :rAngAx= :r_ang_ax=
81
+
72
82
  # @see perspective
73
83
  def perspective=(v) DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
74
84
 
@@ -78,11 +88,11 @@ module Axlsx
78
88
  # @return [String]
79
89
  def to_xml_string(str = '')
80
90
  str << '<c:view3D>'
81
- str << '<c:rotX val="' << @rotX.to_s << '"/>' unless @rotX.nil?
82
- str << '<c:hPercent val="' << @hPercent.to_s << '"/>' unless @hPercent.nil?
83
- str << '<c:rotY val="' << @rotY.to_s << '"/>' unless @rotY.nil?
84
- str << '<c:depthPercent val="' << @depthPercent.to_s << '"/>' unless @depthPercent.nil?
85
- str << '<c:rAngAx val="' << @rAngAx.to_s << '"/>' unless @rAngAx.nil?
91
+ str << '<c:rotX val="' << @rot_x.to_s << '"/>' unless @rot_x.nil?
92
+ str << '<c:hPercent val="' << @h_percent.to_s << '"/>' unless @h_percent.nil?
93
+ str << '<c:rotY val="' << @rot_y.to_s << '"/>' unless @rot_y.nil?
94
+ str << '<c:depthPercent val="' << @depth_percent.to_s << '"/>' unless @depth_percent.nil?
95
+ str << '<c:rAngAx val="' << @r_ang_ax.to_s << '"/>' unless @r_ang_ax.nil?
86
96
  str << '<c:perspective val="' << @perspective.to_s << '"/>' unless @perspective.nil?
87
97
  str << '</c:view3D>'
88
98
  end
@@ -4,7 +4,7 @@ module Axlsx
4
4
  class VmlDrawing
5
5
 
6
6
  # creates a new Vml Drawing object.
7
- # @param [Comments] the comments object this drawing is associated with
7
+ # @param [Comments] comments the comments object this drawing is associated with
8
8
  def initialize(comments)
9
9
  raise ArgumentError, "you must provide a comments object" unless comments.is_a?(Comments)
10
10
  @comments = comments
data/lib/axlsx/package.rb CHANGED
@@ -80,9 +80,8 @@ module Axlsx
80
80
 
81
81
  # Serialize your workbook to disk as an xlsx document.
82
82
  #
83
- # @param [File] output The file you want to serialize your package to
83
+ # @param [String] output The name of the file you want to serialize your package to
84
84
  # @param [Boolean] confirm_valid Validate the package prior to serialization.
85
- # @option options stream indicates if we should be writing to a stream or a file. True for stream, nil for file
86
85
  # @return [Boolean] False if confirm_valid and validation errors exist. True if the package was serialized
87
86
  # @note A tremendous amount of effort has gone into ensuring that you cannot create invalid xlsx documents.
88
87
  # confirm_valid should be used in the rare case that you cannot open the serialized file.
@@ -90,10 +89,15 @@ module Axlsx
90
89
  # @example
91
90
  # # This is how easy it is to create a valid xlsx file. Of course you might want to add a sheet or two, and maybe some data, styles and charts.
92
91
  # # Take a look at the README for an example of how to do it!
93
- # f = File.open('test.xlsx', 'w')
94
- # Package.new.serialize(f)
95
92
  #
96
- # # You will find a file called test.xlsx
93
+ # #serialize to a file
94
+ # p = Axlsx::Package.new
95
+ # # ......add cool stuff to your workbook......
96
+ # p.serialize("example.xlsx")
97
+ #
98
+ # # Serialize to a stream
99
+ # s = p.to_stream()
100
+ # File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
97
101
  def serialize(output, confirm_valid=false)
98
102
  return false unless !confirm_valid || self.validate.empty?
99
103
  Zip::ZipOutputStream.open(output) do |zip|
@@ -152,18 +156,18 @@ module Axlsx
152
156
  # @return [Zip::ZipOutputStream]
153
157
  def write_parts(zip)
154
158
  p = parts
155
- p.each do |part|
156
- unless part[:doc].nil?
157
- zip.put_next_entry(part[:entry]);
158
- entry = ['1.9.2', '1.9.3'].include?(RUBY_VERSION) ? part[:doc].force_encoding('BINARY') : part[:doc]
159
- zip.puts(entry)
160
- end
161
- unless part[:path].nil?
162
- zip.put_next_entry(part[:entry]);
163
- # binread for 1.9.3
164
- zip.write IO.respond_to?(:binread) ? IO.binread(part[:path]) : IO.read(part[:path])
165
- end
159
+ p.each do |part|
160
+ unless part[:doc].nil?
161
+ zip.put_next_entry(part[:entry])
162
+ entry = ['1.9.2', '1.9.3'].include?(RUBY_VERSION) ? part[:doc].force_encoding('BINARY') : part[:doc]
163
+ zip.puts(entry)
164
+ end
165
+ unless part[:path].nil?
166
+ zip.put_next_entry(part[:entry]);
167
+ # binread for 1.9.3
168
+ zip.write IO.respond_to?(:binread) ? IO.binread(part[:path]) : IO.read(part[:path])
166
169
  end
170
+ end
167
171
  zip
168
172
  end
169
173
 
@@ -30,9 +30,9 @@ module Axlsx
30
30
  attr_reader :TargetMode
31
31
 
32
32
  # creates a new relationship
33
- # @param [String] Type The type of the relationship
34
- # @param [String] Target The target for the relationship
35
- # @option [Symbol] target_mode only accepts :external.
33
+ # @param [String] type The type of the relationship
34
+ # @param [String] target The target for the relationship
35
+ # @option [Symbol] :target_mode only accepts :external.
36
36
  def initialize(type, target, options={})
37
37
  self.Target=target
38
38
  self.Type=type
@@ -133,7 +133,7 @@ module Axlsx
133
133
  # @option options [Integer] family The font family to use.
134
134
  # @option options [String] font_name The name of the font to use
135
135
  # @option options [Integer] num_fmt The number format to apply
136
- # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored.
136
+ # @option options [String] format_code The formatting to apply.
137
137
  # @option options [Integer|Hash] border The border style to use.
138
138
  # @option options [String] bg_color The background color to apply to the cell
139
139
  # @option options [Boolean] hidden Indicates if the cell should be hidden
@@ -249,6 +249,10 @@ module Axlsx
249
249
 
250
250
  # error message for sheets that use a name which is longer than 31 bytes
251
251
  ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less"
252
+
253
+ # error message for sheets that use a name which includes a colon
254
+
255
+ ERR_SHEET_NAME_COLON_FORBIDDEN = "Your worksheet name '%s' contains a colon, which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet."
252
256
 
253
257
  # error message for duplicate sheet names
254
258
  ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
@@ -18,7 +18,7 @@ module Axlsx
18
18
 
19
19
  # Creats a new typed list
20
20
  # @param [Array, Class] type An array of Class objects or a single Class object
21
- # @param [String] serialize The tag name to use in serialization
21
+ # @param [String] serialize_as The tag name to use in serialization
22
22
  # @raise [ArgumentError] if all members of type are not Class objects
23
23
  def initialize type, serialize_as=nil
24
24
  if type.is_a? Array
@@ -50,6 +50,18 @@ module Axlsx
50
50
  @locked_at = nil
51
51
  self
52
52
  end
53
+
54
+ # join operator
55
+ # @param [Array] v the array to join
56
+ # @raise [ArgumentError] if any of the values being joined are not
57
+ # one of the allowed types
58
+ # @return [SimpleTypedList]
59
+ def +(v)
60
+ v.each do |item|
61
+ DataTypeValidator.validate "SimpleTypedList.+", @allowed_types, item
62
+ @list << item
63
+ end
64
+ end
53
65
 
54
66
  # Concat operator
55
67
  # @param [Any] v the data to be added
@@ -60,12 +72,7 @@ module Axlsx
60
72
  @list << v
61
73
  @list.size - 1
62
74
  end
63
-
64
- # alternate of << method
65
- # @see <<
66
- def push(v)
67
- self.<< v
68
- end
75
+ alias :push :<<
69
76
 
70
77
  # delete the item from the list
71
78
  # @param [Any] v The item to be deleted.
@@ -149,7 +156,7 @@ module Axlsx
149
156
 
150
157
  def to_xml_string(str = '')
151
158
  classname = @allowed_types[0].name.split('::').last
152
- el_name = serialize_as || (classname[0,1].downcase + classname[1..-1])
159
+ el_name = serialize_as.to_s || (classname[0,1].downcase + classname[1..-1])
153
160
  str << '<' << el_name << ' count="' << @list.size.to_s << '">'
154
161
  @list.each { |item| item.to_xml_string(str) }
155
162
  str << '</' << el_name << '>'
@@ -109,9 +109,14 @@ module Axlsx
109
109
  end
110
110
 
111
111
  # Requires that the value is an integer ranging from 10 to 400.
112
- def self.validate_page_scale(v)
112
+ def self.validate_scale_10_400(v)
113
113
  DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg >= 10 && arg <= 400 }
114
114
  end
115
+
116
+ # Requires that the value is an integer ranging from 10 to 400 or 0.
117
+ def self.validate_scale_0_10_400(v)
118
+ DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg == 0 || (arg >= 10 && arg <= 400) }
119
+ end
115
120
 
116
121
  # Requires that the value is one of :default, :landscape, or :portrait.
117
122
  def self.validate_page_orientation(v)
@@ -132,8 +137,6 @@ module Axlsx
132
137
  # thisMonth, lastMonth, nextMonth, thisWeek, lastWeek, nextWeek
133
138
  def self.validate_time_period_type(v)
134
139
  RestrictionValidator.validate :time_period_type, [:today, :yesterday, :tomorrow, :last7Days, :thisMonth, :lastMonth, :nextMonth, :thisWeek, :lastWeek, :nextWeek], v
135
-
136
-
137
140
  end
138
141
 
139
142
  # Requires that the value is one of the valid ST_IconSet types
@@ -178,7 +181,7 @@ module Axlsx
178
181
  # Requires that the value is a valid scatterStyle
179
182
  # must be one of :none | :line | :lineMarker | :marker | :smooth | :smoothMarker
180
183
  # must be one of "none" | "line" | "lineMarker" | "marker" | "smooth" | "smoothMarker"
181
- # @param [Symbol|String] the value to validate
184
+ # @param [Symbol|String] v the value to validate
182
185
  def self.validate_scatter_style(v)
183
186
  Axlsx::RestrictionValidator.validate "ScatterChart.scatterStyle", [:none, :line, :lineMarker, :marker, :smooth, :smoothMarker], v.to_sym
184
187
  end
@@ -238,4 +241,25 @@ module Axlsx
238
241
  def self.validate_data_validation_type(v)
239
242
  RestrictionValidator.validate :data_validation_type, [:custom, :data, :decimal, :list, :none, :textLength, :time, :whole], v
240
243
  end
244
+
245
+ # Requires that the value is a valid sheet view type.
246
+ # valid types must be one of normal, page_break_preview, page_layout
247
+ # @param [Any] v The value validated
248
+ def self.validate_sheet_view_type(v)
249
+ RestrictionValidator.validate :sheet_view_type, [:normal, :page_break_preview, :page_layout], v
250
+ end
251
+
252
+ # Requires that the value is a valid active pane type.
253
+ # valid types must be one of bottom_left, bottom_right, top_left, top_right
254
+ # @param [Any] v The value validated
255
+ def self.validate_pane_type(v)
256
+ RestrictionValidator.validate :active_pane_type, [:bottom_left, :bottom_right, :top_left, :top_right], v
257
+ end
258
+
259
+ # Requires that the value is a valid split state type.
260
+ # valid types must be one of frozen, frozen_split, split
261
+ # @param [Any] v The value validated
262
+ def self.validate_split_state_type(v)
263
+ RestrictionValidator.validate :split_state_type, [:frozen, :frozen_split, :split], v
264
+ end
241
265
  end
data/lib/axlsx/version.rb CHANGED
@@ -1,10 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
-
4
- # The version of the gem
5
- # When using bunle exec rake and referencing the gem on github or locally
6
- # it will use the gemspec, which preloads this constant for the gem's version.
7
- # We check to make sure that it has not already been loaded
8
- VERSION="1.1.6" unless defined? Axlsx::VERSION
9
-
3
+ # The current version
4
+ VERSION="1.2.0"
10
5
  end