axlsx 1.0.16 → 1.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -0
- data/CHANGELOG.md +7 -0
- data/README.md +38 -12
- data/examples/example.rb +18 -1
- data/lib/axlsx.rb +14 -8
- data/lib/axlsx/content_type/content_type.rb +1 -0
- data/lib/axlsx/content_type/default.rb +1 -0
- data/lib/axlsx/content_type/override.rb +1 -0
- data/lib/axlsx/doc_props/app.rb +1 -1
- data/lib/axlsx/doc_props/core.rb +1 -0
- data/lib/axlsx/drawing/axis.rb +1 -0
- data/lib/axlsx/drawing/bar_3D_chart.rb +1 -0
- data/lib/axlsx/drawing/bar_series.rb +1 -0
- data/lib/axlsx/drawing/cat_axis.rb +1 -0
- data/lib/axlsx/drawing/cat_axis_data.rb +1 -0
- data/lib/axlsx/drawing/chart.rb +1 -1
- data/lib/axlsx/drawing/drawing.rb +1 -0
- data/lib/axlsx/drawing/graphic_frame.rb +1 -0
- data/lib/axlsx/drawing/hyperlink.rb +1 -1
- data/lib/axlsx/drawing/line_3D_chart.rb +1 -0
- data/lib/axlsx/drawing/line_series.rb +1 -0
- data/lib/axlsx/drawing/marker.rb +1 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +1 -0
- data/lib/axlsx/drawing/pic.rb +1 -1
- data/lib/axlsx/drawing/picture_locking.rb +1 -0
- data/lib/axlsx/drawing/pie_3D_chart.rb +1 -0
- data/lib/axlsx/drawing/pie_series.rb +1 -0
- data/lib/axlsx/drawing/scaling.rb +1 -0
- data/lib/axlsx/drawing/ser_axis.rb +1 -0
- data/lib/axlsx/drawing/series.rb +1 -0
- data/lib/axlsx/drawing/series_title.rb +1 -0
- data/lib/axlsx/drawing/title.rb +1 -0
- data/lib/axlsx/drawing/two_cell_anchor.rb +1 -0
- data/lib/axlsx/drawing/val_axis.rb +1 -0
- data/lib/axlsx/drawing/val_axis_data.rb +1 -0
- data/lib/axlsx/drawing/view_3D.rb +1 -0
- data/lib/axlsx/package.rb +63 -15
- data/lib/axlsx/rels/relationship.rb +1 -0
- data/lib/axlsx/rels/relationships.rb +1 -0
- data/lib/axlsx/stylesheet/border.rb +1 -0
- data/lib/axlsx/stylesheet/border_pr.rb +1 -0
- data/lib/axlsx/stylesheet/cell_alignment.rb +1 -0
- data/lib/axlsx/stylesheet/cell_protection.rb +1 -0
- data/lib/axlsx/stylesheet/cell_style.rb +1 -0
- data/lib/axlsx/stylesheet/color.rb +1 -0
- data/lib/axlsx/stylesheet/fill.rb +1 -0
- data/lib/axlsx/stylesheet/font.rb +1 -0
- data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
- data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
- data/lib/axlsx/stylesheet/num_fmt.rb +1 -0
- data/lib/axlsx/stylesheet/pattern_fill.rb +1 -0
- data/lib/axlsx/stylesheet/styles.rb +6 -6
- data/lib/axlsx/stylesheet/table_style.rb +1 -0
- data/lib/axlsx/stylesheet/table_style_element.rb +1 -0
- data/lib/axlsx/stylesheet/table_styles.rb +1 -0
- data/lib/axlsx/stylesheet/xf.rb +1 -0
- data/lib/axlsx/util/cbf.rb +1 -0
- data/lib/axlsx/util/constants.rb +7 -0
- data/lib/axlsx/util/ms_off_crypto.rb +1 -1
- data/lib/axlsx/util/parser.rb +1 -0
- data/lib/axlsx/util/simple_typed_list.rb +2 -1
- data/lib/axlsx/util/storage.rb +1 -0
- data/lib/axlsx/util/validators.rb +11 -2
- data/lib/axlsx/version.rb +2 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +71 -0
- data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
- data/lib/axlsx/workbook/workbook.rb +25 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +75 -37
- data/lib/axlsx/workbook/worksheet/row.rb +15 -0
- data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +35 -3
- data/test/content_type/tc_content_type.rb +2 -0
- data/test/content_type/tc_default.rb +2 -0
- data/test/content_type/tc_override.rb +1 -0
- data/test/tc_package.rb +31 -0
- data/test/workbook/tc_shared_strings_table.rb +39 -0
- data/test/workbook/tc_shared_strings_table.rb~ +8 -0
- data/test/workbook/tc_workbook.rb +8 -0
- data/test/workbook/worksheet/tc_cell.rb +13 -0
- data/test/workbook/worksheet/tc_worksheet.rb +20 -3
- metadata +126 -101
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: UTF-8
|
2
2
|
module Axlsx
|
3
3
|
# A cell in a worksheet.
|
4
4
|
# Cell stores inforamation requried to serialize a single worksheet cell to xml. You must provde the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
|
@@ -23,6 +23,14 @@ module Axlsx
|
|
23
23
|
# @see Worksheet#add_row
|
24
24
|
class Cell
|
25
25
|
|
26
|
+
|
27
|
+
# An array of available inline styes.
|
28
|
+
INLINE_STYLES = ['value', 'type', 'font_name', 'charset',
|
29
|
+
'family', 'b', 'i', 'strike','outline',
|
30
|
+
'shadow', 'condense', 'extend', 'u',
|
31
|
+
'vertAlign', 'sz', 'color', 'scheme']
|
32
|
+
|
33
|
+
|
26
34
|
# The index of the cellXfs item to be applied to this cell.
|
27
35
|
# @return [Integer]
|
28
36
|
# @see Axlsx::Styles
|
@@ -186,6 +194,24 @@ module Axlsx
|
|
186
194
|
@value = cast_value(value)
|
187
195
|
end
|
188
196
|
|
197
|
+
# The Shared Strings Table index for this cell
|
198
|
+
# @return [Integer]
|
199
|
+
attr_reader :ssti
|
200
|
+
|
201
|
+
# equality comparison to test value, type and inline style attributes
|
202
|
+
# this is how we work out if the cell needs to be added or already exists in the shared strings table
|
203
|
+
def shareable(v)
|
204
|
+
|
205
|
+
#using reject becase 1.8.7 select returns an array...
|
206
|
+
v_hash = v.instance_values.reject { |k, v| !INLINE_STYLES.include?(k) }
|
207
|
+
self_hash = self.instance_values.reject { |k, v| !INLINE_STYLES.include?(k) }
|
208
|
+
# required as color is an object, and the comparison will fail even though both use the same color.
|
209
|
+
v_hash['color'] = v_hash['color'].instance_values if v_hash['color']
|
210
|
+
self_hash['color'] = self_hash['color'].instance_values if self_hash['color']
|
211
|
+
|
212
|
+
v_hash == self_hash
|
213
|
+
end
|
214
|
+
|
189
215
|
# @return [Integer] The index of the cell in the containing row.
|
190
216
|
def index
|
191
217
|
@row.cells.index(self)
|
@@ -231,14 +257,42 @@ module Axlsx
|
|
231
257
|
self.row.worksheet.merge_cells "#{self.r}:#{range_end}" unless range_end.nil?
|
232
258
|
end
|
233
259
|
|
260
|
+
# builds an xml text run based on this cells attributes. This is extracted from to_xml so that shared strings can use it.
|
261
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this output will be added to.
|
262
|
+
# @return [String] the xml for this cell's text run
|
263
|
+
def run_xml(xml)
|
264
|
+
if (self.instance_values.keys & INLINE_STYLES).size > 0
|
265
|
+
xml.r {
|
266
|
+
xml.rPr {
|
267
|
+
xml.rFont(:val=>@font_name) if @font_name
|
268
|
+
xml.charset(:val=>@charset) if @charset
|
269
|
+
xml.family(:val=>@family) if @family
|
270
|
+
xml.b(:val=>@b) if @b
|
271
|
+
xml.i(:val=>@i) if @i
|
272
|
+
xml.strike(:val=>@strike) if @strike
|
273
|
+
xml.outline(:val=>@outline) if @outline
|
274
|
+
xml.shadow(:val=>@shadow) if @shadow
|
275
|
+
xml.condense(:val=>@condense) if @condense
|
276
|
+
xml.extend(:val=>@extend) if @extend
|
277
|
+
@color.to_xml(xml) if @color
|
278
|
+
xml.sz(:val=>@sz) if @sz
|
279
|
+
xml.u(:val=>@u) if @u
|
280
|
+
# :baseline, :subscript, :superscript
|
281
|
+
xml.vertAlign(:val=>@vertAlign) if @verAlign
|
282
|
+
# :none, major, :minor
|
283
|
+
xml.scheme(:val=>@scheme) if @scheme
|
284
|
+
}
|
285
|
+
xml.t @value.to_s
|
286
|
+
}
|
287
|
+
else
|
288
|
+
xml.t @value.to_s
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
234
292
|
# Serializes the cell
|
235
293
|
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
236
294
|
# @return [String] xml text for the cell
|
237
|
-
|
238
|
-
# Shared Strings are not used in this library. All values are set directly in the each sheet.
|
239
|
-
def to_xml(xml)
|
240
|
-
|
241
|
-
# however nokogiri does a nice 'force_encoding' which we shall remove!
|
295
|
+
def to_xml(xml)
|
242
296
|
if @type == :string
|
243
297
|
#parse formula
|
244
298
|
if @value.start_with?('=')
|
@@ -246,41 +300,20 @@ module Axlsx
|
|
246
300
|
xml.f @value.to_s.gsub('=', '')
|
247
301
|
}
|
248
302
|
else
|
249
|
-
#parse
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
xml.rPr {
|
258
|
-
xml.rFont(:val=>@font_name) if @font_name
|
259
|
-
xml.charset(:val=>@charset) if @charset
|
260
|
-
xml.family(:val=>@family) if @family
|
261
|
-
xml.b(:val=>@b) if @b
|
262
|
-
xml.i(:val=>@i) if @i
|
263
|
-
xml.strike(:val=>@strike) if @strike
|
264
|
-
xml.outline(:val=>@outline) if @outline
|
265
|
-
xml.shadow(:val=>@shadow) if @shadow
|
266
|
-
xml.condense(:val=>@condense) if @condense
|
267
|
-
xml.extend(:val=>@extend) if @extend
|
268
|
-
@color.to_xml(xml) if @color
|
269
|
-
xml.sz(:val=>@sz) if @sz
|
270
|
-
xml.u(:val=>@u) if @u
|
271
|
-
# :baseline, :subscript, :superscript
|
272
|
-
xml.vertAlign(:val=>@vertAlign) if @verAlign
|
273
|
-
# :none, major, :minor
|
274
|
-
xml.scheme(:val=>@scheme) if @scheme
|
275
|
-
}
|
276
|
-
xml.t @value.to_s
|
303
|
+
#parse shared
|
304
|
+
if @ssti
|
305
|
+
xml.c(:r => r, :s=>style, :t => :s) { xml.v ssti }
|
306
|
+
else
|
307
|
+
#parse inline string
|
308
|
+
xml.c(:r => r, :s=>style, :t => :inlineStr) {
|
309
|
+
xml.is {
|
310
|
+
run_xml(xml)
|
277
311
|
}
|
278
312
|
}
|
279
|
-
|
313
|
+
end
|
280
314
|
end
|
281
315
|
elsif @type == :time
|
282
316
|
# Using hardcoded offsets here as some operating systems will not except a 'negative' offset from the ruby epoc.
|
283
|
-
# (1970)
|
284
317
|
epoc1900 = -2209021200 #Time.local(1900, 1, 1)
|
285
318
|
epoc1904 = -2082877200 #Time.local(1904, 1, 1)
|
286
319
|
epoc = Workbook.date1904 ? epoc1904 : epoc1900
|
@@ -291,9 +324,14 @@ module Axlsx
|
|
291
324
|
end
|
292
325
|
end
|
293
326
|
|
294
|
-
|
295
327
|
private
|
296
328
|
|
329
|
+
# @see ssti
|
330
|
+
def ssti=(v)
|
331
|
+
Axlsx::validate_unsigned_int(v)
|
332
|
+
@ssti = v
|
333
|
+
end
|
334
|
+
|
297
335
|
# assigns the owning row for this cell.
|
298
336
|
def row=(v) DataTypeValidator.validate "Cell.row", Row, v; @row=v end
|
299
337
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module Axlsx
|
2
3
|
# A Row is a single row in a worksheet.
|
3
4
|
# @note The recommended way to manage rows and cells is to use Worksheet#add_row
|
@@ -12,6 +13,20 @@ module Axlsx
|
|
12
13
|
# @return [SimpleTypedList]
|
13
14
|
attr_reader :cells
|
14
15
|
|
16
|
+
# TODO 18.3.1.73
|
17
|
+
# collapsed
|
18
|
+
# customFormat
|
19
|
+
# customHeight
|
20
|
+
# hidden
|
21
|
+
# ht (height)
|
22
|
+
# outlineLevel
|
23
|
+
# ph
|
24
|
+
# s (style)
|
25
|
+
# spans
|
26
|
+
# thickTop
|
27
|
+
# thickBottom
|
28
|
+
|
29
|
+
|
15
30
|
# Creates a new row. New Cell objects are created based on the values, types and style options.
|
16
31
|
# A new cell is created for each item in the values array. style and types options are applied as follows:
|
17
32
|
# If the types option is defined and is a symbol it is applied to all the cells created.
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: UTF-8
|
2
2
|
module Axlsx
|
3
3
|
|
4
4
|
# The Worksheet class represents a worksheet in the workbook.
|
@@ -51,6 +51,12 @@ module Axlsx
|
|
51
51
|
@merged_cells = []
|
52
52
|
end
|
53
53
|
|
54
|
+
# convinience method to access all cells in this worksheet
|
55
|
+
# @return [Array] cells
|
56
|
+
def cells
|
57
|
+
rows.flatten
|
58
|
+
end
|
59
|
+
|
54
60
|
# Creates merge information for this worksheet.
|
55
61
|
# Cells can be merged by calling the merge_cells method on a worksheet.
|
56
62
|
# @example This would merge the three cells C1..E1 #
|
@@ -70,6 +76,14 @@ module Axlsx
|
|
70
76
|
end
|
71
77
|
|
72
78
|
|
79
|
+
# The demensions of a worksheet. This is not actually a required element by the spec,
|
80
|
+
# but at least a few other document readers expect this for conversion
|
81
|
+
# @return [String] the A1:B2 style reference for the first and last row column intersection in the workbook
|
82
|
+
def dimension
|
83
|
+
"#{rows.first.cells.first.r}:#{rows.last.cells.last.r}"
|
84
|
+
end
|
85
|
+
|
86
|
+
|
73
87
|
# Returns the cell or cells defined using excel style A1:B3 references.
|
74
88
|
# @param [String] cell_def the string defining the cell or range of cells
|
75
89
|
# @return [Cell, Array]
|
@@ -203,7 +217,22 @@ module Axlsx
|
|
203
217
|
end
|
204
218
|
end
|
205
219
|
end
|
206
|
-
|
220
|
+
|
221
|
+
# This is a helper method that Lets you specify a fixed width for multiple columns in a worksheet in one go.
|
222
|
+
# Axlsx is sparse, so if you have not set data for a column, you cannot set the width.
|
223
|
+
# Setting a fixed column width to nil will revert the behaviour back to calculating the width for you.
|
224
|
+
# @example This would set the first and third column widhts but leave the second column in autofit state.
|
225
|
+
# ws.column_widths 7.2, nil, 3
|
226
|
+
# @note For updating only a single column it is probably easier to just set ws.auto_fit_data[col_index][:fixed] directly
|
227
|
+
# @param [Integer|Float|Fixnum|nil] values
|
228
|
+
def column_widths(*args)
|
229
|
+
args.each_with_index do |value, index|
|
230
|
+
raise ArgumentError, "Invalid column specification" unless index < @auto_fit_data.size
|
231
|
+
Axlsx::validate_unsigned_numeric(value) unless value == nil
|
232
|
+
@auto_fit_data[index][:fixed] = value
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
207
236
|
# Adds a chart to this worksheets drawing. This is the recommended way to create charts for your worksheet. This method wraps the complexity of dealing with ooxml drawing, anchors, markers graphic frames chart objects and all the other dirty details.
|
208
237
|
# @param [Class] chart_type
|
209
238
|
# @option options [Array] start_at
|
@@ -238,6 +267,7 @@ module Axlsx
|
|
238
267
|
builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
|
239
268
|
xml.worksheet(:xmlns => XML_NS,
|
240
269
|
:'xmlns:r' => XML_NS_R) {
|
270
|
+
xml.dimension :ref=>dimension unless rows.size == 0
|
241
271
|
if @auto_fit_data.size > 0
|
242
272
|
xml.cols {
|
243
273
|
@auto_fit_data.each_with_index do |col, index|
|
@@ -288,7 +318,7 @@ module Axlsx
|
|
288
318
|
# ignore formula - there is no way for us to know the result
|
289
319
|
next if item.value.is_a?(String) && item.value.start_with?('=')
|
290
320
|
|
291
|
-
col = @auto_fit_data[index] || {:longest=>"", :sz=>sz}
|
321
|
+
col = @auto_fit_data[index] || {:longest=>"", :sz=>sz, :fixed=>nil}
|
292
322
|
cell_xf = cellXfs[item.style]
|
293
323
|
font = fonts[cell_xf.fontId || 0]
|
294
324
|
sz = item.sz || font.sz || fonts[0].sz
|
@@ -307,6 +337,8 @@ module Axlsx
|
|
307
337
|
# @return [Float]
|
308
338
|
# @param [Hash] A hash of auto_fit_data
|
309
339
|
def auto_width(col)
|
340
|
+
return col[:fixed] unless col[:fixed] == nil
|
341
|
+
|
310
342
|
mdw_count, font_scale, mdw = 0, col[:sz]/11.0, 6.0
|
311
343
|
mdw_count = col[:longest].scan(/./mu).reduce(0) do | count, char |
|
312
344
|
count +=1 if @magick_draw.get_type_metrics(char).max_advance >= mdw
|
data/test/tc_package.rb
CHANGED
@@ -21,6 +21,13 @@ class TestPackage < Test::Unit::TestCase
|
|
21
21
|
assert_raise(NoMethodError) {@package.app = nil }
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_use_shared_strings
|
25
|
+
assert_equal(@package.use_shared_strings, nil)
|
26
|
+
assert_raise(ArgumentError) {@package.use_shared_strings 9}
|
27
|
+
assert_nothing_raised {@package.use_shared_strings = true}
|
28
|
+
assert_equal(@package.use_shared_strings, @package.workbook.use_shared_strings)
|
29
|
+
end
|
30
|
+
|
24
31
|
def test_default_objects_are_created
|
25
32
|
assert(@package.instance_values["app"].is_a?(Axlsx::App), 'App object not created')
|
26
33
|
assert(@package.instance_values["core"].is_a?(Axlsx::Core), 'Core object not created')
|
@@ -69,10 +76,34 @@ class TestPackage < Test::Unit::TestCase
|
|
69
76
|
|
70
77
|
#no mystery parts
|
71
78
|
assert_equal(p.size, 12)
|
79
|
+
|
80
|
+
end
|
72
81
|
|
82
|
+
def test_shared_strings_requires_part
|
83
|
+
@package.use_shared_strings = true
|
84
|
+
p = @package.send(:parts)
|
85
|
+
assert_equal(p.select{ |part| part[:entry] =~/xl\/sharedStrings.xml/}.size, 1, "shared strings table missing")
|
73
86
|
end
|
74
87
|
|
75
88
|
def test_workbook_is_a_workbook
|
76
89
|
assert @package.workbook.is_a? Axlsx::Workbook
|
77
90
|
end
|
91
|
+
|
92
|
+
def test_base_content_types
|
93
|
+
ct = @package.send(:base_content_types)
|
94
|
+
assert(ct.select { |c| c.ContentType == Axlsx::RELS_CT }.size == 1, "rels content type missing")
|
95
|
+
assert(ct.select { |c| c.ContentType == Axlsx::XML_CT }.size == 1, "xml content type missing")
|
96
|
+
assert(ct.select { |c| c.ContentType == Axlsx::APP_CT }.size == 1, "app content type missing")
|
97
|
+
assert(ct.select { |c| c.ContentType == Axlsx::CORE_CT }.size == 1, "core content type missing")
|
98
|
+
assert(ct.select { |c| c.ContentType == Axlsx::STYLES_CT }.size == 1, "styles content type missing")
|
99
|
+
assert(ct.select { |c| c.ContentType == Axlsx::WORKBOOK_CT }.size == 1, "workbook content type missing")
|
100
|
+
assert(ct.size == 6)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_content_type_added_with_shared_strings
|
104
|
+
@package.use_shared_strings = true
|
105
|
+
ct = @package.send(:content_types)
|
106
|
+
assert(ct.select { |ct| ct.ContentType == Axlsx::SHARED_STRINGS_CT }.size == 1)
|
107
|
+
end
|
108
|
+
|
78
109
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestSharedStringsTable < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@p = Axlsx::Package.new :use_shared_strings=>true
|
8
|
+
ws = @p.workbook.add_worksheet
|
9
|
+
ws.add_row ['a', 1, 'b']
|
10
|
+
ws.add_row ['b', 1, 'c']
|
11
|
+
ws.add_row ['c', 1, 'd']
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_workbook_has_shared_strings
|
15
|
+
assert(@p.workbook.shared_strings.is_a?(Axlsx::SharedStringsTable), "shared string table was not created")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_count
|
19
|
+
sst = @p.workbook.shared_strings
|
20
|
+
assert_equal(sst.count, 6)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_unique_count
|
24
|
+
sst = @p.workbook.shared_strings
|
25
|
+
assert_equal(sst.unique_count, 4)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_valid_document
|
29
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|
30
|
+
doc = Nokogiri::XML(@p.workbook.shared_strings.to_xml)
|
31
|
+
errors = []
|
32
|
+
schema.validate(doc).each do |error|
|
33
|
+
puts error.message
|
34
|
+
errors << error
|
35
|
+
end
|
36
|
+
assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map{ |e| e.message }.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -18,6 +18,12 @@ class TestWorkbook < Test::Unit::TestCase
|
|
18
18
|
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
|
19
19
|
end
|
20
20
|
|
21
|
+
def test_shared_strings
|
22
|
+
assert_equal(@wb.use_shared_strings, nil)
|
23
|
+
assert_raise(ArgumentError) {@wb.use_shared_strings = 'bpb'}
|
24
|
+
assert_nothing_raised {@wb.use_shared_strings = :true}
|
25
|
+
end
|
26
|
+
|
21
27
|
def test_add_worksheet
|
22
28
|
assert(@wb.worksheets.empty?, "worbook has no worksheets by default")
|
23
29
|
ws = @wb.add_worksheet(:name=>"bob")
|
@@ -30,6 +36,8 @@ class TestWorkbook < Test::Unit::TestCase
|
|
30
36
|
assert(@wb.relationships.size == 1)
|
31
37
|
@wb.add_worksheet
|
32
38
|
assert(@wb.relationships.size == 2)
|
39
|
+
@wb.use_shared_strings = true
|
40
|
+
assert(@wb.relationships.size == 3)
|
33
41
|
end
|
34
42
|
|
35
43
|
def test_to_xml
|
@@ -18,6 +18,7 @@ class TestCell < Test::Unit::TestCase
|
|
18
18
|
assert_equal(@c.value, 1.0, "type option is applied and value is casted")
|
19
19
|
end
|
20
20
|
|
21
|
+
|
21
22
|
def test_style_date_data
|
22
23
|
c = Axlsx::Cell.new(@c.row, Time.now)
|
23
24
|
assert_equal(Axlsx::STYLE_DATE, c.style)
|
@@ -191,4 +192,16 @@ class TestCell < Test::Unit::TestCase
|
|
191
192
|
assert_equal(@c.row.worksheet.merged_cells.last, "A1:C1")
|
192
193
|
end
|
193
194
|
|
195
|
+
def test_equality
|
196
|
+
c2 = @row.add_cell 1, :type=>:float, :style=>1
|
197
|
+
assert(c2.shareable(@c))
|
198
|
+
c3 = @row.add_cell 2, :type=>:float, :style=>1
|
199
|
+
c4 = @row.add_cell 1, :type=>:float, :style=>1, :color => "#FFFFFFFF"
|
200
|
+
assert_equal(c4.shareable(c2) ,false)
|
201
|
+
c5 = @row.add_cell 1, :type=>:float, :style=>1, :color => "#FFFFFFFF"
|
202
|
+
assert(c5.shareable(c4))
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
|
194
207
|
end
|
@@ -28,7 +28,13 @@ class TestWorksheet < Test::Unit::TestCase
|
|
28
28
|
def test_index
|
29
29
|
assert_equal(@ws.index, @ws.workbook.worksheets.index(@ws))
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
|
+
def test_dimension
|
33
|
+
@ws.add_row [1, 2, 3]
|
34
|
+
@ws.add_row [4, 5, 6]
|
35
|
+
assert_equal @ws.dimension, "A1:C2"
|
36
|
+
end
|
37
|
+
|
32
38
|
def test_referencing
|
33
39
|
@ws.add_row [1, 2, 3]
|
34
40
|
@ws.add_row [4, 5, 6]
|
@@ -130,20 +136,31 @@ class TestWorksheet < Test::Unit::TestCase
|
|
130
136
|
@ws.add_row ["chasing windmills", "penut"], :style=>small
|
131
137
|
assert(@ws.auto_fit_data.size == 2, "a data item for each column")
|
132
138
|
|
133
|
-
assert_equal(@ws.auto_fit_data[0], {:sz=>2
|
139
|
+
assert_equal(@ws.auto_fit_data[0], {:sz => 2, :longest => "chasing windmills", :fixed=>nil}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
|
134
140
|
|
135
141
|
|
136
142
|
@ws.add_row ["mule"], :style=>big
|
137
|
-
assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
|
143
|
+
assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule", :fixed=>nil}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
|
138
144
|
end
|
139
145
|
|
140
146
|
def test_auto_width
|
141
147
|
assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fisheries"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "longer strings get a longer auto_width at the same font size")
|
142
148
|
|
143
149
|
assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fish"}) < @ws.send(:auto_width, {:sz=>12, :longest=>"fish"}), "larger fonts produce longer with with same string")
|
150
|
+
assert_equal(@ws.send(:auto_width, {:sz=>11, :longest => "This is a really long string", :fixed=>0.2}), 0.2, "fixed rules!")
|
151
|
+
end
|
144
152
|
|
153
|
+
def test_set_column_width
|
154
|
+
@ws.add_row ["chasing windmills", "penut"]
|
155
|
+
assert_equal(@ws.auto_fit_data[0][:fixed], nil, 'no fixed by default')
|
156
|
+
@ws.column_widths nil, 0.5
|
157
|
+
assert_equal(@ws.auto_fit_data[1][:fixed], 0.5, 'eat my width')
|
158
|
+
assert_raise(ArgumentError, 'reject invalid columns') { @ws.column_widths 2, 7, nil }
|
159
|
+
assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths 2, 7, -1 }
|
160
|
+
assert_raise(ArgumentError, 'only accept Integer, Float or Fixnum') { @ws.column_widths 2, 7, "-1" }
|
145
161
|
end
|
146
162
|
|
163
|
+
|
147
164
|
def test_merge_cells
|
148
165
|
assert(@ws.merged_cells.is_a?(Array))
|
149
166
|
assert_equal(@ws.merged_cells.size, 0)
|