caxlsx 3.1.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -1
  3. data/README.md +4 -11
  4. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  5. data/lib/axlsx/doc_props/app.rb +1 -1
  6. data/lib/axlsx/drawing/chart.rb +25 -2
  7. data/lib/axlsx/drawing/d_lbls.rb +3 -2
  8. data/lib/axlsx/drawing/scatter_series.rb +31 -0
  9. data/lib/axlsx/drawing/title.rb +11 -1
  10. data/lib/axlsx/drawing/view_3D.rb +1 -1
  11. data/lib/axlsx/package.rb +15 -5
  12. data/lib/axlsx/rels/relationship.rb +1 -1
  13. data/lib/axlsx/stylesheet/border.rb +2 -0
  14. data/lib/axlsx/stylesheet/font.rb +1 -1
  15. data/lib/axlsx/stylesheet/styles.rb +139 -24
  16. data/lib/axlsx/util/constants.rb +16 -1
  17. data/lib/axlsx/util/serialized_attributes.rb +2 -2
  18. data/lib/axlsx/util/storage.rb +9 -9
  19. data/lib/axlsx/version.rb +1 -1
  20. data/lib/axlsx/workbook/workbook.rb +55 -0
  21. data/lib/axlsx/workbook/worksheet/border_creator.rb +76 -0
  22. data/lib/axlsx/workbook/worksheet/cell.rb +29 -2
  23. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  24. data/lib/axlsx/workbook/worksheet/col.rb +4 -4
  25. data/lib/axlsx/workbook/worksheet/data_validation.rb +26 -5
  26. data/lib/axlsx/workbook/worksheet/pivot_table.rb +55 -14
  27. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +1 -1
  28. data/lib/axlsx/workbook/worksheet/worksheet.rb +68 -7
  29. data/lib/axlsx.rb +43 -10
  30. metadata +6 -253
  31. data/test/benchmark.rb +0 -72
  32. data/test/content_type/tc_content_type.rb +0 -76
  33. data/test/content_type/tc_default.rb +0 -16
  34. data/test/content_type/tc_override.rb +0 -14
  35. data/test/doc_props/tc_app.rb +0 -43
  36. data/test/doc_props/tc_core.rb +0 -42
  37. data/test/drawing/tc_area_chart.rb +0 -39
  38. data/test/drawing/tc_area_series.rb +0 -71
  39. data/test/drawing/tc_axes.rb +0 -8
  40. data/test/drawing/tc_axis.rb +0 -112
  41. data/test/drawing/tc_bar_3D_chart.rb +0 -86
  42. data/test/drawing/tc_bar_chart.rb +0 -86
  43. data/test/drawing/tc_bar_series.rb +0 -46
  44. data/test/drawing/tc_bubble_chart.rb +0 -44
  45. data/test/drawing/tc_bubble_series.rb +0 -21
  46. data/test/drawing/tc_cat_axis.rb +0 -31
  47. data/test/drawing/tc_cat_axis_data.rb +0 -27
  48. data/test/drawing/tc_chart.rb +0 -123
  49. data/test/drawing/tc_d_lbls.rb +0 -57
  50. data/test/drawing/tc_data_source.rb +0 -23
  51. data/test/drawing/tc_drawing.rb +0 -80
  52. data/test/drawing/tc_graphic_frame.rb +0 -27
  53. data/test/drawing/tc_hyperlink.rb +0 -64
  54. data/test/drawing/tc_line_3d_chart.rb +0 -47
  55. data/test/drawing/tc_line_chart.rb +0 -39
  56. data/test/drawing/tc_line_series.rb +0 -71
  57. data/test/drawing/tc_marker.rb +0 -44
  58. data/test/drawing/tc_named_axis_data.rb +0 -27
  59. data/test/drawing/tc_num_data.rb +0 -31
  60. data/test/drawing/tc_num_val.rb +0 -29
  61. data/test/drawing/tc_one_cell_anchor.rb +0 -66
  62. data/test/drawing/tc_pic.rb +0 -103
  63. data/test/drawing/tc_picture_locking.rb +0 -72
  64. data/test/drawing/tc_pie_3D_chart.rb +0 -28
  65. data/test/drawing/tc_pie_series.rb +0 -33
  66. data/test/drawing/tc_scaling.rb +0 -36
  67. data/test/drawing/tc_scatter_chart.rb +0 -48
  68. data/test/drawing/tc_scatter_series.rb +0 -56
  69. data/test/drawing/tc_ser_axis.rb +0 -31
  70. data/test/drawing/tc_series.rb +0 -23
  71. data/test/drawing/tc_series_title.rb +0 -54
  72. data/test/drawing/tc_str_data.rb +0 -18
  73. data/test/drawing/tc_str_val.rb +0 -30
  74. data/test/drawing/tc_title.rb +0 -70
  75. data/test/drawing/tc_two_cell_anchor.rb +0 -36
  76. data/test/drawing/tc_val_axis.rb +0 -24
  77. data/test/drawing/tc_view_3D.rb +0 -54
  78. data/test/drawing/tc_vml_drawing.rb +0 -25
  79. data/test/drawing/tc_vml_shape.rb +0 -106
  80. data/test/fixtures/image1.gif +0 -0
  81. data/test/fixtures/image1.jpeg +0 -0
  82. data/test/fixtures/image1.jpg +0 -0
  83. data/test/fixtures/image1.png +0 -0
  84. data/test/fixtures/image1_fake.jpg +0 -0
  85. data/test/profile.rb +0 -24
  86. data/test/rels/tc_relationship.rb +0 -52
  87. data/test/rels/tc_relationships.rb +0 -37
  88. data/test/stylesheet/tc_border.rb +0 -37
  89. data/test/stylesheet/tc_border_pr.rb +0 -32
  90. data/test/stylesheet/tc_cell_alignment.rb +0 -81
  91. data/test/stylesheet/tc_cell_protection.rb +0 -29
  92. data/test/stylesheet/tc_cell_style.rb +0 -57
  93. data/test/stylesheet/tc_color.rb +0 -43
  94. data/test/stylesheet/tc_dxf.rb +0 -81
  95. data/test/stylesheet/tc_fill.rb +0 -18
  96. data/test/stylesheet/tc_font.rb +0 -133
  97. data/test/stylesheet/tc_gradient_fill.rb +0 -72
  98. data/test/stylesheet/tc_gradient_stop.rb +0 -31
  99. data/test/stylesheet/tc_num_fmt.rb +0 -30
  100. data/test/stylesheet/tc_pattern_fill.rb +0 -43
  101. data/test/stylesheet/tc_styles.rb +0 -261
  102. data/test/stylesheet/tc_table_style.rb +0 -44
  103. data/test/stylesheet/tc_table_style_element.rb +0 -45
  104. data/test/stylesheet/tc_table_styles.rb +0 -29
  105. data/test/stylesheet/tc_xf.rb +0 -120
  106. data/test/tc_axlsx.rb +0 -109
  107. data/test/tc_helper.rb +0 -10
  108. data/test/tc_package.rb +0 -314
  109. data/test/util/tc_mime_type_utils.rb +0 -13
  110. data/test/util/tc_serialized_attributes.rb +0 -19
  111. data/test/util/tc_simple_typed_list.rb +0 -77
  112. data/test/util/tc_validators.rb +0 -210
  113. data/test/workbook/tc_defined_name.rb +0 -49
  114. data/test/workbook/tc_shared_strings_table.rb +0 -59
  115. data/test/workbook/tc_workbook.rb +0 -160
  116. data/test/workbook/tc_workbook_view.rb +0 -50
  117. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +0 -38
  118. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +0 -76
  119. data/test/workbook/worksheet/auto_filter/tc_filters.rb +0 -50
  120. data/test/workbook/worksheet/tc_break.rb +0 -49
  121. data/test/workbook/worksheet/tc_cell.rb +0 -453
  122. data/test/workbook/worksheet/tc_cfvo.rb +0 -31
  123. data/test/workbook/worksheet/tc_col.rb +0 -93
  124. data/test/workbook/worksheet/tc_color_scale.rb +0 -58
  125. data/test/workbook/worksheet/tc_comment.rb +0 -72
  126. data/test/workbook/worksheet/tc_comments.rb +0 -57
  127. data/test/workbook/worksheet/tc_conditional_formatting.rb +0 -224
  128. data/test/workbook/worksheet/tc_data_bar.rb +0 -46
  129. data/test/workbook/worksheet/tc_data_validation.rb +0 -265
  130. data/test/workbook/worksheet/tc_date_time_converter.rb +0 -124
  131. data/test/workbook/worksheet/tc_header_footer.rb +0 -151
  132. data/test/workbook/worksheet/tc_icon_set.rb +0 -45
  133. data/test/workbook/worksheet/tc_outline_pr.rb +0 -19
  134. data/test/workbook/worksheet/tc_page_margins.rb +0 -97
  135. data/test/workbook/worksheet/tc_page_set_up_pr.rb +0 -15
  136. data/test/workbook/worksheet/tc_page_setup.rb +0 -143
  137. data/test/workbook/worksheet/tc_pane.rb +0 -54
  138. data/test/workbook/worksheet/tc_pivot_table.rb +0 -143
  139. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +0 -62
  140. data/test/workbook/worksheet/tc_print_options.rb +0 -72
  141. data/test/workbook/worksheet/tc_protected_range.rb +0 -17
  142. data/test/workbook/worksheet/tc_rich_text.rb +0 -44
  143. data/test/workbook/worksheet/tc_rich_text_run.rb +0 -173
  144. data/test/workbook/worksheet/tc_row.rb +0 -160
  145. data/test/workbook/worksheet/tc_selection.rb +0 -55
  146. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +0 -18
  147. data/test/workbook/worksheet/tc_sheet_format_pr.rb +0 -88
  148. data/test/workbook/worksheet/tc_sheet_pr.rb +0 -49
  149. data/test/workbook/worksheet/tc_sheet_protection.rb +0 -117
  150. data/test/workbook/worksheet/tc_sheet_view.rb +0 -214
  151. data/test/workbook/worksheet/tc_table.rb +0 -77
  152. data/test/workbook/worksheet/tc_table_style_info.rb +0 -53
  153. data/test/workbook/worksheet/tc_worksheet.rb +0 -601
  154. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +0 -55
@@ -1,4 +1,7 @@
1
1
  # encoding: UTF-8
2
+
3
+ require_relative "border_creator"
4
+
2
5
  module Axlsx
3
6
 
4
7
  # The Worksheet class represents a worksheet in the workbook.
@@ -168,7 +171,7 @@ module Axlsx
168
171
  # @return Boolean
169
172
  # @see #page_setup
170
173
  def fit_to_page?
171
- return false unless self.instance_values.keys.include?('page_setup')
174
+ return false unless Axlsx.instance_values_for(self).keys.include?('page_setup')
172
175
  page_setup.fit_to_page?
173
176
  end
174
177
 
@@ -303,7 +306,8 @@ module Axlsx
303
306
  end
304
307
 
305
308
  # The name of the worksheet
306
- # The name of a worksheet must be unique in the workbook, and must not exceed 31 characters
309
+ # The name of a worksheet must be unique in the workbook, and must not exceed the number
310
+ # of characters defined in Axlsx::WORKSHEET_MAX_NAME_LENGTH
307
311
  # @param [String] name
308
312
  def name=(name)
309
313
  validate_sheet_name name
@@ -559,6 +563,41 @@ module Axlsx
559
563
  cells.each { |cell| cell.style = style }
560
564
  end
561
565
 
566
+ # Set the style for cells in a specific column
567
+ # @param [String|Array] cell references
568
+ # @param [Hash] styles
569
+ def add_style(cell_refs, *styles)
570
+ if !cell_refs.is_a?(Array)
571
+ cell_refs = [cell_refs]
572
+ end
573
+
574
+ cell_refs.each do |cell_ref|
575
+ item = self[cell_ref]
576
+
577
+ cells = item.is_a?(Array) ? item : [item]
578
+
579
+ cells.each do |cell|
580
+ styles.each do |style|
581
+ cell.add_style(style)
582
+ end
583
+ end
584
+ end
585
+ end
586
+
587
+ # Set the style for cells in a specific column
588
+ # @param [String|Array] cell references
589
+ # @param [Hash|Array|Symbol] border options
590
+ def add_border(cell_refs, options = Axlsx::Border::EDGES)
591
+ if !cell_refs.is_a?(Array)
592
+ cell_refs = [cell_refs]
593
+ end
594
+
595
+ cell_refs.each do |cell_ref|
596
+ cells = self[cell_ref]
597
+ Axlsx::BorderCreator.new(self, cells, options).draw
598
+ end
599
+ end
600
+
562
601
  # Returns a sheet node serialization for this sheet in the workbook.
563
602
  def to_sheet_node_xml_string(str='')
564
603
  add_autofilter_defined_name_to_workbook
@@ -599,10 +638,20 @@ module Axlsx
599
638
  # @return [Cell, Array]
600
639
  def [](cell_def)
601
640
  return rows[cell_def] if cell_def.is_a?(Integer)
641
+
602
642
  parts = cell_def.split(':').map{ |part| name_to_cell part }
643
+
603
644
  if parts.size == 1
604
645
  parts.first
605
646
  else
647
+ if parts.size > 2
648
+ raise ArgumentError, (ERR_CELL_REFERENCE_INVALID % cell_def)
649
+ elsif parts.first.nil?
650
+ raise ArgumentError, (ERR_CELL_REFERENCE_MISSING_CELL % [cell_def.split(":").first, cell_def])
651
+ elsif parts.last.nil?
652
+ raise ArgumentError, (ERR_CELL_REFERENCE_MISSING_CELL % [cell_def.split(":").last, cell_def])
653
+ end
654
+
606
655
  range(*parts)
607
656
  end
608
657
  end
@@ -612,11 +661,16 @@ module Axlsx
612
661
  # @return [Cell]
613
662
  def name_to_cell(name)
614
663
  col_index, row_index = *Axlsx::name_to_indices(name)
664
+
615
665
  r = rows[row_index]
616
- r[col_index] if r
666
+
667
+ if r
668
+ return r[col_index]
669
+ end
617
670
  end
618
671
 
619
- # shortcut method to access styles direclty from the worksheet
672
+ # Shortcut method to access workbook styles
673
+ #
620
674
  # This lets us do stuff like:
621
675
  # @example
622
676
  # p = Axlsx::Package.new
@@ -625,6 +679,9 @@ module Axlsx
625
679
  # sheet.add_row ['Oh No!'], :styles => my_style
626
680
  # end
627
681
  # p.serialize 'foo.xlsx'
682
+ #
683
+ # @note The XLSX format does not support worksheet-specific styles. Even when using this method
684
+ # you're still working with the single global {Axlsx::Styles} object in the workbook.
628
685
  def styles
629
686
  @styles ||= self.workbook.styles
630
687
  end
@@ -668,9 +725,10 @@ module Axlsx
668
725
  def validate_sheet_name(name)
669
726
  DataTypeValidator.validate :worksheet_name, String, name
670
727
  # ignore first character (BOM) after encoding to utf16 because Excel does so, too.
728
+ raise ArgumentError, (ERR_SHEET_NAME_EMPTY) if name.empty?
671
729
  character_length = name.encode("utf-16")[1..-1].encode("utf-16").bytesize / 2
672
- raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > 31
673
- raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if '[]*/\?:'.chars.any? { |char| name.include? char }
730
+ raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > WORKSHEET_MAX_NAME_LENGTH
731
+ raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if WORKSHEET_NAME_FORBIDDEN_CHARS.any? { |char| name.include? char }
674
732
  name = Axlsx::coder.encode(name)
675
733
  sheet_names = @workbook.worksheets.reject { |s| s == self }.map { |s| s.name }
676
734
  raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % name) if sheet_names.include?(name)
@@ -688,11 +746,13 @@ module Axlsx
688
746
  def range(*cell_def)
689
747
  first, last = cell_def
690
748
  cells = []
749
+
691
750
  rows[(first.row.row_index..last.row.row_index)].each do |r|
692
751
  r[(first.index..last.index)].each do |c|
693
752
  cells << c
694
753
  end
695
754
  end
755
+
696
756
  cells
697
757
  end
698
758
 
@@ -746,11 +806,12 @@ module Axlsx
746
806
 
747
807
  def workbook=(v) DataTypeValidator.validate "Worksheet.workbook", Workbook, v; @workbook = v; end
748
808
 
749
- def update_column_info(cells, widths=nil)
809
+ def update_column_info(cells, widths = nil)
750
810
  cells.each_with_index do |cell, index|
751
811
  width = widths ? widths[index] : nil
752
812
  col = find_or_create_column_info(index)
753
813
  next if width == :ignore
814
+
754
815
  col.update_width(cell, width, workbook.use_autowidth)
755
816
  end
756
817
  end
data/lib/axlsx.rb CHANGED
@@ -28,16 +28,15 @@ require 'zip'
28
28
 
29
29
  #core dependencies
30
30
  require 'bigdecimal'
31
+ require 'set'
31
32
  require 'time'
32
33
 
33
- #if object does not have this already, I am borrowing it from active_support.
34
- # I am a very big fan of activesupports instance_values method, but do not want to require nor include the entire
35
- # library just for this one method.
36
- if !Object.respond_to?(:instance_values)
37
- Object.send :public # patch for 1.8.7 as it uses private scope
38
- Object.send :define_method, :instance_values do
39
- Hash[instance_variables.map { |name| [name.to_s[1..-1], instance_variable_get(name)] }]
34
+ begin
35
+ if Gem.loaded_specs.has_key?("axlsx_styler")
36
+ raise StandardError.new("Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly.")
40
37
  end
38
+ rescue
39
+ # Do nothing
41
40
  end
42
41
 
43
42
  # xlsx generation with charts, images, automated column width, customizable styles
@@ -47,6 +46,13 @@ end
47
46
  # Best of all, you can validate your xlsx file before serialization so you know
48
47
  # for sure that anything generated is going to load on your client's machine.
49
48
  module Axlsx
49
+ # I am a very big fan of activesupports instance_values method, but do not want to require nor include the entire
50
+ # library just for this one method.
51
+ #
52
+ # Defining as a class method on Axlsx to refrain from monkeypatching Object for all users of this gem.
53
+ def self.instance_values_for(object)
54
+ Hash[object.instance_variables.map { |name| [name.to_s[1..-1], object.instance_variable_get(name)] }]
55
+ end
50
56
 
51
57
  # determines the cell range for the items provided
52
58
  def self.cell_range(cells, absolute=true)
@@ -79,11 +85,25 @@ module Axlsx
79
85
  # returns the x, y position of a cell
80
86
  def self.name_to_indices(name)
81
87
  raise ArgumentError, 'invalid cell name' unless name.size > 1
88
+
89
+ letters_str = name[/[A-Z]+/]
90
+
82
91
  # capitalization?!?
83
- v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |val, c|
84
- val[:i] += ((c.bytes.first - 64) * val[:base]); val[:base] *= 26; val
92
+ v = letters_str.reverse.chars.reduce({:base=>1, :i=>0}) do |val, c|
93
+ val[:i] += ((c.bytes.first - 64) * val[:base])
94
+
95
+ val[:base] *= 26
96
+
97
+ next val
85
98
  end
86
- [v[:i]-1, ((name[/[1-9][0-9]*/]).to_i)-1]
99
+
100
+ col_index = (v[:i] - 1)
101
+
102
+ numbers_str = name[/[1-9][0-9]*/]
103
+
104
+ row_index = (numbers_str.to_i - 1)
105
+
106
+ return [col_index, row_index]
87
107
  end
88
108
 
89
109
  # converts the column index into alphabetical values.
@@ -155,6 +175,19 @@ module Axlsx
155
175
  end
156
176
  end
157
177
 
178
+ # utility method for performing a deep merge on a Hash
179
+ # @param [Hash] Hash to merge into
180
+ # @param [Hash] Hash to be added
181
+ def self.hash_deep_merge(first_hash, second_hash)
182
+ first_hash.merge(second_hash) do |key, this_val, other_val|
183
+ if this_val.is_a?(Hash) && other_val.is_a?(Hash)
184
+ Axlsx.hash_deep_merge(this_val, other_val)
185
+ else
186
+ other_val
187
+ end
188
+ end
189
+ end
190
+
158
191
  # Instructs the serializer to not try to escape cell value input.
159
192
  # This will give you a huge speed bonus, but if you content has <, > or other xml character data
160
193
  # the workbook will be invalid and excel will complain.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caxlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Randy Morgan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-22 00:00:00.000000000 Z
12
+ date: 2022-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -119,14 +119,14 @@ dependencies:
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: 0.8.1
122
+ version: 0.9.0
123
123
  type: :development
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: 0.8.1
129
+ version: 0.9.0
130
130
  description: " xlsx spreadsheet generation with charts, images, automated column
131
131
  width, customizable styles and full schema validation. Axlsx helps you create beautiful
132
132
  Office Open XML Spreadsheet documents ( Excel, Google Spreadsheets, Numbers, LibreOffice)
@@ -236,6 +236,7 @@ files:
236
236
  - lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
237
237
  - lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
238
238
  - lib/axlsx/workbook/worksheet/auto_filter/filters.rb
239
+ - lib/axlsx/workbook/worksheet/border_creator.rb
239
240
  - lib/axlsx/workbook/worksheet/break.rb
240
241
  - lib/axlsx/workbook/worksheet/cell.rb
241
242
  - lib/axlsx/workbook/worksheet/cell_serializer.rb
@@ -324,130 +325,6 @@ files:
324
325
  - lib/schema/vml-wordprocessingDrawing.xsd
325
326
  - lib/schema/wml.xsd
326
327
  - lib/schema/xml.xsd
327
- - test/benchmark.rb
328
- - test/content_type/tc_content_type.rb
329
- - test/content_type/tc_default.rb
330
- - test/content_type/tc_override.rb
331
- - test/doc_props/tc_app.rb
332
- - test/doc_props/tc_core.rb
333
- - test/drawing/tc_area_chart.rb
334
- - test/drawing/tc_area_series.rb
335
- - test/drawing/tc_axes.rb
336
- - test/drawing/tc_axis.rb
337
- - test/drawing/tc_bar_3D_chart.rb
338
- - test/drawing/tc_bar_chart.rb
339
- - test/drawing/tc_bar_series.rb
340
- - test/drawing/tc_bubble_chart.rb
341
- - test/drawing/tc_bubble_series.rb
342
- - test/drawing/tc_cat_axis.rb
343
- - test/drawing/tc_cat_axis_data.rb
344
- - test/drawing/tc_chart.rb
345
- - test/drawing/tc_d_lbls.rb
346
- - test/drawing/tc_data_source.rb
347
- - test/drawing/tc_drawing.rb
348
- - test/drawing/tc_graphic_frame.rb
349
- - test/drawing/tc_hyperlink.rb
350
- - test/drawing/tc_line_3d_chart.rb
351
- - test/drawing/tc_line_chart.rb
352
- - test/drawing/tc_line_series.rb
353
- - test/drawing/tc_marker.rb
354
- - test/drawing/tc_named_axis_data.rb
355
- - test/drawing/tc_num_data.rb
356
- - test/drawing/tc_num_val.rb
357
- - test/drawing/tc_one_cell_anchor.rb
358
- - test/drawing/tc_pic.rb
359
- - test/drawing/tc_picture_locking.rb
360
- - test/drawing/tc_pie_3D_chart.rb
361
- - test/drawing/tc_pie_series.rb
362
- - test/drawing/tc_scaling.rb
363
- - test/drawing/tc_scatter_chart.rb
364
- - test/drawing/tc_scatter_series.rb
365
- - test/drawing/tc_ser_axis.rb
366
- - test/drawing/tc_series.rb
367
- - test/drawing/tc_series_title.rb
368
- - test/drawing/tc_str_data.rb
369
- - test/drawing/tc_str_val.rb
370
- - test/drawing/tc_title.rb
371
- - test/drawing/tc_two_cell_anchor.rb
372
- - test/drawing/tc_val_axis.rb
373
- - test/drawing/tc_view_3D.rb
374
- - test/drawing/tc_vml_drawing.rb
375
- - test/drawing/tc_vml_shape.rb
376
- - test/fixtures/image1.gif
377
- - test/fixtures/image1.jpeg
378
- - test/fixtures/image1.jpg
379
- - test/fixtures/image1.png
380
- - test/fixtures/image1_fake.jpg
381
- - test/profile.rb
382
- - test/rels/tc_relationship.rb
383
- - test/rels/tc_relationships.rb
384
- - test/stylesheet/tc_border.rb
385
- - test/stylesheet/tc_border_pr.rb
386
- - test/stylesheet/tc_cell_alignment.rb
387
- - test/stylesheet/tc_cell_protection.rb
388
- - test/stylesheet/tc_cell_style.rb
389
- - test/stylesheet/tc_color.rb
390
- - test/stylesheet/tc_dxf.rb
391
- - test/stylesheet/tc_fill.rb
392
- - test/stylesheet/tc_font.rb
393
- - test/stylesheet/tc_gradient_fill.rb
394
- - test/stylesheet/tc_gradient_stop.rb
395
- - test/stylesheet/tc_num_fmt.rb
396
- - test/stylesheet/tc_pattern_fill.rb
397
- - test/stylesheet/tc_styles.rb
398
- - test/stylesheet/tc_table_style.rb
399
- - test/stylesheet/tc_table_style_element.rb
400
- - test/stylesheet/tc_table_styles.rb
401
- - test/stylesheet/tc_xf.rb
402
- - test/tc_axlsx.rb
403
- - test/tc_helper.rb
404
- - test/tc_package.rb
405
- - test/util/tc_mime_type_utils.rb
406
- - test/util/tc_serialized_attributes.rb
407
- - test/util/tc_simple_typed_list.rb
408
- - test/util/tc_validators.rb
409
- - test/workbook/tc_defined_name.rb
410
- - test/workbook/tc_shared_strings_table.rb
411
- - test/workbook/tc_workbook.rb
412
- - test/workbook/tc_workbook_view.rb
413
- - test/workbook/worksheet/auto_filter/tc_auto_filter.rb
414
- - test/workbook/worksheet/auto_filter/tc_filter_column.rb
415
- - test/workbook/worksheet/auto_filter/tc_filters.rb
416
- - test/workbook/worksheet/tc_break.rb
417
- - test/workbook/worksheet/tc_cell.rb
418
- - test/workbook/worksheet/tc_cfvo.rb
419
- - test/workbook/worksheet/tc_col.rb
420
- - test/workbook/worksheet/tc_color_scale.rb
421
- - test/workbook/worksheet/tc_comment.rb
422
- - test/workbook/worksheet/tc_comments.rb
423
- - test/workbook/worksheet/tc_conditional_formatting.rb
424
- - test/workbook/worksheet/tc_data_bar.rb
425
- - test/workbook/worksheet/tc_data_validation.rb
426
- - test/workbook/worksheet/tc_date_time_converter.rb
427
- - test/workbook/worksheet/tc_header_footer.rb
428
- - test/workbook/worksheet/tc_icon_set.rb
429
- - test/workbook/worksheet/tc_outline_pr.rb
430
- - test/workbook/worksheet/tc_page_margins.rb
431
- - test/workbook/worksheet/tc_page_set_up_pr.rb
432
- - test/workbook/worksheet/tc_page_setup.rb
433
- - test/workbook/worksheet/tc_pane.rb
434
- - test/workbook/worksheet/tc_pivot_table.rb
435
- - test/workbook/worksheet/tc_pivot_table_cache_definition.rb
436
- - test/workbook/worksheet/tc_print_options.rb
437
- - test/workbook/worksheet/tc_protected_range.rb
438
- - test/workbook/worksheet/tc_rich_text.rb
439
- - test/workbook/worksheet/tc_rich_text_run.rb
440
- - test/workbook/worksheet/tc_row.rb
441
- - test/workbook/worksheet/tc_selection.rb
442
- - test/workbook/worksheet/tc_sheet_calc_pr.rb
443
- - test/workbook/worksheet/tc_sheet_format_pr.rb
444
- - test/workbook/worksheet/tc_sheet_pr.rb
445
- - test/workbook/worksheet/tc_sheet_protection.rb
446
- - test/workbook/worksheet/tc_sheet_view.rb
447
- - test/workbook/worksheet/tc_table.rb
448
- - test/workbook/worksheet/tc_table_style_info.rb
449
- - test/workbook/worksheet/tc_worksheet.rb
450
- - test/workbook/worksheet/tc_worksheet_hyperlink.rb
451
328
  homepage: https://github.com/caxlsx/caxlsx
452
329
  licenses:
453
330
  - MIT
@@ -471,128 +348,4 @@ rubygems_version: 3.0.9
471
348
  signing_key:
472
349
  specification_version: 4
473
350
  summary: Excel OOXML (xlsx) with charts, styles, images and autowidth columns.
474
- test_files:
475
- - test/drawing/tc_num_data.rb
476
- - test/drawing/tc_two_cell_anchor.rb
477
- - test/drawing/tc_view_3D.rb
478
- - test/drawing/tc_series_title.rb
479
- - test/drawing/tc_cat_axis.rb
480
- - test/drawing/tc_chart.rb
481
- - test/drawing/tc_num_val.rb
482
- - test/drawing/tc_axis.rb
483
- - test/drawing/tc_line_chart.rb
484
- - test/drawing/tc_marker.rb
485
- - test/drawing/tc_bubble_series.rb
486
- - test/drawing/tc_d_lbls.rb
487
- - test/drawing/tc_str_val.rb
488
- - test/drawing/tc_bar_chart.rb
489
- - test/drawing/tc_line_3d_chart.rb
490
- - test/drawing/tc_cat_axis_data.rb
491
- - test/drawing/tc_area_chart.rb
492
- - test/drawing/tc_line_series.rb
493
- - test/drawing/tc_scatter_series.rb
494
- - test/drawing/tc_bar_series.rb
495
- - test/drawing/tc_hyperlink.rb
496
- - test/drawing/tc_pic.rb
497
- - test/drawing/tc_named_axis_data.rb
498
- - test/drawing/tc_bubble_chart.rb
499
- - test/drawing/tc_str_data.rb
500
- - test/drawing/tc_drawing.rb
501
- - test/drawing/tc_scatter_chart.rb
502
- - test/drawing/tc_series.rb
503
- - test/drawing/tc_title.rb
504
- - test/drawing/tc_ser_axis.rb
505
- - test/drawing/tc_picture_locking.rb
506
- - test/drawing/tc_pie_series.rb
507
- - test/drawing/tc_vml_shape.rb
508
- - test/drawing/tc_axes.rb
509
- - test/drawing/tc_vml_drawing.rb
510
- - test/drawing/tc_pie_3D_chart.rb
511
- - test/drawing/tc_area_series.rb
512
- - test/drawing/tc_graphic_frame.rb
513
- - test/drawing/tc_one_cell_anchor.rb
514
- - test/drawing/tc_data_source.rb
515
- - test/drawing/tc_val_axis.rb
516
- - test/drawing/tc_scaling.rb
517
- - test/drawing/tc_bar_3D_chart.rb
518
- - test/util/tc_simple_typed_list.rb
519
- - test/util/tc_mime_type_utils.rb
520
- - test/util/tc_validators.rb
521
- - test/util/tc_serialized_attributes.rb
522
- - test/tc_axlsx.rb
523
- - test/stylesheet/tc_fill.rb
524
- - test/stylesheet/tc_border.rb
525
- - test/stylesheet/tc_gradient_stop.rb
526
- - test/stylesheet/tc_gradient_fill.rb
527
- - test/stylesheet/tc_table_style.rb
528
- - test/stylesheet/tc_font.rb
529
- - test/stylesheet/tc_pattern_fill.rb
530
- - test/stylesheet/tc_color.rb
531
- - test/stylesheet/tc_num_fmt.rb
532
- - test/stylesheet/tc_styles.rb
533
- - test/stylesheet/tc_border_pr.rb
534
- - test/stylesheet/tc_cell_protection.rb
535
- - test/stylesheet/tc_xf.rb
536
- - test/stylesheet/tc_cell_style.rb
537
- - test/stylesheet/tc_table_styles.rb
538
- - test/stylesheet/tc_dxf.rb
539
- - test/stylesheet/tc_table_style_element.rb
540
- - test/stylesheet/tc_cell_alignment.rb
541
- - test/tc_helper.rb
542
- - test/doc_props/tc_core.rb
543
- - test/doc_props/tc_app.rb
544
- - test/content_type/tc_override.rb
545
- - test/content_type/tc_content_type.rb
546
- - test/content_type/tc_default.rb
547
- - test/rels/tc_relationship.rb
548
- - test/rels/tc_relationships.rb
549
- - test/profile.rb
550
- - test/fixtures/image1_fake.jpg
551
- - test/fixtures/image1.jpeg
552
- - test/fixtures/image1.gif
553
- - test/fixtures/image1.png
554
- - test/fixtures/image1.jpg
555
- - test/benchmark.rb
556
- - test/tc_package.rb
557
- - test/workbook/tc_workbook_view.rb
558
- - test/workbook/tc_defined_name.rb
559
- - test/workbook/worksheet/tc_data_bar.rb
560
- - test/workbook/worksheet/tc_worksheet_hyperlink.rb
561
- - test/workbook/worksheet/tc_data_validation.rb
562
- - test/workbook/worksheet/tc_pivot_table_cache_definition.rb
563
- - test/workbook/worksheet/tc_protected_range.rb
564
- - test/workbook/worksheet/tc_selection.rb
565
- - test/workbook/worksheet/tc_rich_text.rb
566
- - test/workbook/worksheet/tc_date_time_converter.rb
567
- - test/workbook/worksheet/tc_table_style_info.rb
568
- - test/workbook/worksheet/tc_conditional_formatting.rb
569
- - test/workbook/worksheet/tc_page_setup.rb
570
- - test/workbook/worksheet/tc_comments.rb
571
- - test/workbook/worksheet/tc_sheet_view.rb
572
- - test/workbook/worksheet/tc_sheet_calc_pr.rb
573
- - test/workbook/worksheet/tc_color_scale.rb
574
- - test/workbook/worksheet/tc_worksheet.rb
575
- - test/workbook/worksheet/tc_rich_text_run.rb
576
- - test/workbook/worksheet/tc_sheet_pr.rb
577
- - test/workbook/worksheet/auto_filter/tc_filters.rb
578
- - test/workbook/worksheet/auto_filter/tc_auto_filter.rb
579
- - test/workbook/worksheet/auto_filter/tc_filter_column.rb
580
- - test/workbook/worksheet/tc_cell.rb
581
- - test/workbook/worksheet/tc_sheet_protection.rb
582
- - test/workbook/worksheet/tc_pane.rb
583
- - test/workbook/worksheet/tc_header_footer.rb
584
- - test/workbook/worksheet/tc_table.rb
585
- - test/workbook/worksheet/tc_page_margins.rb
586
- - test/workbook/worksheet/tc_cfvo.rb
587
- - test/workbook/worksheet/tc_col.rb
588
- - test/workbook/worksheet/tc_pivot_table.rb
589
- - test/workbook/worksheet/tc_break.rb
590
- - test/workbook/worksheet/tc_sheet_format_pr.rb
591
- - test/workbook/worksheet/tc_print_options.rb
592
- - test/workbook/worksheet/tc_comment.rb
593
- - test/workbook/worksheet/tc_outline_pr.rb
594
- - test/workbook/worksheet/tc_row.rb
595
- - test/workbook/worksheet/tc_icon_set.rb
596
- - test/workbook/worksheet/tc_page_set_up_pr.rb
597
- - test/workbook/tc_shared_strings_table.rb
598
- - test/workbook/tc_workbook.rb
351
+ test_files: []
data/test/benchmark.rb DELETED
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env ruby -s
2
- $:.unshift "#{File.dirname(__FILE__)}/../lib"
3
- require 'axlsx'
4
- require 'csv'
5
- require 'benchmark'
6
- Axlsx::trust_input = true
7
- row = []
8
- input = (32..126).to_a.pack('U*').chars.to_a
9
- 20.times { row << input.shuffle.join}
10
- times = 3000
11
- Benchmark.bmbm(30) do |x|
12
-
13
- x.report('axlsx_noautowidth') {
14
- p = Axlsx::Package.new
15
- p.workbook do |wb|
16
- wb.add_worksheet do |sheet|
17
- times.times do
18
- sheet << row
19
- end
20
- end
21
- end
22
- p.use_autowidth = false
23
- p.serialize("example_noautowidth.xlsx")
24
- }
25
-
26
- x.report('axlsx') {
27
- p = Axlsx::Package.new
28
- p.workbook do |wb|
29
- wb.add_worksheet do |sheet|
30
- times.times do
31
- sheet << row
32
- end
33
- end
34
- end
35
- p.serialize("example_autowidth.xlsx")
36
- }
37
-
38
- x.report('axlsx_shared') {
39
- p = Axlsx::Package.new
40
- p.workbook do |wb|
41
- wb.add_worksheet do |sheet|
42
- times.times do
43
- sheet << row
44
- end
45
- end
46
- end
47
- p.use_shared_strings = true
48
- p.serialize("example_shared.xlsx")
49
- }
50
-
51
- x.report('axlsx_stream') {
52
- p = Axlsx::Package.new
53
- p.workbook do |wb|
54
- wb.add_worksheet do |sheet|
55
- times.times do
56
- sheet << row
57
- end
58
- end
59
- end
60
- s = p.to_stream()
61
- File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
62
- }
63
-
64
- x.report('csv') {
65
- CSV.open("example.csv", "wb") do |csv|
66
- times.times do
67
- csv << row
68
- end
69
- end
70
- }
71
- end
72
- File.delete("example.csv", "example_streamed.xlsx", "example_shared.xlsx", "example_autowidth.xlsx", "example_noautowidth.xlsx")
@@ -1,76 +0,0 @@
1
- # encoding: UTF-8
2
- require 'tc_helper.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_string)
8
- end
9
-
10
- def test_valid_document
11
- schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
12
- assert(schema.validate(@doc).map{ |e| puts e.message; e.message }.empty?)
13
- end
14
-
15
- def test_pre_built_types
16
-
17
- o_path = "//xmlns:Override[@ContentType='%s']"
18
- d_path = "//xmlns:Default[@ContentType='%s']"
19
-
20
- #default
21
- assert_equal(@doc.xpath("//xmlns:Default").size, 2, "There should be 2 default types")
22
-
23
- node = @doc.xpath(d_path % Axlsx::XML_CT).first
24
- assert_equal(node["Extension"], "#{Axlsx::XML_EX}", "xml content type invalid")
25
-
26
- node = @doc.xpath(d_path % Axlsx::RELS_CT).first
27
- assert_equal(node["Extension"],"#{Axlsx::RELS_EX}", "relationships content type invalid")
28
-
29
- #overrride
30
- assert_equal(@doc.xpath("//xmlns:Override").size, 4, "There should be 4 Override types")
31
-
32
- node = @doc.xpath(o_path % Axlsx::APP_CT).first
33
- assert_equal(node["PartName"], "/#{Axlsx::APP_PN}", "App part name invalid")
34
-
35
- node = @doc.xpath(o_path % Axlsx::CORE_CT).first
36
- assert_equal(node["PartName"], "/#{Axlsx::CORE_PN}", "Core part name invalid")
37
-
38
- node = @doc.xpath(o_path % Axlsx::STYLES_CT).first
39
- assert_equal(node["PartName"], "/xl/#{Axlsx::STYLES_PN}", "Styles part name invalid")
40
-
41
- node = @doc.xpath(o_path % Axlsx::WORKBOOK_CT).first
42
- assert_equal(node["PartName"], "/#{Axlsx::WORKBOOK_PN}", "Workbook part invalid")
43
- end
44
-
45
- def test_should_get_worksheet_for_worksheets
46
- o_path = "//xmlns:Override[@ContentType='%s']"
47
-
48
- ws = @package.workbook.add_worksheet
49
- doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
50
- assert_equal(doc.xpath("//xmlns:Override").size, 5, "adding a worksheet should add another type")
51
- assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
52
-
53
- ws = @package.workbook.add_worksheet
54
- doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
55
- assert_equal(doc.xpath("//xmlns:Override").size, 6, "adding workship should add another type")
56
- assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
57
-
58
- end
59
-
60
- def test_drawings_and_charts_need_content_types
61
- o_path = "//xmlns:Override[@ContentType='%s']"
62
- ws = @package.workbook.add_worksheet
63
-
64
- c = ws.add_chart Axlsx::Pie3DChart
65
- doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
66
- assert_equal(doc.xpath("//xmlns:Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}")
67
- assert_equal(doc.xpath(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
68
- assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
69
-
70
- c = ws.add_chart Axlsx::Pie3DChart
71
- doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
72
- assert_equal(doc.xpath("//xmlns:Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}")
73
- assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
74
- end
75
-
76
- end