axlsx 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/README.md +7 -3
  2. data/lib/axlsx.rb +57 -0
  3. data/lib/axlsx/content_type/content_type.rb +23 -0
  4. data/lib/axlsx/content_type/default.rb +37 -0
  5. data/lib/axlsx/content_type/override.rb +37 -0
  6. data/lib/axlsx/doc_props/app.rb +178 -0
  7. data/lib/axlsx/doc_props/core.rb +34 -0
  8. data/lib/axlsx/drawing/axis.rb +90 -0
  9. data/lib/axlsx/drawing/bar_3D_chart.rb +128 -0
  10. data/lib/axlsx/drawing/bar_series.rb +64 -0
  11. data/lib/axlsx/drawing/cat_axis.rb +63 -0
  12. data/lib/axlsx/drawing/cat_axis_data.rb +35 -0
  13. data/lib/axlsx/drawing/chart.rb +179 -0
  14. data/lib/axlsx/drawing/drawing.rb +137 -0
  15. data/lib/axlsx/drawing/graphic_frame.rb +52 -0
  16. data/lib/axlsx/drawing/line_3D_chart.rb +106 -0
  17. data/lib/axlsx/drawing/line_series.rb +46 -0
  18. data/lib/axlsx/drawing/marker.rb +61 -0
  19. data/lib/axlsx/drawing/one_cell_anchor.rb +89 -0
  20. data/lib/axlsx/drawing/pic.rb +153 -0
  21. data/lib/axlsx/drawing/picture_locking.rb +72 -0
  22. data/lib/axlsx/drawing/picture_locking.rb~ +36 -0
  23. data/lib/axlsx/drawing/pie_3D_chart.rb +41 -0
  24. data/lib/axlsx/drawing/pie_series.rb +56 -0
  25. data/lib/axlsx/drawing/scaling.rb +59 -0
  26. data/lib/axlsx/drawing/ser_axis.rb +45 -0
  27. data/lib/axlsx/drawing/series.rb +71 -0
  28. data/lib/axlsx/drawing/series_title.rb +22 -0
  29. data/lib/axlsx/drawing/title.rb +61 -0
  30. data/lib/axlsx/drawing/two_cell_anchor.rb +76 -0
  31. data/lib/axlsx/drawing/val_axis.rb +34 -0
  32. data/lib/axlsx/drawing/val_axis_data.rb +28 -0
  33. data/lib/axlsx/drawing/view_3D.rb +85 -0
  34. data/lib/axlsx/package.rb +215 -0
  35. data/lib/axlsx/rels/relationship.rb +44 -0
  36. data/lib/axlsx/rels/relationships.rb +25 -0
  37. data/lib/axlsx/stylesheet/border.rb +57 -0
  38. data/lib/axlsx/stylesheet/border_pr.rb +68 -0
  39. data/lib/axlsx/stylesheet/cell_alignment.rb +105 -0
  40. data/lib/axlsx/stylesheet/cell_protection.rb +36 -0
  41. data/lib/axlsx/stylesheet/cell_style.rb +65 -0
  42. data/lib/axlsx/stylesheet/color.rb +69 -0
  43. data/lib/axlsx/stylesheet/fill.rb +32 -0
  44. data/lib/axlsx/stylesheet/font.rb +139 -0
  45. data/lib/axlsx/stylesheet/gradient_fill.rb +76 -0
  46. data/lib/axlsx/stylesheet/gradient_stop.rb +33 -0
  47. data/lib/axlsx/stylesheet/num_fmt.rb +63 -0
  48. data/lib/axlsx/stylesheet/pattern_fill.rb +66 -0
  49. data/lib/axlsx/stylesheet/styles.rb +298 -0
  50. data/lib/axlsx/stylesheet/table_style.rb +47 -0
  51. data/lib/axlsx/stylesheet/table_style_element.rb +71 -0
  52. data/lib/axlsx/stylesheet/table_styles.rb +39 -0
  53. data/lib/axlsx/stylesheet/xf.rb +138 -0
  54. data/lib/axlsx/util/constants.rb +220 -0
  55. data/lib/axlsx/util/parser.rb +43 -0
  56. data/lib/axlsx/util/parser.rb~ +6 -0
  57. data/lib/axlsx/util/simple_typed_list.rb +160 -0
  58. data/lib/axlsx/util/validators.rb +132 -0
  59. data/lib/axlsx/version.rb +4 -0
  60. data/lib/axlsx/workbook/#workbook.rb# +165 -0
  61. data/lib/axlsx/workbook/workbook.rb +160 -0
  62. data/lib/axlsx/workbook/worksheet/cell.rb +337 -0
  63. data/lib/axlsx/workbook/worksheet/row.rb +107 -0
  64. data/lib/axlsx/workbook/worksheet/worksheet.rb +279 -0
  65. metadata +93 -141
  66. data/examples/follow_20111202.xlsx +0 -0
  67. data/test/content_type/tc_content_type.rb +0 -81
  68. data/test/content_type/tc_default.rb +0 -40
  69. data/test/content_type/tc_override.rb +0 -40
  70. data/test/doc_props/tc_app.rb +0 -19
  71. data/test/doc_props/tc_core.rb +0 -34
  72. data/test/drawing/tc_axis.rb +0 -40
  73. data/test/drawing/tc_bar_3D_chart.rb +0 -66
  74. data/test/drawing/tc_bar_series.rb +0 -34
  75. data/test/drawing/tc_cat_axis.rb +0 -32
  76. data/test/drawing/tc_cat_axis_data.rb +0 -18
  77. data/test/drawing/tc_chart.rb +0 -73
  78. data/test/drawing/tc_drawing.rb +0 -80
  79. data/test/drawing/tc_graphic_frame.rb +0 -26
  80. data/test/drawing/tc_line_3d_chart.rb +0 -48
  81. data/test/drawing/tc_line_series.rb +0 -27
  82. data/test/drawing/tc_marker.rb +0 -45
  83. data/test/drawing/tc_one_cell_anchor.rb +0 -67
  84. data/test/drawing/tc_pic.rb +0 -71
  85. data/test/drawing/tc_picture_locking.rb +0 -73
  86. data/test/drawing/tc_pie_3D_chart.rb +0 -33
  87. data/test/drawing/tc_pie_series.rb +0 -35
  88. data/test/drawing/tc_scaling.rb +0 -37
  89. data/test/drawing/tc_ser_axis.rb +0 -31
  90. data/test/drawing/tc_series.rb +0 -24
  91. data/test/drawing/tc_series_title.rb +0 -34
  92. data/test/drawing/tc_title.rb +0 -34
  93. data/test/drawing/tc_two_cell_anchor.rb +0 -38
  94. data/test/drawing/tc_val_axis.rb +0 -25
  95. data/test/drawing/tc_val_axis_data.rb +0 -18
  96. data/test/drawing/tc_view_3D.rb +0 -55
  97. data/test/rels/tc_relationship.rb +0 -16
  98. data/test/rels/tc_relationships.rb +0 -27
  99. data/test/stylesheet/tc_border.rb +0 -38
  100. data/test/stylesheet/tc_border_pr.rb +0 -33
  101. data/test/stylesheet/tc_cell_alignment.rb +0 -77
  102. data/test/stylesheet/tc_cell_protection.rb +0 -30
  103. data/test/stylesheet/tc_cell_style.rb +0 -58
  104. data/test/stylesheet/tc_color.rb +0 -38
  105. data/test/stylesheet/tc_fill.rb +0 -19
  106. data/test/stylesheet/tc_font.rb +0 -114
  107. data/test/stylesheet/tc_gradient_fill.rb +0 -65
  108. data/test/stylesheet/tc_gradient_stop.rb +0 -32
  109. data/test/stylesheet/tc_num_fmt.rb +0 -31
  110. data/test/stylesheet/tc_pattern_fill.rb +0 -38
  111. data/test/stylesheet/tc_styles.rb +0 -52
  112. data/test/stylesheet/tc_table_style.rb +0 -37
  113. data/test/stylesheet/tc_table_style_element.rb +0 -37
  114. data/test/stylesheet/tc_table_styles.rb +0 -30
  115. data/test/stylesheet/tc_xf.rb +0 -121
  116. data/test/tc_package.rb +0 -68
  117. data/test/util/tc_simple_typed_list.rb +0 -66
  118. data/test/util/tc_validators.rb +0 -76
  119. data/test/workbook/tc_workbook.rb +0 -60
  120. data/test/workbook/worksheet/tc_cell.rb +0 -179
  121. data/test/workbook/worksheet/tc_row.rb +0 -36
  122. data/test/workbook/worksheet/tc_worksheet.rb +0 -138
data/README.md CHANGED
@@ -7,10 +7,10 @@ Axlsx: Office Open XML Spreadsheet Generation
7
7
  **Author**: Randy Morgan
8
8
  **Copyright**: 2011
9
9
  **License**: MIT License
10
- **Latest Version**: 1.0.12
10
+ **Latest Version**: 1.0.13
11
11
  **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
12
12
 
13
- **Release Date**: December 7th 2011
13
+ **Release Date**: December 8th 2011
14
14
 
15
15
  Synopsis
16
16
  --------
@@ -244,8 +244,12 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
244
244
 
245
245
  Changelog
246
246
  ---------
247
+ - **December.8.11**: 1.0.13 release
248
+ Fixing .gemspec errors that caused gem to miss the lib directory. Sorry about that.
249
+
247
250
  - **December.7.11**: 1.0.12 release
248
- - changed dependency from 'zip' jem to 'rubyzip' and added conditional code to force binary encoding to resolve issue with excel 2011
251
+ DO NOT USE THIS VERSION = THE GEM IS BROKEN
252
+ - changed dependency from 'zip' gem to 'rubyzip' and added conditional code to force binary encoding to resolve issue with excel 2011
249
253
  - Patched bug in app.xml that would ignore user specified properties.
250
254
  - **December.5.11**: 1.0.11 release
251
255
  - Added [] methods to worksheet and workbook to provide name based access to cells.
@@ -0,0 +1,57 @@
1
+ Encoding::default_internal = 'UTF-8' unless RUBY_VERSION < '1.9'
2
+ Encoding::default_external = 'UTF-8' unless RUBY_VERSION < '1.9'
3
+
4
+ require 'axlsx/version.rb'
5
+
6
+ require 'axlsx/util/simple_typed_list.rb'
7
+ require 'axlsx/util/constants.rb'
8
+ require 'axlsx/util/validators.rb'
9
+
10
+
11
+ # to be included with parsable intitites.
12
+ #require 'axlsx/util/parser.rb'
13
+
14
+ require 'axlsx/stylesheet/styles.rb'
15
+
16
+ require 'axlsx/doc_props/app.rb'
17
+ require 'axlsx/doc_props/core.rb'
18
+ require 'axlsx/content_type/content_type.rb'
19
+ require 'axlsx/rels/relationships.rb'
20
+
21
+ require 'axlsx/drawing/drawing.rb'
22
+ require 'axlsx/workbook/workbook.rb'
23
+ require 'axlsx/package.rb'
24
+
25
+ #required gems
26
+ require 'nokogiri'
27
+ require 'active_support/core_ext/object/instance_variables'
28
+ require 'active_support/inflector'
29
+ require 'RMagick'
30
+ require 'zip/zip'
31
+
32
+ #core dependencies
33
+ require 'bigdecimal'
34
+ require 'time'
35
+
36
+
37
+ # xlsx generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
38
+ module Axlsx
39
+ # determines the cell range for the items provided
40
+ def self.cell_range(items)
41
+ return "" unless items.first.is_a? Cell
42
+ ref = "#{items.first.row.worksheet.name}!" +
43
+ "#{items.first.r_abs}"
44
+ ref += ":#{items.last.r_abs}" if items.size > 1
45
+ ref
46
+ end
47
+
48
+ def self.name_to_indices(name)
49
+ raise ArgumentError, 'invalid cell name' unless name.size > 1
50
+ v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |v, c|
51
+ v[:i] += ((c.bytes.first - 65) + v[:base]); v[:base] *= 26; v
52
+ end
53
+
54
+ [v[:i]-1, ((name[/[1-9]+/]).to_i)-1]
55
+
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ module Axlsx
2
+ require 'axlsx/content_type/default.rb'
3
+ require 'axlsx/content_type/override.rb'
4
+
5
+ # ContentTypes used in the package. This is automatcially managed by the package package.
6
+ class ContentType < SimpleTypedList
7
+
8
+ def initialize
9
+ super [Override, Default]
10
+ end
11
+
12
+ # Generates the xml document for [Content_Types].xml
13
+ # @return [String] The document as a string.
14
+ def to_xml()
15
+ builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
16
+ xml.Types(:xmlns => Axlsx::XML_NS_T) {
17
+ each { |type| type.to_xml(xml) }
18
+ }
19
+ end
20
+ builder.to_xml
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ module Axlsx
2
+ # An default content part. These parts are automatically created by for you based on the content of your package.
3
+ class Default
4
+
5
+ # The extension of the content type.
6
+ # @return [String]
7
+ attr_reader :Extension
8
+
9
+ # The type of content.
10
+ # @return [String]
11
+ attr_reader :ContentType
12
+
13
+ #Creates a new Default object
14
+ # @option options [String] Extension
15
+ # @option options [String] ContentType
16
+ # @raise [ArgumentError] An argument error is raised if both Extension and ContentType are not specified.
17
+ def initialize(options={})
18
+ raise ArgumentError, "Extension and ContentType are required" unless options[:Extension] && options[:ContentType]
19
+ options.each do |o|
20
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
21
+ end
22
+ end
23
+ # Sets the file extension for this content type.
24
+ def Extension=(v) Axlsx::validate_string v; @Extension = v end
25
+
26
+ # Sets the content type
27
+ # @see Axlsx#validate_content_type
28
+ def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end
29
+
30
+ # Serializes the object to xml
31
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
32
+ # @return [String]
33
+ def to_xml(xml)
34
+ xml.Default(self.instance_values)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ module Axlsx
2
+ # An override content part. These parts are automatically created by for you based on the content of your package.
3
+ class Override
4
+
5
+ # The type of content.
6
+ # @return [String]
7
+ attr_reader :ContentType
8
+
9
+ # The name and location of the part.
10
+ # @return [String]
11
+ attr_reader :PartName
12
+
13
+ #Creates a new Override object
14
+ # @option options [String] PartName
15
+ # @option options [String] ContentType
16
+ # @raise [ArgumentError] An argument error is raised if both PartName and ContentType are not specified.
17
+ def initialize(options={})
18
+ raise ArgumentError, "PartName and ContentType are required" unless options[:PartName] && options[:ContentType]
19
+ options.each do |o|
20
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
21
+ end
22
+ end
23
+
24
+ # The name and location of the part.
25
+ def PartName=(v) Axlsx::validate_string v; @PartName = v end
26
+
27
+ # The content type.
28
+ # @see Axlsx#validate_content_type
29
+ def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end
30
+
31
+ # Serializes the Override object to xml
32
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
33
+ def to_xml(xml)
34
+ xml.Override(self.instance_values)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,178 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Axlsx
3
+ # 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
+ # @see shared-documentPropertiesExtended.xsd
5
+ # @note Support is not implemented for the following complex types:
6
+ #
7
+ # HeadingPairs (VectorVariant),
8
+ # TitlesOfParts (VectorLpstr),
9
+ # HLinks (VectorVariant),
10
+ # DigSig (DigSigBlob)
11
+ class App
12
+
13
+ # @return [String] The name of the document template.
14
+ attr_reader :Template
15
+
16
+ # @return [String] The name of the manager for the document.
17
+ attr_reader :Manager
18
+
19
+ # @return [String] The name of the company generating the document.
20
+ attr_reader :Company
21
+
22
+ # @return [Integer] The number of pages in the document.
23
+ attr_reader :Pages
24
+
25
+ # @return [Integer] The number of words in the document.
26
+ attr_reader :Words
27
+
28
+ # @return [Integer] The number of characters in the document.
29
+ attr_reader :Characters
30
+
31
+ # @return [String] The intended format of the presentation.
32
+ attr_reader :PresentationFormat
33
+
34
+ # @return [Integer] The number of lines in the document.
35
+ attr_reader :Lines
36
+
37
+ # @return [Integer] The number of paragraphs in the document
38
+ attr_reader :Paragraphs
39
+
40
+ # @return [Intger] The number of slides in the document.
41
+ attr_reader :Slides
42
+
43
+ # @return [Integer] The number of slides that have notes.
44
+ attr_reader :Notes
45
+
46
+ # @return [Integer] The total amount of time spent editing.
47
+ attr_reader :TotalTime
48
+
49
+ # @return [Integer] The number of hidden slides.
50
+ attr_reader :HiddenSlides
51
+
52
+ # @return [Integer] The total number multimedia clips
53
+ attr_reader :MMClips
54
+
55
+ # @return [Boolean] The display mode for the document thumbnail.
56
+ attr_reader :ScaleCrop
57
+
58
+ # @return [Boolean] The links in the document are up to date.
59
+ attr_reader :LinksUpToDate
60
+
61
+ # @return [Integer] The number of characters in the document including spaces.
62
+ attr_reader :CharactersWithSpaces
63
+
64
+ # @return [Boolean] Indicates if the document is shared.
65
+ attr_reader :ShareDoc
66
+
67
+ # @return [String] The base for hyper links in the document.
68
+ attr_reader :HyperLinkBase
69
+
70
+ # @return [Boolean] Indicates that the hyper links in the document have been changed.
71
+ attr_reader :HyperlinksChanged
72
+
73
+ # @return [String] The name of the application
74
+ attr_reader :Application
75
+
76
+ # @return [String] The version of the application.
77
+ attr_reader :AppVersion
78
+
79
+ # @return [Integer] Document security
80
+ attr_reader :DocSecurity
81
+
82
+ # Creates an App object
83
+ # @option options [String] Template
84
+ # @option options [String] Manager
85
+ # @option options [Integer] Pages
86
+ # @option options [Integer] Words
87
+ # @option options [Integer] Characters
88
+ # @option options [String] PresentationFormat
89
+ # @option options [Integer] Lines
90
+ # @option options [Integer] Paragraphs
91
+ # @option options [Integer] Slides
92
+ # @option options [Integer] Notes
93
+ # @option options [Integer] TotalTime
94
+ # @option options [Integer] HiddenSlides
95
+ # @option options [Integer] MMClips
96
+ # @option options [Boolean] ScaleCrop
97
+ # @option options [Boolean] LinksUpToDate
98
+ # @option options [Integer] CharactersWithSpaces
99
+ # @option options [Boolean] ShareDoc
100
+ # @option options [String] HyperLinkBase
101
+ # @option options [String] HyperlinksChanged
102
+ # @option options [String] Application
103
+ # @option options [String] AppVersion
104
+ # @option options [Integer] DocSecurity
105
+ def initialize(options={})
106
+ options.each do |o|
107
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
108
+ end
109
+ end
110
+
111
+ # Sets the Template property of your app.xml file
112
+ def Template=(v) Axlsx::validate_string v; @Template = v; end
113
+
114
+ # Sets the Manager property of your app.xml file
115
+ def Manager=(v) Axlsx::validate_string v; @Manager = v; end
116
+
117
+ # Sets the Company property of your app.xml file
118
+ def Company=(v) Axlsx::validate_string v; @Company = v; end
119
+
120
+ # Sets the Pages property of your app.xml file
121
+ def Pages=(v) Axlsx::validate_int v; @Pages = v; end
122
+
123
+ # Sets the Words property of your app.xml file
124
+ def Words=(v) Axlsx::validate_int v; @Words = v; end
125
+
126
+ # Sets the Characters property of your app.xml file
127
+ def Characters=(v) Axlsx::validate_int v; @Characters = v; end
128
+
129
+
130
+ # Sets the PresentationFormat property of your app.xml file
131
+ def PresentationFormat=(v) Axlsx::validate_string v; @PresentationFormat = v; end
132
+ # Sets the Lines property of your app.xml file
133
+ def Lines=(v) Axlsx::validate_int v; @Lines = v; end
134
+ # Sets the Paragraphs property of your app.xml file
135
+ def Paragraphs=(v) Axlsx::validate_int v; @Paragraphs = v; end
136
+ # Sets the Slides property of your app.xml file
137
+ def Slides=(v) Axlsx::validate_int v; @Slides = v; end
138
+ # Sets the Notes property of your app.xml file
139
+ def Notes=(v) Axlsx::validate_int v; @Notes = v; end
140
+ # Sets the TotalTime property of your app.xml file
141
+ def TotalTime=(v) Axlsx::validate_int v; @TotalTime = v; end
142
+ # Sets the HiddenSlides property of your app.xml file
143
+ def HiddenSlides=(v) Axlsx::validate_int v; @HiddenSlides = v; end
144
+ # Sets the MMClips property of your app.xml file
145
+ def MMClips=(v) Axlsx::validate_int v; @MMClips = v; end
146
+ # Sets the ScaleCrop property of your app.xml file
147
+ def ScaleCrop=(v) Axlsx::validate_boolean v; @ScaleCrop = v; end
148
+ # Sets the LinksUpToDate property of your app.xml file
149
+ def LinksUpToDate=(v) Axlsx::validate_boolean v; @LinksUpToDate = v; end
150
+ # Sets the CharactersWithSpaces property of your app.xml file
151
+ def CharactersWithSpaces=(v) Axlsx::validate_int v; @CharactersWithSpaces = v; end
152
+ # Sets the ShareDoc property of your app.xml file
153
+ def ShareDoc=(v) Axlsx::validate_boolean v; @ShareDoc = v; end
154
+ # Sets the HyperLinkBase property of your app.xml file
155
+ def HyperLinkBase=(v) Axlsx::validate_string v; @HyperLinkBase = v; end
156
+ # Sets the HyperLinksChanged property of your app.xml file
157
+ def HyperlinksChanged=(v) Axlsx::validate_boolean v; @HyperlinksChanged = v; end
158
+ # Sets the Application property of your app.xml file
159
+ def Application=(v) Axlsx::validate_string v; @Application = v; end
160
+ # Sets the AppVersion property of your app.xml file
161
+ def AppVersion=(v) Axlsx::validate_string v; @AppVersion = v; end
162
+ # Sets the DocSecurity property of your app.xml file
163
+ def DocSecurity=(v) Axlsx::validate_int v; @DocSecurity = v; end
164
+
165
+ # Generate an app.xml document
166
+ # @return [String] The document as a string
167
+ def to_xml()
168
+ builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
169
+ xml.send(:Properties, :xmlns => APP_NS, :'xmlns:vt' => APP_NS_VT) {
170
+ self.instance_values.each do |name, value|
171
+ xml.send(name, value)
172
+ end
173
+ }
174
+ end
175
+ builder.to_xml
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,34 @@
1
+ module Axlsx
2
+ # The core object for the package.
3
+ # @note Packages manage their own core object.
4
+ # @see Package#core
5
+ class Core
6
+ # The author of the document. By default this is 'axlsx'
7
+ # @return [String]
8
+ attr_accessor :creator
9
+
10
+ # Creates a new Core object.
11
+ # @option options [String] creator
12
+ def initialize(options={})
13
+ @creator = options[:creator] || 'axlsx'
14
+ end
15
+
16
+ # Serializes the core object. The created dcterms item is set to the current time when this method is called.
17
+ # @return [String]
18
+ def to_xml()
19
+ builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
20
+ xml.send('cp:coreProperties',
21
+ :"xmlns:cp" => CORE_NS,
22
+ :'xmlns:dc' => CORE_NS_DC,
23
+ :'xmlns:dcmitype'=>CORE_NS_DCMIT,
24
+ :'xmlns:dcterms'=>CORE_NS_DCT,
25
+ :'xmlns:xsi'=>CORE_NS_XSI) {
26
+ xml['dc'].creator self.creator
27
+ xml['dcterms'].created Time.now.strftime('%Y-%m-%dT%H:%M:%S'), :'xsi:type'=>"dcterms:W3CDTF"
28
+ xml['cp'].revision 0
29
+ }
30
+ end
31
+ builder.to_xml
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,90 @@
1
+ module Axlsx
2
+ # the access class defines common properties and values for a chart axis.
3
+ class Axis
4
+
5
+ # the id of the axis.
6
+ # @return [Integer]
7
+ attr_reader :axId
8
+
9
+ # The perpendicular axis
10
+ # @return [Integer]
11
+ attr_reader :crossAx
12
+
13
+ # The scaling of the axis
14
+ # @see Scaling
15
+ # @return [Scaling]
16
+ attr_reader :scaling
17
+
18
+ # The position of the axis
19
+ # must be one of [:l, :r, :t, :b]
20
+ # @return [Symbol]
21
+ attr_reader :axPos
22
+
23
+ # the position of the tick labels
24
+ # must be one of [:nextTo, :high, :low]
25
+ # @return [Symbol]
26
+ attr_reader :tickLblPos
27
+
28
+ # The number format format code for this axis
29
+ # default :General
30
+ # @return [String]
31
+ attr_reader :format_code
32
+
33
+ # specifies how the perpendicular axis is crossed
34
+ # must be one of [:autoZero, :min, :max]
35
+ # @return [Symbol]
36
+ attr_reader :crosses
37
+
38
+ # Creates an Axis object
39
+ # @param [Integer] axId the id of this axis
40
+ # @param [Integer] crossAx the id of the perpendicular axis
41
+ # @option options [Symbol] axPos
42
+ # @option options [Symbol] crosses
43
+ # @option options [Symbol] tickLblPos
44
+ # @raise [ArgumentError] If axId or crossAx are not unsigned integers
45
+ def initialize(axId, crossAx, options={})
46
+ Axlsx::validate_unsigned_int(axId)
47
+ Axlsx::validate_unsigned_int(crossAx)
48
+ @axId = axId
49
+ @crossAx = crossAx
50
+ @format_code = "General"
51
+ @scaling = Scaling.new(:orientation=>:minMax)
52
+ self.axPos = :l
53
+ self.tickLblPos = :nextTo
54
+ self.format_code = "General"
55
+ self.crosses = :autoZero
56
+ options.each do |o|
57
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
58
+ end
59
+ end
60
+ # The position of the axis
61
+ # must be one of [:l, :r, :t, :b]
62
+ def axPos=(v) RestrictionValidator.validate "#{self.class}.axPos", [:l, :r, :b, :t], v; @axPos = v; end
63
+
64
+ # the position of the tick labels
65
+ # must be one of [:nextTo, :high, :low1]
66
+ def tickLblPos=(v) RestrictionValidator.validate "#{self.class}.tickLblPos", [:nextTo, :high, :low], v; @tickLblPos = v; end
67
+
68
+ # The number format format code for this axis
69
+ # default :General
70
+ def format_code=(v) Axlsx::validate_string(v); @formatCode = v; end
71
+
72
+ # specifies how the perpendicular axis is crossed
73
+ # must be one of [:autoZero, :min, :max]
74
+ def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
75
+
76
+ # Serializes the common axis
77
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
78
+ # @return [String]
79
+ def to_xml(xml)
80
+ xml.send('c:axId', :val=>@axId)
81
+ @scaling.to_xml(xml)
82
+ xml.send('c:axPos', :val=>@axPos)
83
+ xml.send('c:majorGridlines')
84
+ xml.send('c:numFmt', :formatCode => @format_code, :sourceLinked=>"1")
85
+ xml.send('c:tickLblPos', :val=>@tickLblPos)
86
+ xml.send('c:crossAx', :val=>@crossAx)
87
+ xml.send('c:crosses', :val=>@crosses)
88
+ end
89
+ end
90
+ end