write_xlsx 0.75.0 → 0.76.0

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/Changes +4 -0
  3. data/Gemfile +8 -2
  4. data/README.md +4 -2
  5. data/lib/write_xlsx/chart/axis.rb +69 -96
  6. data/lib/write_xlsx/chart/bar.rb +18 -21
  7. data/lib/write_xlsx/chart/caption.rb +1 -1
  8. data/lib/write_xlsx/chart/column.rb +1 -5
  9. data/lib/write_xlsx/chart/line.rb +2 -16
  10. data/lib/write_xlsx/chart/pie.rb +18 -40
  11. data/lib/write_xlsx/chart/radar.rb +2 -5
  12. data/lib/write_xlsx/chart/scatter.rb +24 -32
  13. data/lib/write_xlsx/chart/series.rb +218 -236
  14. data/lib/write_xlsx/chart/stock.rb +15 -27
  15. data/lib/write_xlsx/chart.rb +303 -392
  16. data/lib/write_xlsx/chartsheet.rb +22 -20
  17. data/lib/write_xlsx/colors.rb +9 -15
  18. data/lib/write_xlsx/drawing.rb +26 -28
  19. data/lib/write_xlsx/format.rb +15 -15
  20. data/lib/write_xlsx/package/comments.rb +1 -1
  21. data/lib/write_xlsx/package/conditional_format.rb +8 -8
  22. data/lib/write_xlsx/package/relationships.rb +4 -15
  23. data/lib/write_xlsx/package/styles.rb +9 -16
  24. data/lib/write_xlsx/shape.rb +1 -15
  25. data/lib/write_xlsx/sparkline.rb +1 -1
  26. data/lib/write_xlsx/utility.rb +69 -13
  27. data/lib/write_xlsx/version.rb +1 -1
  28. data/lib/write_xlsx/workbook.rb +19 -7
  29. data/lib/write_xlsx/worksheet/cell_data.rb +1 -1
  30. data/lib/write_xlsx/worksheet/hyperlink.rb +39 -37
  31. data/lib/write_xlsx/worksheet.rb +44 -72
  32. data/lib/write_xlsx/zip_file_utils.rb +99 -0
  33. data/test/chart/test_add_series.rb +5 -5
  34. data/test/chart/test_write_d_lbls.rb +1 -1
  35. data/test/chart/test_write_major_gridlines.rb +1 -1
  36. data/test/chart/test_write_marker.rb +1 -1
  37. data/test/chart/test_write_number_format.rb +1 -1
  38. data/test/helper.rb +7 -4
  39. data/test/regression/klt.csv +4 -0
  40. data/test/regression/test_chart_column07.rb +44 -0
  41. data/test/regression/test_chart_column08.rb +46 -0
  42. data/test/regression/test_chart_date01.rb +57 -0
  43. data/test/regression/test_chart_date02.rb +59 -0
  44. data/test/regression/test_chart_date03.rb +59 -0
  45. data/test/regression/test_chart_date04.rb +61 -0
  46. data/test/regression/test_chart_stock01.rb +1 -6
  47. data/test/regression/test_chart_title02.rb +44 -0
  48. data/test/regression/test_escapes01.rb +1 -1
  49. data/test/regression/test_escapes02.rb +1 -1
  50. data/test/regression/test_escapes03.rb +1 -1
  51. data/test/regression/test_escapes04.rb +1 -1
  52. data/test/regression/test_escapes05.rb +1 -1
  53. data/test/regression/test_escapes06.rb +1 -1
  54. data/test/regression/test_escapes07.rb +1 -1
  55. data/test/regression/test_escapes08.rb +1 -1
  56. data/test/regression/test_set_column09.rb +31 -0
  57. data/test/regression/test_shared_strings_encoding.rb +103 -0
  58. data/test/regression/xlsx_files/chart_column07.xlsx +0 -0
  59. data/test/regression/xlsx_files/chart_column08.xlsx +0 -0
  60. data/test/regression/xlsx_files/chart_date01.xlsx +0 -0
  61. data/test/regression/xlsx_files/chart_date02.xlsx +0 -0
  62. data/test/regression/xlsx_files/chart_date03.xlsx +0 -0
  63. data/test/regression/xlsx_files/chart_date04.xlsx +0 -0
  64. data/test/regression/xlsx_files/chart_title02.xlsx +0 -0
  65. data/test/regression/xlsx_files/set_column09.xlsx +0 -0
  66. data/test/regression/xlsx_files/shared_strings_encoding.xlsx +0 -0
  67. data/test/worksheet/test_write_hyperlink.rb +10 -15
  68. data/write_xlsx.gemspec +0 -3
  69. metadata +48 -39
  70. data/test/worksheet/test_set_column.rb +0 -25
@@ -5,22 +5,19 @@ module Writexlsx
5
5
  class Hyperlink # :nodoc:
6
6
  include Writexlsx::Utility
7
7
 
8
- attr_reader :url, :link_type, :str, :url_str
9
- attr_accessor :tip, :display
10
-
11
- def self.factory(url, str = nil)
12
- if url =~ /^internal:/
13
- InternalHyperlink.new(url, str)
14
- elsif url =~ /^external:/
15
- ExternalHyperlink.new(url, str)
8
+ attr_reader :str, :tip
9
+
10
+ def self.factory(url, str = nil, tip = nil)
11
+ if url =~ /^internal:(.+)/
12
+ InternalHyperlink.new($~[1], str, tip)
13
+ elsif url =~ /^external:(.+)/
14
+ ExternalHyperlink.new($~[1], str, tip)
16
15
  else
17
- new(url, str)
16
+ new(url, str, tip)
18
17
  end
19
18
  end
20
19
 
21
- def initialize(url, str = nil)
22
- @link_type = 1
23
-
20
+ def initialize(url, str, tip)
24
21
  # The displayed string defaults to the url string.
25
22
  str ||= url.dup
26
23
 
@@ -51,38 +48,35 @@ module Writexlsx
51
48
  @url = url
52
49
  @str = str
53
50
  @url_str = nil
51
+ @tip = tip
54
52
  end
55
53
 
56
- def write_external_attributes(row, col, id)
54
+ def attributes(row, col, id)
57
55
  ref = xl_rowcol_to_cell(row, col)
58
56
 
59
- attributes = [ ['ref', ref] ]
60
- attributes << r_id_attributes(id)
57
+ attr = [ ['ref', ref] ]
58
+ attr << r_id_attributes(id)
61
59
 
62
- attributes << ['location', url_str] if url_str
63
- attributes << ['display', display] if display
64
- attributes << ['tooltip', tip] if tip
65
- attributes
60
+ attr << ['location', @url_str] if @url_str
61
+ attr << ['display', @display] if @display
62
+ attr << ['tooltip', @tip] if @tip
63
+ attr
66
64
  end
67
65
 
68
- def write_internal_attributes(row, col)
69
- ref = xl_rowcol_to_cell(row, col)
70
-
71
- attributes = [
72
- ['ref', ref],
73
- ['location', url]
74
- ]
66
+ def external_hyper_link
67
+ ['/hyperlink', @url, 'External']
68
+ end
75
69
 
76
- attributes << ['tooltip', tip] if tip
77
- attributes << ['display', str]
70
+ def display_on
71
+ @display = @url_str
78
72
  end
79
73
  end
80
74
 
81
75
  class InternalHyperlink < Hyperlink
82
- def initialize(url, str)
83
- @link_type = 2
84
- @url = url.sub(/^internal:/, '')
76
+ undef external_hyper_link
85
77
 
78
+ def initialize(url, str, tip)
79
+ @url = url
86
80
  # The displayed string defaults to the url string.
87
81
  str ||= @url.dup
88
82
 
@@ -96,16 +90,23 @@ module Writexlsx
96
90
  if @url.bytesize > 255
97
91
  raise "URL '#{@url}' > 255 characters, it exceeds Excel's limit for URLS."
98
92
  end
93
+
94
+ @tip = tip
99
95
  end
100
- end
101
96
 
102
- class ExternalHyperlink < Hyperlink
103
- def initialize(url, str = nil)
104
- @link_type = 1
97
+ def attributes(row, col, dummy = nil)
98
+ attr = [
99
+ ['ref', xl_rowcol_to_cell(row, col)],
100
+ ['location', @url]
101
+ ]
105
102
 
106
- # Remove the URI scheme from internal links.
107
- url = url.sub(/^external:/, '')
103
+ attr << ['tooltip', @tip] if @tip
104
+ attr << ['display', @str]
105
+ end
106
+ end
108
107
 
108
+ class ExternalHyperlink < Hyperlink
109
+ def initialize(url, str, tip)
109
110
  # The displayed string defaults to the url string.
110
111
  str ||= url.dup
111
112
 
@@ -138,6 +139,7 @@ module Writexlsx
138
139
  @url = url
139
140
  @str = str
140
141
  @url_str = url_str
142
+ @tip = tip
141
143
  end
142
144
  end
143
145
  end
@@ -299,9 +299,10 @@ module Writexlsx
299
299
  @workbook = workbook
300
300
  @index = index
301
301
  @name = name
302
- @colinfo = []
302
+ @colinfo = {}
303
303
  @cell_data_table = {}
304
304
  @excel_version = 2007
305
+ @palette = workbook.palette
305
306
 
306
307
  @page_setup = PageSetup.new
307
308
 
@@ -335,7 +336,6 @@ module Writexlsx
335
336
  @last_shape_id = 1
336
337
  @rel_count = 0
337
338
  @hlink_count = 0
338
- @hlink_refs = []
339
339
  @external_hyper_links = []
340
340
  @external_drawing_links = []
341
341
  @external_comment_links = []
@@ -730,8 +730,8 @@ module Writexlsx
730
730
 
731
731
  @outline_col_level = level if level > @outline_col_level
732
732
 
733
- # Store the column data.
734
- @colinfo << [firstcol, lastcol, width, format, hidden, level, collapsed]
733
+ # Store the column data based on the first column. Padded for sorting.
734
+ @colinfo[sprintf("%05d", firstcol)] = [firstcol, lastcol, width, format, hidden, level, collapsed]
735
735
 
736
736
  # Store the column change to allow optimisations.
737
737
  @col_size_changed = 1
@@ -777,9 +777,7 @@ module Writexlsx
777
777
  row_first, col_first, row_last, col_last = row_col_notation(args)
778
778
  active_cell = xl_rowcol_to_cell(row_first, col_first)
779
779
 
780
- if row_last.nil? # Single cell selection.
781
- sqref = active_cell
782
- else # Range selection.
780
+ if row_last # Range selection.
783
781
  # Swap last row/col for first row/col as necessary
784
782
  row_first, row_last = row_last, row_first if row_first > row_last
785
783
  col_first, col_last = col_last, col_first if col_first > col_last
@@ -790,6 +788,8 @@ module Writexlsx
790
788
  else
791
789
  sqref = xl_range(row_first, row_last, col_first, col_last)
792
790
  end
791
+ else # Single cell selection.
792
+ sqref = active_cell
793
793
  end
794
794
 
795
795
  # Selection isn't set for cell A1.
@@ -941,7 +941,7 @@ module Writexlsx
941
941
  # See the tab_colors.rb program in the examples directory of the distro.
942
942
  #
943
943
  def tab_color=(color)
944
- @tab_color = Colors.new.get_color(color)
944
+ @tab_color = Colors.new.color(color)
945
945
  end
946
946
 
947
947
  # This method is deprecated. use tab_color=().
@@ -2289,7 +2289,7 @@ module Writexlsx
2289
2289
  check_dimensions(row, col)
2290
2290
  store_row_col_max_min_values(row, col)
2291
2291
 
2292
- store_data_to_table(BlankCellData.new(self, row, col, nil, xf))
2292
+ store_data_to_table(BlankCellData.new(self, row, col, xf))
2293
2293
  end
2294
2294
 
2295
2295
  #
@@ -2470,7 +2470,7 @@ module Writexlsx
2470
2470
 
2471
2471
  #
2472
2472
  # :call-seq:
2473
- # write_url(row, column, url [ , format, label ] )
2473
+ # write_url(row, column, url [ , format, label, tip ] )
2474
2474
  #
2475
2475
  # Write a hyperlink to a URL in the cell specified by +row+ and +column+.
2476
2476
  # The hyperlink is comprised of two elements: the visible label and
@@ -2558,22 +2558,15 @@ module Writexlsx
2558
2558
  check_dimensions(row, col)
2559
2559
  store_row_col_max_min_values(row, col)
2560
2560
 
2561
- hyperlink = Hyperlink.factory(url, str)
2562
- hyperlink.tip = tip
2561
+ hyperlink = Hyperlink.factory(url, str, tip)
2562
+ store_hyperlink(row, col, hyperlink)
2563
2563
 
2564
- @hlink_count += 1
2565
-
2566
- if @hlink_count > 65_530
2567
- raise "URL '#{hyperlink.url}' added but number of URLS is over Excel's limit of 65,530 URLS per worksheet."
2564
+ if hyperlinks_count > 65_530
2565
+ raise "URL '#{url}' added but number of URLS is over Excel's limit of 65,530 URLS per worksheet."
2568
2566
  end
2569
2567
 
2570
2568
  # Write the hyperlink string.
2571
2569
  write_string(row, col, hyperlink.str, xf)
2572
-
2573
- # Store the hyperlink data in a separate structure.
2574
- @hyperlinks ||= {}
2575
- @hyperlinks[row] ||= {}
2576
- @hyperlinks[row][col] = hyperlink
2577
2570
  end
2578
2571
 
2579
2572
  #
@@ -3046,6 +3039,7 @@ module Writexlsx
3046
3039
  # worksheet method, see above.
3047
3040
  #
3048
3041
  def set_row(*args)
3042
+ return unless args[0]
3049
3043
  row = args[0]
3050
3044
  height = args[1] || @default_height
3051
3045
  xf = args[2]
@@ -3053,8 +3047,6 @@ module Writexlsx
3053
3047
  level = args[4] || 0
3054
3048
  collapsed = args[5] || 0
3055
3049
 
3056
- return if row.nil?
3057
-
3058
3050
  # Get the default row height.
3059
3051
  default_height = @default_row_height
3060
3052
 
@@ -5692,19 +5684,12 @@ module Writexlsx
5692
5684
  # Convert from an Excel internal colour index to a XML style #RRGGBB index
5693
5685
  # based on the default or user defined values in the Workbook palette.
5694
5686
  #
5695
- def get_palette_color(index) #:nodoc:
5687
+ def palette_color(index) #:nodoc:
5696
5688
  if index =~ /^#([0-9A-F]{6})$/i
5697
- return "FF#{$~[1]}"
5689
+ "FF#{$1.upcase}"
5690
+ else
5691
+ "FF#{super(index)}"
5698
5692
  end
5699
-
5700
- # Adjust the colour index.
5701
- index -= 8
5702
-
5703
- # Palette is passed in from the Workbook class.
5704
- rgb = @workbook.palette[index]
5705
-
5706
- # TODO Add the alpha part to the RGB.
5707
- sprintf("FF%02X%02X%02X", *rgb[0, 3])
5708
5693
  end
5709
5694
 
5710
5695
  def buttons_data # :nodoc:
@@ -5769,6 +5754,16 @@ module Writexlsx
5769
5754
 
5770
5755
  private
5771
5756
 
5757
+ def hyperlinks_count
5758
+ @hyperlinks.keys.inject(0) { |s, n| s += @hyperlinks[n].keys.size }
5759
+ end
5760
+
5761
+ def store_hyperlink(row, col, hyperlink)
5762
+ @hyperlinks ||= {}
5763
+ @hyperlinks[row] ||= {}
5764
+ @hyperlinks[row][col] = hyperlink
5765
+ end
5766
+
5772
5767
  def cell_format_of_rich_string(rich_strings)
5773
5768
  # If the last arg is a format we use it as the cell format.
5774
5769
  if rich_strings[-1].respond_to?(:xf_index)
@@ -6526,7 +6521,7 @@ module Writexlsx
6526
6521
  return if @colinfo.empty?
6527
6522
 
6528
6523
  @writer.tag_elements('cols') do
6529
- @colinfo.each {|col_info| write_col_info(col_info) }
6524
+ @colinfo.keys.sort.each {|col| write_col_info(@colinfo[col]) }
6530
6525
  end
6531
6526
  end
6532
6527
 
@@ -6551,9 +6546,7 @@ module Writexlsx
6551
6546
  custom_width = false if width.nil? && hidden == 0
6552
6547
  custom_width = false if width == 8.43
6553
6548
 
6554
- if width.nil?
6555
- width = hidden == 0 ? 8.43 : 0
6556
- end
6549
+ width = hidden == 0 ? 8.43 : 0 unless width
6557
6550
 
6558
6551
  # Convert column width from user units to character width.
6559
6552
  if width && width < 1
@@ -6676,7 +6669,7 @@ module Writexlsx
6676
6669
  return if @panes.empty?
6677
6670
 
6678
6671
  if @panes[4] == 2
6679
- write_split_panes(*(@panes))
6672
+ write_split_panes
6680
6673
  else
6681
6674
  write_freeze_panes(*(@panes))
6682
6675
  end
@@ -6724,7 +6717,8 @@ module Writexlsx
6724
6717
  #
6725
6718
  # See also, implementers note for split_panes().
6726
6719
  #
6727
- def write_split_panes(row, col, top_row, left_col, type) #:nodoc:
6720
+ def write_split_panes #:nodoc:
6721
+ row, col, top_row, left_col = @panes
6728
6722
  has_selection = false
6729
6723
  y_split = row
6730
6724
  x_split = col
@@ -7053,7 +7047,7 @@ module Writexlsx
7053
7047
  #
7054
7048
  def write_hyperlinks #:nodoc:
7055
7049
  return unless @hyperlinks
7056
-
7050
+ hlink_attributes = []
7057
7051
  @hyperlinks.keys.sort.each do |row_num|
7058
7052
  # Sort the hyperlinks into column order.
7059
7053
  col_nums = @hyperlinks[row_num].keys.sort
@@ -7064,56 +7058,34 @@ module Writexlsx
7064
7058
 
7065
7059
  # If the cell isn't a string then we have to add the url as
7066
7060
  # the string to display
7067
- if ptrue?(@cell_data_table) &&
7061
+ if ptrue?(@cell_data_table) &&
7068
7062
  ptrue?(@cell_data_table[row_num]) &&
7069
7063
  ptrue?(@cell_data_table[row_num][col_num])
7070
7064
  if @cell_data_table[row_num][col_num].display_url_string?
7071
- link.display = link.url_str
7065
+ link.display_on
7072
7066
  end
7073
7067
  end
7074
7068
 
7075
- if link.link_type == 1
7069
+ if link.respond_to?(:external_hyper_link)
7076
7070
  # External link with rel file relationship.
7077
7071
  @rel_count += 1
7078
- @hlink_refs << [link, row_num, col_num, @rel_count]
7079
7072
  # Links for use by the packager.
7080
- @external_hyper_links << ['/hyperlink', link.url, 'External']
7081
- else
7082
- # Internal link with rel file relationship.
7083
- @hlink_refs << [link, row_num, col_num]
7073
+ @external_hyper_links << link.external_hyper_link
7084
7074
  end
7075
+ hlink_attributes << link.attributes(row_num, col_num, @rel_count)
7085
7076
  end
7086
7077
  end
7087
7078
 
7088
- return if @hlink_refs.empty?
7079
+ return if hlink_attributes.empty?
7089
7080
 
7090
7081
  # Write the hyperlink elements.
7091
7082
  @writer.tag_elements('hyperlinks') do
7092
- @hlink_refs.each do |aref|
7093
- case aref[0].link_type
7094
- when 1
7095
- write_hyperlink_external(*aref)
7096
- when 2
7097
- write_hyperlink_internal(*aref)
7098
- end
7083
+ hlink_attributes.each do |attributes|
7084
+ @writer.empty_tag('hyperlink', attributes)
7099
7085
  end
7100
7086
  end
7101
7087
  end
7102
7088
 
7103
- #
7104
- # Write the <hyperlink> element for external links.
7105
- #
7106
- def write_hyperlink_external(link, row, col, id) # :nodoc:
7107
- @writer.empty_tag('hyperlink', link.write_external_attributes(row, col, id))
7108
- end
7109
-
7110
- #
7111
- # Write the <hyperlink> element for internal links.
7112
- #
7113
- def write_hyperlink_internal(link, row, col) #:nodoc:
7114
- @writer.empty_tag('hyperlink', link.write_internal_attributes(row, col))
7115
- end
7116
-
7117
7089
  #
7118
7090
  # Write the <tabColor> element.
7119
7091
  #
@@ -7122,7 +7094,7 @@ module Writexlsx
7122
7094
 
7123
7095
  @writer.empty_tag('tabColor',
7124
7096
  [
7125
- ['rgb', get_palette_color(@tab_color)]
7097
+ ['rgb', palette_color(@tab_color)]
7126
7098
  ])
7127
7099
  end
7128
7100
 
@@ -0,0 +1,99 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # from http://d.hatena.ne.jp/alunko/20071021
4
+ #
5
+ require 'kconv'
6
+ require 'zip/zipfilesystem'
7
+ require 'fileutils'
8
+
9
+ module ZipFileUtils
10
+
11
+ # src file or directory
12
+ # dest zip filename
13
+ # options :fs_encoding=[UTF-8,Shift_JIS,EUC-JP]
14
+ def self.zip(src, dest, options = {})
15
+ src = File.expand_path(src)
16
+ dest = File.expand_path(dest)
17
+ File.unlink(dest) if File.exist?(dest)
18
+ Zip::ZipFile.open(dest, Zip::ZipFile::CREATE) {|zf|
19
+ if(File.file?(src))
20
+ zf.add(encode_path(File.basename(src), options[:fs_encoding]), src)
21
+ break
22
+ else
23
+ each_dir_for(src){ |path|
24
+ if File.file?(path)
25
+ zf.add(encode_path(relative(path, src), options[:fs_encoding]), path)
26
+ elsif File.directory?(path)
27
+ zf.mkdir(encode_path(relative(path, src), options[:fs_encoding]))
28
+ end
29
+ }
30
+ end
31
+ }
32
+ FileUtils.chmod(0644, dest)
33
+ end
34
+
35
+ # src zip filename
36
+ # dest destination directory
37
+ # options :fs_encoding=[UTF-8,Shift_JIS,EUC-JP]
38
+ def self.unzip(src, dest, options = {})
39
+ FileUtils.makedirs(dest)
40
+ Zip::ZipInputStream.open(src) do |is|
41
+ loop do
42
+ entry = is.get_next_entry()
43
+ break unless entry
44
+ dir = File.dirname(entry.name)
45
+ FileUtils.makedirs(dest+ '/' + dir)
46
+ path = encode_path(dest + '/' + entry.name, options[:fs_encoding])
47
+ if(entry.file?())
48
+ File.open(path, File::CREAT|File::WRONLY|File::BINARY) do |w|
49
+ w.puts(is.read())
50
+ end
51
+ else
52
+ FileUtils.makedirs(path)
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def self.each_dir_for(dir_path, &block)
61
+ dir = Dir.open(dir_path)
62
+ each_file_for(dir_path){ |file_path|
63
+ yield(file_path)
64
+ }
65
+ end
66
+
67
+ def self.each_file_for(path, &block)
68
+ if File.file?(path)
69
+ yield(path)
70
+ return true
71
+ end
72
+ dir = Dir.open(path)
73
+ file_exist = false
74
+ dir.each(){ |file|
75
+ next if file == '.' || file == '..'
76
+ file_exist = true if each_file_for(path + "/" + file, &block)
77
+ }
78
+ yield(path) unless file_exist
79
+ return file_exist
80
+ end
81
+
82
+ def self.relative(path, base_dir)
83
+ path[base_dir.length() + 1 .. path.length()] if path.index(base_dir) == 0
84
+ end
85
+
86
+ def self.encode_path(path, encode_s)
87
+ return path unless encode_s
88
+ case(encode_s)
89
+ when('UTF-8')
90
+ return path.toutf8()
91
+ when('Shift_JIS')
92
+ return path.tosjis()
93
+ when('EUC-JP')
94
+ return path.toeuc()
95
+ else
96
+ return path
97
+ end
98
+ end
99
+ end
@@ -8,7 +8,7 @@ class TestAddSeries < Test::Unit::TestCase
8
8
  end
9
9
 
10
10
  def test_add_series_only_values
11
- series = Series.new(@chart)
11
+ series = Writexlsx::Chart::Series.new(@chart)
12
12
  series.instance_variable_set(:@categories, nil)
13
13
  series.instance_variable_set(:@values, '=Sheet1!$A$1:$A$5')
14
14
  series.instance_variable_set(:@name, nil)
@@ -40,7 +40,7 @@ class TestAddSeries < Test::Unit::TestCase
40
40
  end
41
41
 
42
42
  def test_add_series_with_categories_and_values
43
- series = Series.new(@chart)
43
+ series = Writexlsx::Chart::Series.new(@chart)
44
44
  series.instance_variable_set(:@categories, '=Sheet1!$A$1:$A$5')
45
45
  series.instance_variable_set(:@values, '=Sheet1!$B$1:$B$5')
46
46
  series.instance_variable_set(:@name, 'Text')
@@ -75,7 +75,7 @@ class TestAddSeries < Test::Unit::TestCase
75
75
  end
76
76
 
77
77
  def test_add_series_only_values_checked_by_array
78
- series = Series.new(@chart)
78
+ series = Writexlsx::Chart::Series.new(@chart)
79
79
  series.instance_variable_set(:@categories, nil)
80
80
  series.instance_variable_set(:@values, '=Sheet1!$A$1:$A$5')
81
81
  series.instance_variable_set(:@name, nil)
@@ -106,7 +106,7 @@ class TestAddSeries < Test::Unit::TestCase
106
106
  end
107
107
 
108
108
  def test_add_series_both_checked_by_array
109
- series = Series.new(@chart)
109
+ series = Writexlsx::Chart::Series.new(@chart)
110
110
  series.instance_variable_set(:@categories, '=Sheet1!$A$1:$A$5')
111
111
  series.instance_variable_set(:@values, '=Sheet1!$B$1:$B$5')
112
112
  series.instance_variable_set(:@name, 'Text')
@@ -141,7 +141,7 @@ class TestAddSeries < Test::Unit::TestCase
141
141
  end
142
142
 
143
143
  def test_add_series_secondary_axis
144
- series = Series.new(@chart)
144
+ series = Writexlsx::Chart::Series.new(@chart)
145
145
  series.instance_variable_set(:@categories, '=Sheet1!$A$1:$A$5')
146
146
  series.instance_variable_set(:@values, '=Sheet1!$B$1:$B$5')
147
147
  series.instance_variable_set(:@name, 'Text')
@@ -5,7 +5,7 @@ require 'write_xlsx/chart'
5
5
  class TestWriteDLbls < Test::Unit::TestCase
6
6
  def setup
7
7
  @chart = Writexlsx::Chart.new('Pie')
8
- @series = Series.new(@chart)
8
+ @series = Writexlsx::Chart::Series.new(@chart)
9
9
  end
10
10
 
11
11
  def test_write_d_lbls_value_only
@@ -9,7 +9,7 @@ class TestWriteMajorGridlines < Test::Unit::TestCase
9
9
 
10
10
  def test_write_major_gridlines
11
11
  expected = '<c:majorGridlines/>'
12
- result = @chart.__send__('write_major_gridlines', {:_visible => 1})
12
+ result = @chart.__send__('write_major_gridlines', Writexlsx::Chart::Gridline.new(:_visible => 1))
13
13
  assert_equal(expected, result)
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ class TestWriteMarker < Test::Unit::TestCase
9
9
 
10
10
  def test_write_marker
11
11
  expected = '<c:marker><c:symbol val="none"/></c:marker>'
12
- @chart.instance_variable_set(:@default_marker, { :type => 'none'})
12
+ @chart.instance_variable_set(:@default_marker, Writexlsx::Chart::Marker.new(:type => 'none'))
13
13
  @chart.__send__('write_marker')
14
14
  result = @chart.instance_variable_get(:@writer).string
15
15
  assert_equal(expected, result)
@@ -32,7 +32,7 @@ class TestWriteNumberFormat < Test::Unit::TestCase
32
32
  axis.num_format = 'General'
33
33
  axis.defaults = { :num_format => 'General' }
34
34
 
35
- expected = ''
35
+ expected = nil
36
36
  result = @chart.__send__('write_cat_number_format', axis)
37
37
  assert_equal(expected, result)
38
38
  end
data/test/helper.rb CHANGED
@@ -68,7 +68,8 @@ class Test::Unit::TestCase
68
68
 
69
69
  def entrys(xlsx)
70
70
  result = []
71
- Zip::File.foreach(xlsx) { |entry| result << entry }
71
+ ruby_19 { Zip::File.foreach(xlsx) { |entry| result << entry } } ||
72
+ ruby_18 { Zip::ZipFile.foreach(xlsx) { |entry| result << entry } }
72
73
  result
73
74
  end
74
75
 
@@ -100,11 +101,13 @@ class Test::Unit::TestCase
100
101
  got_xml_str = got_str.gsub(%r!(\S)/>!, '\1 />')
101
102
  # exp_xml_str = exp_members[i].get_input_stream.read.gsub(%r!(\S)/>!, '\1 />')
102
103
  exp_str = exp_members[i].get_input_stream.read
103
- exp_str.force_encoding("ASCII-8BIT") if got_str.encoding == Encoding::ASCII_8BIT
104
+ ruby_19 do
105
+ exp_str.force_encoding("ASCII-8BIT") if got_str.encoding == Encoding::ASCII_8BIT
106
+ end
104
107
  exp_xml_str = exp_str.gsub(%r!(\S)/>!, '\1 />')
105
108
  rescue
106
- p got_str.encoding
107
- p exp_str.encoding
109
+ p ruby_19 { got_str.encoding } || ruby_18 { got_str }
110
+ p ruby_19 { exp_str.encoding } || ruby_18 { exp_str }
108
111
  end
109
112
  # Remove dates and user specific data from the core.xml data.
110
113
  if exp_members[i].name == 'docProps/core.xml'
@@ -0,0 +1,4 @@
1
+ ����� ������� ������ ������
2
+ ����� ����,��� ����,�� ����,���� ����,���� ����,��,���� ������,����,����,����,�����,����
3
+ 01/11/2012,09:04:20,_���� , 131, 39977777,����������� ,00171044973, , ,�� ����� , ,����� ����/����� �� ���� ������
4
+ 01/11/2012,09:04:24,_���� , 131, 36888865,������� ,00171081635,���� ������ ,���� ������ ,�� ����� , ,
@@ -0,0 +1,44 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartColumn07 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ File.delete(@xlsx) if File.exist?(@xlsx)
11
+ end
12
+
13
+ def test_chart_column07
14
+ @xlsx = 'chart_column07.xlsx'
15
+ workbook = WriteXLSX.new(@xlsx)
16
+ worksheet = workbook.add_worksheet
17
+ chart = workbook.add_chart(:type => 'column', :embedded => 1)
18
+
19
+ # For testing, copy the randomly generated axis ids in the target xlsx file.
20
+ chart.instance_variable_set(:@axis_ids, [68810240, 68811776])
21
+
22
+ data = [
23
+ [ 1, 2, 3, 4, 5 ],
24
+ [ 2, 4, 6, 8, 10 ],
25
+ [ 3, 6, 9, 12, 15 ]
26
+ ]
27
+
28
+ worksheet.write('A1', data)
29
+
30
+ chart.add_series(
31
+ :values => '=(Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5)',
32
+ :values_data => [1, 2, 4, 5]
33
+ )
34
+
35
+ worksheet.insert_chart('E9', chart)
36
+
37
+ workbook.close
38
+ compare_xlsx_for_regression(File.join(@regression_output, @xlsx),
39
+ @xlsx,
40
+ nil,
41
+ nil
42
+ )
43
+ end
44
+ end