axlsx 1.2.3 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +3 -2
- data/CHANGELOG.md +34 -1
- data/README.md +26 -37
- data/Rakefile +1 -1
- data/examples/auto_filter.rb +16 -0
- data/examples/auto_filter.xlsx +0 -0
- data/examples/example.rb +3 -2
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/skydrive/real_example.rb +6 -6
- data/examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png +0 -0
- data/examples/sprk2012/basics.rb +1 -0
- data/examples/sprk2012/basics.xlsx +0 -0
- data/examples/sprk2012/gravatar.jpeg +0 -0
- data/examples/sprk2012/hair_club.jpg +0 -0
- data/examples/sprk2012/images.rb +7 -12
- data/examples/sprk2012/images.xlsx +0 -0
- data/examples/sprk2012/line_chart.rb +56 -0
- data/examples/sprk2012/line_chart.xlsx +0 -0
- data/examples/sprk2012/sprk2012.key +0 -0
- data/examples/sprk2012/styles.rb +13 -12
- data/examples/sprk2012/styles.xlsx +0 -0
- data/examples/styles.rb +62 -0
- data/examples/styles.xlsx +0 -0
- data/lib/axlsx.rb +8 -1
- data/lib/axlsx/stylesheet/styles.rb +4 -0
- data/lib/axlsx/util/constants.rb +90 -5
- data/lib/axlsx/util/validators.rb +26 -8
- data/lib/axlsx/version.rb +2 -2
- data/lib/axlsx/workbook/workbook.rb +4 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +102 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +253 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +9 -4
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +47 -0
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +49 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +87 -4
- data/lib/axlsx/workbook/worksheet/table.rb +8 -1
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +68 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +18 -3
- data/test/stylesheet/tc_styles.rb +13 -0
- data/test/util/tc_validators.rb +8 -1
- data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
- data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
- data/test/workbook/worksheet/tc_cell.rb +5 -0
- data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
- data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
- data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +6 -1
- data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
- data/test/workbook/worksheet/tc_worksheet.rb +17 -3
- metadata +45 -7
- data/examples/~$extractive.xlsx +0 -0
- data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -35
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestTableStyleInfo < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
p = Axlsx::Package.new
|
6
|
+
@ws = p.workbook.add_worksheet
|
7
|
+
40.times do
|
8
|
+
@ws.add_row %w(aa bb cc dd ee ff gg hh ii jj kk)
|
9
|
+
end
|
10
|
+
@table = @ws.add_table(Axlsx::cell_range([@ws.rows.first.cells.first,@ws.rows.last.cells.last], false), :name => 'foo')
|
11
|
+
@options = { :show_first_column => 1,
|
12
|
+
:show_last_column => 1,
|
13
|
+
:show_row_stripes => 1,
|
14
|
+
:show_column_stripes => 1,
|
15
|
+
:name => "TableStyleDark4" }
|
16
|
+
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialize
|
21
|
+
table_style = Axlsx::TableStyleInfo.new @options
|
22
|
+
@options.each do |key, value|
|
23
|
+
assert_equal(value, table_style.send(key.to_sym))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_boolean_properties
|
28
|
+
table_style = Axlsx::TableStyleInfo.new
|
29
|
+
@options.keys.each do |key|
|
30
|
+
assert_nothing_raised { table_style.send("#{key.to_sym}=", true) }
|
31
|
+
assert_raises(ArgumentError) { table_style.send(key.to_sym, 'foo') }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def doc
|
35
|
+
@doc ||= Nokogiri::XML(Axlsx::TableStyleInfo.new(@options).to_xml_string)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_to_xml_string_first_column
|
39
|
+
assert(doc.xpath('//tableStyleInfo[@showLastColumn=1]'))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_to_xml_string_row_stripes
|
43
|
+
assert(doc.xpath('//tableStyleInfo[@showRowStripes=1]'))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_to_xml_string_column_stripes
|
47
|
+
assert(doc.xpath('//tableStyleInfo[@showColumnStripes=1]'))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_to_xml_string_name
|
51
|
+
assert(doc.xpath("//tableStyleInfo[@name=#{@options[:name]}]"))
|
52
|
+
end
|
53
|
+
end
|
@@ -246,7 +246,7 @@ class TestWorksheet < Test::Unit::TestCase
|
|
246
246
|
|
247
247
|
def test_to_xml_string_auto_filter
|
248
248
|
@ws.add_row [1, "two"]
|
249
|
-
@ws.auto_filter = "A1:B1"
|
249
|
+
@ws.auto_filter.range = "A1:B1"
|
250
250
|
doc = Nokogiri::XML(@ws.to_xml_string)
|
251
251
|
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:autoFilter[@ref="A1:B1"]').size, 1)
|
252
252
|
end
|
@@ -324,13 +324,20 @@ class TestWorksheet < Test::Unit::TestCase
|
|
324
324
|
assert_equal(0, @ws.rows.last.cells.last.value.index("\v"))
|
325
325
|
assert_equal(nil,@ws.to_xml_string.index("\v"))
|
326
326
|
end
|
327
|
+
|
328
|
+
def test_to_xml_string_with_newlines
|
329
|
+
cell_with_newline = "foo\n\r\nbar"
|
330
|
+
@ws.add_row [cell_with_newline]
|
331
|
+
assert_equal("foo\n\r\nbar", @ws.rows.last.cells.last.value)
|
332
|
+
assert_not_nil(@ws.to_xml_string.index("foo\n\r\nbar"))
|
333
|
+
end
|
327
334
|
# Make sure the XML for all optional elements (like pageMargins, autoFilter, ...)
|
328
335
|
# is generated in correct order.
|
329
336
|
def test_valid_with_optional_elements
|
330
337
|
@ws.page_margins.set :left => 9
|
331
338
|
@ws.page_setup.set :fit_to_width => 1
|
332
339
|
@ws.print_options.set :headings => true
|
333
|
-
@ws.auto_filter = "A1:C3"
|
340
|
+
@ws.auto_filter.range = "A1:C3"
|
334
341
|
@ws.merge_cells "A4:A5"
|
335
342
|
@ws.add_chart Axlsx::Pie3DChart
|
336
343
|
@ws.add_table "E1:F3"
|
@@ -417,7 +424,14 @@ class TestWorksheet < Test::Unit::TestCase
|
|
417
424
|
def test_auto_filter
|
418
425
|
assert(@ws.auto_filter.range.nil?)
|
419
426
|
assert_raise(ArgumentError) { @ws.auto_filter = 123 }
|
420
|
-
@ws.auto_filter = "A1:D9"
|
427
|
+
@ws.auto_filter.range = "A1:D9"
|
421
428
|
assert_equal(@ws.auto_filter.range, "A1:D9")
|
422
429
|
end
|
430
|
+
|
431
|
+
def test_sheet_pr_for_auto_filter
|
432
|
+
@ws.auto_filter.range = 'A1:D9'
|
433
|
+
@ws.auto_filter.add_column 0, :filters, :filter_items => [1]
|
434
|
+
doc = Nokogiri::XML(@ws.to_xml_string)
|
435
|
+
assert(doc.xpath('//sheetPr[@filterMode="true"]'))
|
436
|
+
end
|
423
437
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: axlsx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -191,7 +191,9 @@ files:
|
|
191
191
|
- lib/axlsx/workbook/defined_names.rb
|
192
192
|
- lib/axlsx/workbook/shared_strings_table.rb
|
193
193
|
- lib/axlsx/workbook/workbook.rb
|
194
|
-
- lib/axlsx/workbook/worksheet/auto_filter.rb
|
194
|
+
- lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
|
195
|
+
- lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
|
196
|
+
- lib/axlsx/workbook/worksheet/auto_filter/filters.rb
|
195
197
|
- lib/axlsx/workbook/worksheet/cell.rb
|
196
198
|
- lib/axlsx/workbook/worksheet/cfvo.rb
|
197
199
|
- lib/axlsx/workbook/worksheet/col.rb
|
@@ -210,6 +212,7 @@ files:
|
|
210
212
|
- lib/axlsx/workbook/worksheet/icon_set.rb
|
211
213
|
- lib/axlsx/workbook/worksheet/merged_cells.rb
|
212
214
|
- lib/axlsx/workbook/worksheet/page_margins.rb
|
215
|
+
- lib/axlsx/workbook/worksheet/page_set_up_pr.rb
|
213
216
|
- lib/axlsx/workbook/worksheet/page_setup.rb
|
214
217
|
- lib/axlsx/workbook/worksheet/pane.rb
|
215
218
|
- lib/axlsx/workbook/worksheet/print_options.rb
|
@@ -217,11 +220,13 @@ files:
|
|
217
220
|
- lib/axlsx/workbook/worksheet/protected_ranges.rb
|
218
221
|
- lib/axlsx/workbook/worksheet/row.rb
|
219
222
|
- lib/axlsx/workbook/worksheet/selection.rb
|
223
|
+
- lib/axlsx/workbook/worksheet/sheet_calc_pr.rb
|
220
224
|
- lib/axlsx/workbook/worksheet/sheet_data.rb
|
221
225
|
- lib/axlsx/workbook/worksheet/sheet_pr.rb
|
222
226
|
- lib/axlsx/workbook/worksheet/sheet_protection.rb
|
223
227
|
- lib/axlsx/workbook/worksheet/sheet_view.rb
|
224
228
|
- lib/axlsx/workbook/worksheet/table.rb
|
229
|
+
- lib/axlsx/workbook/worksheet/table_style_info.rb
|
225
230
|
- lib/axlsx/workbook/worksheet/tables.rb
|
226
231
|
- lib/axlsx/workbook/worksheet/worksheet.rb
|
227
232
|
- lib/axlsx/workbook/worksheet/worksheet_comments.rb
|
@@ -264,6 +269,8 @@ files:
|
|
264
269
|
- lib/schema/vml-wordprocessingDrawing.xsd
|
265
270
|
- lib/schema/wml.xsd
|
266
271
|
- lib/schema/xml.xsd
|
272
|
+
- examples/auto_filter.rb
|
273
|
+
- examples/auto_filter.xlsx
|
267
274
|
- examples/basic_charts.rb
|
268
275
|
- examples/chart_colors.rb
|
269
276
|
- examples/conditional_formatting/example_conditional_formatting.rb
|
@@ -296,10 +303,27 @@ files:
|
|
296
303
|
- examples/skydrive/axlsx.xlsx
|
297
304
|
- examples/skydrive/real_example.rb
|
298
305
|
- examples/sprk2012/basics.rb
|
306
|
+
- examples/sprk2012/basics.xlsx
|
307
|
+
- examples/sprk2012/gravatar.jpeg
|
308
|
+
- examples/sprk2012/hair_club.jpg
|
299
309
|
- examples/sprk2012/images.rb
|
310
|
+
- examples/sprk2012/images.xlsx
|
311
|
+
- examples/sprk2012/line_chart.rb
|
312
|
+
- examples/sprk2012/line_chart.xlsx
|
313
|
+
- examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png
|
314
|
+
- examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png
|
315
|
+
- examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png
|
316
|
+
- examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png
|
317
|
+
- examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png
|
318
|
+
- examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png
|
319
|
+
- examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png
|
320
|
+
- examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png
|
321
|
+
- examples/sprk2012/sprk2012.key
|
300
322
|
- examples/sprk2012/styles.rb
|
323
|
+
- examples/sprk2012/styles.xlsx
|
324
|
+
- examples/styles.rb
|
325
|
+
- examples/styles.xlsx
|
301
326
|
- examples/two_cell_anchor_image.rb
|
302
|
-
- examples/~$extractive.xlsx
|
303
327
|
- LICENSE
|
304
328
|
- README.md
|
305
329
|
- Rakefile
|
@@ -376,7 +400,9 @@ files:
|
|
376
400
|
- test/workbook/tc_defined_name.rb
|
377
401
|
- test/workbook/tc_shared_strings_table.rb
|
378
402
|
- test/workbook/tc_workbook.rb
|
379
|
-
- test/workbook/worksheet/
|
403
|
+
- test/workbook/worksheet/auto_filter/tc_auto_filter.rb
|
404
|
+
- test/workbook/worksheet/auto_filter/tc_filter_column.rb
|
405
|
+
- test/workbook/worksheet/auto_filter/tc_filters.rb
|
380
406
|
- test/workbook/worksheet/tc_cell.rb
|
381
407
|
- test/workbook/worksheet/tc_cfvo.rb
|
382
408
|
- test/workbook/worksheet/tc_col.rb
|
@@ -389,14 +415,19 @@ files:
|
|
389
415
|
- test/workbook/worksheet/tc_date_time_converter.rb
|
390
416
|
- test/workbook/worksheet/tc_icon_set.rb
|
391
417
|
- test/workbook/worksheet/tc_page_margins.rb
|
418
|
+
- test/workbook/worksheet/tc_page_set_up_pr.rb
|
392
419
|
- test/workbook/worksheet/tc_page_setup.rb
|
393
420
|
- test/workbook/worksheet/tc_pane.rb
|
394
421
|
- test/workbook/worksheet/tc_print_options.rb
|
395
422
|
- test/workbook/worksheet/tc_protected_range.rb
|
396
423
|
- test/workbook/worksheet/tc_row.rb
|
397
424
|
- test/workbook/worksheet/tc_selection.rb
|
425
|
+
- test/workbook/worksheet/tc_sheet_calc_pr.rb
|
426
|
+
- test/workbook/worksheet/tc_sheet_pr.rb
|
398
427
|
- test/workbook/worksheet/tc_sheet_protection.rb
|
399
428
|
- test/workbook/worksheet/tc_sheet_view.rb
|
429
|
+
- test/workbook/worksheet/tc_table.rb
|
430
|
+
- test/workbook/worksheet/tc_table_style_info.rb
|
400
431
|
- test/workbook/worksheet/tc_worksheet.rb
|
401
432
|
- test/workbook/worksheet/tc_worksheet_hyperlink.rb
|
402
433
|
homepage: https://github.com/randym/axlsx
|
@@ -419,7 +450,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
419
450
|
version: '0'
|
420
451
|
segments:
|
421
452
|
- 0
|
422
|
-
hash:
|
453
|
+
hash: 2473429157853002876
|
423
454
|
requirements: []
|
424
455
|
rubyforge_project:
|
425
456
|
rubygems_version: 1.8.24
|
@@ -498,7 +529,9 @@ test_files:
|
|
498
529
|
- test/workbook/tc_defined_name.rb
|
499
530
|
- test/workbook/tc_shared_strings_table.rb
|
500
531
|
- test/workbook/tc_workbook.rb
|
501
|
-
- test/workbook/worksheet/
|
532
|
+
- test/workbook/worksheet/auto_filter/tc_auto_filter.rb
|
533
|
+
- test/workbook/worksheet/auto_filter/tc_filter_column.rb
|
534
|
+
- test/workbook/worksheet/auto_filter/tc_filters.rb
|
502
535
|
- test/workbook/worksheet/tc_cell.rb
|
503
536
|
- test/workbook/worksheet/tc_cfvo.rb
|
504
537
|
- test/workbook/worksheet/tc_col.rb
|
@@ -511,14 +544,19 @@ test_files:
|
|
511
544
|
- test/workbook/worksheet/tc_date_time_converter.rb
|
512
545
|
- test/workbook/worksheet/tc_icon_set.rb
|
513
546
|
- test/workbook/worksheet/tc_page_margins.rb
|
547
|
+
- test/workbook/worksheet/tc_page_set_up_pr.rb
|
514
548
|
- test/workbook/worksheet/tc_page_setup.rb
|
515
549
|
- test/workbook/worksheet/tc_pane.rb
|
516
550
|
- test/workbook/worksheet/tc_print_options.rb
|
517
551
|
- test/workbook/worksheet/tc_protected_range.rb
|
518
552
|
- test/workbook/worksheet/tc_row.rb
|
519
553
|
- test/workbook/worksheet/tc_selection.rb
|
554
|
+
- test/workbook/worksheet/tc_sheet_calc_pr.rb
|
555
|
+
- test/workbook/worksheet/tc_sheet_pr.rb
|
520
556
|
- test/workbook/worksheet/tc_sheet_protection.rb
|
521
557
|
- test/workbook/worksheet/tc_sheet_view.rb
|
558
|
+
- test/workbook/worksheet/tc_table.rb
|
559
|
+
- test/workbook/worksheet/tc_table_style_info.rb
|
522
560
|
- test/workbook/worksheet/tc_worksheet.rb
|
523
561
|
- test/workbook/worksheet/tc_worksheet_hyperlink.rb
|
524
562
|
has_rdoc: axlsx
|
data/examples/~$extractive.xlsx
DELETED
Binary file
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Axlsx
|
2
|
-
|
3
|
-
#This class represents an auto filter range in a worksheet
|
4
|
-
class AutoFilter
|
5
|
-
|
6
|
-
# creates a new Autofilter object
|
7
|
-
# @param [Worksheet] worksheet
|
8
|
-
def initialize(worksheet)
|
9
|
-
raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
|
10
|
-
@worksheet = worksheet
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :worksheet
|
14
|
-
|
15
|
-
# The range the autofilter should be applied to.
|
16
|
-
# This should be a string like 'A1:B8'
|
17
|
-
# @return [String]
|
18
|
-
attr_accessor :range
|
19
|
-
|
20
|
-
# the formula for the defined name required for this auto filter
|
21
|
-
# @return [String]
|
22
|
-
def defined_name
|
23
|
-
return unless range
|
24
|
-
Axlsx.cell_range(range.split(':').collect { |name| worksheet.name_to_cell(name)})
|
25
|
-
end
|
26
|
-
|
27
|
-
# serialize the object
|
28
|
-
# @return [String]
|
29
|
-
def to_xml_string(str='')
|
30
|
-
return unless range
|
31
|
-
str << "<autoFilter ref='#{range}'></autoFilter>"
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|