axlsx 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/README.md +21 -3
  2. data/doc/Axlsx.html +150 -6
  3. data/doc/Axlsx/App.html +1 -1
  4. data/doc/Axlsx/Axis.html +1 -1
  5. data/doc/Axlsx/Bar3DChart.html +1 -1
  6. data/doc/Axlsx/BarSeries.html +1 -1
  7. data/doc/Axlsx/Border.html +1 -1
  8. data/doc/Axlsx/BorderPr.html +1 -1
  9. data/doc/Axlsx/CatAxis.html +1 -1
  10. data/doc/Axlsx/CatAxisData.html +7 -5
  11. data/doc/Axlsx/Cell.html +1 -1
  12. data/doc/Axlsx/CellAlignment.html +1 -1
  13. data/doc/Axlsx/CellProtection.html +1 -1
  14. data/doc/Axlsx/CellStyle.html +1 -1
  15. data/doc/Axlsx/Chart.html +16 -16
  16. data/doc/Axlsx/Color.html +1 -1
  17. data/doc/Axlsx/ContentType.html +1 -1
  18. data/doc/Axlsx/Core.html +1 -1
  19. data/doc/Axlsx/DataTypeValidator.html +1 -1
  20. data/doc/Axlsx/Default.html +1 -1
  21. data/doc/Axlsx/Drawing.html +243 -65
  22. data/doc/Axlsx/Fill.html +1 -1
  23. data/doc/Axlsx/Font.html +1 -1
  24. data/doc/Axlsx/GradientFill.html +1 -1
  25. data/doc/Axlsx/GradientStop.html +1 -1
  26. data/doc/Axlsx/GraphicFrame.html +21 -21
  27. data/doc/Axlsx/Line3DChart.html +1 -1
  28. data/doc/Axlsx/LineSeries.html +6 -8
  29. data/doc/Axlsx/Marker.html +1 -1
  30. data/doc/Axlsx/NumFmt.html +1 -1
  31. data/doc/Axlsx/OneCellAnchor.html +988 -0
  32. data/doc/Axlsx/Override.html +1 -1
  33. data/doc/Axlsx/Package.html +127 -75
  34. data/doc/Axlsx/PatternFill.html +1 -1
  35. data/doc/Axlsx/Pic.html +1532 -0
  36. data/doc/Axlsx/Pie3DChart.html +5 -7
  37. data/doc/Axlsx/PieSeries.html +1 -1
  38. data/doc/Axlsx/RegexValidator.html +1 -1
  39. data/doc/Axlsx/Relationship.html +6 -6
  40. data/doc/Axlsx/Relationships.html +1 -1
  41. data/doc/Axlsx/RestrictionValidator.html +1 -1
  42. data/doc/Axlsx/Row.html +1 -1
  43. data/doc/Axlsx/Scaling.html +1 -1
  44. data/doc/Axlsx/SerAxis.html +1 -1
  45. data/doc/Axlsx/Series.html +1 -1
  46. data/doc/Axlsx/SeriesTitle.html +1 -1
  47. data/doc/Axlsx/SimpleTypedList.html +1 -1
  48. data/doc/Axlsx/Styles.html +1 -1
  49. data/doc/Axlsx/TableStyle.html +1 -1
  50. data/doc/Axlsx/TableStyleElement.html +1 -1
  51. data/doc/Axlsx/TableStyles.html +1 -1
  52. data/doc/Axlsx/Title.html +1 -1
  53. data/doc/Axlsx/TwoCellAnchor.html +165 -61
  54. data/doc/Axlsx/ValAxis.html +1 -1
  55. data/doc/Axlsx/ValAxisData.html +1 -1
  56. data/doc/Axlsx/View3D.html +1 -1
  57. data/doc/Axlsx/Workbook.html +151 -47
  58. data/doc/Axlsx/Worksheet.html +172 -35
  59. data/doc/Axlsx/Xf.html +1 -1
  60. data/doc/_index.html +15 -1
  61. data/doc/class_list.html +1 -1
  62. data/doc/file.README.html +29 -4
  63. data/doc/index.html +29 -4
  64. data/doc/method_list.html +571 -363
  65. data/doc/top-level-namespace.html +1 -1
  66. data/examples/example.rb +13 -0
  67. data/examples/image1.gif +0 -0
  68. data/examples/image1.jpeg +0 -0
  69. data/examples/image1.jpg +0 -0
  70. data/examples/image1.png +0 -0
  71. data/lib/axlsx/drawing/bar_series.rb +0 -1
  72. data/lib/axlsx/drawing/cat_axis_data.rb +1 -0
  73. data/lib/axlsx/drawing/chart.rb +0 -1
  74. data/lib/axlsx/drawing/drawing.rb +31 -7
  75. data/lib/axlsx/drawing/graphic_frame.rb +0 -2
  76. data/lib/axlsx/drawing/line_series.rb +0 -1
  77. data/lib/axlsx/drawing/one_cell_anchor.rb +89 -0
  78. data/lib/axlsx/drawing/pic.rb +158 -0
  79. data/lib/axlsx/drawing/pie_3D_chart.rb +0 -1
  80. data/lib/axlsx/drawing/two_cell_anchor.rb +17 -4
  81. data/lib/axlsx/package.rb +31 -5
  82. data/lib/axlsx/rels/relationship.rb +1 -2
  83. data/lib/axlsx/util/constants.rb +24 -0
  84. data/lib/axlsx/util/validators.rb +2 -2
  85. data/lib/axlsx/version.rb +1 -1
  86. data/lib/axlsx/workbook/workbook.rb +8 -0
  87. data/lib/axlsx/workbook/worksheet/worksheet.rb +10 -1
  88. data/test/drawing/tc_drawing.rb +10 -1
  89. data/test/drawing/tc_one_cell_anchor.rb +67 -0
  90. data/test/drawing/tc_pic.rb +71 -0
  91. data/test/tc_package.rb +0 -2
  92. metadata +13 -118
  93. data/examples/#example.rb# +0 -87
  94. data/examples/example.rb~ +0 -79
  95. data/examples/multi_chart.xlsx +0 -0
  96. data/lib/axlsx.rb~ +0 -67
  97. data/lib/axlsx/content_type/content_type.rb~ +0 -20
  98. data/lib/axlsx/content_type/default.rb~ +0 -32
  99. data/lib/axlsx/content_type/override.rb~ +0 -30
  100. data/lib/axlsx/doc_props/app.rb~ +0 -127
  101. data/lib/axlsx/doc_props/core.rb~ +0 -25
  102. data/lib/axlsx/drawing/#bar_series.rb# +0 -62
  103. data/lib/axlsx/drawing/axis.rb~ +0 -0
  104. data/lib/axlsx/drawing/bar_3D_chart.rb~ +0 -64
  105. data/lib/axlsx/drawing/bar_series.rb~ +0 -92
  106. data/lib/axlsx/drawing/cat_axis.rb~ +0 -32
  107. data/lib/axlsx/drawing/cat_axis_data.rb~ +0 -28
  108. data/lib/axlsx/drawing/chart.rb~ +0 -0
  109. data/lib/axlsx/drawing/drawing.rb~ +0 -102
  110. data/lib/axlsx/drawing/graphic_frame.rb~ +0 -40
  111. data/lib/axlsx/drawing/line_3D_chart.rb~ +0 -138
  112. data/lib/axlsx/drawing/line_series.rb~ +0 -91
  113. data/lib/axlsx/drawing/marker.rb~ +0 -50
  114. data/lib/axlsx/drawing/pie_3D_chart.rb~ +0 -132
  115. data/lib/axlsx/drawing/pie_series.rb~ +0 -0
  116. data/lib/axlsx/drawing/scaling.rb~ +0 -0
  117. data/lib/axlsx/drawing/ser_axis.rb~ +0 -48
  118. data/lib/axlsx/drawing/series.rb~ +0 -114
  119. data/lib/axlsx/drawing/series_title.rb~ +0 -18
  120. data/lib/axlsx/drawing/title.rb~ +0 -69
  121. data/lib/axlsx/drawing/two_cell_anchor.rb~ +0 -70
  122. data/lib/axlsx/drawing/val_axis.rb~ +0 -34
  123. data/lib/axlsx/drawing/val_axis_data.rb~ +0 -29
  124. data/lib/axlsx/drawing/view_3D.rb~ +0 -21
  125. data/lib/axlsx/package.rb~ +0 -181
  126. data/lib/axlsx/rels/relationship.rb~ +0 -18
  127. data/lib/axlsx/rels/relationships.rb~ +0 -23
  128. data/lib/axlsx/stylesheet/border.rb~ +0 -24
  129. data/lib/axlsx/stylesheet/border_pr.rb~ +0 -64
  130. data/lib/axlsx/stylesheet/cell_alignment.rb~ +0 -93
  131. data/lib/axlsx/stylesheet/cell_protection.rb~ +0 -16
  132. data/lib/axlsx/stylesheet/cell_style.rb~ +0 -61
  133. data/lib/axlsx/stylesheet/color.rb~ +0 -56
  134. data/lib/axlsx/stylesheet/fill.rb~ +0 -31
  135. data/lib/axlsx/stylesheet/font.rb~ +0 -33
  136. data/lib/axlsx/stylesheet/gradient_fill.rb~ +0 -70
  137. data/lib/axlsx/stylesheet/gradient_stop.rb~ +0 -15
  138. data/lib/axlsx/stylesheet/num_fmt.rb~ +0 -60
  139. data/lib/axlsx/stylesheet/pattern_fill.rb~ +0 -63
  140. data/lib/axlsx/stylesheet/styles.rb~ +0 -279
  141. data/lib/axlsx/stylesheet/table_style.rb~ +0 -43
  142. data/lib/axlsx/stylesheet/table_style_element.rb~ +0 -66
  143. data/lib/axlsx/stylesheet/table_styles.rb~ +0 -36
  144. data/lib/axlsx/stylesheet/xf.rb~ +0 -37
  145. data/lib/axlsx/util/constants.rb~ +0 -187
  146. data/lib/axlsx/util/monkey_patches_for_true_zip_stream.rb~ +0 -61
  147. data/lib/axlsx/util/simple_typed_list.rb~ +0 -79
  148. data/lib/axlsx/util/validators.rb~ +0 -132
  149. data/lib/axlsx/util/xml_escape.rb~ +0 -6
  150. data/lib/axlsx/workbook/workbook.rb~ +0 -130
  151. data/lib/axlsx/workbook/worksheet/cell.rb~ +0 -185
  152. data/lib/axlsx/workbook/worksheet/row.rb~ +0 -92
  153. data/lib/axlsx/workbook/worksheet/worksheet.rb~ +0 -194
  154. data/test/content_type/tc_content_type.rb~ +0 -81
  155. data/test/content_type/tc_default.rb~ +0 -40
  156. data/test/content_type/tc_override.rb~ +0 -40
  157. data/test/doc_props/tc_app.rb~ +0 -19
  158. data/test/drawing/tc_axis.rb~ +0 -0
  159. data/test/drawing/tc_bar_3D_chart.rb~ +0 -66
  160. data/test/drawing/tc_bar_series.rb~ +0 -31
  161. data/test/drawing/tc_cat_axis.rb~ +0 -39
  162. data/test/drawing/tc_cat_axis_data.rb~ +0 -32
  163. data/test/drawing/tc_chart.rb~ +0 -59
  164. data/test/drawing/tc_graphic_frame.rb~ +0 -21
  165. data/test/drawing/tc_line_3d_chart.rb~ +0 -48
  166. data/test/drawing/tc_line_series.rb~ +0 -34
  167. data/test/drawing/tc_marker.rb~ +0 -26
  168. data/test/drawing/tc_pie_3D_chart.rb~ +0 -33
  169. data/test/drawing/tc_pie_series.rb~ +0 -26
  170. data/test/drawing/tc_scaling.rb~ +0 -45
  171. data/test/drawing/tc_ser_axis.rb~ +0 -20
  172. data/test/drawing/tc_series.rb~ +0 -31
  173. data/test/drawing/tc_series_title.rb~ +0 -34
  174. data/test/drawing/tc_title.rb~ +0 -34
  175. data/test/drawing/tc_two_cell_anchor.rb~ +0 -37
  176. data/test/drawing/tc_val_axis.rb~ +0 -32
  177. data/test/drawing/tc_val_axis_data.rb~ +0 -18
  178. data/test/drawing/tc_view_3D.rb~ +0 -37
  179. data/test/rels/tc_relationship.rb~ +0 -39
  180. data/test/rels/tc_relationships.rb~ +0 -37
  181. data/test/stylesheet/tc_border.rb~ +0 -31
  182. data/test/stylesheet/tc_border_pr.rb~ +0 -31
  183. data/test/stylesheet/tc_cell_alignment.rb~ +0 -38
  184. data/test/stylesheet/tc_cell_protection.rb~ +0 -77
  185. data/test/stylesheet/tc_cell_style.rb~ +0 -30
  186. data/test/stylesheet/tc_color.rb~ +0 -38
  187. data/test/stylesheet/tc_fill.rb~ +0 -19
  188. data/test/stylesheet/tc_font.rb~ +0 -19
  189. data/test/stylesheet/tc_gradient_fill.rb~ +0 -114
  190. data/test/stylesheet/tc_gradient_stop.rb~ +0 -65
  191. data/test/stylesheet/tc_num_fmt.rb~ +0 -32
  192. data/test/stylesheet/tc_pattern_fill.rb~ +0 -31
  193. data/test/stylesheet/tc_table_style.rb~ +0 -38
  194. data/test/stylesheet/tc_table_style_element.rb~ +0 -37
  195. data/test/stylesheet/tc_table_styles.rb~ +0 -37
  196. data/test/stylesheet/tc_xf.rb~ +0 -30
  197. data/test/tc_app.rb~ +0 -19
  198. data/test/tc_border_pr.rb~ +0 -21
  199. data/test/tc_package.rb~ +0 -64
  200. data/test/tc_pie_3D_chart.rb~ +0 -66
  201. data/test/tc_relationships.rb~ +0 -37
  202. data/test/tc_series.rb~ +0 -31
  203. data/test/tc_styles.rb~ +0 -64
  204. data/test/tc_validators.rb~ +0 -77
  205. data/test/tc_worksheet.rb~ +0 -85
  206. data/test/workbook/worksheet/tc_row.rb~ +0 -30
  207. data/test/workbook/worksheet/tc_worksheet.rb~ +0 -85
@@ -1,114 +0,0 @@
1
- module Axlsx
2
- # A Series defines the title, data and labels for chart data.
3
- # @note The recommended way to manage series is to use Chart#add_series
4
- # @see Worksheet#add_chart
5
- # @see Chart#add_series
6
- class Series
7
-
8
- # The series title.
9
- # @return [String]
10
- attr_accessor :title
11
-
12
- # The chart that owns this series
13
- # @return [Chart]
14
- attr_reader :chart
15
-
16
- # The data for this series.
17
- # @return [Array, SimpleTypedList]
18
- attr_reader :data
19
-
20
-
21
- # The index of this series in the chart's series.
22
- # @return [Integer]
23
- attr_reader :index
24
-
25
- # The labels for this series.
26
- # @return [Array, SimpleTypedList]
27
- attr_reader :labels
28
-
29
-
30
- # Creates a new series
31
- # @option options [Array, SimpleTypedList] data
32
- # @option options [Array, SimpleTypedList] labels
33
- # @option options [String] title
34
- # @param [Chart] chart
35
- def initialize(chart, options={})
36
- self.chart = chart
37
- @chart.series << self
38
- self.data = options[:data] || []
39
- self.labels = options[:labels] || []
40
- @title = options[:title] || ''
41
- end
42
-
43
- # Serializes the series
44
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
45
- # @return [String]
46
- def to_xml(xml)
47
- xml.send('c:ser') {
48
- xml.send('c:idx', :val=>index)
49
- xml.send('c:order', :val=>index)
50
- xml.send('c:tx') {
51
- xml.send('c:v', self.title)
52
- }
53
-
54
- if !labels.empty?
55
- xml.send('c:cat') {
56
- xml.send('c:strRef') {
57
- xml.send('c:f', range(labels))
58
- xml.send('c:strCache') {
59
- xml.send('c:ptCount', :val=>labels.size)
60
- labels.each_with_index do |cell, index|
61
- v = cell.is_a?(Cell) ? cell.value : cell
62
- xml.send('c:pt', :idx=>index) {
63
- xml.send('c:v', v)
64
- }
65
- end
66
- }
67
- }
68
- }
69
- end
70
- xml.send('c:val') {
71
- xml.send('c:numRef') {
72
- xml.send('c:f', range(data))
73
- xml.send('c:numCache') {
74
- xml.send('c:formatCode', 'General')
75
- xml.send('c:ptCount', :val=>data.size)
76
- data.each_with_index do |cell, index|
77
- v = cell.is_a?(Cell) ? cell.value : cell
78
- xml.send('c:pt', :idx=>index) {
79
- xml.send('c:v', v)
80
- }
81
- end
82
- }
83
- }
84
- }
85
- }
86
-
87
- end
88
-
89
- def index
90
- @chart.series.index(self)
91
- end
92
-
93
- private
94
-
95
- # determines the cell range for the items provided
96
- def range(items)
97
- return "" unless items.first.is_a? Cell
98
-
99
- "#{items.first.row.worksheet.name}!" +
100
- "#{items.first.r_abs}:#{items.last.r_abs}"
101
- end
102
-
103
-
104
- # assigns the data for this series
105
- def data=(v) DataTypeValidator.validate "Series.data", [Array, SimpleTypedList], v; @data = v; end
106
-
107
- # assigns the labels for this series
108
- def labels=(v) DataTypeValidator.validate "Series.labels", [Array, SimpleTypedList], v; @labels = v; end
109
-
110
- # assigns the chart for this series
111
- def chart=(v) DataTypeValidator.validate "Series.chart", [Chart, Pie3DChart], v; @chart = v; end
112
- end
113
-
114
- end
@@ -1,18 +0,0 @@
1
- module Axlsx
2
- class SeriesTitle < Title
3
-
4
- def to_xml(xml)
5
- xml.send('c:tx') {
6
- xml.send('c:strRef') {
7
- xml.send('c:f', range)
8
- xml.send('c:strCache') {
9
- xml.send('c:ptCount', :val=>1)
10
- xml.send('c:pt', :idx=>0) {
11
- xml.send('c:v', @text)
12
- }
13
- }
14
- }
15
- }
16
- end
17
- end
18
- end
@@ -1,69 +0,0 @@
1
- module Axlsx
2
- # A Title stores information about the title of a chart
3
- class Title
4
-
5
- # The text to be shown. Setting this property directly with a string will remove the cell reference.
6
- # @return [String]
7
- attr_accessor :text
8
-
9
- # The cell that holds the text for the title. Setting this property will automatically update the text attribute.
10
- # @return [Cell]
11
- attr_accessor :cell
12
-
13
- # Creates a new Title object
14
- # @param [String, Cell] title The cell or string to be used for the chart's title
15
- def initialize(title="")
16
- self.cell = title if title.is_a?(Cell)
17
- self.text = title.to_s unless title.is_a?(Cell)
18
- end
19
-
20
- def text=(v)
21
- DataTypeValidator.validate 'Title.text', String, v
22
- @text = v
23
- @cell = nil
24
- v
25
- end
26
-
27
- def cell=(v)
28
- DataTypeValidator.validate 'Title.text', Cell, v
29
- @cell = v
30
- @text = v.value.to_s
31
- v
32
- end
33
-
34
- # Not implemented at this time.
35
- #def tx=(v) DataTypeValidator.validate 'Title.tx', Tx, v; @tx=v; end
36
- #def layout=(v) DataTypeValidator.validate 'Title.layout', Layout, v; @layout = v; end
37
- #def overlay=(v) Axlsx::validate_boolean v; @overlay=v; end
38
- #def spPr=(v) DataTypeValidator.validate 'Title.spPr', SpPr, v; @spPr = v; end
39
-
40
- # Serializes the chart title
41
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
42
- # @return [String]
43
- def to_xml(xml)
44
- xml.send('c:title') {
45
- xml.send('c:tx') {
46
- xml.send('c:strRef') {
47
- xml.send('c:f', range)
48
- xml.send('c:strCache') {
49
- xml.send('c:ptCount', :val=>1)
50
- xml.send('c:pt', :idx=>0) {
51
- xml.send('c:v', @text)
52
- }
53
- }
54
- }
55
- }
56
- }
57
- end
58
-
59
- private
60
-
61
- # returns the excel style abslute reference for the title when title is a Cell object
62
- # @return [String]
63
- def range
64
- return "" unless @data.is_a?(Cell)
65
- "#{@data.row.worksheet.name}!#{data.row.r_abs}"
66
- end
67
-
68
- end
69
- end
@@ -1,70 +0,0 @@
1
- module Axlsx
2
- # This class details the anchor points for drawings.
3
- # @note The recommended way to manage drawings and charts is Worksheet#add_chart. Anchors are specified by the :start_at and :end_at options to that method.
4
- # @see Worksheet#add_chart
5
- class TwoCellAnchor
6
-
7
- # A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively
8
- # @return [Marker]
9
- attr_reader :from
10
- # A marker that returns the to cell anchor. The default to column and row are 5 and 10 respectively
11
- # @return [Marker]
12
- attr_reader :to
13
-
14
- # The frame for your chart
15
- # @return [GraphicFrame]
16
- attr_reader :graphic_frame
17
-
18
- # Creates a new TwoCellAnchor object
19
- # @param [Drawing] drawing
20
- # @param [Chart] chart
21
- # @option options [Array] start_at
22
- # @option options [Array] end_at
23
- def initialize(drawing, chart, options)
24
- raise ArgumentError, "TwoCellAnchor.chart must be a Chart" unless chart.is_a? Chart
25
- @from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
26
- @graphic_frame = GraphicFrame.new(chart)
27
- # BUG? what happens if :start_at is not defined?
28
- self.start_at(options[:start_at][0], options[:start_at][1]) if options[:start_at].is_a?(Array)
29
- self.end_at(options[:end_at][0], options[:end_at][1]) if options[:end_at].is_a?(Array)
30
- drawing.anchors << self
31
- end
32
-
33
- # This is a short cut method to set the start anchor position
34
- # @param [Integer] x The column
35
- # @param [Integer] y The row
36
- # @return [Marker]
37
- def start_at(x, y)
38
- @from.col = x
39
- @from.row = y
40
- @from
41
- end
42
-
43
- # This is a short cut method to set the end anchor position
44
- # @param [Integer] x The column
45
- # @param [Integer] y The row
46
- # @return [Marker]
47
- def end_at(x, y)
48
- @to.col = x
49
- @to.row = y
50
- @to
51
- end
52
-
53
- # Serializes the two cell anchor
54
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
55
- # @return [String]
56
- def to_xml(xml)
57
- #build it for now, break it down later!
58
- xml.send('xdr:twoCellAnchor') {
59
- xml.send('xdr:from') {
60
- from.to_xml(xml)
61
- }
62
- xml.send('xdr:to') {
63
- to.to_xml(xml)
64
- }
65
- @graphic_frame.to_xml(xml)
66
- xml.send('xdr:clientData')
67
- }
68
- end
69
- end
70
- end
@@ -1,34 +0,0 @@
1
- module Axlsx
2
- # the ValAxis class defines a chart value axis.
3
- class ValAxis < Axis
4
-
5
- # This element specifies whether the value axis crosses the category axis between categories.
6
- # must be one of [:between, :midCat]
7
- # @return [Symbol]
8
- attr_accessor :crossesBetween
9
-
10
- # Creates a new ValAxis object
11
- # @param [Integer] axId the id of this axis
12
- # @param [Integer] crossAx the id of the perpendicular axis
13
- # @option options [Symbol] axPos
14
- # @option options [Symbol] crosses
15
- # @option options [Symbol] tickLblPos
16
- # @option options [Symbol] crossesBetween
17
- def initialize(axId, crossAx, options={})
18
- super(axId, crossAx, options)
19
- @crossesBetween = :between
20
- end
21
-
22
- # Serializes the value axis
23
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
24
- # @return [String]
25
- def to_xml(xml)
26
- xml.send('c:valAx') {
27
- super(xml)
28
- xml.send('c:axId', :val=>@axId)
29
- @scaling.to_xml(xml)
30
- xml.send('c:crossesBetween', :val=>@crossesBetween)
31
- }
32
- end
33
- end
34
- end
@@ -1,29 +0,0 @@
1
- module Axlsx
2
-
3
- class ValAxisData < SimpleTypedList
4
- def initialize(data=[])
5
- super Object
6
- @list.concat data if data.is_a?(Array)
7
- end
8
-
9
- def to_xml(xml)
10
- xml.send('c:val') {
11
- xml.send('c:numRef') {
12
- xml.send('c:f', Axlsx::cell_range(@list))
13
- xml.send('c:numCache') {
14
- xml.send('c:formatCode', 'General')
15
- xml.send('c:ptCount', :val=>data.size)
16
- each_with_index do |item, index|
17
- v = item.is_a?(Cell) ? item.value : item
18
- xml.send('c:pt', :idx=>index) {
19
- xml.send('c:v', v)
20
- }
21
- end
22
- }
23
- }
24
- }
25
- end
26
-
27
- end
28
-
29
- end
@@ -1,21 +0,0 @@
1
- module Axlsx
2
-
3
-
4
- attr_accessor :rotX
5
- attr_accessor :hPercent
6
- attr_accessor :rotY
7
- attr_accessor :depthPercent
8
- attr_accessor :rAngAx
9
- attr_accessor :perspective
10
-
11
- def initialize(options={})
12
-
13
- end
14
-
15
- def rotX=(v) DataTypeValidator.validate "#{self.class}.rotX", [Integer, Fixnum], v, lambda {|v| v >= -90 && v <= 90 }; @rotX = v; end
16
-
17
- def to_xml(xml)
18
-
19
- end
20
-
21
- end
@@ -1,181 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # Create Office Open XML Spreadsheets (xlsx) with safe and full control over cell styles, automatically resized column widths and 3D pie charts.
3
- module Axlsx
4
- # Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
5
- # xlsx document including valdation and serialization.
6
- class Package
7
-
8
- # The workbook this package will serialize or validate.
9
- # @attribute
10
- # @return [Workbook] If no workbook instance has been assigned with this package a new Workbook instance is returned.
11
- # @raise ArgumentError if workbook parameter is not a Workbook instance.
12
- # @note As there are multiple ways to instantiate a workbook for the package,
13
- # here are a few examples:
14
- # # assign directly during package instanciation
15
- # wb = Package.new(:workbook => Workbook.new).workbook
16
- #
17
- # # get a fresh workbook automatically from the package
18
- # wb = Pacakge.new().workbook
19
- # # # set the workbook after creating the package
20
- # wb = Package.new().workbook = Workbook.new
21
- attr_accessor :workbook
22
-
23
- # Initializes your package
24
- #
25
- # @param [Hash] options A hash that you can use to specify the author and workbook for this package.
26
- # @option options [String] :author The author of the document
27
- # @option options [Workbook] :workbook The workbook associated with this package.
28
- # @example Package.new :author => 'you!', :workbook => Workbook.new
29
- def initialize(options={})
30
- @core, @app = Core.new, App.new
31
- @core.creator = options[:author] || @core.creator
32
- self.workbook= options[:workbook] if options[:workbook]
33
- end
34
-
35
- def workbook=(workbook) DataTypeValidator.validate "Package.workbook", Workbook, workbook; @workbook = workbook; end
36
-
37
- def workbook
38
- @workbook || @workbook = Workbook.new
39
- end
40
-
41
- # Serialize your workbook to disk as an xlsx document.
42
- #
43
- # @param [File] output The file you want to serialize your package to
44
- # @param [Boolean] confirm_valid Validate the package prior to serialization.
45
- # @return [Boolean] False if confirm_valid and validation errors exist. True if the package was serialized
46
- # @note A tremendous amount of effort has gone into ensuring that you cannot create invalid xlsx documents.
47
- # confirm_valid should be used in the rare case that you cannot open the serialized file.
48
- # @see Package#validate
49
- # @example
50
- # # This is how easy it is to create a valid xlsx file. Of course you might want to add a sheet or two, and maybe some data, styles and charts.
51
- # # Take a look at the README for an example of how to do it!
52
- # f = File.open('test.xlsx', 'w')
53
- # Package.new.serialize(f)
54
- #
55
- # # You will find a file called test.xlsx
56
- def serialize(output, confirm_valid=false)
57
- return false unless !confirm_valid || self.validate.empty?
58
- Zip::ZipOutputStream.open(output.path) do |zip|
59
- parts.each{ |part| zip.put_next_entry(part[:entry]); zip.puts(part[:doc]) }
60
- end
61
- true
62
- end
63
-
64
- # Validate all parts of the package against xsd schema.
65
- # @return [Array] An array of all validation errors found.
66
- # @note This gem includes all schema from OfficeOpenXML-XMLSchema-Transitional.zip and OpenPackagingConventions-XMLSchema.zip
67
- # as per ECMA-376, Third edition. opc schema require an internet connection to import remote schema from dublin core for dc,
68
- # dcterms and xml namespaces. Those remote schema are included in this gem, and the original files have been altered to
69
- # refer to the local versions.
70
- #
71
- # If by chance you are able to creat a package that does not validate it indicates that the internal
72
- # validation is not robust enough and needs to be improved. Please report your errors to the gem author.
73
- # @see http://www.ecma-international.org/publications/standards/Ecma-376.htm
74
- # @example
75
- # # The following will output any error messages found in serialization.
76
- # p = Axlsx::Package.new
77
- # # ... code to create sheets, charts, styles etc.
78
- # p.validate.each { |error| puts error.message }
79
- def validate
80
- errors = []
81
- parts.each { |part| errors.concat validate_single_doc(part[:schema], part[:doc]) }
82
- errors
83
- end
84
-
85
- private
86
-
87
- # The parts of a package
88
- # @return [Array] An array of hashes that define the entry, document and schema for each part of the package.
89
- # @private
90
- def parts
91
- @parts = [
92
- {:entry => RELS_PN, :doc => relationships.to_xml, :schema => RELS_XSD},
93
- {:entry => CORE_PN, :doc => @core.to_xml, :schema => CORE_XSD},
94
- {:entry => APP_PN, :doc => @app.to_xml, :schema => APP_XSD},
95
- {:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships.to_xml, :schema => RELS_XSD},
96
- {:entry => WORKBOOK_PN, :doc => workbook.to_xml, :schema => SML_XSD},
97
- {:entry => CONTENT_TYPES_PN, :doc => content_types.to_xml, :schema => CONTENT_TYPES_XSD},
98
- {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml, :schema => SML_XSD}
99
- ]
100
- workbook.drawings.each do |drawing|
101
- @parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml, :schema => RELS_XSD}
102
- @parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml, :schema => DRAWING_XSD}
103
- end
104
-
105
- workbook.charts.each do |chart|
106
- @parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml, :schema => DRAWING_XSD}
107
- end
108
-
109
- workbook.worksheets.each do |sheet|
110
- @parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml, :schema => RELS_XSD}
111
- @parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml, :schema => SML_XSD}
112
- end
113
- @parts
114
- end
115
-
116
- # Performs xsd validation for a signle document
117
- #
118
- # @param [String] schema path to the xsd schema to be used in validation.
119
- # @param [String] doc The xml text to be validated
120
- # @return [Array] An array of all validation errors encountered.
121
- # @private
122
- def validate_single_doc(schema, doc)
123
- schema = Nokogiri::XML::Schema(File.open(schema))
124
- doc = Nokogiri::XML(doc)
125
-
126
- errors = []
127
- schema.validate(doc).each do |error|
128
- errors << error
129
- end
130
- errors
131
- end
132
-
133
- # Appends override objects for drawings, charts, and sheets as they exist in your workbook to the default content types.
134
- # @return [ContentType]
135
- # @private
136
- def content_types
137
- c_types = base_content_types
138
- workbook.drawings.each do |drawing|
139
- c_types << Axlsx::Override.new(:PartName => "/xl/#{drawing.pn}",
140
- :ContentType => DRAWING_CT)
141
- end
142
- workbook.charts.each do |chart|
143
- c_types << Axlsx::Override.new(:PartName => "/xl/#{chart.pn}",
144
- :ContentType => CHART_CT)
145
- end
146
- workbook.worksheets.each do |sheet|
147
- c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}",
148
- :ContentType => WORKSHEET_CT)
149
- end
150
- c_types
151
- end
152
-
153
- # Creates the minimum content types for generating a valid xlsx document.
154
- # @return [ContentType]
155
- # @private
156
- def base_content_types
157
- c_types = ContentType.new()
158
- c_types << Default.new(:ContentType => RELS_CT, :Extension => RELS_EX)
159
- c_types << Default.new(:Extension => XML_EX, :ContentType => XML_CT)
160
- c_types << Override.new(:PartName => "/#{APP_PN}", :ContentType => APP_CT)
161
- c_types << Override.new(:PartName => "/#{CORE_PN}", :ContentType => CORE_CT)
162
- c_types << Override.new(:PartName => "/xl/#{STYLES_PN}", :ContentType => STYLES_CT)
163
- c_types << Axlsx::Override.new(:PartName => "/#{WORKBOOK_PN}", :ContentType => WORKBOOK_CT)
164
- c_types.lock
165
- c_types
166
- end
167
-
168
- # Creates the relationships required for a valid xlsx document
169
- # @return [Relationships]
170
- # @private
171
- def relationships
172
- rels = Axlsx::Relationships.new
173
- rels << Relationship.new(WORKBOOK_R, WORKBOOK_PN)
174
- rels << Relationship.new(CORE_R, CORE_PN)
175
- rels << Relationship.new(APP_R, APP_PN)
176
- rels.lock
177
- rels
178
- end
179
- end
180
- end
181
-