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
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+
5
+ #```ruby
6
+ require 'axlsx'
7
+ package = Axlsx::Package.new
8
+ package.workbook do |workbook|
9
+ workbook.add_worksheet name: 'merged_cells' do |sheet|
10
+ 4.times do
11
+ sheet.add_row %w(a b c d e f g)
12
+ end
13
+ sheet.merge_cells "A1:A2"
14
+ sheet.merge_cells "B1:B2"
15
+ end
16
+ end
17
+ package.serialize 'merged_cells.xlsx'
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+
5
+ #```ruby
6
+ require 'axlsx'
7
+ package = Axlsx::Package.new
8
+ package.workbook do |workbook|
9
+ workbook.styles do |s|
10
+ gridstyle_border = s.add_style :border => { :style => :thin, :color =>"FFCDCDCD" }
11
+ workbook.add_worksheet :name => "Custom Borders" do |sheet|
12
+ sheet.sheet_view.show_grid_lines = false
13
+ sheet.add_row ["with", "grid", "style"], :style => gridstyle_border
14
+ sheet.add_row ["no", "border"]
15
+ end
16
+ end
17
+ end
18
+ package.serialize 'no_grid_with_borders.xlsx'
@@ -0,0 +1,63 @@
1
+ class RandomReportGenerator
2
+ def date
3
+ Date.today.strftime("%m/%d/%Y")
4
+ end
5
+ def member_id
6
+ @i ||= 0
7
+ @i += 1
8
+ end
9
+ def name
10
+ "John S."
11
+ end
12
+ def gender
13
+ ["Male", "Female"].sample
14
+ end
15
+ def age
16
+ rand(100)
17
+ end
18
+ def city
19
+ ["New York", "Mountain View", "Newark", "Phoenix"].sample
20
+ end
21
+ def state
22
+ ["NY", "CA", "NJ", "AZ"].sample
23
+ end
24
+ def parenting
25
+ "Foo"
26
+ end
27
+ def student
28
+ "Bar"
29
+ end
30
+ def income
31
+ "Bar"
32
+ end
33
+ def education
34
+ "Bar"
35
+ end
36
+ def answer
37
+ ["Yes", "No", "Maybe", "I dont know"].sample
38
+ end
39
+ def run
40
+ package = Axlsx::Package.new
41
+ workbook = package.workbook
42
+
43
+ workbook.add_worksheet(:name => "Data Sheet") do |sheet|
44
+ sheet.add_row [
45
+ "Date", "Member ID", "Name", "Gender", "Age", "City", "State",
46
+ "Parenting Status", "Student Status", "Income", "Education", "Answer"
47
+ ]
48
+ 30.times do
49
+ sheet.add_row [date, member_id, name, gender, age, city, state,
50
+ parenting, student, income, education, answer]
51
+ end
52
+ end
53
+
54
+ workbook.add_worksheet(:name => "Summary") do |sheet|
55
+ pivot_table = Axlsx::PivotTable.new 'A1:B15', "A1:L31", workbook.worksheets[0]
56
+ pivot_table.rows = ['Answer']
57
+ pivot_table.data = [{:ref => "Member ID", :subtotal => "count"}]
58
+ sheet.pivot_tables << pivot_table
59
+ end
60
+
61
+ package.serialize("pivot_table.xlsx")
62
+ end
63
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+ p = Axlsx::Package.new
6
+ wb = p.workbook
7
+ wb.add_worksheet name: 'pane' do |sheet|
8
+ sheet.sheet_view.pane do |pane|
9
+ pane.top_left_cell = "B2"
10
+ pane.state = :frozen_split
11
+ pane.y_split = 2
12
+ pane.x_split = 1
13
+ pane.active_pane = :bottom_right
14
+ end
15
+ end
16
+ p.serialize 'pane.xlsx'
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'htmlentities'
3
3
  require 'axlsx/version.rb'
4
+ require 'mimemagic'
4
5
 
5
6
  require 'axlsx/util/simple_typed_list.rb'
6
7
  require 'axlsx/util/constants.rb'
@@ -10,6 +11,7 @@ require 'axlsx/util/serialized_attributes'
10
11
  require 'axlsx/util/options_parser'
11
12
  # to be included with parsable intitites.
12
13
  #require 'axlsx/util/parser.rb'
14
+ require 'axlsx/util/mime_type_utils'
13
15
 
14
16
  require 'axlsx/stylesheet/styles.rb'
15
17
 
@@ -53,7 +55,7 @@ module Axlsx
53
55
  cells = sort_cells(cells)
54
56
  reference = "#{cells.first.reference(absolute)}:#{cells.last.reference(absolute)}"
55
57
  if absolute
56
- escaped_name = cells.first.row.worksheet.name.gsub "&apos;", "''"
58
+ escaped_name = cells.first.row.worksheet.name.gsub '&apos;', "''"
57
59
  "'#{escaped_name}'!#{reference}"
58
60
  else
59
61
  reference
@@ -65,7 +67,7 @@ module Axlsx
65
67
  # @param [Array] cells
66
68
  # @return [Array]
67
69
  def self.sort_cells(cells)
68
- cells.sort { |x, y| [x.index, x.row.index] <=> [y.index, y.row.index] }
70
+ cells.sort { |x, y| [x.index, x.row.row_index] <=> [y.index, y.row.row_index] }
69
71
  end
70
72
 
71
73
  #global reference html entity encoding
@@ -88,20 +90,21 @@ module Axlsx
88
90
  # @note This follows the standard spreadsheet convention of naming columns A to Z, followed by AA to AZ etc.
89
91
  # @return [String]
90
92
  def self.col_ref(index)
91
- chars = []
93
+ chars = ''
92
94
  while index >= 26 do
93
- chars << ((index % 26) + 65).chr
94
- index = (index / 26).to_i - 1
95
+ index, char = index.divmod(26)
96
+ chars.prepend((char + 65).chr)
97
+ index -= 1
95
98
  end
96
- chars << (index + 65).chr
97
- chars.reverse.join
99
+ chars.prepend((index + 65).chr)
100
+ chars
98
101
  end
99
102
 
100
103
  # @return [String] The alpha(column)numeric(row) reference for this sell.
101
104
  # @example Relative Cell Reference
102
105
  # ws.rows.first.cells.first.r #=> "A1"
103
106
  def self.cell_r(c_index, r_index)
104
- Axlsx::col_ref(c_index).to_s << (r_index+1).to_s
107
+ col_ref(c_index) << (r_index+1).to_s
105
108
  end
106
109
 
107
110
  # Creates an array of individual cell references based on an excel reference range.
@@ -113,7 +116,7 @@ module Axlsx
113
116
  end_col, end_row = name_to_indices($2)
114
117
  (start_row..end_row).to_a.map do |row_num|
115
118
  (start_col..end_col).to_a.map do |col_num|
116
- "#{col_ref(col_num)}#{row_num+1}"
119
+ cell_r(col_num, row_num)
117
120
  end
118
121
  end
119
122
  end
@@ -127,14 +130,30 @@ module Axlsx
127
130
  s.gsub(/_(.)/){ $1.upcase }
128
131
  end
129
132
 
130
- # returns the provided string with all invalid control charaters
131
- # removed.
132
- # @param [String] str The sting to process
133
- # @return [String]
134
- def self.sanitize(str)
135
- str.gsub(CONTROL_CHAR_REGEX, '')
133
+ # returns the provided string with all invalid control charaters
134
+ # removed.
135
+ # @param [String] str The string to process
136
+ # @return [String]
137
+ def self.sanitize(str)
138
+ if str.frozen?
139
+ str.delete(CONTROL_CHARS)
140
+ else
141
+ str.delete!(CONTROL_CHARS)
142
+ str
136
143
  end
144
+ end
137
145
 
146
+ # If value is boolean return 1 or 0
147
+ # else return the value
148
+ # @param [Object] value The value to process
149
+ # @return [Object]
150
+ def self.booleanize(value)
151
+ if value == true || value == false
152
+ value ? 1 : 0
153
+ else
154
+ value
155
+ end
156
+ end
138
157
 
139
158
  # Instructs the serializer to not try to escape cell value input.
140
159
  # This will give you a huge speed bonus, but if you content has <, > or other xml character data
@@ -24,7 +24,7 @@ module Axlsx
24
24
  # Serialize the contenty type to xml
25
25
  def to_xml_string(node_name = '', str = '')
26
26
  str << "<#{node_name} "
27
- str << instance_values.map { |key, value| '' << Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
27
+ str << instance_values.map { |key, value| Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
28
28
  str << '/>'
29
29
  end
30
30
 
@@ -16,7 +16,7 @@ module Axlsx
16
16
  # @return [String]
17
17
  def to_xml_string(str = '')
18
18
  str << '<?xml version="1.0" encoding="UTF-8"?>'
19
- str << '<Types xmlns="' << XML_NS_T << '">'
19
+ str << ('<Types xmlns="' << XML_NS_T << '">')
20
20
  each { |type| type.to_xml_string(str) }
21
21
  str << '</Types>'
22
22
  end
@@ -222,7 +222,7 @@ module Axlsx
222
222
  # @return [String]
223
223
  def to_xml_string(str = '')
224
224
  str << '<?xml version="1.0" encoding="UTF-8"?>'
225
- str << '<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">'
225
+ str << ('<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">')
226
226
  instance_values.each do |key, value|
227
227
  node_name = Axlsx.camel(key)
228
228
  str << "<#{node_name}>#{value}</#{node_name}>"
@@ -25,11 +25,11 @@ module Axlsx
25
25
  # @return [String]
26
26
  def to_xml_string(str = '')
27
27
  str << '<?xml version="1.0" encoding="UTF-8"?>'
28
- str << '<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" '
29
- str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
30
- str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
31
- str << '<dc:creator>' << self.creator << '</dc:creator>'
32
- str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
28
+ str << ('<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" ')
29
+ str << ('xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" ')
30
+ str << ('xmlns:xsi="' << CORE_NS_XSI << '">')
31
+ str << ('<dc:creator>' << self.creator << '</dc:creator>')
32
+ str << ('<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>')
33
33
  str << '<cp:revision>0</cp:revision>'
34
34
  str << '</cp:coreProperties>'
35
35
  end
@@ -0,0 +1,99 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+
4
+ # The AreaChart is a two dimentional line chart (who would have guessed?) that you can add to your worksheet.
5
+ # @example Creating a chart
6
+ # # This example creates a line in a single sheet.
7
+ # require "rubygems" # if that is your preferred way to manage gems!
8
+ # require "axlsx"
9
+ #
10
+ # p = Axlsx::Package.new
11
+ # ws = p.workbook.add_worksheet
12
+ # ws.add_row ["This is a chart with no data in the sheet"]
13
+ #
14
+ # chart = ws.add_chart(Axlsx::AreaChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
15
+ # chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
16
+ #
17
+ # @see Worksheet#add_chart
18
+ # @see Worksheet#add_row
19
+ # @see Chart#add_series
20
+ # @see Series
21
+ # @see Package#serialize
22
+ class AreaChart < Chart
23
+
24
+ # the category axis
25
+ # @return [CatAxis]
26
+ def cat_axis
27
+ axes[:cat_axis]
28
+ end
29
+ alias :catAxis :cat_axis
30
+
31
+ # the category axis
32
+ # @return [ValAxis]
33
+ def val_axis
34
+ axes[:val_axis]
35
+ end
36
+ alias :valAxis :val_axis
37
+
38
+ # must be one of [:percentStacked, :clustered, :standard, :stacked]
39
+ # @return [Symbol]
40
+ attr_reader :grouping
41
+
42
+ # Creates a new line chart object
43
+ # @param [GraphicFrame] frame The workbook that owns this chart.
44
+ # @option options [Cell, String] title
45
+ # @option options [Boolean] show_legend
46
+ # @option options [Symbol] grouping
47
+ # @see Chart
48
+ def initialize(frame, options={})
49
+ @vary_colors = false
50
+ @grouping = :standard
51
+ super(frame, options)
52
+ @series_type = AreaSeries
53
+ @d_lbls = nil
54
+ end
55
+
56
+ # @see grouping
57
+ def grouping=(v)
58
+ RestrictionValidator.validate "AreaChart.grouping", [:percentStacked, :standard, :stacked], v
59
+ @grouping = v
60
+ end
61
+
62
+ # The node name to use in serialization. As AreaChart is used as the
63
+ # base class for Liine3DChart we need to be sure to serialize the
64
+ # chart based on the actual class type and not a fixed node name.
65
+ # @return [String]
66
+ def node_name
67
+ path = self.class.to_s
68
+ if i = path.rindex('::')
69
+ path = path[(i+2)..-1]
70
+ end
71
+ path[0] = path[0].chr.downcase
72
+ path
73
+ end
74
+
75
+ # Serializes the object
76
+ # @param [String] str
77
+ # @return [String]
78
+ def to_xml_string(str = '')
79
+ super(str) do
80
+ str << ("<c:" << node_name << ">")
81
+ str << ('<c:grouping val="' << grouping.to_s << '"/>')
82
+ str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
83
+ @series.each { |ser| ser.to_xml_string(str) }
84
+ @d_lbls.to_xml_string(str) if @d_lbls
85
+ yield if block_given?
86
+ axes.to_xml_string(str, :ids => true)
87
+ str << ("</c:" << node_name << ">")
88
+ axes.to_xml_string(str)
89
+ end
90
+ end
91
+
92
+ # The axes for this chart. AreaCharts have a category and value
93
+ # axis.
94
+ # @return [Axes]
95
+ def axes
96
+ @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,110 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+ # A AreaSeries defines the title, data and labels for line charts
4
+ # @note The recommended way to manage series is to use Chart#add_series
5
+ # @see Worksheet#add_chart
6
+ # @see Chart#add_series
7
+ class AreaSeries < Series
8
+
9
+ # The data for this series.
10
+ # @return [ValAxisData]
11
+ attr_reader :data
12
+
13
+ # The labels for this series.
14
+ # @return [CatAxisData]
15
+ attr_reader :labels
16
+
17
+ # The fill color for this series.
18
+ # Red, green, and blue is expressed as sequence of hex digits, RRGGBB. A perceptual gamma of 2.2 is used.
19
+ # @return [String]
20
+ attr_reader :color
21
+
22
+ # show markers on values
23
+ # @return [Boolean]
24
+ attr_reader :show_marker
25
+
26
+ # custom marker symbol
27
+ # @return [String]
28
+ attr_reader :marker_symbol
29
+
30
+ # line smoothing on values
31
+ # @return [Boolean]
32
+ attr_reader :smooth
33
+
34
+ # Creates a new series
35
+ # @option options [Array, SimpleTypedList] data
36
+ # @option options [Array, SimpleTypedList] labels
37
+ # @param [Chart] chart
38
+ def initialize(chart, options={})
39
+ @show_marker = false
40
+ @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default
41
+ @smooth = false
42
+ @labels, @data = nil, nil
43
+ super(chart, options)
44
+ @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
45
+ @data = NumDataSource.new(options) unless options[:data].nil?
46
+ end
47
+
48
+ # @see color
49
+ def color=(v)
50
+ @color = v
51
+ end
52
+
53
+ # @see show_marker
54
+ def show_marker=(v)
55
+ Axlsx::validate_boolean(v)
56
+ @show_marker = v
57
+ end
58
+
59
+ # @see marker_symbol
60
+ def marker_symbol=(v)
61
+ Axlsx::validate_marker_symbol(v)
62
+ @marker_symbol = v
63
+ end
64
+
65
+ # @see smooth
66
+ def smooth=(v)
67
+ Axlsx::validate_boolean(v)
68
+ @smooth = v
69
+ end
70
+
71
+ # Serializes the object
72
+ # @param [String] str
73
+ # @return [String]
74
+ def to_xml_string(str = '')
75
+ super(str) do
76
+ if color
77
+ str << '<c:spPr><a:solidFill>'
78
+ str << ('<a:srgbClr val="' << color << '"/>')
79
+ str << '</a:solidFill>'
80
+ str << '<a:ln w="28800">'
81
+ str << '<a:solidFill>'
82
+ str << ('<a:srgbClr val="' << color << '"/>')
83
+ str << '</a:solidFill>'
84
+ str << '</a:ln>'
85
+ str << '<a:round/>'
86
+ str << '</c:spPr>'
87
+ end
88
+
89
+ if !@show_marker
90
+ str << '<c:marker><c:symbol val="none"/></c:marker>'
91
+ elsif @marker_symbol != :default
92
+ str << '<c:marker><c:symbol val="' + @marker_symbol.to_s + '"/></c:marker>'
93
+ end
94
+
95
+ @labels.to_xml_string(str) unless @labels.nil?
96
+ @data.to_xml_string(str) unless @data.nil?
97
+ str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ # assigns the data for this series
104
+ def data=(v) DataTypeValidator.validate "Series.data", [NumDataSource], v; @data = v; end
105
+
106
+ # assigns the labels for this series
107
+ def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
108
+
109
+ end
110
+ end