axlsx 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/Rakefile +13 -0
  2. data/lib/axlsx.rb +38 -0
  3. data/lib/axlsx/content_type/content_type.rb +23 -0
  4. data/lib/axlsx/content_type/default.rb +32 -0
  5. data/lib/axlsx/content_type/override.rb +30 -0
  6. data/lib/axlsx/doc_props/app.rb +148 -0
  7. data/lib/axlsx/doc_props/core.rb +34 -0
  8. data/lib/axlsx/drawing/axis.rb +78 -0
  9. data/lib/axlsx/drawing/bar_3D_chart.rb +138 -0
  10. data/lib/axlsx/drawing/bar_series.rb +91 -0
  11. data/lib/axlsx/drawing/cat_axis.rb +58 -0
  12. data/lib/axlsx/drawing/chart.rb +120 -0
  13. data/lib/axlsx/drawing/drawing.rb +121 -0
  14. data/lib/axlsx/drawing/graphic_frame.rb +55 -0
  15. data/lib/axlsx/drawing/marker.rb +57 -0
  16. data/lib/axlsx/drawing/pie_3D_chart.rb +59 -0
  17. data/lib/axlsx/drawing/pie_series.rb +88 -0
  18. data/lib/axlsx/drawing/scaling.rb +53 -0
  19. data/lib/axlsx/drawing/series.rb +70 -0
  20. data/lib/axlsx/drawing/title.rb +69 -0
  21. data/lib/axlsx/drawing/two_cell_anchor.rb +88 -0
  22. data/lib/axlsx/drawing/val_axis.rb +34 -0
  23. data/lib/axlsx/drawing/view_3D.rb +72 -0
  24. data/lib/axlsx/package.rb +181 -0
  25. data/lib/axlsx/rels/relationship.rb +43 -0
  26. data/lib/axlsx/rels/relationships.rb +25 -0
  27. data/lib/axlsx/stylesheet/border.rb +52 -0
  28. data/lib/axlsx/stylesheet/border_pr.rb +65 -0
  29. data/lib/axlsx/stylesheet/cell_alignment.rb +96 -0
  30. data/lib/axlsx/stylesheet/cell_protection.rb +33 -0
  31. data/lib/axlsx/stylesheet/cell_style.rb +60 -0
  32. data/lib/axlsx/stylesheet/color.rb +57 -0
  33. data/lib/axlsx/stylesheet/fill.rb +31 -0
  34. data/lib/axlsx/stylesheet/font.rb +128 -0
  35. data/lib/axlsx/stylesheet/gradient_fill.rb +70 -0
  36. data/lib/axlsx/stylesheet/gradient_stop.rb +31 -0
  37. data/lib/axlsx/stylesheet/num_fmt.rb +61 -0
  38. data/lib/axlsx/stylesheet/pattern_fill.rb +64 -0
  39. data/lib/axlsx/stylesheet/styles.rb +296 -0
  40. data/lib/axlsx/stylesheet/table_style.rb +44 -0
  41. data/lib/axlsx/stylesheet/table_style_element.rb +66 -0
  42. data/lib/axlsx/stylesheet/table_styles.rb +39 -0
  43. data/lib/axlsx/stylesheet/xf.rb +117 -0
  44. data/lib/axlsx/util/constants.rb +189 -0
  45. data/lib/axlsx/util/simple_typed_list.rb +150 -0
  46. data/lib/axlsx/util/validators.rb +132 -0
  47. data/lib/axlsx/workbook/workbook.rb +130 -0
  48. data/lib/axlsx/workbook/worksheet/cell.rb +184 -0
  49. data/lib/axlsx/workbook/worksheet/row.rb +92 -0
  50. data/lib/axlsx/workbook/worksheet/worksheet.rb +194 -0
  51. data/lib/schema/dc.xsd +118 -0
  52. data/lib/schema/dcmitype.xsd +50 -0
  53. data/lib/schema/dcterms.xsd +331 -0
  54. data/lib/schema/dml-chart.xsd +1499 -0
  55. data/lib/schema/dml-chartDrawing.xsd +146 -0
  56. data/lib/schema/dml-compatibility.xsd +14 -0
  57. data/lib/schema/dml-diagram.xsd +1091 -0
  58. data/lib/schema/dml-lockedCanvas.xsd +11 -0
  59. data/lib/schema/dml-main.xsd +3048 -0
  60. data/lib/schema/dml-picture.xsd +23 -0
  61. data/lib/schema/dml-spreadsheetDrawing.xsd +185 -0
  62. data/lib/schema/dml-wordprocessingDrawing.xsd +185 -0
  63. data/lib/schema/opc-contentTypes.xsd +42 -0
  64. data/lib/schema/opc-coreProperties.xsd +50 -0
  65. data/lib/schema/opc-digSig.xsd +49 -0
  66. data/lib/schema/opc-relationships.xsd +33 -0
  67. data/lib/schema/pml.xsd +1676 -0
  68. data/lib/schema/shared-additionalCharacteristics.xsd +28 -0
  69. data/lib/schema/shared-bibliography.xsd +144 -0
  70. data/lib/schema/shared-commonSimpleTypes.xsd +166 -0
  71. data/lib/schema/shared-customXmlDataProperties.xsd +25 -0
  72. data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -0
  73. data/lib/schema/shared-documentPropertiesCustom.xsd +59 -0
  74. data/lib/schema/shared-documentPropertiesExtended.xsd +56 -0
  75. data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -0
  76. data/lib/schema/shared-math.xsd +582 -0
  77. data/lib/schema/shared-relationshipReference.xsd +25 -0
  78. data/lib/schema/sml.xsd +4430 -0
  79. data/lib/schema/vml-main.xsd +569 -0
  80. data/lib/schema/vml-officeDrawing.xsd +509 -0
  81. data/lib/schema/vml-presentationDrawing.xsd +12 -0
  82. data/lib/schema/vml-spreadsheetDrawing.xsd +108 -0
  83. data/lib/schema/vml-wordprocessingDrawing.xsd +96 -0
  84. data/lib/schema/wml.xsd +3644 -0
  85. data/lib/schema/xml.xsd +117 -0
  86. data/test/content_type/tc_content_type.rb +81 -0
  87. data/test/content_type/tc_content_type.rb~ +81 -0
  88. data/test/content_type/tc_default.rb +40 -0
  89. data/test/content_type/tc_default.rb~ +40 -0
  90. data/test/content_type/tc_override.rb +40 -0
  91. data/test/content_type/tc_override.rb~ +40 -0
  92. data/test/doc_props/tc_app.rb +19 -0
  93. data/test/doc_props/tc_app.rb~ +19 -0
  94. data/test/doc_props/tc_core.rb +34 -0
  95. data/test/drawing/tc_axis.rb +39 -0
  96. data/test/drawing/tc_axis.rb~ +0 -0
  97. data/test/drawing/tc_bar_3D_chart.rb +66 -0
  98. data/test/drawing/tc_bar_3D_chart.rb~ +4 -0
  99. data/test/drawing/tc_bar_series.rb +34 -0
  100. data/test/drawing/tc_bar_series.rb~ +31 -0
  101. data/test/drawing/tc_cat_axis.rb +32 -0
  102. data/test/drawing/tc_cat_axis.rb~ +39 -0
  103. data/test/drawing/tc_chart.rb +59 -0
  104. data/test/drawing/tc_chart.rb~ +58 -0
  105. data/test/drawing/tc_drawing.rb +71 -0
  106. data/test/drawing/tc_graphic_frame.rb +26 -0
  107. data/test/drawing/tc_graphic_frame.rb~ +21 -0
  108. data/test/drawing/tc_marker.rb +45 -0
  109. data/test/drawing/tc_marker.rb~ +26 -0
  110. data/test/drawing/tc_pie_3D_chart.rb +33 -0
  111. data/test/drawing/tc_pie_3D_chart.rb~ +58 -0
  112. data/test/drawing/tc_pie_series.rb +35 -0
  113. data/test/drawing/tc_pie_series.rb~ +26 -0
  114. data/test/drawing/tc_scaling.rb +37 -0
  115. data/test/drawing/tc_scaling.rb~ +45 -0
  116. data/test/drawing/tc_series.rb +24 -0
  117. data/test/drawing/tc_series.rb~ +31 -0
  118. data/test/drawing/tc_title.rb +34 -0
  119. data/test/drawing/tc_title.rb~ +37 -0
  120. data/test/drawing/tc_two_cell_anchor.rb +37 -0
  121. data/test/drawing/tc_two_cell_anchor.rb~ +35 -0
  122. data/test/drawing/tc_val_axis.rb +20 -0
  123. data/test/drawing/tc_val_axis.rb~ +32 -0
  124. data/test/drawing/tc_view_3D.rb +46 -0
  125. data/test/drawing/tc_view_3D.rb~ +37 -0
  126. data/test/rels/tc_relationship.rb +16 -0
  127. data/test/rels/tc_relationship.rb~ +39 -0
  128. data/test/rels/tc_relationships.rb +32 -0
  129. data/test/rels/tc_relationships.rb~ +37 -0
  130. data/test/stylesheet/tc_border.rb +38 -0
  131. data/test/stylesheet/tc_border.rb~ +31 -0
  132. data/test/stylesheet/tc_border_pr.rb +33 -0
  133. data/test/stylesheet/tc_border_pr.rb~ +31 -0
  134. data/test/stylesheet/tc_cell_alignment.rb +77 -0
  135. data/test/stylesheet/tc_cell_alignment.rb~ +38 -0
  136. data/test/stylesheet/tc_cell_protection.rb +30 -0
  137. data/test/stylesheet/tc_cell_protection.rb~ +77 -0
  138. data/test/stylesheet/tc_cell_style.rb +58 -0
  139. data/test/stylesheet/tc_cell_style.rb~ +30 -0
  140. data/test/stylesheet/tc_color.rb +38 -0
  141. data/test/stylesheet/tc_color.rb~ +38 -0
  142. data/test/stylesheet/tc_fill.rb +19 -0
  143. data/test/stylesheet/tc_fill.rb~ +19 -0
  144. data/test/stylesheet/tc_font.rb +114 -0
  145. data/test/stylesheet/tc_font.rb~ +19 -0
  146. data/test/stylesheet/tc_gradient_fill.rb +65 -0
  147. data/test/stylesheet/tc_gradient_fill.rb~ +114 -0
  148. data/test/stylesheet/tc_gradient_stop.rb +32 -0
  149. data/test/stylesheet/tc_gradient_stop.rb~ +65 -0
  150. data/test/stylesheet/tc_num_fmt.rb +31 -0
  151. data/test/stylesheet/tc_num_fmt.rb~ +32 -0
  152. data/test/stylesheet/tc_pattern_fill.rb +38 -0
  153. data/test/stylesheet/tc_pattern_fill.rb~ +31 -0
  154. data/test/stylesheet/tc_styles.rb +64 -0
  155. data/test/stylesheet/tc_table_style.rb +37 -0
  156. data/test/stylesheet/tc_table_style.rb~ +38 -0
  157. data/test/stylesheet/tc_table_style_element.rb +37 -0
  158. data/test/stylesheet/tc_table_style_element.rb~ +37 -0
  159. data/test/stylesheet/tc_table_styles.rb +30 -0
  160. data/test/stylesheet/tc_table_styles.rb~ +37 -0
  161. data/test/stylesheet/tc_xf.rb +121 -0
  162. data/test/stylesheet/tc_xf.rb~ +30 -0
  163. data/test/tc_app.rb~ +19 -0
  164. data/test/tc_border_pr.rb~ +21 -0
  165. data/test/tc_package.rb +70 -0
  166. data/test/tc_package.rb~ +64 -0
  167. data/test/tc_pie_3D_chart.rb~ +66 -0
  168. data/test/tc_relationships.rb~ +37 -0
  169. data/test/tc_series.rb~ +31 -0
  170. data/test/tc_styles.rb~ +64 -0
  171. data/test/tc_validators.rb~ +77 -0
  172. data/test/tc_worksheet.rb~ +85 -0
  173. data/test/util/tc_simple_typed_list.rb +66 -0
  174. data/test/util/tc_validators.rb +76 -0
  175. data/test/workbook/tc_workbook.rb +53 -0
  176. data/test/workbook/worksheet/tc_cell.rb +78 -0
  177. data/test/workbook/worksheet/tc_row.rb +30 -0
  178. data/test/workbook/worksheet/tc_worksheet.rb +85 -0
  179. metadata +378 -0
@@ -0,0 +1,13 @@
1
+ require 'rake/testtask'
2
+
3
+ # gems not loading? try this
4
+ #RUBYOPT="rubygems"
5
+ #export RUBYOPT
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ t.test_files = FileList['test/**/tc_*.rb']
10
+ t.verbose = true
11
+ end
12
+
13
+ task :default => :test
@@ -0,0 +1,38 @@
1
+ require 'axlsx/util/simple_typed_list.rb'
2
+ require 'axlsx/util/constants.rb'
3
+ require 'axlsx/util/validators.rb'
4
+ require 'axlsx/stylesheet/styles.rb'
5
+
6
+ require 'axlsx/doc_props/app.rb'
7
+ require 'axlsx/doc_props/core.rb'
8
+ require 'axlsx/content_type/content_type.rb'
9
+ require 'axlsx/rels/relationships.rb'
10
+
11
+ require 'axlsx/drawing/drawing.rb'
12
+ require 'axlsx/workbook/workbook.rb'
13
+ require 'axlsx/package.rb'
14
+
15
+
16
+ module Axlsx
17
+
18
+ #required gems
19
+ require 'Nokogiri'
20
+ require 'active_support/core_ext/object/instance_variables'
21
+ require 'active_support/inflector'
22
+ require 'rmagick'
23
+ require 'zip/zip'
24
+
25
+ #core dependencies
26
+ require 'bigdecimal'
27
+ require 'time'
28
+ require 'CGI'
29
+
30
+ # determines the cell range for the items provided
31
+ def self.cell_range(items)
32
+ return "" unless items.first.is_a? Cell
33
+ "#{items.first.row.worksheet.name}!" +
34
+ "#{items.first.r_abs}:#{items.last.r_abs}"
35
+ end
36
+
37
+
38
+ 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,32 @@
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_accessor :Extension
8
+
9
+ # @return [String] ContentType The type of content. TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT are allowed
10
+ attr_accessor :ContentType
11
+
12
+ #Creates a new Default object
13
+ # @option options [String] Extension
14
+ # @option options [String] ContentType
15
+ # @raise [ArgumentError] An argument error is raised if both Extension and ContentType are not specified.
16
+ def initialize(options={})
17
+ raise ArgumentError, "Extension and ContentType are required" unless options[:Extension] && options[:ContentType]
18
+ options.each do |o|
19
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
20
+ end
21
+ end
22
+ def Extension=(v) Axlsx::validate_string v; @Extension = v end
23
+ def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end
24
+
25
+ # Serializes the object to xml
26
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
27
+ # @return [String]
28
+ def to_xml(xml)
29
+ xml.Default(self.instance_values)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
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
+ # @return [String] ContentType The type of content. TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT are allowed
6
+ attr_accessor :ContentType
7
+
8
+ # @return [String] PartName The name and location of the part.
9
+ attr_accessor :PartName
10
+
11
+ #Creates a new Override object
12
+ # @option options [String] PartName
13
+ # @option options [String] ContentType
14
+ # @raise [ArgumentError] An argument error is raised if both PartName and ContentType are not specified.
15
+ def initialize(options={})
16
+ raise ArgumentError, "PartName and ContentType are required" unless options[:PartName] && options[:ContentType]
17
+ options.each do |o|
18
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
19
+ end
20
+ end
21
+ def PartName=(v) Axlsx::validate_string v; @PartName = v end
22
+ def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end
23
+
24
+ # Serializes the Override object to xml
25
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
26
+ def to_xml(xml)
27
+ xml.Override(self.instance_values)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,148 @@
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_accessor :Template
15
+
16
+ # @return [String] The name of the manager for the document.
17
+ attr_accessor :Manager
18
+
19
+ # @return [String] The name of the company generating the document.
20
+ attr_accessor :Company
21
+
22
+ # @return [Integer] The number of pages in the document.
23
+ attr_accessor :Pages
24
+
25
+ # @return [Integer] The number of words in the document.
26
+ attr_accessor :Words
27
+
28
+ # @return [Integer] The number of characters in the document.
29
+ attr_accessor :Characters
30
+
31
+ # @return [String] The intended format of the presentation.
32
+ attr_accessor :PresentationFormat
33
+
34
+ # @return [Integer] The number of lines in the document.
35
+ attr_accessor :Lines
36
+
37
+ # @return [Integer] The number of paragraphs in the document
38
+ attr_accessor :Paragraphs
39
+
40
+ # @return [Intger] The number of slides in the document.
41
+ attr_accessor :Slides
42
+
43
+ # @return [Integer] The number of slides that have notes.
44
+ attr_accessor :Notes
45
+
46
+ # @return [Integer] The total amount of time spent editing.
47
+ attr_accessor :TotalTime
48
+
49
+ # @return [Integer] The number of hidden slides.
50
+ attr_accessor :HiddenSlides
51
+
52
+ # @return [Integer] The total number multimedia clips
53
+ attr_accessor :MMClips
54
+
55
+ # @return [Boolean] The display mode for the document thumbnail.
56
+ attr_accessor :ScaleCrop
57
+
58
+ # @return [Boolean] The links in the document are up to date.
59
+ attr_accessor :LinksUpToDate
60
+
61
+ # @return [Integer] The number of characters in the document including spaces.
62
+ attr_accessor :CharactersWithSpaces
63
+
64
+ # @return [Boolean] Indicates if the document is shared.
65
+ attr_accessor :ShareDoc
66
+
67
+ # @return [String] The base for hyper links in the document.
68
+ attr_accessor :HyperLinkBase
69
+
70
+ # @return [Boolean] Indicates that the hyper links in the document have been changed.
71
+ attr_accessor :HyperlinksChanged
72
+
73
+ # @return [String] The name of the application
74
+ attr_accessor :Application
75
+
76
+ # @return [String] The version of the application.
77
+ attr_accessor :AppVersion
78
+
79
+ # @return [Integer] Document security
80
+ attr_accessor :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 initalize(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
+ def Template=(v) Axlsx::validate_string v; @Template = v; end
112
+ def Manager=(v) Axlsx::validate_string v; @Manager = v; end
113
+ def Company=(v) Axlsx::validate_string v; @Company = v; end
114
+ def Pages=(v) Axlsx::validate_int v; @Pages = v; end
115
+ def Words=(v) Axlsx::validate_int v; @Words = v; end
116
+ def Characters=(v) Axlsx::validate_int v; @Characters = v; end
117
+ def PresentationFormat=(v) Axlsx::validate_string v; @PresentationFormat = v; end
118
+ def Lines=(v) Axlsx::validate_int v; @Lines = v; end
119
+ def Paragraphs=(v) Axlsx::validate_int v; @Paragraphs = v; end
120
+ def Slides=(v) Axlsx::validate_int v; @Slides = v; end
121
+ def Notes=(v) Axlsx::validate_int v; @Notes = v; end
122
+ def TotalTime=(v) Axlsx::validate_int v; @TotalTime = v; end
123
+ def HiddenSlides=(v) Axlsx::validate_int v; @HiddenSlides = v; end
124
+ def MMClips=(v) Axlsx::validate_int v; @MMClips = v; end
125
+ def ScaleCrop=(v) Axlsx::validate_boolean v; @ScaleCrop = v; end
126
+ def LinksUpToDate=(v) Axlsx::validate_boolean v; @LinksUpToDate = v; end
127
+ def CharactersWithSpaces=(v) Axlsx::validate_int v; @CharactersWithSpaces = v; end
128
+ def ShareDoc=(v) Axlsx::validate_boolean v; @ShareDoc = v; end
129
+ def HyperLinkBase=(v) Axlsx::validate_string v; @HyperLinkBase = v; end
130
+ def HyperlinksChanged=(v) Axlsx::validate_boolean v; @HyperlinksChanged = v; end
131
+ def Application=(v) Axlsx::validate_string v; @Application = v; end
132
+ def AppVersion=(v) Axlsx::validate_string v; @AppVersion = v; end
133
+ def DocSecurity=(v) Axlsx::validate_int v; @DocSecurity = v; end
134
+
135
+ # Generate an app.xml document
136
+ # @return [String] The document as a string
137
+ def to_xml()
138
+ builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
139
+ xml.send(:Properties, :xmlns => APP_NS, :'xmlns:vt' => APP_NS_VT) {
140
+ self.instance_values.each do |name, value|
141
+ xml.send("ap:#{name}", value)
142
+ end
143
+ }
144
+ end
145
+ builder.to_xml
146
+ end
147
+ end
148
+ 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,78 @@
1
+ module Axlsx
2
+ # the access class defines common properties and values for chart axis
3
+ class Axis
4
+
5
+
6
+ # the id of the axis
7
+ # @return [Integer]
8
+ attr_reader :axId
9
+
10
+ # The perpendicular axis
11
+ # @return [Integer]
12
+ attr_reader :crossAx
13
+
14
+ # The scaling of the axis
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_accessor :axPos
22
+
23
+ # the position of the tick labels
24
+ # must be one of [:nextTo, :high, :low]
25
+ # @return [Symbol]
26
+ attr_accessor :tickLblPos
27
+
28
+
29
+ # The number format format code for this axis
30
+ # @return [String]
31
+ attr_accessor :format_code
32
+
33
+ # specifies how the perpendicular axis is crossed
34
+ # must be one of [:autoZero, :min, :max]
35
+ # @return [Symbol]
36
+ attr_accessor :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
+ def initialize(axId, crossAx, options={})
45
+ Axlsx::validate_unsigned_int(axId)
46
+ Axlsx::validate_unsigned_int(crossAx)
47
+ @axId = axId
48
+ @crossAx = crossAx
49
+ self.axPos = :l
50
+ self.tickLblPos = :nextTo
51
+ @scaling = Scaling.new(:orientation=>:minMax)
52
+ @formatCode = ""
53
+ self.crosses = :autoZero
54
+ options.each do |o|
55
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
56
+ end
57
+ end
58
+
59
+ def axPos=(v) RestrictionValidator.validate "#{self.class}.axPos", [:l, :r, :b, :t], v; @axPos = v; end
60
+ def tickLblPos=(v) RestrictionValidator.validate "#{self.class}.tickLblPos", [:nextTo, :high, :low], v; @tickLblPos = v; end
61
+ def format_code=(v) Axlsx::validate_string(v); @formatCode = v; end
62
+ def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
63
+
64
+ # Serializes the common axis
65
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
66
+ # @return [String]
67
+ def to_xml(xml)
68
+ xml.send('c:axId', :val=>@axId)
69
+ @scaling.to_xml(xml)
70
+ xml.send('c:axPos', :val=>@axPos)
71
+ xml.send('c:majorGridlines')
72
+ xml.send('c:numFmt', :formatCode => @format_code, :sourceLinked=>"1")
73
+ xml.send('c:tickLblPos', :val=>@tickLblPos)
74
+ xml.send('c:crossAx', :val=>@crossAx)
75
+ xml.send('c:crosses', :val=>@crosses)
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,138 @@
1
+ module Axlsx
2
+
3
+ # The Bar3DChart is a three dimentional barchart (who would have guessed?) that you can add to your worksheet.
4
+ # @example Creating a chart
5
+ # # This example creates two charts in a single sheet.
6
+ # # The first uses data directly fed to the sheet, while the second references cells withing the worksheet for data.
7
+ #
8
+ # require "rubygems" # if that is your preferred way to manage gems!
9
+ # require "axlsx"
10
+ #
11
+ # p = Axlsx::Package.new
12
+ # ws = p.workbook.add_worksheet
13
+ # ws.add_row :values => ["This is a chart with no data in the sheet"]
14
+ #
15
+ # chart = ws.add_chart(Axlsx::Bar3DChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
16
+ # chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
17
+ #
18
+ # ws.add_row :values => ["This chart uses the data below"]
19
+ # title_row = ws.add_row :values => ["Least Popular Pets"]
20
+ # label_row = ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"]
21
+ # data_row = ws.add_row :values => ["Votes", 6, 4, 1]
22
+ #
23
+ # chart = ws.add_chart(Axlsx::Pie3DChart, :start_at => [0,11], :end_at =>[0,16], :title => title_row.cells.last)
24
+ # chart.add_series :data => data_row.cells[(1..-1)], :labels => label_row.cells
25
+ #
26
+ # f = File.open('example_pie_3d_chart.xlsx', 'w')
27
+ # p.serialize(f)
28
+ #
29
+ # @see Worksheet#add_chart
30
+ # @see Worksheet#add_row
31
+ # @see Chart#add_series
32
+ # @see Series
33
+ # @see Package#serialize
34
+ class Bar3DChart < Chart
35
+
36
+ # the category axis
37
+ # @return [CatAxis]
38
+ attr_reader :catAxis
39
+
40
+ # the category axis
41
+ # @return [ValAxis]
42
+ attr_reader :valAxis
43
+
44
+ # The direction of the bars in the chart
45
+ # must be one of [:bar, :col]
46
+ # @return [Symbol]
47
+ attr_accessor :barDir
48
+
49
+ # space between bar or column clusters, as a percentage of the bar or column width.
50
+ # @return [String]
51
+ attr_accessor :gapDepth
52
+
53
+ # space between bar or column clusters, as a percentage of the bar or column width.
54
+ # @return [String]
55
+ attr_accessor :gapWidth
56
+
57
+ #grouping for a column, line, or area chart.
58
+ # must be one of [:percentStacked, :clustered, :standard, :stacked]
59
+ # @return [Symbol]
60
+ attr_accessor :grouping
61
+
62
+ # The shabe of the bars or columns
63
+ # must be one of [:percentStacked, :clustered, :standard, :stacked]
64
+ # @return [Symbol]
65
+ attr_accessor :shape
66
+
67
+ # validation regex for gap amount percent
68
+ GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
69
+
70
+ # Creates a new bar chart object
71
+ # @param [GraphicFrame] frame The workbook that owns this chart.
72
+ # @option options [Cell, String] title
73
+ # @option options [Boolean] show_legend
74
+ # @option options [Symbol] barDir
75
+ # @option options [Symbol] grouping
76
+ # @option options [String] gapWidth
77
+ # @option options [String] gapDepth
78
+ # @option options [Symbol] shape
79
+ def initialize(frame, options={})
80
+ super(frame, options)
81
+ @series_type = BarSeries
82
+ @barDir = :bar
83
+ @grouping = :clustered
84
+ @catAxId = rand(8 ** 8)
85
+ @valAxId = rand(8 ** 8)
86
+ @catAxis = CatAxis.new(@catAxId, @valAxId)
87
+ @valAxis = ValAxis.new(@valAxId, @catAxId)
88
+ @view3D = View3D.new(:rAngAx=>1)
89
+ end
90
+
91
+ def barDir=(v)
92
+ RestrictionValidator.validate "Bar3DChart.barDir", [:bar, :col], v
93
+ @barDir = v
94
+ end
95
+
96
+
97
+ def grouping=(v)
98
+ RestrictionValidator.validate "Bar3DChart.grouping", [:percentStacked, :clustered, :standard, :stacked], v
99
+ @grouping = v
100
+ end
101
+
102
+ def gapWidth=(v)
103
+ RegexValidator.validate "Bar3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
104
+ @gapWidth=(v)
105
+ end
106
+
107
+ def gapDepth=(v)
108
+ RegexValidator.validate "Bar3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
109
+ @gapDepth=(v)
110
+ end
111
+
112
+ def shape=(v)
113
+ RestrictionValidator.validate "Bar3DChart.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
114
+ @shape = v
115
+ end
116
+
117
+ # Serializes the bar chart
118
+ # @return [String]
119
+ def to_xml
120
+ super() do |xml|
121
+ xml.send('c:bar3DChart') {
122
+ xml.send('c:barDir', :val => barDir)
123
+ xml.send('c:grouping', :val=>grouping)
124
+ xml.send('c:varyColors', :val=>1)
125
+ @series.each { |ser| ser.to_xml(xml) }
126
+ xml.send('c:gapWidth', :val=>@gapWidth) unless @gapWidth.nil?
127
+ xml.send('c:gapDepth', :val=>@gapDepth) unless @gapDepth.nil?
128
+ xml.send('c:shape', :val=>@shape) unless @shape.nil?
129
+ xml.send('c:axId', :val=>@catAxId)
130
+ xml.send('c:axId', :val=>@valAxId)
131
+ xml.send('c:axId', :val=>0)
132
+ }
133
+ @catAxis.to_xml(xml)
134
+ @valAxis.to_xml(xml)
135
+ end
136
+ end
137
+ end
138
+ end