caxlsx 2.0.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +41 -33
  4. data/Rakefile +9 -11
  5. data/examples/auto_filter.rb +10 -1
  6. data/examples/conditional_formatting/example_conditional_formatting.rb +18 -3
  7. data/examples/data_validation.rb +57 -40
  8. data/examples/example.rb +115 -7
  9. data/examples/merge_cells.rb +17 -0
  10. data/examples/no_grid_with_borders.rb +18 -0
  11. data/examples/pivot_test.rb +63 -0
  12. data/examples/split.rb +16 -0
  13. data/lib/axlsx.rb +34 -15
  14. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  15. data/lib/axlsx/content_type/content_type.rb +1 -1
  16. data/lib/axlsx/doc_props/app.rb +1 -1
  17. data/lib/axlsx/doc_props/core.rb +5 -5
  18. data/lib/axlsx/drawing/area_chart.rb +99 -0
  19. data/lib/axlsx/drawing/area_series.rb +110 -0
  20. data/lib/axlsx/drawing/axes.rb +1 -1
  21. data/lib/axlsx/drawing/axis.rb +12 -9
  22. data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
  23. data/lib/axlsx/drawing/bar_chart.rb +143 -0
  24. data/lib/axlsx/drawing/bar_series.rb +9 -9
  25. data/lib/axlsx/drawing/bubble_chart.rb +59 -0
  26. data/lib/axlsx/drawing/bubble_series.rb +63 -0
  27. data/lib/axlsx/drawing/cat_axis.rb +5 -5
  28. data/lib/axlsx/drawing/chart.rb +52 -8
  29. data/lib/axlsx/drawing/d_lbls.rb +3 -3
  30. data/lib/axlsx/drawing/drawing.rb +6 -1
  31. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  32. data/lib/axlsx/drawing/hyperlink.rb +1 -3
  33. data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
  34. data/lib/axlsx/drawing/line_chart.rb +10 -10
  35. data/lib/axlsx/drawing/line_series.rb +32 -3
  36. data/lib/axlsx/drawing/marker.rb +1 -1
  37. data/lib/axlsx/drawing/num_data.rb +4 -4
  38. data/lib/axlsx/drawing/num_data_source.rb +6 -6
  39. data/lib/axlsx/drawing/num_val.rb +3 -1
  40. data/lib/axlsx/drawing/one_cell_anchor.rb +3 -2
  41. data/lib/axlsx/drawing/pic.rb +25 -19
  42. data/lib/axlsx/drawing/picture_locking.rb +1 -3
  43. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
  44. data/lib/axlsx/drawing/pie_series.rb +6 -6
  45. data/lib/axlsx/drawing/scaling.rb +6 -6
  46. data/lib/axlsx/drawing/scatter_chart.rb +10 -10
  47. data/lib/axlsx/drawing/scatter_series.rb +40 -7
  48. data/lib/axlsx/drawing/ser_axis.rb +2 -2
  49. data/lib/axlsx/drawing/series.rb +3 -3
  50. data/lib/axlsx/drawing/series_title.rb +2 -2
  51. data/lib/axlsx/drawing/str_data.rb +3 -3
  52. data/lib/axlsx/drawing/str_val.rb +3 -1
  53. data/lib/axlsx/drawing/title.rb +22 -4
  54. data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
  55. data/lib/axlsx/drawing/val_axis.rb +1 -1
  56. data/lib/axlsx/drawing/view_3D.rb +2 -2
  57. data/lib/axlsx/drawing/vml_drawing.rb +1 -1
  58. data/lib/axlsx/package.rb +33 -31
  59. data/lib/axlsx/rels/relationship.rb +1 -1
  60. data/lib/axlsx/rels/relationships.rb +7 -4
  61. data/lib/axlsx/stylesheet/border_pr.rb +2 -2
  62. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
  63. data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
  64. data/lib/axlsx/stylesheet/cell_style.rb +1 -3
  65. data/lib/axlsx/stylesheet/color.rb +1 -3
  66. data/lib/axlsx/stylesheet/font.rb +1 -1
  67. data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
  68. data/lib/axlsx/stylesheet/num_fmt.rb +10 -3
  69. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
  70. data/lib/axlsx/stylesheet/styles.rb +7 -7
  71. data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
  72. data/lib/axlsx/util/accessors.rb +6 -6
  73. data/lib/axlsx/util/constants.rb +107 -99
  74. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  75. data/lib/axlsx/util/options_parser.rb +2 -1
  76. data/lib/axlsx/util/parser.rb +4 -4
  77. data/lib/axlsx/util/serialized_attributes.rb +16 -6
  78. data/lib/axlsx/util/simple_typed_list.rb +28 -52
  79. data/lib/axlsx/util/storage.rb +4 -4
  80. data/lib/axlsx/util/validators.rb +29 -17
  81. data/lib/axlsx/version.rb +1 -1
  82. data/lib/axlsx/workbook/defined_name.rb +11 -12
  83. data/lib/axlsx/workbook/defined_names.rb +2 -2
  84. data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
  85. data/lib/axlsx/workbook/workbook.rb +36 -11
  86. data/lib/axlsx/workbook/workbook_view.rb +80 -0
  87. data/lib/axlsx/workbook/workbook_views.rb +22 -0
  88. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
  89. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
  90. data/lib/axlsx/workbook/worksheet/break.rb +1 -3
  91. data/lib/axlsx/workbook/worksheet/cell.rb +136 -74
  92. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +63 -43
  93. data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
  94. data/lib/axlsx/workbook/worksheet/cfvos.rb +4 -1
  95. data/lib/axlsx/workbook/worksheet/col.rb +7 -10
  96. data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
  97. data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
  98. data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
  99. data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
  100. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
  101. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  102. data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
  103. data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
  104. data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
  105. data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
  106. data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
  107. data/lib/axlsx/workbook/worksheet/merged_cells.rb +4 -2
  108. data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
  109. data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
  110. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
  111. data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
  112. data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
  113. data/lib/axlsx/workbook/worksheet/pivot_table.rb +44 -28
  114. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
  115. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
  116. data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
  117. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -2
  118. data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -0
  119. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -0
  120. data/lib/axlsx/workbook/worksheet/row.rb +40 -51
  121. data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
  122. data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
  123. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  124. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
  125. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
  126. data/lib/axlsx/workbook/worksheet/table.rb +6 -6
  127. data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
  128. data/lib/axlsx/workbook/worksheet/tables.rb +4 -1
  129. data/lib/axlsx/workbook/worksheet/worksheet.rb +64 -78
  130. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
  131. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
  132. data/test/drawing/tc_area_chart.rb +39 -0
  133. data/test/drawing/tc_area_series.rb +71 -0
  134. data/test/drawing/tc_axis.rb +27 -0
  135. data/test/drawing/tc_bar_chart.rb +71 -0
  136. data/test/drawing/tc_bubble_chart.rb +44 -0
  137. data/test/drawing/tc_bubble_series.rb +21 -0
  138. data/test/drawing/tc_chart.rb +23 -10
  139. data/test/drawing/tc_data_source.rb +6 -0
  140. data/test/drawing/tc_drawing.rb +2 -2
  141. data/test/drawing/tc_line_chart.rb +5 -5
  142. data/test/drawing/tc_line_series.rb +47 -6
  143. data/test/drawing/tc_pic.rb +11 -15
  144. data/test/drawing/tc_scatter_series.rb +36 -1
  145. data/test/drawing/tc_str_val.rb +9 -0
  146. data/test/drawing/tc_title.rb +5 -0
  147. data/test/stylesheet/tc_styles.rb +2 -2
  148. data/test/tc_axlsx.rb +31 -0
  149. data/test/tc_helper.rb +2 -0
  150. data/test/tc_package.rb +19 -1
  151. data/test/util/tc_mime_type_utils.rb +13 -0
  152. data/test/util/tc_simple_typed_list.rb +2 -3
  153. data/test/util/tc_validators.rb +34 -10
  154. data/test/workbook/tc_defined_name.rb +12 -4
  155. data/test/workbook/tc_shared_strings_table.rb +16 -1
  156. data/test/workbook/tc_workbook.rb +38 -3
  157. data/test/workbook/tc_workbook_view.rb +50 -0
  158. data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
  159. data/test/workbook/worksheet/tc_break.rb +1 -1
  160. data/test/workbook/worksheet/tc_cell.rb +76 -8
  161. data/test/workbook/worksheet/tc_col.rb +2 -2
  162. data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
  163. data/test/workbook/worksheet/tc_data_bar.rb +1 -1
  164. data/test/workbook/worksheet/tc_data_validation.rb +11 -11
  165. data/test/workbook/worksheet/tc_header_footer.rb +2 -2
  166. data/test/workbook/worksheet/tc_icon_set.rb +1 -1
  167. data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
  168. data/test/workbook/worksheet/tc_page_setup.rb +3 -3
  169. data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
  170. data/test/workbook/worksheet/tc_print_options.rb +1 -1
  171. data/test/workbook/worksheet/tc_rich_text.rb +44 -0
  172. data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
  173. data/test/workbook/worksheet/tc_row.rb +7 -2
  174. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
  175. data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
  176. data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
  177. data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
  178. data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
  179. data/test/workbook/worksheet/tc_table.rb +2 -3
  180. data/test/workbook/worksheet/tc_worksheet.rb +99 -45
  181. metadata +89 -16
@@ -6,7 +6,7 @@ module Axlsx
6
6
  include Axlsx::OptionsParser
7
7
 
8
8
  # creates a new Scaling object
9
- # @option options [Integer, Fixnum] logBase
9
+ # @option options [Integer] logBase
10
10
  # @option options [Symbol] orientation
11
11
  # @option options [Float] max
12
12
  # @option options [Float] min
@@ -35,7 +35,7 @@ module Axlsx
35
35
  attr_reader :min
36
36
 
37
37
  # @see logBase
38
- def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer, Fixnum], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end
38
+ def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end
39
39
  # @see orientation
40
40
  def orientation=(v) RestrictionValidator.validate "Scaling.orientation", [:minMax, :maxMin], v; @orientation = v; end
41
41
  # @see max
@@ -49,10 +49,10 @@ module Axlsx
49
49
  # @return [String]
50
50
  def to_xml_string(str = '')
51
51
  str << '<c:scaling>'
52
- str << '<c:logBase val="' << @logBase.to_s << '"/>' unless @logBase.nil?
53
- str << '<c:orientation val="' << @orientation.to_s << '"/>' unless @orientation.nil?
54
- str << '<c:min val="' << @min.to_s << '"/>' unless @min.nil?
55
- str << '<c:max val="' << @max.to_s << '"/>' unless @max.nil?
52
+ str << ('<c:logBase val="' << @logBase.to_s << '"/>') unless @logBase.nil?
53
+ str << ('<c:orientation val="' << @orientation.to_s << '"/>') unless @orientation.nil?
54
+ str << ('<c:min val="' << @min.to_s << '"/>') unless @min.nil?
55
+ str << ('<c:max val="' << @max.to_s << '"/>') unless @max.nil?
56
56
  str << '</c:scaling>'
57
57
  end
58
58
 
@@ -25,7 +25,7 @@ module Axlsx
25
25
  # the y value axis
26
26
  # @return [ValAxis]
27
27
  def y_val_axis
28
- axes[:x_val_axis]
28
+ axes[:y_val_axis]
29
29
  end
30
30
  alias :yValAxis :y_val_axis
31
31
 
@@ -51,15 +51,15 @@ module Axlsx
51
51
  # @param [String] str
52
52
  # @return [String]
53
53
  def to_xml_string(str = '')
54
- super(str) do |str_inner|
55
- str_inner << '<c:scatterChart>'
56
- str_inner << '<c:scatterStyle val="' << scatter_style.to_s << '"/>'
57
- str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
58
- @series.each { |ser| ser.to_xml_string(str_inner) }
59
- d_lbls.to_xml_string(str_inner) if @d_lbls
60
- axes.to_xml_string(str_inner, :ids => true)
61
- str_inner << '</c:scatterChart>'
62
- axes.to_xml_string(str_inner)
54
+ super(str) do
55
+ str << '<c:scatterChart>'
56
+ str << ('<c:scatterStyle val="' << scatter_style.to_s << '"/>')
57
+ str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
58
+ @series.each { |ser| ser.to_xml_string(str) }
59
+ d_lbls.to_xml_string(str) if @d_lbls
60
+ axes.to_xml_string(str, :ids => true)
61
+ str << '</c:scatterChart>'
62
+ axes.to_xml_string(str)
63
63
  end
64
64
  str
65
65
  end
@@ -21,9 +21,25 @@ module Axlsx
21
21
  # @return [String]
22
22
  attr_reader :color
23
23
 
24
+ # @return [String]
25
+ attr_reader :ln_width
26
+
27
+ # Line smoothing between data points
28
+ # @return [Boolean]
29
+ attr_reader :smooth
30
+
24
31
  # Creates a new ScatterSeries
25
32
  def initialize(chart, options={})
26
33
  @xData, @yData = nil
34
+ if options[:smooth].nil?
35
+ # If caller hasn't specified smoothing or not, turn smoothing on or off based on scatter style
36
+ @smooth = [:smooth, :smoothMarker].include?(chart.scatter_style)
37
+ else
38
+ # Set smoothing according to the option provided
39
+ Axlsx::validate_boolean(options[:smooth])
40
+ @smooth = options[:smooth]
41
+ end
42
+ @ln_width = options[:ln_width] unless options[:ln_width].nil?
27
43
  super(chart, options)
28
44
  @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
29
45
  @yData = NumDataSource.new({:tag_name => :yVal, :data => options[:yData]}) unless options[:yData].nil?
@@ -34,30 +50,47 @@ module Axlsx
34
50
  @color = v
35
51
  end
36
52
 
53
+ # @see smooth
54
+ def smooth=(v)
55
+ Axlsx::validate_boolean(v)
56
+ @smooth = v
57
+ end
58
+
59
+ # @see ln_width
60
+ def ln_width=(v)
61
+ @ln_width = v
62
+ end
63
+
37
64
  # Serializes the object
38
65
  # @param [String] str
39
66
  # @return [String]
40
67
  def to_xml_string(str = '')
41
- super(str) do |inner_str|
68
+ super(str) do
42
69
  # needs to override the super color here to push in ln/and something else!
43
70
  if color
44
71
  str << '<c:spPr><a:solidFill>'
45
- str << '<a:srgbClr val="' << color << '"/>'
72
+ str << ('<a:srgbClr val="' << color << '"/>')
46
73
  str << '</a:solidFill>'
47
74
  str << '<a:ln><a:solidFill>'
48
- str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
75
+ str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
49
76
  str << '</c:spPr>'
50
77
  str << '<c:marker>'
51
78
  str << '<c:spPr><a:solidFill>'
52
- str << '<a:srgbClr val="' << color << '"/>'
79
+ str << ('<a:srgbClr val="' << color << '"/>')
53
80
  str << '</a:solidFill>'
54
81
  str << '<a:ln><a:solidFill>'
55
- str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
82
+ str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
56
83
  str << '</c:spPr>'
57
84
  str << '</c:marker>'
58
85
  end
59
- @xData.to_xml_string(inner_str) unless @xData.nil?
60
- @yData.to_xml_string(inner_str) unless @yData.nil?
86
+ if ln_width
87
+ str << '<c:spPr>'
88
+ str << '<a:ln w="' << ln_width.to_s << '"/>'
89
+ str << '</c:spPr>'
90
+ end
91
+ @xData.to_xml_string(str) unless @xData.nil?
92
+ @yData.to_xml_string(str) unless @yData.nil?
93
+ str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
61
94
  end
62
95
  str
63
96
  end
@@ -35,8 +35,8 @@ module Axlsx
35
35
  def to_xml_string(str = '')
36
36
  str << '<c:serAx>'
37
37
  super(str)
38
- str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>' unless @tick_lbl_skip.nil?
39
- str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>' unless @tick_mark_skip.nil?
38
+ str << ('<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>') unless @tick_lbl_skip.nil?
39
+ str << ('<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>') unless @tick_mark_skip.nil?
40
40
  str << '</c:serAx>'
41
41
  end
42
42
  end
@@ -59,10 +59,10 @@ module Axlsx
59
59
  # @return [String]
60
60
  def to_xml_string(str = '')
61
61
  str << '<c:ser>'
62
- str << '<c:idx val="' << index.to_s << '"/>'
63
- str << '<c:order val="' << (order || index).to_s << '"/>'
62
+ str << ('<c:idx val="' << index.to_s << '"/>')
63
+ str << ('<c:order val="' << (order || index).to_s << '"/>')
64
64
  title.to_xml_string(str) unless title.nil?
65
- yield str if block_given?
65
+ yield if block_given?
66
66
  str << '</c:ser>'
67
67
  end
68
68
  end
@@ -9,11 +9,11 @@ module Axlsx
9
9
  def to_xml_string(str = '')
10
10
  str << '<c:tx>'
11
11
  str << '<c:strRef>'
12
- str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
12
+ str << ('<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>')
13
13
  str << '<c:strCache>'
14
14
  str << '<c:ptCount val="1"/>'
15
15
  str << '<c:pt idx="0">'
16
- str << '<c:v>' << @text << '</c:v>'
16
+ str << ('<c:v>' << @text << '</c:v>')
17
17
  str << '</c:pt>'
18
18
  str << '</c:strCache>'
19
19
  str << '</c:strRef>'
@@ -29,12 +29,12 @@ module Axlsx
29
29
 
30
30
  # serialize the object
31
31
  def to_xml_string(str = "")
32
- str << '<c:' << @tag_name.to_s << '>'
33
- str << '<c:ptCount val="' << @pt.size.to_s << '"/>'
32
+ str << ('<c:' << @tag_name.to_s << '>')
33
+ str << ('<c:ptCount val="' << @pt.size.to_s << '"/>')
34
34
  @pt.each_with_index do |value, index|
35
35
  value.to_xml_string index, str
36
36
  end
37
- str << '</c:' << @tag_name.to_s << '>'
37
+ str << ('</c:' << @tag_name.to_s << '>')
38
38
  end
39
39
 
40
40
  end
@@ -26,7 +26,9 @@ module Axlsx
26
26
  # serialize the object
27
27
  def to_xml_string(idx, str = "")
28
28
  Axlsx::validate_unsigned_int(idx)
29
- str << '<c:pt idx="' << idx.to_s << '"><c:v>' << v.to_s << '</c:v></c:pt>'
29
+ if !v.to_s.empty?
30
+ str << ('<c:pt idx="' << idx.to_s << '"><c:v>' << ::CGI.escapeHTML(v.to_s) << '</c:v></c:pt>')
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -7,15 +7,24 @@ module Axlsx
7
7
  # @return [String]
8
8
  attr_reader :text
9
9
 
10
+ # Text size property
11
+ # @return [String]
12
+ attr_reader :text_size
13
+
10
14
  # The cell that holds the text for the title. Setting this property will automatically update the text attribute.
11
15
  # @return [Cell]
12
16
  attr_reader :cell
13
17
 
14
18
  # Creates a new Title object
15
19
  # @param [String, Cell] title The cell or string to be used for the chart's title
16
- def initialize(title="")
20
+ def initialize(title="", title_size="")
17
21
  self.cell = title if title.is_a?(Cell)
18
22
  self.text = title.to_s unless title.is_a?(Cell)
23
+ if title_size.to_s.empty?
24
+ self.text_size = "1600"
25
+ else
26
+ self.text_size = title_size.to_s
27
+ end
19
28
  end
20
29
 
21
30
  # @see text
@@ -26,6 +35,14 @@ module Axlsx
26
35
  v
27
36
  end
28
37
 
38
+ # @see text_size
39
+ def text_size=(v)
40
+ DataTypeValidator.validate 'Title.text_size', String, v
41
+ @text_size = v
42
+ @cell = nil
43
+ v
44
+ end
45
+
29
46
  # @see cell
30
47
  def cell=(v)
31
48
  DataTypeValidator.validate 'Title.text', Cell, v
@@ -48,11 +65,11 @@ module Axlsx
48
65
  str << '<c:tx>'
49
66
  if @cell.is_a?(Cell)
50
67
  str << '<c:strRef>'
51
- str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
68
+ str << ('<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>')
52
69
  str << '<c:strCache>'
53
70
  str << '<c:ptCount val="1"/>'
54
71
  str << '<c:pt idx="0">'
55
- str << '<c:v>' << @text << '</c:v>'
72
+ str << ('<c:v>' << @text << '</c:v>')
56
73
  str << '</c:pt>'
57
74
  str << '</c:strCache>'
58
75
  str << '</c:strRef>'
@@ -62,7 +79,8 @@ module Axlsx
62
79
  str << '<a:lstStyle/>'
63
80
  str << '<a:p>'
64
81
  str << '<a:r>'
65
- str << '<a:t>' << @text.to_s << '</a:t>'
82
+ str << ('<a:rPr sz="' << @text_size.to_s << '"/>')
83
+ str << ('<a:t>' << @text.to_s << '</a:t>')
66
84
  str << '</a:r>'
67
85
  str << '</a:p>'
68
86
  str << '</c:rich>'
@@ -37,11 +37,16 @@ module Axlsx
37
37
  drawing.anchors << self
38
38
  @from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
39
39
  parse_options options
40
+
41
+ # bit of a hack to work around the fact that the coords for start at and end at
42
+ # are passed in as an array when specified in intialization options - however
43
+ start_at(*options[:start_at]) if options[:start_at]
44
+ end_at(*options[:end_at]) if options[:end_at]
40
45
  end
41
46
 
42
47
  # sets the col, row attributes for the from marker.
43
48
  # @note The recommended way to set the start position for graphical
44
- # objects is directly thru the object.
49
+ # objects is directly thru the object.
45
50
  # @see Chart#start_at
46
51
  def start_at(x, y=nil)
47
52
  from.coord x, y
@@ -29,7 +29,7 @@ module Axlsx
29
29
  def to_xml_string(str = '')
30
30
  str << '<c:valAx>'
31
31
  super(str)
32
- str << '<c:crossBetween val="' << @cross_between.to_s << '"/>'
32
+ str << ('<c:crossBetween val="' << @cross_between.to_s << '"/>')
33
33
  str << '</c:valAx>'
34
34
  end
35
35
 
@@ -86,12 +86,12 @@ module Axlsx
86
86
  alias :rAngAx= :r_ang_ax=
87
87
 
88
88
  # @see perspective
89
- def perspective=(v)
89
+ def perspective=(v)
90
90
  RangeValidator.validate "View3D.perspective", 0, 240, v
91
91
  @perspective = v
92
92
  end
93
93
 
94
- # DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
94
+ # DataTypeValidator.validate "#{self.class}.perspective", [Integer], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
95
95
 
96
96
  # Serializes the object
97
97
  # @param [String] str
@@ -20,7 +20,7 @@ module Axlsx
20
20
  # @param [String] str
21
21
  # @return [String]
22
22
  def to_xml_string(str = '')
23
- str = <<BAD_PROGRAMMER
23
+ str << <<BAD_PROGRAMMER
24
24
  <xml xmlns:v="urn:schemas-microsoft-com:vml"
25
25
  xmlns:o="urn:schemas-microsoft-com:office:office"
26
26
  xmlns:x="urn:schemas-microsoft-com:office:excel">
@@ -1,4 +1,4 @@
1
- # encoding: UTF-8
1
+ # encoding: utf-8
2
2
  module Axlsx
3
3
  # Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
4
4
  # xlsx document including valdation and serialization.
@@ -22,7 +22,7 @@ module Axlsx
22
22
  # @example Package.new :author => 'you!', :workbook => Workbook.new
23
23
  def initialize(options={})
24
24
  @workbook = nil
25
- @core, @app = Core.new, App.new
25
+ @core, @app = Core.new, App.new
26
26
  @core.creator = options[:author] || @core.creator
27
27
  @core.created = options[:created_at]
28
28
  parse_options options
@@ -76,7 +76,7 @@ module Axlsx
76
76
  #end
77
77
 
78
78
  # @see workbook
79
- def workbook=(workbook) DataTypeValidator.validate "Package.workbook", Workbook, workbook; @workbook = workbook; end
79
+ def workbook=(workbook) DataTypeValidator.validate :Package_workbook, Workbook, workbook; @workbook = workbook; end
80
80
 
81
81
  # Serialize your workbook to disk as an xlsx document.
82
82
  #
@@ -146,7 +146,9 @@ module Axlsx
146
146
  def validate
147
147
  errors = []
148
148
  parts.each do |part|
149
- errors.concat validate_single_doc(part[:schema], part[:doc]) unless part[:schema].nil?
149
+ unless part[:schema].nil?
150
+ errors.concat validate_single_doc(part[:schema], part[:doc].to_xml_string)
151
+ end
150
152
  end
151
153
  errors
152
154
  end
@@ -161,13 +163,11 @@ module Axlsx
161
163
  p.each do |part|
162
164
  unless part[:doc].nil?
163
165
  zip.put_next_entry(zip_entry_for_part(part))
164
- entry = ['1.9.2', '1.9.3'].include?(RUBY_VERSION) ? part[:doc].force_encoding('BINARY') : part[:doc]
165
- zip.puts(entry)
166
+ part[:doc].to_xml_string(zip)
166
167
  end
167
168
  unless part[:path].nil?
168
169
  zip.put_next_entry(zip_entry_for_part(part))
169
- # binread for 1.9.3
170
- zip.write IO.respond_to?(:binread) ? IO.binread(part[:path]) : IO.read(part[:path])
170
+ zip.write IO.read(part[:path])
171
171
  end
172
172
  end
173
173
  zip
@@ -194,40 +194,40 @@ module Axlsx
194
194
  # @private
195
195
  def parts
196
196
  parts = [
197
- {:entry => RELS_PN, :doc => relationships.to_xml_string, :schema => RELS_XSD},
198
- {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml_string, :schema => SML_XSD},
199
- {:entry => CORE_PN, :doc => @core.to_xml_string, :schema => CORE_XSD},
200
- {:entry => APP_PN, :doc => @app.to_xml_string, :schema => APP_XSD},
201
- {:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships.to_xml_string, :schema => RELS_XSD},
202
- {:entry => CONTENT_TYPES_PN, :doc => content_types.to_xml_string, :schema => CONTENT_TYPES_XSD},
203
- {:entry => WORKBOOK_PN, :doc => workbook.to_xml_string, :schema => SML_XSD}
197
+ {:entry => RELS_PN, :doc => relationships, :schema => RELS_XSD},
198
+ {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles, :schema => SML_XSD},
199
+ {:entry => CORE_PN, :doc => @core, :schema => CORE_XSD},
200
+ {:entry => APP_PN, :doc => @app, :schema => APP_XSD},
201
+ {:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships, :schema => RELS_XSD},
202
+ {:entry => CONTENT_TYPES_PN, :doc => content_types, :schema => CONTENT_TYPES_XSD},
203
+ {:entry => WORKBOOK_PN, :doc => workbook, :schema => SML_XSD}
204
204
  ]
205
205
 
206
206
  workbook.drawings.each do |drawing|
207
- parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml_string, :schema => RELS_XSD}
208
- parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml_string, :schema => DRAWING_XSD}
207
+ parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships, :schema => RELS_XSD}
208
+ parts << {:entry => "xl/#{drawing.pn}", :doc => drawing, :schema => DRAWING_XSD}
209
209
  end
210
210
 
211
211
 
212
212
  workbook.tables.each do |table|
213
- parts << {:entry => "xl/#{table.pn}", :doc => table.to_xml_string, :schema => SML_XSD}
213
+ parts << {:entry => "xl/#{table.pn}", :doc => table, :schema => SML_XSD}
214
214
  end
215
215
  workbook.pivot_tables.each do |pivot_table|
216
216
  cache_definition = pivot_table.cache_definition
217
- parts << {:entry => "xl/#{pivot_table.rels_pn}", :doc => pivot_table.relationships.to_xml_string, :schema => RELS_XSD}
218
- parts << {:entry => "xl/#{pivot_table.pn}", :doc => pivot_table.to_xml_string} #, :schema => SML_XSD}
219
- parts << {:entry => "xl/#{cache_definition.pn}", :doc => cache_definition.to_xml_string} #, :schema => SML_XSD}
217
+ parts << {:entry => "xl/#{pivot_table.rels_pn}", :doc => pivot_table.relationships, :schema => RELS_XSD}
218
+ parts << {:entry => "xl/#{pivot_table.pn}", :doc => pivot_table} #, :schema => SML_XSD}
219
+ parts << {:entry => "xl/#{cache_definition.pn}", :doc => cache_definition} #, :schema => SML_XSD}
220
220
  end
221
221
 
222
222
  workbook.comments.each do|comment|
223
223
  if comment.size > 0
224
- parts << { :entry => "xl/#{comment.pn}", :doc => comment.to_xml_string, :schema => SML_XSD }
225
- parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing.to_xml_string, :schema => nil }
224
+ parts << { :entry => "xl/#{comment.pn}", :doc => comment, :schema => SML_XSD }
225
+ parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing, :schema => nil }
226
226
  end
227
227
  end
228
228
 
229
229
  workbook.charts.each do |chart|
230
- parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml_string, :schema => DRAWING_XSD}
230
+ parts << {:entry => "xl/#{chart.pn}", :doc => chart, :schema => DRAWING_XSD}
231
231
  end
232
232
 
233
233
  workbook.images.each do |image|
@@ -235,14 +235,16 @@ module Axlsx
235
235
  end
236
236
 
237
237
  if use_shared_strings
238
- parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings.to_xml_string, :schema => SML_XSD}
238
+ parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings, :schema => SML_XSD}
239
239
  end
240
240
 
241
241
  workbook.worksheets.each do |sheet|
242
- parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml_string, :schema => RELS_XSD}
243
- parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml_string, :schema => SML_XSD}
242
+ parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships, :schema => RELS_XSD}
243
+ parts << {:entry => "xl/#{sheet.pn}", :doc => sheet, :schema => SML_XSD}
244
244
  end
245
- parts
245
+
246
+ # Sort parts for correct MIME detection
247
+ parts.sort_by { |part| part[:entry] }
246
248
  end
247
249
 
248
250
  # Performs xsd validation for a signle document
@@ -303,7 +305,7 @@ module Axlsx
303
305
  c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}",
304
306
  :ContentType => WORKSHEET_CT)
305
307
  end
306
- exts = workbook.images.map { |image| image.extname }
308
+ exts = workbook.images.map { |image| image.extname.downcase }
307
309
  exts.uniq.each do |ext|
308
310
  ct = if ['jpeg', 'jpg'].include?(ext)
309
311
  JPEG_CT
@@ -326,8 +328,8 @@ module Axlsx
326
328
  # @private
327
329
  def base_content_types
328
330
  c_types = ContentType.new()
329
- c_types << Default.new(:ContentType => RELS_CT, :Extension => RELS_EX)
330
- c_types << Default.new(:Extension => XML_EX, :ContentType => XML_CT)
331
+ c_types << Default.new(:ContentType => RELS_CT, :Extension => RELS_EX)
332
+ c_types << Default.new(:Extension => XML_EX, :ContentType => XML_CT)
331
333
  c_types << Override.new(:PartName => "/#{APP_PN}", :ContentType => APP_CT)
332
334
  c_types << Override.new(:PartName => "/#{CORE_PN}", :ContentType => CORE_CT)
333
335
  c_types << Override.new(:PartName => "/xl/#{STYLES_PN}", :ContentType => STYLES_CT)