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
@@ -54,10 +54,21 @@ module Axlsx
54
54
  # # You will find a file called test.xlsx
55
55
  def serialize(output, confirm_valid=false)
56
56
  return false unless !confirm_valid || self.validate.empty?
57
- f = File.new(output, "w")
58
- Zip::ZipOutputStream.open(f.path) do |zip|
59
- parts.each{ |part| zip.put_next_entry(part[:entry]); zip.puts(part[:doc]) }
57
+ p = parts
58
+ Zip::ZipOutputStream.open(output) do |zip|
59
+ p.each do |part|
60
+ zip.put_next_entry(part[:entry]); zip.puts(part[:doc]) unless part[:doc].nil?
61
+ end
60
62
  end
63
+ Zip::ZipFile.open(output) do |zip|
64
+ p.each do |part|
65
+ if part[:path]
66
+ zip.add(part[:entry], part[:path], &proc{ true })
67
+ end
68
+ end
69
+ end
70
+
71
+
61
72
  true
62
73
  end
63
74
 
@@ -78,7 +89,7 @@ module Axlsx
78
89
  # p.validate.each { |error| puts error.message }
79
90
  def validate
80
91
  errors = []
81
- parts.each { |part| errors.concat validate_single_doc(part[:schema], part[:doc]) }
92
+ parts.each { |part| errors.concat validate_single_doc(part[:schema], part[:doc]) unless part[:schema].nil? }
82
93
  errors
83
94
  end
84
95
 
@@ -105,7 +116,11 @@ module Axlsx
105
116
  workbook.charts.each do |chart|
106
117
  @parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml, :schema => DRAWING_XSD}
107
118
  end
108
-
119
+
120
+ workbook.images.each do |image|
121
+ @parts << {:entry => "xl/#{image.pn}", :path => image.image_src}
122
+ end
123
+
109
124
  workbook.worksheets.each do |sheet|
110
125
  @parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml, :schema => RELS_XSD}
111
126
  @parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml, :schema => SML_XSD}
@@ -147,6 +162,17 @@ module Axlsx
147
162
  c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}",
148
163
  :ContentType => WORKSHEET_CT)
149
164
  end
165
+ exts = workbook.images.map { |image| image.extname }
166
+ exts.uniq.each do |ext|
167
+ ct = if ['jpeg', 'jpg'].include?(ext)
168
+ JPEG_CT
169
+ elsif ext == 'gif'
170
+ GIF_CT
171
+ elsif ext == 'png'
172
+ PNG_CT
173
+ end
174
+ c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext )
175
+ end
150
176
  c_types
151
177
  end
152
178
 
@@ -29,8 +29,7 @@ module Axlsx
29
29
  def Target=(v) Axlsx::validate_string v; @Target = v end
30
30
  def Type=(v) Axlsx::validate_relationship_type v; @Type = v end
31
31
 
32
- # Serializes the relationship
33
- # TODO: use object.rId to get this infomation
32
+ # Serializes the relationship
34
33
  # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
35
34
  # @param [String] rId the reference id of the object.
36
35
  # @return [String]
@@ -70,6 +70,9 @@ module Axlsx
70
70
  # chart rels namespace
71
71
  CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
72
72
 
73
+ # image rels namespace
74
+ IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
75
+
73
76
  # table content type
74
77
  TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
75
78
 
@@ -100,12 +103,30 @@ module Axlsx
100
103
  # chart content type
101
104
  CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
102
105
 
106
+ # jpeg content type
107
+ JPEG_CT = "image/jpeg"
108
+
109
+ # gif content type
110
+ GIF_CT = "image/gif"
111
+
112
+ # png content type
113
+ PNG_CT = "image/png"
114
+
103
115
  #drawing content type
104
116
  DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
105
117
 
106
118
  # xml content type extensions
107
119
  XML_EX = "xml"
108
120
 
121
+ # jpeg extension
122
+ JPEG_EX = "jpeg"
123
+
124
+ # gif extension
125
+ GIF_EX = "gif"
126
+
127
+ # png extension
128
+ PNG_EX = "png"
129
+
109
130
  # rels content type extension
110
131
  RELS_EX = "rels"
111
132
 
@@ -145,6 +166,9 @@ module Axlsx
145
166
  # chart part
146
167
  CHART_PN = "charts/chart%d.xml"
147
168
 
169
+ # chart part
170
+ IMAGE_PN = "media/image%d.%s"
171
+
148
172
  # App validation schema
149
173
  APP_XSD = "lib/schema/shared-documentPropertiesExtended.xsd"
150
174
 
@@ -112,14 +112,14 @@ module Axlsx
112
112
  # 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
113
113
  # @param [Any] v The value validated
114
114
  def self.validate_content_type(v)
115
- RestrictionValidator.validate :content_type, [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT], v
115
+ RestrictionValidator.validate :content_type, [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, JPEG_CT, GIF_CT, PNG_CT, DRAWING_CT], v
116
116
  end
117
117
 
118
118
  # Requires that the value is a valid relationship_type
119
119
  # XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R are allowed
120
120
  # @param [Any] v The value validated
121
121
  def self.validate_relationship_type(v)
122
- RestrictionValidator.validate :relationship_type, [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R], v
122
+ RestrictionValidator.validate :relationship_type, [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R, IMAGE_R], v
123
123
  end
124
124
 
125
125
  # Requires that the value is a valid table element type
@@ -1,4 +1,4 @@
1
1
  module Axlsx
2
2
  # version
3
- VERSION="1.0.7"
3
+ VERSION="1.0.8"
4
4
  end
@@ -44,6 +44,13 @@ require 'axlsx/workbook/worksheet/worksheet.rb'
44
44
  # @return [SimpleTypedList]
45
45
  attr_reader :charts
46
46
 
47
+ # A colllection of images associated with this workbook
48
+ # @note The recommended way to manage images is Worksheet#add_image
49
+ # @see Worksheet#add_image
50
+ # @see Pic
51
+ # @return [SimpleTypedList]
52
+ attr_reader :images
53
+
47
54
  # A colllection of drawings associated with this workbook
48
55
  # @note The recommended way to manage drawings is Worksheet#add_chart
49
56
  # @see Worksheet#add_chart
@@ -77,6 +84,7 @@ require 'axlsx/workbook/worksheet/worksheet.rb'
77
84
  @worksheets = SimpleTypedList.new Worksheet
78
85
  @drawings = SimpleTypedList.new Drawing
79
86
  @charts = SimpleTypedList.new Chart
87
+ @images = SimpleTypedList.new Pic
80
88
  self.date1904= options[:date1904] unless options[:date1904].nil?
81
89
  yield self if block_given?
82
90
  end
@@ -119,6 +119,15 @@ module Axlsx
119
119
  chart
120
120
  end
121
121
 
122
+ # Adds a media item to the worksheets drawing
123
+ # @param [Class] media_type
124
+ # @option options [] unknown
125
+ def add_image(options={})
126
+ image = drawing.add_image(options)
127
+ yield image if block_given?
128
+ image
129
+ end
130
+
122
131
  # Serializes the worksheet document
123
132
  # @return [String]
124
133
  def to_xml
@@ -188,7 +197,7 @@ module Axlsx
188
197
  # @return [Float]
189
198
  # @param [Hash] A hash of auto_fit_data
190
199
  def auto_width(col)
191
- mdw = 6.0 # maximum digit with is always 6.0 in testable fonts so instead of beating RMagick every time, I am hardcoding it here.
200
+ mdw = 6.0 # maximum digit with is always 6.0 with RMagick's default font
192
201
  mdw_count = 0
193
202
  best_guess = 1.5 #direct testing shows the results of the documented formula to be a bit too small. This is a best guess scaling
194
203
  font_scale = col[:sz].to_f / (self.workbook.styles.fonts[0].sz.to_f || 11.0)
@@ -18,13 +18,22 @@ class TestDrawing < Test::Unit::TestCase
18
18
  chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
19
19
  assert(chart.is_a?(Axlsx::Pie3DChart), "must create a chart")
20
20
  assert_equal(@ws.workbook.charts.last, chart, "must be added to workbook charts collection")
21
- assert_equal(@ws.drawing.anchors.last.graphic_frame.chart, chart, "an anchor has been created and holds a reference to this chart")
21
+ assert_equal(@ws.drawing.anchors.last.object.chart, chart, "an anchor has been created and holds a reference to this chart")
22
22
  anchor = @ws.drawing.anchors.last
23
23
  assert_equal([anchor.from.row, anchor.from.col], [0,0], "options for start at are applied")
24
24
  assert_equal([anchor.to.row, anchor.to.col], [1,1], "options for start at are applied")
25
25
  assert_equal(chart.title.text, "bob", "option for title is applied")
26
26
  end
27
27
 
28
+ def test_add_image
29
+ src = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
30
+ image = @ws.add_image(:image_src => src, :start_at=>[0,0], :width=>600, :height=>400)
31
+ assert(@ws.drawing.anchors.last.is_a?(Axlsx::OneCellAnchor))
32
+ assert(image.is_a?(Axlsx::Pic))
33
+ assert_equal(600, image.width)
34
+ assert_equal(400, image.height)
35
+ end
36
+
28
37
  def test_charts
29
38
  assert(@ws.drawing.charts.empty?)
30
39
  chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
@@ -0,0 +1,67 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestOneCellAnchor < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @p = Axlsx::Package.new
8
+ @ws = @p.workbook.add_worksheet
9
+ @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
10
+ @image = @ws.add_image :image_src => @test_img
11
+ @anchor = @image.anchor
12
+ end
13
+
14
+ def teardown
15
+ end
16
+
17
+ def test_initialization
18
+ assert(@anchor.from.col == 0)
19
+ assert(@anchor.from.row == 0)
20
+ assert(@anchor.width == 0)
21
+ assert(@anchor.height == 0)
22
+ end
23
+
24
+ def test_from
25
+ assert(@anchor.from.is_a?(Axlsx::Marker))
26
+ end
27
+
28
+ def test_object
29
+ assert(@anchor.object.is_a?(Axlsx::Pic))
30
+ end
31
+
32
+ def test_index
33
+ assert(@anchor.index, @anchor.drawing.anchors.index(@anchor))
34
+ end
35
+
36
+ def test_width
37
+ assert_raise(ArgumentError) { @anchor.width = "a" }
38
+ assert_nothing_raised { @anchor.width = 600 }
39
+ assert_equal(@anchor.width, 600)
40
+ end
41
+
42
+ def test_height
43
+ assert_raise(ArgumentError) { @anchor.height = "a" }
44
+ assert_nothing_raised { @anchor.height = 400 }
45
+ assert_equal(400, @anchor.height)
46
+ end
47
+
48
+ def test_ext
49
+ ext = @anchor.send(:ext)
50
+ assert_equal(ext[:cx], (@anchor.width * 914400 / 96))
51
+ assert_equal(ext[:cy], (@anchor.height * 914400 / 96))
52
+ end
53
+
54
+ def test_options
55
+ assert_raise(ArgumentError, 'invalid start_at') { @ws.add_image :image_src=>@test_img, :start_at=>[1] }
56
+ i = @ws.add_image :image_src=>@test_img, :start_at => [1,2], :width=>100, :height=>200, :name=>"someimage", :descr=>"a neat image"
57
+
58
+ assert_equal("a neat image", i.descr)
59
+ assert_equal("someimage", i.name)
60
+ assert_equal(200, i.height)
61
+ assert_equal(100, i.width)
62
+ assert_equal(1, i.anchor.from.col)
63
+ assert_equal(2, i.anchor.from.row)
64
+ assert_equal(@test_img, i.image_src)
65
+ end
66
+
67
+ end
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestPic < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @p = Axlsx::Package.new
8
+ ws = @p.workbook.add_worksheet
9
+ @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
10
+ @image = ws.add_image :image_src => @test_img
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def test_initialization
17
+ assert_equal(@p.workbook.images.first, @image)
18
+ assert_equal(@image.image_src, @test_img)
19
+ end
20
+
21
+ def test_name
22
+ assert_raise(ArgumentError) { @image.name = 49 }
23
+ assert_nothing_raised { @image.name = "unknown" }
24
+ assert_equal(@image.name, "unknown")
25
+ end
26
+
27
+ def test_start_at
28
+ assert_raise(ArgumentError) { @image.start_at "a", 1 }
29
+ assert_nothing_raised { @image.start_at 6, 7 }
30
+ assert_equal(@image.anchor.from.col, 6)
31
+ assert_equal(@image.anchor.from.row, 7)
32
+ end
33
+
34
+ def test_width
35
+ assert_raise(ArgumentError) { @image.width = "a" }
36
+ assert_nothing_raised { @image.width = 600 }
37
+ assert_equal(@image.width, 600)
38
+ end
39
+
40
+ def test_height
41
+ assert_raise(ArgumentError) { @image.height = "a" }
42
+ assert_nothing_raised { @image.height = 600 }
43
+ assert_equal(600, @image.height)
44
+ end
45
+
46
+ def test_image_src
47
+ assert_raise(ArgumentError) { @image.image_src = 49 }
48
+ assert_raise(ArgumentError) { @image.image_src = 'Unknown' }
49
+ assert_raise(ArgumentError) { @image.image_src = __FILE__ }
50
+ assert_nothing_raised { @image.image_src = @test_img }
51
+ assert_equal(@image.image_src, @test_img)
52
+ end
53
+
54
+ def test_descr
55
+ assert_raise(ArgumentError) { @image.descr = 49 }
56
+ assert_nothing_raised { @image.descr = "test" }
57
+ assert_equal(@image.descr, "test")
58
+ end
59
+
60
+ def test_to_xml
61
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
62
+ doc = Nokogiri::XML(@image.anchor.drawing.to_xml)
63
+ errors = []
64
+ schema.validate(doc).each do |error|
65
+ errors.push error
66
+ puts error.message
67
+ end
68
+ assert(errors.empty?, "error free validation")
69
+ end
70
+
71
+ end
@@ -16,8 +16,6 @@ class TestPackage < Test::Unit::TestCase
16
16
  assert(Axlsx::Package.new.workbook.worksheets.size == 0, 'Workbook should not have sheets by default')
17
17
  end
18
18
 
19
- # TODO this test needs better file access validation!
20
- # as does serialization!
21
19
  def test_serialization
22
20
  fname = 'axlsx_test_serialization.xlsx'
23
21
  assert_nothing_raised do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axlsx
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 7
10
- version: 1.0.7
9
+ - 8
10
+ version: 1.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Randy Morgan
@@ -114,9 +114,11 @@ files:
114
114
  - doc/Axlsx/LineSeries.html
115
115
  - doc/Axlsx/Marker.html
116
116
  - doc/Axlsx/NumFmt.html
117
+ - doc/Axlsx/OneCellAnchor.html
117
118
  - doc/Axlsx/Override.html
118
119
  - doc/Axlsx/Package.html
119
120
  - doc/Axlsx/PatternFill.html
121
+ - doc/Axlsx/Pic.html
120
122
  - doc/Axlsx/Pie3DChart.html
121
123
  - doc/Axlsx/PieSeries.html
122
124
  - doc/Axlsx/RegexValidator.html
@@ -156,119 +158,63 @@ files:
156
158
  - doc/method_list.html
157
159
  - doc/top-level-namespace.html
158
160
  - lib/axlsx/content_type/content_type.rb
159
- - lib/axlsx/content_type/content_type.rb~
160
161
  - lib/axlsx/content_type/default.rb
161
- - lib/axlsx/content_type/default.rb~
162
162
  - lib/axlsx/content_type/override.rb
163
- - lib/axlsx/content_type/override.rb~
164
163
  - lib/axlsx/doc_props/app.rb
165
- - lib/axlsx/doc_props/app.rb~
166
164
  - lib/axlsx/doc_props/core.rb
167
- - lib/axlsx/doc_props/core.rb~
168
- - lib/axlsx/drawing/#bar_series.rb#
169
165
  - lib/axlsx/drawing/axis.rb
170
- - lib/axlsx/drawing/axis.rb~
171
166
  - lib/axlsx/drawing/bar_3D_chart.rb
172
- - lib/axlsx/drawing/bar_3D_chart.rb~
173
167
  - lib/axlsx/drawing/bar_series.rb
174
- - lib/axlsx/drawing/bar_series.rb~
175
168
  - lib/axlsx/drawing/cat_axis.rb
176
- - lib/axlsx/drawing/cat_axis.rb~
177
169
  - lib/axlsx/drawing/cat_axis_data.rb
178
- - lib/axlsx/drawing/cat_axis_data.rb~
179
170
  - lib/axlsx/drawing/chart.rb
180
- - lib/axlsx/drawing/chart.rb~
181
171
  - lib/axlsx/drawing/drawing.rb
182
- - lib/axlsx/drawing/drawing.rb~
183
172
  - lib/axlsx/drawing/graphic_frame.rb
184
- - lib/axlsx/drawing/graphic_frame.rb~
185
173
  - lib/axlsx/drawing/line_3D_chart.rb
186
- - lib/axlsx/drawing/line_3D_chart.rb~
187
174
  - lib/axlsx/drawing/line_series.rb
188
- - lib/axlsx/drawing/line_series.rb~
189
175
  - lib/axlsx/drawing/marker.rb
190
- - lib/axlsx/drawing/marker.rb~
176
+ - lib/axlsx/drawing/one_cell_anchor.rb
177
+ - lib/axlsx/drawing/pic.rb
191
178
  - lib/axlsx/drawing/pie_3D_chart.rb
192
- - lib/axlsx/drawing/pie_3D_chart.rb~
193
179
  - lib/axlsx/drawing/pie_series.rb
194
- - lib/axlsx/drawing/pie_series.rb~
195
180
  - lib/axlsx/drawing/scaling.rb
196
- - lib/axlsx/drawing/scaling.rb~
197
181
  - lib/axlsx/drawing/ser_axis.rb
198
- - lib/axlsx/drawing/ser_axis.rb~
199
182
  - lib/axlsx/drawing/series.rb
200
- - lib/axlsx/drawing/series.rb~
201
183
  - lib/axlsx/drawing/series_title.rb
202
- - lib/axlsx/drawing/series_title.rb~
203
184
  - lib/axlsx/drawing/title.rb
204
- - lib/axlsx/drawing/title.rb~
205
185
  - lib/axlsx/drawing/two_cell_anchor.rb
206
- - lib/axlsx/drawing/two_cell_anchor.rb~
207
186
  - lib/axlsx/drawing/val_axis.rb
208
- - lib/axlsx/drawing/val_axis.rb~
209
187
  - lib/axlsx/drawing/val_axis_data.rb
210
- - lib/axlsx/drawing/val_axis_data.rb~
211
188
  - lib/axlsx/drawing/view_3D.rb
212
- - lib/axlsx/drawing/view_3D.rb~
213
189
  - lib/axlsx/package.rb
214
- - lib/axlsx/package.rb~
215
190
  - lib/axlsx/rels/relationship.rb
216
- - lib/axlsx/rels/relationship.rb~
217
191
  - lib/axlsx/rels/relationships.rb
218
- - lib/axlsx/rels/relationships.rb~
219
192
  - lib/axlsx/stylesheet/border.rb
220
- - lib/axlsx/stylesheet/border.rb~
221
193
  - lib/axlsx/stylesheet/border_pr.rb
222
- - lib/axlsx/stylesheet/border_pr.rb~
223
194
  - lib/axlsx/stylesheet/cell_alignment.rb
224
- - lib/axlsx/stylesheet/cell_alignment.rb~
225
195
  - lib/axlsx/stylesheet/cell_protection.rb
226
- - lib/axlsx/stylesheet/cell_protection.rb~
227
196
  - lib/axlsx/stylesheet/cell_style.rb
228
- - lib/axlsx/stylesheet/cell_style.rb~
229
197
  - lib/axlsx/stylesheet/color.rb
230
- - lib/axlsx/stylesheet/color.rb~
231
198
  - lib/axlsx/stylesheet/fill.rb
232
- - lib/axlsx/stylesheet/fill.rb~
233
199
  - lib/axlsx/stylesheet/font.rb
234
- - lib/axlsx/stylesheet/font.rb~
235
200
  - lib/axlsx/stylesheet/gradient_fill.rb
236
- - lib/axlsx/stylesheet/gradient_fill.rb~
237
201
  - lib/axlsx/stylesheet/gradient_stop.rb
238
- - lib/axlsx/stylesheet/gradient_stop.rb~
239
202
  - lib/axlsx/stylesheet/num_fmt.rb
240
- - lib/axlsx/stylesheet/num_fmt.rb~
241
203
  - lib/axlsx/stylesheet/pattern_fill.rb
242
- - lib/axlsx/stylesheet/pattern_fill.rb~
243
204
  - lib/axlsx/stylesheet/styles.rb
244
- - lib/axlsx/stylesheet/styles.rb~
245
205
  - lib/axlsx/stylesheet/table_style.rb
246
- - lib/axlsx/stylesheet/table_style.rb~
247
206
  - lib/axlsx/stylesheet/table_style_element.rb
248
- - lib/axlsx/stylesheet/table_style_element.rb~
249
207
  - lib/axlsx/stylesheet/table_styles.rb
250
- - lib/axlsx/stylesheet/table_styles.rb~
251
208
  - lib/axlsx/stylesheet/xf.rb
252
- - lib/axlsx/stylesheet/xf.rb~
253
209
  - lib/axlsx/util/constants.rb
254
- - lib/axlsx/util/constants.rb~
255
- - lib/axlsx/util/monkey_patches_for_true_zip_stream.rb~
256
210
  - lib/axlsx/util/simple_typed_list.rb
257
- - lib/axlsx/util/simple_typed_list.rb~
258
211
  - lib/axlsx/util/validators.rb
259
- - lib/axlsx/util/validators.rb~
260
- - lib/axlsx/util/xml_escape.rb~
261
212
  - lib/axlsx/version.rb
262
213
  - lib/axlsx/workbook/workbook.rb
263
- - lib/axlsx/workbook/workbook.rb~
264
214
  - lib/axlsx/workbook/worksheet/cell.rb
265
- - lib/axlsx/workbook/worksheet/cell.rb~
266
215
  - lib/axlsx/workbook/worksheet/row.rb
267
- - lib/axlsx/workbook/worksheet/row.rb~
268
216
  - lib/axlsx/workbook/worksheet/worksheet.rb
269
- - lib/axlsx/workbook/worksheet/worksheet.rb~
270
217
  - lib/axlsx.rb
271
- - lib/axlsx.rb~
272
218
  - lib/schema/dc.xsd
273
219
  - lib/schema/dc.xsd~
274
220
  - lib/schema/dcmitype.xsd
@@ -308,117 +254,66 @@ files:
308
254
  - lib/schema/wml.xsd
309
255
  - lib/schema/xml.xsd
310
256
  - test/content_type/tc_content_type.rb
311
- - test/content_type/tc_content_type.rb~
312
257
  - test/content_type/tc_default.rb
313
- - test/content_type/tc_default.rb~
314
258
  - test/content_type/tc_override.rb
315
- - test/content_type/tc_override.rb~
316
259
  - test/doc_props/tc_app.rb
317
- - test/doc_props/tc_app.rb~
318
260
  - test/doc_props/tc_core.rb
319
261
  - test/drawing/tc_axis.rb
320
- - test/drawing/tc_axis.rb~
321
262
  - test/drawing/tc_bar_3D_chart.rb
322
- - test/drawing/tc_bar_3D_chart.rb~
323
263
  - test/drawing/tc_bar_series.rb
324
- - test/drawing/tc_bar_series.rb~
325
264
  - test/drawing/tc_cat_axis.rb
326
- - test/drawing/tc_cat_axis.rb~
327
265
  - test/drawing/tc_cat_axis_data.rb
328
- - test/drawing/tc_cat_axis_data.rb~
329
266
  - test/drawing/tc_chart.rb
330
- - test/drawing/tc_chart.rb~
331
267
  - test/drawing/tc_drawing.rb
332
268
  - test/drawing/tc_graphic_frame.rb
333
- - test/drawing/tc_graphic_frame.rb~
334
269
  - test/drawing/tc_line_3d_chart.rb
335
- - test/drawing/tc_line_3d_chart.rb~
336
270
  - test/drawing/tc_line_series.rb
337
- - test/drawing/tc_line_series.rb~
338
271
  - test/drawing/tc_line_series.tc~
339
272
  - test/drawing/tc_marker.rb
340
- - test/drawing/tc_marker.rb~
273
+ - test/drawing/tc_one_cell_anchor.rb
274
+ - test/drawing/tc_pic.rb
341
275
  - test/drawing/tc_pie_3D_chart.rb
342
- - test/drawing/tc_pie_3D_chart.rb~
343
276
  - test/drawing/tc_pie_series.rb
344
- - test/drawing/tc_pie_series.rb~
345
277
  - test/drawing/tc_scaling.rb
346
- - test/drawing/tc_scaling.rb~
347
278
  - test/drawing/tc_ser_axis.rb
348
- - test/drawing/tc_ser_axis.rb~
349
279
  - test/drawing/tc_series.rb
350
- - test/drawing/tc_series.rb~
351
280
  - test/drawing/tc_series_title.rb
352
- - test/drawing/tc_series_title.rb~
353
281
  - test/drawing/tc_title.rb
354
- - test/drawing/tc_title.rb~
355
282
  - test/drawing/tc_two_cell_anchor.rb
356
- - test/drawing/tc_two_cell_anchor.rb~
357
283
  - test/drawing/tc_val_axis.rb
358
- - test/drawing/tc_val_axis.rb~
359
284
  - test/drawing/tc_val_axis_data.rb
360
- - test/drawing/tc_val_axis_data.rb~
361
285
  - test/drawing/tc_view_3D.rb
362
- - test/drawing/tc_view_3D.rb~
363
286
  - test/rels/tc_relationship.rb
364
- - test/rels/tc_relationship.rb~
365
287
  - test/rels/tc_relationships.rb
366
- - test/rels/tc_relationships.rb~
367
288
  - test/stylesheet/tc_border.rb
368
- - test/stylesheet/tc_border.rb~
369
289
  - test/stylesheet/tc_border_pr.rb
370
- - test/stylesheet/tc_border_pr.rb~
371
290
  - test/stylesheet/tc_cell_alignment.rb
372
- - test/stylesheet/tc_cell_alignment.rb~
373
291
  - test/stylesheet/tc_cell_protection.rb
374
- - test/stylesheet/tc_cell_protection.rb~
375
292
  - test/stylesheet/tc_cell_style.rb
376
- - test/stylesheet/tc_cell_style.rb~
377
293
  - test/stylesheet/tc_color.rb
378
- - test/stylesheet/tc_color.rb~
379
294
  - test/stylesheet/tc_fill.rb
380
- - test/stylesheet/tc_fill.rb~
381
295
  - test/stylesheet/tc_font.rb
382
- - test/stylesheet/tc_font.rb~
383
296
  - test/stylesheet/tc_gradient_fill.rb
384
- - test/stylesheet/tc_gradient_fill.rb~
385
297
  - test/stylesheet/tc_gradient_stop.rb
386
- - test/stylesheet/tc_gradient_stop.rb~
387
298
  - test/stylesheet/tc_num_fmt.rb
388
- - test/stylesheet/tc_num_fmt.rb~
389
299
  - test/stylesheet/tc_pattern_fill.rb
390
- - test/stylesheet/tc_pattern_fill.rb~
391
300
  - test/stylesheet/tc_styles.rb
392
301
  - test/stylesheet/tc_table_style.rb
393
- - test/stylesheet/tc_table_style.rb~
394
302
  - test/stylesheet/tc_table_style_element.rb
395
- - test/stylesheet/tc_table_style_element.rb~
396
303
  - test/stylesheet/tc_table_styles.rb
397
- - test/stylesheet/tc_table_styles.rb~
398
304
  - test/stylesheet/tc_xf.rb
399
- - test/stylesheet/tc_xf.rb~
400
- - test/tc_app.rb~
401
- - test/tc_border_pr.rb~
402
305
  - test/tc_package.rb
403
- - test/tc_package.rb~
404
- - test/tc_pie_3D_chart.rb~
405
- - test/tc_relationships.rb~
406
- - test/tc_series.rb~
407
- - test/tc_styles.rb~
408
- - test/tc_validators.rb~
409
- - test/tc_worksheet.rb~
410
306
  - test/util/tc_simple_typed_list.rb
411
307
  - test/util/tc_validators.rb
412
308
  - test/workbook/tc_workbook.rb
413
309
  - test/workbook/worksheet/tc_cell.rb
414
310
  - test/workbook/worksheet/tc_row.rb
415
- - test/workbook/worksheet/tc_row.rb~
416
311
  - test/workbook/worksheet/tc_worksheet.rb
417
- - test/workbook/worksheet/tc_worksheet.rb~
418
- - examples/#example.rb#
419
312
  - examples/example.rb
420
- - examples/example.rb~
421
- - examples/multi_chart.xlsx
313
+ - examples/image1.gif
314
+ - examples/image1.jpeg
315
+ - examples/image1.jpg
316
+ - examples/image1.png
422
317
  - LICENSE
423
318
  - README.md
424
319
  - Rakefile