axlsx 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,92 +0,0 @@
1
- module Axlsx
2
- # A Row is a single row in a worksheet.
3
- # @note The recommended way to manage rows and cells is to use Worksheet#add_row
4
- # @see Worksheet#add_row
5
- class Row
6
-
7
- # The worksheet this row belongs to
8
- # @return [Worksheet]
9
- attr_reader :worksheet
10
-
11
- # The cells this row holds
12
- # @return [SimpleTypedList]
13
- attr_reader :cells
14
-
15
- # The index of this row in the worksheet
16
- # @return [Integer]
17
- attr_reader :index
18
-
19
- # Creates a new row. New Cell objects are created based on the values, types and style options.
20
- # A new cell is created for each item in the values array. style and types options are applied as follows:
21
- # If the types option is defined and is a symbol it is applied to all the cells created.
22
- # If the types option is an array, cell types are applied by index for each cell
23
- # If the types option is not set, the cell will automatically determine its type.
24
- # If the style option is defined and is an Integer, it is applied to all cells created.
25
- # If the style option is an array, style is applied by index for each cell.
26
- # If the style option is not defined, the default style (0) is applied to each cell.
27
- # @param [Worksheet] worksheet
28
- # @option options [Array] values
29
- # @option options [Array, Symbol] types
30
- # @option options [Array, Integer] style
31
- # @see Row#array_to_cells
32
- # @see Cell
33
- def initialize(worksheet, options={})
34
- self.worksheet = worksheet
35
- @cells = SimpleTypedList.new Cell
36
- @worksheet.rows << self
37
- array_to_cells(options)
38
- end
39
-
40
- def index
41
- worksheet.rows.index(self)
42
- end
43
-
44
- # Serializes the row
45
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
46
- # @return [String]
47
- def to_xml(xml)
48
- xml.row(:r => index+1) { @cells.each { |cell| cell.to_xml(xml) } }
49
- end
50
-
51
- # Adds a singel sell to the row based on the data provided and updates the worksheet's autofit data.
52
- # @return [Cell]
53
- def add_cell(value="", options={})
54
- c = Cell.new(self, value, options)
55
- update_auto_fit_data
56
- c
57
- end
58
-
59
-
60
- private
61
-
62
- # assigns the owning worksheet for this row
63
- def worksheet=(v) DataTypeValidator.validate "Row.worksheet", Worksheet, v; @worksheet=v; end
64
-
65
- # Tell the worksheet to update autofit data for the columns based on this row's cells.
66
- # @return [SimpleTypedList]
67
- def update_auto_fit_data
68
- worksheet.send(:update_auto_fit_data, self.cells)
69
- end
70
-
71
- # Converts values, types, and style options into cells and associates them with this row.
72
- # A new cell is created for each item in the values array.
73
- # If value option is defined and is a symbol it is applied to all the cells created.
74
- # If the value option is an array, cell types are applied by index for each cell
75
- # If the style option is defined and is an Integer, it is applied to all cells created.
76
- # If the style option is an array, style is applied by index for each cell.
77
- # @option options [Array] values
78
- # @option options [Array, Symbol] types
79
- # @option options [Array, Integer] style
80
- def array_to_cells(options={})
81
- values = options[:values] || []
82
- DataTypeValidator.validate 'Row.array_to_cells', Array, values
83
- types, style = options[:types], options[:style]
84
- values.each_with_index do |value, index|
85
- cell_style = style.is_a?(Array) ? style[index] : style
86
- cell_type = types.is_a?(Array)? types[index] : types
87
- Cell.new(self, value, :style=>cell_style, :type=>cell_type)
88
- end
89
- end
90
- end
91
-
92
- end
@@ -1,194 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module Axlsx
3
-
4
- # The Worksheet class represents a worksheet in the workbook.
5
- class Worksheet
6
-
7
- # The name of the worksheet
8
- # If not specified, it is Sheet#{index} where index is this worksheets index in the workbook's worksheet collection.
9
- # @return [String]
10
- attr_accessor :name
11
-
12
- # The workbook that owns this worksheet
13
- # @return [Workbook]
14
- attr_reader :workbook
15
-
16
- # The worksheet relationships. This is managed automatically by the worksheet
17
- # @return [Relationships]
18
- attr_reader :relationships
19
-
20
- # The rows in this worksheet
21
- # @note The recommended way to manage rows is Worksheet#add_row
22
- # @return [SimpleTypedList]
23
- # @see Worksheet#add_row
24
- attr_reader :rows
25
-
26
- # The drawing associated with this worksheet.
27
- # @note the recommended way to work with drawings and charts is Worksheet#add_chart
28
- # @return [Drawing]
29
- # @see Worksheet#add_chart
30
- attr_reader :drawing
31
-
32
- # An array of content based calculated column widths.
33
- # @note a single auto fit data item is a hash with :longest => [String] and :sz=> [Integer] members.
34
- # @return [Array] of Hash
35
- attr_reader :auto_fit_data
36
-
37
- # The part name of this worksheet
38
- # @return [String]
39
- attr_reader :pn
40
-
41
- # The relationship part name of this worksheet
42
- # @return [String]
43
- attr_reader :rels_pn
44
-
45
- # The relationship Id of thiw worksheet
46
- # @return [String]
47
- attr_reader :rId
48
-
49
- # The index of this worksheet in the owning Workbook's worksheets list.
50
- # @return [Index]
51
- attr_reader :index
52
-
53
- # TODO Merge Cells
54
- # attr_reader :merge_cells
55
-
56
- # Creates a new worksheet.
57
- # @note the recommended way to manage worksheets is Workbook#add_worksheet
58
- # @see Workbook#add_worksheet
59
- # @option options [String] name The name of this sheet.
60
- def initialize(wb, options={})
61
- @rows = SimpleTypedList.new Row
62
- self.workbook = wb
63
- @workbook.worksheets << self
64
- @auto_fit_data = []
65
- self.name = options[:name] || "Sheet" + (index+1).to_s
66
- @magick_draw = Magick::Draw.new
67
- end
68
-
69
-
70
- def name=(v) DataTypeValidator.validate "Worksheet.name", String, v; @name=v end
71
-
72
- def pn
73
- "#{WORKSHEET_PN % (index+1)}"
74
- end
75
-
76
- def rels_pn
77
- "#{WORKSHEET_RELS_PN % (index+1)}"
78
- end
79
-
80
- def rId
81
- "rId#{index+1}"
82
- end
83
-
84
- def index
85
- @workbook.worksheets.index(self)
86
- end
87
-
88
- def drawing
89
- @drawing || @drawing = Axlsx::Drawing.new(self)
90
- end
91
-
92
- # Adds a row to the worksheet and updates auto fit data
93
- # @return [Row]
94
- # @option options [Array] values
95
- # @option options [Array, Symbol] types
96
- # @option options [Array, Integer] style
97
- def add_row(options={})
98
- Row.new(self, options)
99
- update_auto_fit_data @rows.last.cells
100
- yield @rows.last if block_given?
101
- @rows.last
102
- end
103
-
104
- # Adds a chart to this worksheets drawing.
105
- # @param [Class] chart_type
106
- # @option options [Array] start_at
107
- # @option options [Array] end_at
108
- # @option options [Cell, String] title
109
- def add_chart(chart_type, options={})
110
- chart = drawing.add_chart(chart_type, options)
111
- yield chart if block_given?
112
- chart
113
- end
114
-
115
- # Serializes the worksheet document
116
- # @return [String]
117
- def to_xml
118
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
119
- xml.worksheet(:xmlns => XML_NS, :'xmlns:r' => XML_NS_R) {
120
- if @auto_fit_data.size > 0
121
- xml.cols {
122
- @auto_fit_data.each_with_index do |col, index|
123
- min_max = index+1
124
- xml.col(:min=>min_max, :max=>min_max, :width => auto_width(col), :customWidth=>"true")
125
- end
126
- }
127
- end
128
- xml.sheetData {
129
- @rows.each do |row|
130
- row.to_xml(xml)
131
- end
132
- }
133
- xml.drawing :"r:id"=>"rId1" if @drawing
134
- }
135
- end
136
- builder.to_xml(:indent=>0, :save_with=>0)
137
- end
138
-
139
- # The worksheet's relationships.
140
- def relationships
141
- r = Relationships.new
142
- r << Relationship.new(DRAWING_R, "../#{@drawing.pn}") if @drawing
143
- r
144
- end
145
-
146
- private
147
-
148
- # assigns the owner workbook for this worksheet
149
- def workbook=(v) DataTypeValidator.validate "Worksheet.workbook", Workbook, v; @workbook = v; end
150
-
151
- # Updates auto fit data.
152
- # Autofit data attempts to determine the cell in a column that has the greatest width by comparing the length of the text multiplied by the size of the font.
153
- # @return [Array] of Cell objects
154
- # @param [Array] cells an array of cells
155
- def update_auto_fit_data(cells)
156
- styles = self.workbook.styles
157
- cellXfs, fonts = styles.cellXfs, styles.fonts
158
- sz = fonts[0].sz
159
-
160
- cells.each_with_index do |item, index|
161
- col = @auto_fit_data[index] || {:longest=>"", :sz=>sz}
162
- cell_xf = cellXfs[item.style]
163
- font = fonts[cell_xf.fontId || 0]
164
- sz = font.sz || sz
165
-
166
- if (col[:longest].scan(/./mu).size * col[:sz]) < (item.value.to_s.scan(/./mu).size * sz)
167
- col[:sz] = sz
168
- col[:longest] = item.value.to_s
169
- end
170
- @auto_fit_data[index] = col
171
- end
172
- cells
173
- end
174
-
175
- # Determines the proper width for a column based on content.
176
- # @note
177
- # From ECMA docs
178
- # Column width measured as the number of characters of the maximum digit width of the numbers 0 .. 9 as
179
- # rendered in the normal style's font. There are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.
180
- # width = Truncate([{Number of Characters} * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256
181
- # @return [Float]
182
- # @param [Hash] A hash of auto_fit_data
183
- def auto_width(col)
184
- 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.
185
- mdw_count = 0
186
- 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
187
- font_scale = col[:sz].to_f / (self.workbook.styles.fonts[0].sz.to_f || 11.0)
188
- col[:longest].scan(/./mu).each do |i|
189
- mdw_count +=1 if @magick_draw.get_type_metrics(i).width >= mdw
190
- end
191
- ((mdw_count * mdw + 5) / mdw * 256) / 256.0 * best_guess * font_scale
192
- end
193
- end
194
- end
@@ -1,81 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestContentType < Test::Unit::TestCase
5
- def setup
6
- @package = Axlsx::Package.new
7
- @doc = Nokogiri::XML(@package.send(:content_types).to_xml)
8
- end
9
-
10
- def test_valid_document
11
- schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
12
- errors = []
13
- schema.validate(@doc).each do |error|
14
- puts error.message
15
- errors << error
16
- end
17
- assert_equal(errors.size, 0, "[Content Types].xml Invalid" + errors.map{ |e| e.message }.to_s)
18
- end
19
-
20
- def test_pre_built_types
21
-
22
- o_path = "Types Override [@ContentType='%s']"
23
- d_path = "Types Default [@ContentType='%s']"
24
-
25
- #default
26
- assert_equal(@doc.css("Types Default").size, 2, "There should be 2 default types")
27
-
28
- node = @doc.css(d_path % Axlsx::XML_CT).first
29
- assert_equal(node["Extension"], "#{Axlsx::XML_EX}", "xml content type invalid")
30
-
31
- node = @doc.css(d_path % Axlsx::RELS_CT).first
32
- assert_equal(node["Extension"],"#{Axlsx::RELS_EX}", "relationships content type invalid")
33
-
34
- #overrride
35
- assert_equal(@doc.css("Types Override").size, 4, "There should be 4 Override types")
36
-
37
- node = @doc.css(o_path % Axlsx::APP_CT).first
38
- assert_equal(node["PartName"], "/#{Axlsx::APP_PN}", "App part name invalid")
39
-
40
- node = @doc.css(o_path % Axlsx::CORE_CT).first
41
- assert_equal(node["PartName"], "/#{Axlsx::CORE_PN}", "Core part name invalid")
42
-
43
- node = @doc.css(o_path % Axlsx::STYLES_CT).first
44
- assert_equal(node["PartName"], "/xl/#{Axlsx::STYLES_PN}", "Styles part name invalid")
45
-
46
- node = @doc.css(o_path % Axlsx::WORKBOOK_CT).first
47
- assert_equal(node["PartName"], "/#{Axlsx::WORKBOOK_PN}", "Workbook part invalid")
48
- end
49
-
50
- def test_should_get_worksheet_for_worksheets
51
- o_path = "Types Override [@ContentType='%s']"
52
-
53
- ws = @package.workbook.add_worksheet
54
- doc = Nokogiri::XML(@package.send(:content_types).to_xml)
55
- assert_equal(doc.css("Types Override").size, 5, "adding a worksheet should add another type")
56
- assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
57
-
58
- ws = @package.workbook.add_worksheet
59
- doc = Nokogiri::XML(@package.send(:content_types).to_xml)
60
- assert_equal(doc.css("Types Override").size, 6, "adding workship should add another type")
61
- assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
62
-
63
- end
64
-
65
- def test_drawings_and_charts_need_content_types
66
- o_path = "Types Override [@ContentType='%s']"
67
- ws = @package.workbook.add_worksheet
68
-
69
- c = ws.add_chart Axlsx::Pie3DChart
70
- doc = Nokogiri::XML(@package.send(:content_types).to_xml)
71
- assert_equal(doc.css("Types Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}")
72
- assert_equal(doc.css(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
73
- assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
74
-
75
- c = ws.add_chart Axlsx::Pie3DChart
76
- doc = Nokogiri::XML(@package.send(:content_types).to_xml)
77
- assert_equal(doc.css("Types Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}")
78
- assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
79
- end
80
-
81
- end
@@ -1,40 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestDefault < Test::Unit::TestCase
5
- def setup
6
- end
7
- def teardown
8
- end
9
- def test_initialization_requires_Extension_and_ContentType
10
- assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new }
11
- assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :Extension=>"xml" }
12
- assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :ContentType=>"asdf" }
13
-
14
- assert_nothing_raised {Axlsx::Default.new :Extension=>"foo", :ContentType=>Axlsx::XML_CT}
15
-
16
- end
17
- def test_content_type_restriction
18
- assert_raise(ArgumentError, "raises argument error if invlalid ContentType is") { Axlsx::Default.new :ContentType=>"asdf" }
19
- end
20
-
21
- def test_to_xml
22
- schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
23
- type = Axlsx::Default.new :Extension=>"xml", :ContentType=>Axlsx::XML_CT
24
- builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
25
- xml.Types(:xmlns => Axlsx::XML_NS_T) {
26
- type.to_xml(xml)
27
- }
28
- end
29
- doc = Nokogiri::XML(builder.to_xml)
30
- errors = []
31
- schema.validate(doc).each do |error|
32
- puts error.message
33
- errors << error
34
- end
35
- assert_equal(errors.size, 0, "[Content Types].xml Invalid" + errors.map{ |e| e.message }.to_s)
36
-
37
- end
38
-
39
-
40
- end
@@ -1,40 +0,0 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
3
-
4
- class TestOverride < Test::Unit::TestCase
5
- def setup
6
- end
7
- def teardown
8
- end
9
- def test_initialization_requires_Extension_and_ContentType
10
- err = "requires PartName and ContentType options"
11
- assert_raise(ArgumentError, err) { Axlsx::Override.new }
12
- assert_raise(ArgumentError, err) { Axlsx::Override.new :PartName=>"xml" }
13
- assert_raise(ArgumentError, err) { Axlsx::Override.new :ContentType=>"asdf" }
14
- assert_nothing_raised {Axlsx::Override.new :PartName=>"foo", :ContentType=>Axlsx::CHART_CT}
15
- end
16
-
17
- def test_content_type_restriction
18
- assert_raise(ArgumentError, "requires known content type") { Axlsx::Override.new :ContentType=>"asdf" }
19
- end
20
-
21
- def test_to_xml
22
- schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
23
- type = Axlsx::Override.new :PartName=>"somechart.xml", :ContentType=>Axlsx::CHART_CT
24
- builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
25
- xml.Types(:xmlns => Axlsx::XML_NS_T) {
26
- type.to_xml(xml)
27
- }
28
- end
29
- doc = Nokogiri::XML(builder.to_xml)
30
- errors = []
31
- schema.validate(doc).each do |error|
32
- puts error.message
33
- errors << error
34
- end
35
- assert_equal(errors.size, 0, "Override content type caused invalid content_type doc" + errors.map{ |e| e.message }.to_s)
36
-
37
- end
38
-
39
-
40
- end