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
@@ -0,0 +1,91 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'axlsx'
5
+
6
+ class Scraper
7
+
8
+ def initialize(url, selector)
9
+ @url = url
10
+ @selector = selector
11
+ end
12
+
13
+ def hooks
14
+ @hooks ||= {}
15
+ end
16
+
17
+ def add_hook(clue, p_roc)
18
+ hooks[clue] = p_roc
19
+ end
20
+
21
+ def export(file_name)
22
+ Scraper.clues.each do |clue|
23
+ if detail = parse_clue(clue)
24
+ output << [clue, detail.pop]
25
+ detail.each { |datum| output << ['', datum] }
26
+ end
27
+ end
28
+ serialize(file_name)
29
+ end
30
+
31
+ private
32
+
33
+ def self.clues
34
+ @clues ||= ['Operating system', 'Processors', 'Chipset', 'Memory type', 'Hard drive', 'Graphics',
35
+ 'Ports', 'Webcam', 'Pointing device', 'Keyboard', 'Network interface', 'Chipset', 'Wireless',
36
+ 'Power supply type', 'Energy efficiency', 'Weight', 'Minimum dimensions (W x D x H)',
37
+ 'Warranty', 'Software included', 'Product color']
38
+ end
39
+
40
+ def doc
41
+ @doc ||= begin
42
+ Nokogiri::HTML(open(@url))
43
+ rescue
44
+ raise ArgumentError, 'Invalid URL - Nothing to parse'
45
+ end
46
+ end
47
+
48
+ def output
49
+ @output ||= []
50
+ end
51
+
52
+ def selector_for_clue(clue)
53
+ @selector % clue
54
+ end
55
+
56
+ def parse_clue(clue)
57
+ if element = doc.at(selector_for_clue(clue))
58
+ call_hook(clue, element) || element.inner_html.split('<br>').each(&:strip)
59
+ end
60
+ end
61
+
62
+ def call_hook(clue, element)
63
+ if hooks[clue].is_a? Proc
64
+ value = hooks[clue].call(element)
65
+ value.is_a?(Array) ? value : [value]
66
+ end
67
+ end
68
+
69
+ def package
70
+ @package ||= Axlsx::Package.new
71
+ end
72
+
73
+ def serialize(file_name)
74
+ package.workbook.add_worksheet do |sheet|
75
+ output.each { |datum| sheet.add_row datum }
76
+ end
77
+ package.serialize(file_name)
78
+ end
79
+ end
80
+
81
+ scraper = Scraper.new("http://h10010.www1.hp.com/wwpc/ie/en/ho/WF06b/321957-321957-3329742-89318-89318-5186820-5231694.html?dnr=1", "//td[text()='%s']/following-sibling::td")
82
+
83
+ # define a custom action to take against any elements found.
84
+ os_parse = Proc.new do |element|
85
+ element.inner_html.split('<br>').each(&:strip!).each(&:upcase!)
86
+ end
87
+
88
+ scraper.add_hook('Operating system', os_parse)
89
+
90
+ scraper.export('foo.xlsx')
91
+
Binary file
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby -w -s
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ require 'axlsx'
5
+
6
+ p = Axlsx::Package.new
7
+ ws = p.workbook.add_worksheet :name => "Sheetview - Split"
8
+ ws.sheet_view do |vs|
9
+ vs.pane do |p|
10
+ p.active_pane = :top_right
11
+ p.state = :split
12
+ p.x_split = 11080
13
+ p.y_split = 5000
14
+ p.top_left_cell = 'C44'
15
+ end
16
+
17
+ vs.add_selection(:top_left, { :active_cell => 'A2', :sqref => 'A2' })
18
+ vs.add_selection(:top_right, { :active_cell => 'I10', :sqref => 'I10' })
19
+ vs.add_selection(:bottom_left, { :active_cell => 'E55', :sqref => 'E55' })
20
+ vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' })
21
+ end
22
+
23
+
24
+ ws = p.workbook.add_worksheet :name => "Sheetview - Frozen"
25
+ ws.sheet_view do |vs|
26
+ vs.pane do |p|
27
+ p.state = :frozen
28
+ p.x_split = 3
29
+ p.y_split = 4
30
+ end
31
+ end
32
+
33
+
34
+ p.serialize 'sheet_view.xlsx'
@@ -1,5 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  require 'axlsx/content_type/default.rb'
4
5
  require 'axlsx/content_type/override.rb'
5
6
 
@@ -21,4 +22,5 @@ module Axlsx
21
22
  end
22
23
 
23
24
  end
25
+
24
26
  end
@@ -1,8 +1,23 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  # An default content part. These parts are automatically created by for you based on the content of your package.
4
5
  class Default
5
6
 
7
+ #Creates a new Default object
8
+ # @option options [String] extension
9
+ # @option options [String] content_type
10
+ # @raise [ArgumentError] An argument error is raised if both extension and content_type are not specified.
11
+ def initialize(options={})
12
+ raise ArgumentError, INVALID_ARGUMENTS unless validate_options(options)
13
+ options.each do |name, value|
14
+ self.send("#{name}=", value) if self.respond_to? "#{name}="
15
+ end
16
+ end
17
+
18
+ # Error string for option validation
19
+ INVALID_ARGUMENTS = "extension and content_type are required"
20
+
6
21
  # The extension of the content type.
7
22
  # @return [String]
8
23
  attr_reader :extension
@@ -13,18 +28,6 @@ module Axlsx
13
28
  attr_reader :content_type
14
29
  alias :ContentType :content_type
15
30
 
16
- #Creates a new Default object
17
- # @option options [String] extension
18
- # @option options [String] content_type
19
- # @raise [ArgumentError] An argument error is raised if both extension and content_type are not specified.
20
- def initialize(options={})
21
- raise ArgumentError, "extension and content_type are required" unless (options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
22
- options.each do |o|
23
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
24
- end
25
- end
26
-
27
-
28
31
  # Sets the file extension for this content type.
29
32
  def extension=(v) Axlsx::validate_string v; @extension = v end
30
33
  alias :Extension= :extension=
@@ -43,5 +46,11 @@ module Axlsx
43
46
  str << '/>'
44
47
  end
45
48
 
49
+ private
50
+ def validate_options(options)
51
+ (options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
52
+ end
53
+
46
54
  end
55
+
47
56
  end
@@ -1,8 +1,23 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  # An override content part. These parts are automatically created by for you based on the content of your package.
4
5
  class Override
5
6
 
7
+ #Creates a new Override object
8
+ # @option options [String] PartName
9
+ # @option options [String] ContentType
10
+ # @raise [ArgumentError] An argument error is raised if both PartName and ContentType are not specified.
11
+ def initialize(options={})
12
+ raise ArgumentError, INVALID_ARGUMENTS unless validate_options(options)
13
+ options.each do |name, value|
14
+ self.send("#{name}=", value) if self.respond_to? "#{name}="
15
+ end
16
+ end
17
+
18
+ # Error message for invalid options
19
+ INVALID_ARGUMENTS = 'part_name and content_type are required'
20
+
6
21
  # The type of content.
7
22
  # @return [String]
8
23
  attr_reader :content_type
@@ -13,17 +28,6 @@ module Axlsx
13
28
  attr_reader :part_name
14
29
  alias :PartName :part_name
15
30
 
16
- #Creates a new Override object
17
- # @option options [String] PartName
18
- # @option options [String] ContentType
19
- # @raise [ArgumentError] An argument error is raised if both PartName and ContentType are not specified.
20
- def initialize(options={})
21
- raise ArgumentError, "PartName and ContentType are required" unless (options[:PartName] || options[:part_name]) && (options[:ContentType] || options[:content_type])
22
- options.each do |o|
23
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
24
- end
25
- end
26
-
27
31
  # The name and location of the part.
28
32
  def part_name=(v) Axlsx::validate_string v; @part_name = v end
29
33
  alias :PartName= :part_name=
@@ -42,5 +46,12 @@ module Axlsx
42
46
  str << '/>'
43
47
  end
44
48
 
49
+ private
50
+
51
+ def validate_options(options)
52
+ (options[:PartName] || options[:part_name]) && (options[:ContentType] || options[:content_type])
53
+ end
54
+
45
55
  end
56
+
46
57
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  # App represents the app.xml document. The attributes for this object are primarily managed by the application the end user uses to edit the document. None of the attributes are required to serialize a valid xlsx object.
4
5
  # @see shared-documentPropertiesExtended.xsd
5
6
  # @note Support is not implemented for the following complex types:
@@ -10,6 +11,35 @@ module Axlsx
10
11
  # DigSig (DigSigBlob)
11
12
  class App
12
13
 
14
+ # Creates an App object
15
+ # @option options [String] template
16
+ # @option options [String] manager
17
+ # @option options [Integer] pages
18
+ # @option options [Integer] words
19
+ # @option options [Integer] characters
20
+ # @option options [String] presentation_format
21
+ # @option options [Integer] lines
22
+ # @option options [Integer] paragraphs
23
+ # @option options [Integer] slides
24
+ # @option options [Integer] notes
25
+ # @option options [Integer] total_time
26
+ # @option options [Integer] hidden_slides
27
+ # @option options [Integer] m_m_clips
28
+ # @option options [Boolean] scale_crop
29
+ # @option options [Boolean] links_up_to_date
30
+ # @option options [Integer] characters_with_spaces
31
+ # @option options [Boolean] share_doc
32
+ # @option options [String] hyperlink_base
33
+ # @option options [String] hyperlinks_changed
34
+ # @option options [String] application
35
+ # @option options [String] app_version
36
+ # @option options [Integer] doc_security
37
+ def initialize(options={})
38
+ options.each do |name, value|
39
+ self.send("#{name}=", value) if self.respond_to? "#{name}="
40
+ end
41
+ end
42
+
13
43
  # @return [String] The name of the document template.
14
44
  attr_reader :template
15
45
  alias :Template :template
@@ -89,7 +119,7 @@ module Axlsx
89
119
  # @return [Boolean] Indicates that the hyper links in the document have been changed.
90
120
  attr_reader :hyperlinks_changed
91
121
  alias :HyperlinksChanged :hyperlinks_changed
92
-
122
+
93
123
  # @return [String] The name of the application
94
124
  attr_reader :application
95
125
  alias :Applicatoin :application
@@ -102,44 +132,17 @@ module Axlsx
102
132
  attr_reader :doc_security
103
133
  alias :DocSecurity :doc_security
104
134
 
105
- # Creates an App object
106
- # @option options [String] template
107
- # @option options [String] manager
108
- # @option options [Integer] pages
109
- # @option options [Integer] words
110
- # @option options [Integer] characters
111
- # @option options [String] presentation_format
112
- # @option options [Integer] lines
113
- # @option options [Integer] paragraphs
114
- # @option options [Integer] slides
115
- # @option options [Integer] notes
116
- # @option options [Integer] total_time
117
- # @option options [Integer] hidden_slides
118
- # @option options [Integer] m_m_clips
119
- # @option options [Boolean] scale_crop
120
- # @option options [Boolean] links_up_to_date
121
- # @option options [Integer] characters_with_spaces
122
- # @option options [Boolean] share_doc
123
- # @option options [String] hyperlink_base
124
- # @option options [String] hyperlinks_changed
125
- # @option options [String] application
126
- # @option options [String] app_version
127
- # @option options [Integer] doc_security
128
- def initialize(options={})
129
- options.each do |o|
130
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
131
- end
132
- end
133
-
134
135
  # Sets the template property of your app.xml file
135
136
  def template=(v) Axlsx::validate_string v; @template = v; end
137
+ alias :Template :template
136
138
 
137
139
  # Sets the manager property of your app.xml file
138
140
  def manager=(v) Axlsx::validate_string v; @manager = v; end
141
+ alias :Manager :manager
139
142
 
140
143
  # Sets the company property of your app.xml file
141
144
  def company=(v) Axlsx::validate_string v; @company = v; end
142
-
145
+ alias :Company :company
143
146
  # Sets the pages property of your app.xml file
144
147
  def pages=(v) Axlsx::validate_int v; @pages = v; end
145
148
 
@@ -214,7 +217,7 @@ module Axlsx
214
217
  # Sets the doc_security property of your app.xml file
215
218
  def doc_security=(v) Axlsx::validate_int v; @doc_security = v; end
216
219
  alias :DocSecurity= :doc_security=
217
-
220
+
218
221
  # Serialize the app.xml document
219
222
  # @return [String]
220
223
  def to_xml_string(str = '')
@@ -225,4 +228,5 @@ module Axlsx
225
228
  end
226
229
 
227
230
  end
231
+
228
232
  end
@@ -1,19 +1,21 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  # The core object for the package.
4
5
  # @note Packages manage their own core object.
5
6
  # @see Package#core
6
7
  class Core
7
- # The author of the document. By default this is 'axlsx'
8
- # @return [String]
9
- attr_accessor :creator
10
-
8
+
11
9
  # Creates a new Core object.
12
10
  # @option options [String] creator
13
11
  def initialize(options={})
14
12
  @creator = options[:creator] || 'axlsx'
15
13
  end
16
14
 
15
+ # The author of the document. By default this is 'axlsx'
16
+ # @return [String]
17
+ attr_accessor :creator
18
+
17
19
  # serializes the core.xml document
18
20
  # @return [String]
19
21
  def to_xml_string(str = '')
@@ -22,9 +24,11 @@ module Axlsx
22
24
  str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
23
25
  str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
24
26
  str << '<dc:creator>' << self.creator << '</dc:creator>'
25
- str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << '</dcterms:created>'
27
+ str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
26
28
  str << '<cp:revision>0</cp:revision>'
27
29
  str << '</cp:coreProperties>'
28
30
  end
31
+
29
32
  end
33
+
30
34
  end
@@ -1,14 +1,9 @@
1
1
  module Axlsx
2
+
2
3
  # An axis data source that can contain referenced or literal strings or numbers
3
4
  # @note only string data types are supported - mainly because we have not implemented a chart type that requires a numerical axis value
4
5
  class AxDataSource < NumDataSource
5
6
 
6
- # allowed element tag names
7
- # @return [Array]
8
- def self.allowed_tag_names
9
- [:xVal, :cat]
10
- end
11
-
12
7
  # creates a new NumDataSource object
13
8
  # @option options [Array] data An array of Cells or Numeric objects
14
9
  # @option options [Symbol] tag_name see tag_name
@@ -19,6 +14,12 @@ module Axlsx
19
14
  super(options)
20
15
  end
21
16
 
17
+ # allowed element tag names for serialization
18
+ # @return [Array]
19
+ def self.allowed_tag_names
20
+ [:xVal, :cat]
21
+ end
22
+
22
23
  end
23
24
 
24
25
  end
@@ -1,8 +1,40 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
- # the access class defines common properties and values for a chart axis.
3
+
4
+ # the access class defines common properties and values for a chart axis.
4
5
  class Axis
5
6
 
7
+ # Creates an Axis object
8
+ # @param [Integer] ax_id the id of this axis
9
+ # @param [Integer] cross_ax the id of the perpendicular axis
10
+ # @option options [Symbol] ax_pos
11
+ # @option options [Symbol] crosses
12
+ # @option options [Symbol] tick_lbl_pos
13
+ # @raise [ArgumentError] If axi_id or cross_ax are not unsigned integers
14
+ def initialize(ax_id, cross_ax, options={})
15
+ Axlsx::validate_unsigned_int(ax_id)
16
+ Axlsx::validate_unsigned_int(cross_ax)
17
+ @ax_id = ax_id
18
+ @cross_ax = cross_ax
19
+ @format_code = "General"
20
+ @delete = @label_rotation = 0
21
+ @scaling = Scaling.new(:orientation=>:minMax)
22
+ @title = @color = nil
23
+ self.ax_pos = :b
24
+ self.tick_lbl_pos = :nextTo
25
+ self.format_code = "General"
26
+ self.crosses = :autoZero
27
+ self.gridlines = true
28
+ options.each do |name, value|
29
+ self.send("#{name}=", value) if self.respond_to? "#{name}="
30
+ end
31
+ end
32
+
33
+ # the fill color to use in the axis shape properties. This should be a 6 character long hex string
34
+ # e.g. FF0000 for red
35
+ # @return [String]
36
+ attr_reader :color
37
+
6
38
  # the id of the axis.
7
39
  # @return [Integer]
8
40
  attr_reader :ax_id
@@ -52,29 +84,15 @@ module Axlsx
52
84
  # @return [Boolean]
53
85
  attr_reader :delete
54
86
 
55
- # Creates an Axis object
56
- # @param [Integer] ax_id the id of this axis
57
- # @param [Integer] cross_ax the id of the perpendicular axis
58
- # @option options [Symbol] ax_pos
59
- # @option options [Symbol] crosses
60
- # @option options [Symbol] tick_lbl_pos
61
- # @raise [ArgumentError] If axi_id or cross_ax are not unsigned integers
62
- def initialize(ax_id, cross_ax, options={})
63
- Axlsx::validate_unsigned_int(ax_id)
64
- Axlsx::validate_unsigned_int(cross_ax)
65
- @ax_id = ax_id
66
- @cross_ax = cross_ax
67
- @format_code = "General"
68
- @delete = @label_rotation = 0
69
- @scaling = Scaling.new(:orientation=>:minMax)
70
- self.ax_pos = :b
71
- self.tick_lbl_pos = :nextTo
72
- self.format_code = "General"
73
- self.crosses = :autoZero
74
- self.gridlines = true
75
- options.each do |o|
76
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
77
- end
87
+ # the title for the axis. This can be a cell or a fixed string.
88
+ attr_reader :title
89
+
90
+ # The color for this axis. This value is used when rendering the axis line in the chart.
91
+ # colors should be in 6 character rbg format
92
+ # @return [String] the rbg color assinged.
93
+ # @see color
94
+ def color=(color_rgb)
95
+ @color = color_rgb
78
96
  end
79
97
 
80
98
  # The position of the axis
@@ -95,7 +113,6 @@ module Axlsx
95
113
  # default true
96
114
  def gridlines=(v) Axlsx::validate_boolean(v); @gridlines = v; end
97
115
 
98
-
99
116
  # Specify if axis should be removed from the chart
100
117
  # default false
101
118
  def delete=(v) Axlsx::validate_boolean(v); @delete = v; end
@@ -113,6 +130,18 @@ module Axlsx
113
130
  @label_rotation = adjusted
114
131
  end
115
132
 
133
+ # The title object for the chart.
134
+ # @param [String, Cell] v
135
+ # @return [Title]
136
+ def title=(v)
137
+ DataTypeValidator.validate "#{self.class}.title", [String, Cell], v
138
+ @title ||= Title.new
139
+ if v.is_a?(String)
140
+ @title.text = v
141
+ elsif v.is_a?(Cell)
142
+ @title.cell = v
143
+ end
144
+ end
116
145
 
117
146
  # Serializes the object
118
147
  # @param [String] str
@@ -123,6 +152,7 @@ module Axlsx
123
152
  str << '<c:delete val="'<< @delete.to_s << '"/>'
124
153
  str << '<c:axPos val="' << @ax_pos.to_s << '"/>'
125
154
  str << '<c:majorGridlines>'
155
+ # TODO shape properties need to be extracted into a class
126
156
  if gridlines == false
127
157
  str << '<c:spPr>'
128
158
  str << '<a:ln>'
@@ -131,10 +161,18 @@ module Axlsx
131
161
  str << '</c:spPr>'
132
162
  end
133
163
  str << '</c:majorGridlines>'
164
+ @title.to_xml_string(str) unless @title == nil
134
165
  str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="1"/>'
135
166
  str << '<c:majorTickMark val="none"/>'
136
167
  str << '<c:minorTickMark val="none"/>'
137
168
  str << '<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>'
169
+ # TODO - this is also being used for series colors
170
+ # time to extract this into a class spPr - Shape Properties
171
+ if @color
172
+ str << '<c:spPr><a:ln><a:solidFill>'
173
+ str << '<a:srgbClr val="' << @color << '"/>'
174
+ str << '</a:solidFill></a:ln></c:spPr>'
175
+ end
138
176
  # some potential value in implementing this in full. Very detailed!
139
177
  str << '<c:txPr><a:bodyPr rot="' << @label_rotation.to_s << '"/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>'
140
178
  str << '<c:crossAx val="' << @cross_ax.to_s << '"/>'
@@ -142,4 +180,5 @@ module Axlsx
142
180
  end
143
181
 
144
182
  end
183
+
145
184
  end