caxlsx 3.0.2 → 3.1.1

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 (73) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +31 -8
  3. data/README.md +4 -0
  4. data/examples/{image1.jpeg → assets/image1.jpeg} +0 -0
  5. data/examples/generate.rb +15 -0
  6. data/lib/axlsx/drawing/bar_3D_chart.rb +5 -8
  7. data/lib/axlsx/drawing/bar_chart.rb +13 -18
  8. data/lib/axlsx/drawing/bar_series.rb +18 -1
  9. data/lib/axlsx/drawing/pie_series.rb +1 -1
  10. data/lib/axlsx/package.rb +44 -6
  11. data/lib/axlsx/util/constants.rb +2 -1
  12. data/lib/axlsx/util/mime_type_utils.rb +1 -1
  13. data/lib/axlsx/util/validators.rb +1 -1
  14. data/lib/axlsx/util/zip_command.rb +73 -0
  15. data/lib/axlsx/version.rb +1 -1
  16. data/lib/axlsx/workbook/worksheet/cell.rb +9 -3
  17. data/lib/axlsx/workbook/worksheet/data_validation.rb +4 -4
  18. data/lib/axlsx/workbook/worksheet/pivot_table.rb +7 -2
  19. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +1 -1
  20. data/lib/axlsx/workbook/worksheet/row.rb +6 -4
  21. data/lib/axlsx/workbook/worksheet/table.rb +1 -1
  22. data/lib/axlsx/workbook/worksheet/worksheet.rb +7 -1
  23. data/lib/axlsx.rb +7 -5
  24. data/test/drawing/tc_bar_3D_chart.rb +26 -11
  25. data/test/drawing/tc_bar_chart.rb +26 -11
  26. data/test/drawing/tc_bar_series.rb +10 -1
  27. data/test/drawing/tc_drawing.rb +2 -2
  28. data/test/drawing/tc_hyperlink.rb +1 -1
  29. data/test/drawing/tc_one_cell_anchor.rb +1 -1
  30. data/test/drawing/tc_pic.rb +4 -4
  31. data/test/drawing/tc_pie_series.rb +2 -1
  32. data/test/fixtures/image1.gif +0 -0
  33. data/test/fixtures/image1.jpeg +0 -0
  34. data/test/fixtures/image1.jpg +0 -0
  35. data/test/fixtures/image1.png +0 -0
  36. data/test/fixtures/image1_fake.jpg +0 -0
  37. data/test/tc_helper.rb +0 -2
  38. data/test/tc_package.rb +80 -13
  39. data/test/util/tc_mime_type_utils.rb +1 -1
  40. data/test/util/tc_validators.rb +1 -1
  41. data/test/workbook/worksheet/tc_cell.rb +38 -0
  42. data/test/workbook/worksheet/tc_pivot_table.rb +8 -0
  43. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +8 -0
  44. data/test/workbook/worksheet/tc_row.rb +21 -0
  45. data/test/workbook/worksheet/tc_table.rb +10 -0
  46. data/test/workbook/worksheet/tc_worksheet.rb +16 -18
  47. metadata +116 -137
  48. data/examples/2010_comments.rb +0 -17
  49. data/examples/anchor_swapping.rb +0 -28
  50. data/examples/auto_filter.rb +0 -25
  51. data/examples/basic_charts.rb +0 -58
  52. data/examples/chart_colors.rb +0 -88
  53. data/examples/colored_links.rb +0 -45
  54. data/examples/conditional_formatting/example_conditional_formatting.rb +0 -89
  55. data/examples/conditional_formatting/getting_barred.rb +0 -37
  56. data/examples/conditional_formatting/hitting_the_high_notes.rb +0 -37
  57. data/examples/conditional_formatting/scaled_colors.rb +0 -39
  58. data/examples/conditional_formatting/stop_and_go.rb +0 -37
  59. data/examples/data_validation.rb +0 -67
  60. data/examples/example.rb +0 -900
  61. data/examples/extractive.rb +0 -45
  62. data/examples/ios_preview.rb +0 -14
  63. data/examples/merge_cells.rb +0 -17
  64. data/examples/no_grid_with_borders.rb +0 -18
  65. data/examples/page_setup.rb +0 -11
  66. data/examples/pivot_table.rb +0 -39
  67. data/examples/pivot_test.rb +0 -63
  68. data/examples/sheet_protection.rb +0 -10
  69. data/examples/skydrive/real_example.rb +0 -63
  70. data/examples/split.rb +0 -16
  71. data/examples/styles.rb +0 -66
  72. data/examples/underline.rb +0 -13
  73. data/examples/wrap_text.rb +0 -21
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env ruby -w -s
2
- # -*- coding: utf-8 -*-
3
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
- require 'axlsx'
5
-
6
- p = Axlsx::Package.new
7
- book = p.workbook
8
-
9
- # define your regular styles
10
- percent = book.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER)
11
- money = book.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER)
12
- status = book.styles.add_style(:border => Axlsx::STYLE_THIN_BORDER)
13
-
14
- # define the style for conditional formatting
15
- profitable = book.styles.add_style( :fg_color => "428751", :type => :dxf )
16
- unprofitable = book.styles.add_style( :fg_color => "FF0000", :type => :dxf )
17
-
18
- book.add_worksheet(:name => "Cell Is") do |ws|
19
-
20
- # Generate 20 rows of data
21
- ws.add_row ["Previous Year Quarterly Profits (JPY)"]
22
- ws.add_row ["Quarter", "Profit", "% of Total"]
23
- offset = 3
24
- rows = 20
25
- offset.upto(rows + offset) do |i|
26
- ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
27
- end
28
-
29
- # Apply conditional formatting to range B3:B100 in the worksheet
30
- ws.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
31
- # Apply conditional using the between operator; NOTE: supply an array to :formula for between/notBetween
32
- ws.add_conditional_formatting("C3:C100", { :type => :cellIs, :operator => :between, :formula => ["0.00%","100.00%"], :dxfId => unprofitable, :priority => 1 })
33
- end
34
-
35
- book.add_worksheet(:name => "Color Scale") do |ws|
36
- ws.add_row ["Previous Year Quarterly Profits (JPY)"]
37
- ws.add_row ["Quarter", "Profit", "% of Total"]
38
- offset = 3
39
- rows = 20
40
- offset.upto(rows + offset) do |i|
41
- ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
42
- end
43
- # Apply conditional formatting to range B3:B100 in the worksheet
44
- color_scale = Axlsx::ColorScale.new
45
- ws.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale })
46
- end
47
-
48
-
49
- book.add_worksheet(:name => "Data Bar") do |ws|
50
- ws.add_row ["Previous Year Quarterly Profits (JPY)"]
51
- ws.add_row ["Quarter", "Profit", "% of Total"]
52
- offset = 3
53
- rows = 20
54
- offset.upto(rows + offset) do |i|
55
- ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
56
- end
57
- # Apply conditional formatting to range B3:B100 in the worksheet
58
- data_bar = Axlsx::DataBar.new
59
- ws.add_conditional_formatting("B3:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar })
60
- end
61
-
62
- book.add_worksheet(:name => "Icon Set") do |ws|
63
- ws.add_row ["Previous Year Quarterly Profits (JPY)"]
64
- ws.add_row ["Quarter", "Profit", "% of Total"]
65
- offset = 3
66
- rows = 20
67
- offset.upto(rows + offset) do |i|
68
- ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
69
- end
70
- # Apply conditional formatting to range B3:B100 in the worksheet
71
- icon_set = Axlsx::IconSet.new
72
- ws.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
73
- end
74
-
75
- book.add_worksheet(:name => "Contains Text") do |ws|
76
- ws.add_row ["Previous Year Quarterly Profits (JPY)"]
77
- ws.add_row ["Quarter", "Profit", "% of Total", "Status"]
78
- offset = 3
79
- rows = 20
80
- offset.upto(rows + offset) do |i|
81
- ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})", (10000*((rows/2-i) * (rows/2-i))) > 100000 ? "PROFIT" : "LOSS"], :style=>[nil, money, percent, status]
82
- end
83
-
84
- # Apply conditional formatting to range D3:D100 in the worksheet
85
- ws.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "PROFIT", :dxfId => profitable, :priority => 1 })
86
- ws.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "LOSS", :dxfId => unprofitable, :priority => 1 })
87
- end
88
-
89
- p.serialize('example_conditional_formatting.xlsx')
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env ruby -w -s
2
- # -*- coding: utf-8 -*-
3
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
- require 'axlsx'
5
- p = Axlsx::Package.new
6
- p.workbook do |wb|
7
- # define your regular styles
8
- styles = wb.styles
9
- title = styles.add_style :sz => 15, :b => true, :u => true
10
- default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
- header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
- money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
- percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
-
15
- # define the style for conditional formatting - its the :dxf bit that counts!
16
- profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
-
18
- wb.add_worksheet(:name => 'Data Bar Conditional Formatting') do |ws|
19
- ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
- ws.add_row
21
- ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
- ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
- ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
- ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
- ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
-
27
- ws.merge_cells 'A1:C1'
28
-
29
- # Apply conditional formatting to range B4:B7 in the worksheet
30
- data_bar = Axlsx::DataBar.new
31
- ws.add_conditional_formatting 'B4:B7', { :type => :dataBar,
32
- :dxfId => profitable,
33
- :priority => 1,
34
- :data_bar => data_bar }
35
- end
36
- end
37
- p.serialize 'getting_barred.xlsx'
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env ruby -w -s
2
- # -*- coding: utf-8 -*-
3
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
- require 'axlsx'
5
- p = Axlsx::Package.new
6
- p.workbook do |wb|
7
- # define your regular styles
8
- styles = wb.styles
9
- title = styles.add_style :sz => 15, :b => true, :u => true
10
- default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
- header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
- money = styles.add_style :format_code => '###,###,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
- percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
-
15
- # define the style for conditional formatting - its the :dxf bit that counts!
16
- profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
-
18
- wb.add_worksheet(:name => 'The High Notes') do |ws|
19
- ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
- ws.add_row
21
- ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
- ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
- ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
- ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
- ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
-
27
- ws.merge_cells 'A1:C1'
28
-
29
- # Apply conditional formatting to range B4:B7 in the worksheet
30
- ws.add_conditional_formatting 'B4:B7', { :type => :cellIs,
31
- :operator => :greaterThan,
32
- :formula => '27000000000',
33
- :dxfId => profitable,
34
- :priority => 1 }
35
- end
36
- end
37
- p.serialize 'the_high_notes.xlsx'
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby -w -s
2
- # -*- coding: utf-8 -*-
3
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
- require 'axlsx'
5
- p = Axlsx::Package.new
6
- p.workbook do |wb|
7
- # define your regular styles
8
- styles = wb.styles
9
- title = styles.add_style :sz => 15, :b => true, :u => true
10
- default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
- header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
- money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
- percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
-
15
- # define the style for conditional formatting - its the :dxf bit that counts!
16
- profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
-
18
- wb.add_worksheet(:name => 'Scaled Colors') do |ws|
19
- ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
- ws.add_row
21
- ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
- ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
- ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
- ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
- ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
-
27
- ws.merge_cells 'A1:C1'
28
-
29
- # Apply conditional formatting to range B4:B7 in the worksheet
30
- color_scale = Axlsx::ColorScale.new
31
- ws.add_conditional_formatting 'B4:B7', { :type => :colorScale,
32
- :operator => :greaterThan,
33
- :formula => '27000000000',
34
- :dxfId => profitable,
35
- :priority => 1,
36
- :color_scale => color_scale }
37
- end
38
- end
39
- p.serialize 'scaled_colors.xlsx'
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env ruby -w -s
2
- # -*- coding: utf-8 -*-
3
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
- require 'axlsx'
5
- p = Axlsx::Package.new
6
- p.workbook do |wb|
7
- # define your regular styles
8
- styles = wb.styles
9
- title = styles.add_style :sz => 15, :b => true, :u => true
10
- default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
11
- header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
12
- money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER
13
- percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
14
-
15
- # define the style for conditional formatting - its the :dxf bit that counts!
16
- profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
17
-
18
- wb.add_worksheet(:name => 'Downtown traffic') do |ws|
19
- ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
20
- ws.add_row
21
- ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
22
- ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
23
- ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
24
- ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
25
- ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
26
-
27
- ws.merge_cells 'A1:C1'
28
-
29
- # Apply conditional formatting to range B3:B7 in the worksheet
30
- icon_set = Axlsx::IconSet.new
31
- ws.add_conditional_formatting 'B3:B7', { :type => :iconSet,
32
- :dxfId => profitable,
33
- :priority => 1,
34
- :icon_set => icon_set }
35
- end
36
- end
37
- p.serialize 'stop_and_go.xlsx'
@@ -1,67 +0,0 @@
1
- #!/usr/bin/env ruby -w -s
2
- # -*- coding: utf-8 -*-
3
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
4
- require 'axlsx'
5
-
6
- p = Axlsx::Package.new
7
- p.workbook.add_worksheet do |ws|
8
-
9
- ws.add_row ["between", "lessThan", "bound list", "raw list"]
10
-
11
- 4.times do |i|
12
- ws.add_row [nil, nil, nil, nil, (i+1) * 2]
13
- end
14
-
15
- ws.add_data_validation("A2:A5", {
16
- :type => :whole,
17
- :operator => :between,
18
- :formula1 => '5',
19
- :formula2 => '10',
20
- :showErrorMessage => true,
21
- :errorTitle => 'Wrong input',
22
- :error => 'Only values between 5 and 10',
23
- :errorStyle => :information,
24
- :showInputMessage => true,
25
- :promptTitle => 'Be careful!',
26
- :prompt => %{We really want a value between 5 and 10,
27
- but it is OK if you want to break the rules.
28
- }})
29
-
30
- ws.add_data_validation("B1:B5", {
31
- :type => :textLength,
32
- :operator => :lessThan,
33
- :formula1 => '10',
34
- :showErrorMessage => true,
35
- :errorTitle => 'Text is too long',
36
- :error => 'Max text length is 10 characters',
37
- :errorStyle => :stop,
38
- :showInputMessage => true,
39
- :promptTitle => 'Text length',
40
- :prompt => 'Max text length is 10 characters'})
41
-
42
- ws.add_data_validation("C2:C5", {
43
- :type => :list,
44
- :formula1 => 'E2:E5',
45
- :showDropDown => false,
46
- :showErrorMessage => true,
47
- :errorTitle => '',
48
- :error => 'Only values from E2:E5',
49
- :errorStyle => :stop,
50
- :showInputMessage => true,
51
- :promptTitle => '',
52
- :prompt => 'Only values from E2:E5'})
53
-
54
- ws.add_data_validation("D2:D5", {
55
- :type => :list,
56
- :formula1 => '"Red, Orange, NavyBlue"',
57
- :showDropDown => false,
58
- :showErrorMessage => true,
59
- :errorTitle => '',
60
- :error => 'Please use the dropdown selector to choose the value',
61
- :errorStyle => :stop,
62
- :showInputMessage => true,
63
- :prompt => '& Choose the value from the dropdown'})
64
-
65
- end
66
-
67
- p.serialize 'data_validation.xlsx'