axlsx 1.1.4 → 1.1.5

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 (81) hide show
  1. data/README.md +10 -3
  2. data/Rakefile +7 -1
  3. data/examples/chart_colors.rb +1 -1
  4. data/examples/chart_colors.xlsx +0 -0
  5. data/examples/doc/_index.html +84 -0
  6. data/examples/doc/class_list.html +47 -0
  7. data/examples/doc/css/common.css +1 -0
  8. data/examples/doc/css/full_list.css +55 -0
  9. data/examples/doc/css/style.css +322 -0
  10. data/examples/doc/file_list.html +46 -0
  11. data/examples/doc/frames.html +13 -0
  12. data/examples/doc/index.html +84 -0
  13. data/examples/doc/js/app.js +205 -0
  14. data/examples/doc/js/full_list.js +173 -0
  15. data/examples/doc/js/jquery.js +16 -0
  16. data/examples/doc/method_list.html +46 -0
  17. data/examples/doc/top-level-namespace.html +95 -0
  18. data/examples/example.rb +12 -5
  19. data/examples/example.xlsx +0 -0
  20. data/examples/example_streamed.xlsx +0 -0
  21. data/examples/extractive.rb +3 -0
  22. data/lib/axlsx.rb +4 -4
  23. data/lib/axlsx/drawing/drawing.rb +7 -2
  24. data/lib/axlsx/drawing/graphic_frame.rb +2 -1
  25. data/lib/axlsx/drawing/num_data_source.rb +3 -0
  26. data/lib/axlsx/drawing/vml_drawing.rb +42 -0
  27. data/lib/axlsx/drawing/vml_drawing.rb~ +6 -0
  28. data/lib/axlsx/drawing/vml_shape.rb +128 -0
  29. data/lib/axlsx/drawing/vml_shape.rb~ +61 -0
  30. data/lib/axlsx/package.rb +24 -0
  31. data/lib/axlsx/rels/relationships.rb +0 -10
  32. data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
  33. data/lib/axlsx/util/constants.rb +24 -0
  34. data/lib/axlsx/util/validators.rb +32 -4
  35. data/lib/axlsx/version.rb +1 -1
  36. data/lib/axlsx/workbook/workbook.rb +21 -0
  37. data/lib/axlsx/workbook/worksheet/cell.rb +4 -2
  38. data/lib/axlsx/workbook/worksheet/comment.rb +107 -0
  39. data/lib/axlsx/workbook/worksheet/comment.rb~ +91 -0
  40. data/lib/axlsx/workbook/worksheet/comments.rb +77 -0
  41. data/lib/axlsx/workbook/worksheet/comments.rb~ +86 -0
  42. data/lib/axlsx/workbook/worksheet/page_setup.rb +90 -0
  43. data/lib/axlsx/workbook/worksheet/print_options.rb +63 -0
  44. data/lib/axlsx/workbook/worksheet/row.rb +2 -2
  45. data/lib/axlsx/workbook/worksheet/worksheet.rb +72 -9
  46. data/test/doc_props/tc_core.rb +3 -1
  47. data/test/drawing/tc_hyperlink.rb +4 -0
  48. data/test/drawing/tc_line_series.rb +6 -2
  49. data/test/drawing/tc_pie_series.rb +6 -1
  50. data/test/drawing/tc_vml_drawing.rb +25 -0
  51. data/{examples/#extractive.csv# → test/drawing/tc_vml_drawing.rb~} +0 -0
  52. data/test/drawing/tc_vml_shape.rb +100 -0
  53. data/test/rels/tc_relationship.rb +1 -0
  54. data/test/stylesheet/tc_gradient_fill.rb +8 -0
  55. data/test/stylesheet/tc_pattern_fill.rb +7 -1
  56. data/test/tc_helper.rb +1 -0
  57. data/test/tc_package.rb +16 -5
  58. data/test/util/tc_validators.rb +29 -0
  59. data/test/workbook/worksheet/tc_cell.rb +17 -0
  60. data/test/workbook/worksheet/tc_comment.rb +56 -0
  61. data/test/workbook/worksheet/tc_comments.rb +50 -0
  62. data/test/workbook/worksheet/tc_page_setup.rb +103 -0
  63. data/test/workbook/worksheet/tc_print_options.rb +72 -0
  64. data/test/workbook/worksheet/tc_row.rb +19 -13
  65. data/test/workbook/worksheet/tc_worksheet.rb +60 -7
  66. metadata +56 -24
  67. data/examples/#extractive.rb# +0 -45
  68. data/examples/chart_colors.rb~ +0 -0
  69. data/examples/colored_series_data.xlsx +0 -0
  70. data/examples/example.csv +0 -1000
  71. data/examples/extractive.csv +0 -1
  72. data/examples/extractive.csv~ +0 -1
  73. data/examples/extractive.rb~ +0 -3
  74. data/examples/extractive.xlsx +0 -0
  75. data/examples/no-use_autowidth.xlsx +0 -0
  76. data/examples/shared_strings_example.xlsx +0 -0
  77. data/examples/stack.rb +0 -21
  78. data/examples/stack.rb~ +0 -27
  79. data/examples/stack.xlsx +0 -0
  80. data/examples/~$chart_colors.xlsx +0 -0
  81. data/examples/~$extractive.xlsx +0 -0
@@ -0,0 +1,91 @@
1
+ module Axlsx
2
+
3
+ # A comment is the text data for a comment
4
+ class Comment
5
+
6
+ # The text to render
7
+ # @return [String]
8
+ attr_reader :text
9
+
10
+ # The index of the the author for this comment in the owning Comments object
11
+ # @see Comments
12
+ # @return [Integer]
13
+ attr_reader :author_index
14
+
15
+ # The owning Comments object
16
+ # @return [Comments]
17
+ attr_reader :comments
18
+
19
+
20
+ # The string based cell position reference (e.g. 'A1') that determines the positioning of this comment
21
+ attr_reader :ref
22
+
23
+ # TODO
24
+ # r (Rich Text Run)
25
+ # rPh (Phonetic Text Run)
26
+ # phoneticPr (Phonetic Properties)
27
+
28
+ def initialize(comments, options={})
29
+ raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
30
+ @comments = comments
31
+ options.each do |o|
32
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
33
+ end
34
+ yield self if block_given?
35
+ end
36
+
37
+ def pn
38
+ "#{COMMENT_PN % (index+1)}"
39
+ end
40
+
41
+ def vml_shape
42
+ @vml_shape ||= initialize_vml_shape
43
+ end
44
+
45
+ def initialize_vml_shape
46
+ ws = self.comments.worksheet
47
+ @vml_shape = VmlShape.new(self, :row => ws[ref].row.index, :column => ws[ref].index) do |vml|
48
+ vml.left_column = vml.row + 1
49
+ vml.right_column = vml.column + 4
50
+ vml.top_row = vml.row
51
+ vml.bottom_row = vml.row + 4
52
+ end
53
+ end
54
+
55
+ # The index of this comment
56
+ # @return [Integer]
57
+ def index
58
+ @comments.comment_list.index(self)
59
+ end
60
+
61
+ def ref=(v)
62
+ Axlsx::DataTypeValidator.validate "Comment.ref", [String, Cell], v
63
+ @ref = v if v.is_a?(String)
64
+ @ref = v.r if v.is_a?(Cell)
65
+ end
66
+
67
+ def text=(v)
68
+ Axlsx::validate_string(v)
69
+ @text = v
70
+ end
71
+
72
+ def author_index=(v)
73
+ Axlsx::validate_unsigned_int(v)
74
+ @author_index = v
75
+ end
76
+
77
+ def to_xml_string(str = "")
78
+ author = @comments.authors[author_index]
79
+ str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
80
+ str << '<text><r>'
81
+ str << '<rPr> <b/><color indexed="81"/></rPr>'
82
+ str << '<t>' << author.to_s << ':
83
+ </t></r>'
84
+ str << '<r>'
85
+ str << '<rPr><color indexed="81"/></rPr>'
86
+ str << '<t>' << text << '</t></r></text>'
87
+ str << '</comment>'
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Axlsx
3
+
4
+ # Comments is a collection of Comment objects for a worksheet
5
+ class Comments < SimpleTypedList
6
+
7
+ # the vml_drawing that holds the shapes for comments
8
+ # @return [VmlDrawing]
9
+ attr_reader :vml_drawing
10
+
11
+ # The worksheet that these comments belong to
12
+ # @return [Worksheet]
13
+ attr_reader :worksheet
14
+
15
+ # The index of this collection in the workbook. Effectively the index of the worksheet.
16
+ # @return [Integer]
17
+ def index
18
+ @worksheet.index
19
+ end
20
+
21
+ # The part name for this object
22
+ # @return [String]
23
+ def pn
24
+ "#{COMMENT_PN % (index+1)}"
25
+ end
26
+
27
+ # Creates a new Comments object
28
+ # @param [Worksheet] worksheet The sheet that these comments belong to.
29
+ def initialize(worksheet)
30
+ raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
31
+ super(Comment)
32
+ @worksheet = worksheet
33
+ @vml_drawing = VmlDrawing.new(self)
34
+ end
35
+
36
+ # Adds a new comment to the worksheet that owns these comments.
37
+ # @note the author, text and ref options are required
38
+ # @option options [String] author The name of the author for this comment
39
+ # @option options [String] text The text for this comment
40
+ # @option options [Stirng|Cell] ref The cell that this comment is attached to.
41
+ def add_comment(options={})
42
+ raise ArgumentError, "Comment require an author" unless options[:author]
43
+ raise ArgumentError, "Comment requires text" unless options[:text]
44
+ raise ArgumentError, "Comment requires ref" unless options[:ref]
45
+ @list << Comment.new(self, options)
46
+ yield @list.last if block_given?
47
+ @list.last
48
+ end
49
+
50
+ # A sorted list of the unique authors in the contained comments
51
+ # @return [Array]
52
+ def authors
53
+ @list.map { |comment| comment.author.to_s }.uniq.sort
54
+ end
55
+
56
+ # serialize the object
57
+ # @param [String] str
58
+ # @return [String]
59
+ def to_xml_string(str="")
60
+ str << '<?xml version="1.0" encoding="UTF-8"?>'
61
+ str << '<comments xmlns="' << XML_NS << '">'
62
+ str << '<authors>'
63
+ authors.each do |author|
64
+ str << '<author>' << author.to_s << '</author>'
65
+ end
66
+ str << '</authors>'
67
+ str << '<commentList>'
68
+ @list.each do |comment|
69
+ comment.to_xml_string str
70
+ end
71
+ str << '</commentList></comments>'
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,86 @@
1
+ module Axlsx
2
+
3
+ class Comments
4
+
5
+ # a collection of the comment authors
6
+ # @return [SimpleTypedList]
7
+ attr_reader :authors
8
+
9
+ # a collection of comment objects
10
+ # @return [SimpleTypedList]
11
+ attr_reader :comment_list
12
+
13
+
14
+ # The worksheet that these comments belong to
15
+ # @return [Worksheet]
16
+ attr_reader :worksheet
17
+
18
+ # Creates a new Comments object
19
+ def initialize(worksheet)
20
+ raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
21
+ @worksheet = worksheet
22
+ @authors = SimpleTypedList.new String
23
+ @comment_list = SimpleTypedList.new Comment
24
+ end
25
+
26
+ def add_comment(options={})
27
+ raise ArgumentError, "Comment require an author" unless options[:author]
28
+ raise ArgumentError, "Comment requires text" unless options[:text]
29
+ options[:author_index] = @authors.index(options[:author]) || @authors << options[:author]
30
+ @comment_list << Comment.new(self, options)
31
+ @comment_list.last
32
+ end
33
+
34
+ def to_xml_string(str="")
35
+ end
36
+
37
+ end
38
+
39
+ class Comment
40
+
41
+ attr_reader :text
42
+
43
+ attr_reader :author_index
44
+
45
+ attr_reader :comments
46
+
47
+ # TODO
48
+ # r (Rich Text Run)
49
+ # rPh (Phonetic Text Run)
50
+ # phoneticPr (Phonetic Properties)
51
+ def initialize(comments, options={})
52
+ raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
53
+ @comments = comments
54
+ options.each do |o|
55
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
56
+ end
57
+ yield self if block_given?
58
+ end
59
+
60
+ def pn
61
+ "#{COMMENT_PN % (index+1)}"
62
+ end
63
+
64
+ # The index of this comment
65
+ # @return [Integer]
66
+ def index
67
+ @comments.comment_list.index(self)
68
+ end
69
+
70
+
71
+ def text=(v)
72
+ Axlsx::validate_string(v)
73
+ @text = v
74
+ end
75
+
76
+ def author_index=(v)
77
+ Axlsx::validate_unsigned_int(v)
78
+ @author_index = v
79
+ end
80
+
81
+ def to_xml_string(str = "")
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,90 @@
1
+ module Axlsx
2
+ # Page setup settings for printing a worksheet. All settings are optional.
3
+ #
4
+ # @note The recommended way to manage print options is via Worksheet#page_setup
5
+ # @see Worksheet#print_options
6
+ # @see Worksheet#initialize
7
+ class PageSetup
8
+
9
+ # TODO: Attributes defined by Open XML spec that are not implemented yet:
10
+ #
11
+ # * blackAndWhite
12
+ # * cellComments
13
+ # * copies
14
+ # * draft
15
+ # * errors
16
+ # * firstPageNumber
17
+ # * horizontalDpi
18
+ # * pageOrder
19
+ # * paperSize
20
+ # * useFirstPageNumber
21
+ # * usePrinterDefaults
22
+ # * verticalDpi
23
+
24
+ # Number of vertical pages to fit on.
25
+ # @return [Integer]
26
+ attr_reader :fit_to_height
27
+
28
+ # Number of horizontal pages to fit on.
29
+ # @return [Integer]
30
+ attr_reader :fit_to_width
31
+
32
+ # Orientation of the page (:default, :landscape, :portrait)
33
+ # @return [Symbol]
34
+ attr_reader :orientation
35
+
36
+ # Height of paper (string containing a number followed by a unit identifier: "297mm", "11in")
37
+ # @return [String]
38
+ attr_reader :paper_height
39
+
40
+ # Width of paper (string containing a number followed by a unit identifier: "210mm", "8.5in")
41
+ # @return [String]
42
+ attr_reader :paper_width
43
+
44
+ # Print scaling (percent value, given as integer ranging from 10 to 400)
45
+ # @return [Integer]
46
+ attr_reader :scale
47
+
48
+
49
+ # Creates a new PageSetup object
50
+ # @option options [Integer] fit_to_height Number of vertical pages to fit on
51
+ # @option options [Integer] fit_to_width Number of horizontal pages to fit on
52
+ # @option options [Symbol] orientation Orientation of the page (:default, :landscape, :portrait)
53
+ # @option options [String] paper_height Height of paper (number followed by unit identifier: "297mm", "11in")
54
+ # @option options [String] paper_width Width of paper (number followed by unit identifier: "210mm", "8.5in")
55
+ # @option options [Integer] scale Print scaling (percent value, integer ranging from 10 to 400)
56
+ def initialize(options = {})
57
+ set(options)
58
+ end
59
+
60
+ # Set some or all page settings at once.
61
+ # @param [Hash] options The page settings to set (possible keys are :fit_to_height, :fit_to_width, :orientation, :paper_height, :paper_width, and :scale).
62
+ def set(options)
63
+ options.each do |k, v|
64
+ send("#{k}=", v) if respond_to? "#{k}="
65
+ end
66
+ end
67
+
68
+ # @see fit_to_height
69
+ def fit_to_height=(v); Axlsx::validate_unsigned_int(v); @fit_to_height = v; end
70
+ # @see fit_to_width
71
+ def fit_to_width=(v); Axlsx::validate_unsigned_int(v); @fit_to_width = v; end
72
+ # @see orientation
73
+ def orientation=(v); Axlsx::validate_page_orientation(v); @orientation = v; end
74
+ # @see paper_height
75
+ def paper_height=(v); Axlsx::validate_number_with_unit(v); @paper_height = v; end
76
+ # @see paper_width
77
+ def paper_width=(v); Axlsx::validate_number_with_unit(v); @paper_width = v; end
78
+ # @see scale
79
+ def scale=(v); Axlsx::validate_page_scale(v); @scale = v; end
80
+
81
+ # Serializes the page settings element.
82
+ # @param [String] str
83
+ # @return [String]
84
+ def to_xml_string(str = '')
85
+ str << '<pageSetup '
86
+ str << instance_values.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ')
87
+ str << '/>'
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,63 @@
1
+ module Axlsx
2
+ # Options for printing a worksheet. All options are boolean and false by default.
3
+ #
4
+ # @note The recommended way to manage print options is via Worksheet#print_options
5
+ # @see Worksheet#print_options
6
+ # @see Worksheet#initialize
7
+ class PrintOptions
8
+
9
+ # Whether grid lines should be printed.
10
+ # @return [Boolean]
11
+ attr_reader :grid_lines
12
+
13
+ # Whether row and column headings should be printed.
14
+ # @return [Boolean]
15
+ attr_reader :headings
16
+
17
+ # Whether the content should be centered horizontally on the page.
18
+ # @return [Boolean]
19
+ attr_reader :horizontal_centered
20
+
21
+ # Whether the content should be centered vertically on the page.
22
+ # @return [Boolean]
23
+ attr_reader :vertical_centered
24
+
25
+ # Creates a new PrintOptions object
26
+ # @option options [Boolean] grid_lines Whether grid lines should be printed
27
+ # @option options [Boolean] headings Whether row and column headings should be printed
28
+ # @option options [Boolean] horizontal_centered Whether the content should be centered horizontally
29
+ # @option options [Boolean] vertical_centered Whether the content should be centered vertically
30
+ def initialize(options = {})
31
+ @grid_lines = @headings = @horizontal_centered = @vertical_centered = false
32
+ set(options)
33
+ end
34
+
35
+ # Set some or all options at once.
36
+ # @param [Hash] options The options to set (possible keys are :grid_lines, :headings, :horizontal_centered, and :vertical_centered).
37
+ def set(options)
38
+ options.each do |k, v|
39
+ send("#{k}=", v) if respond_to? "#{k}="
40
+ end
41
+ end
42
+
43
+ # @see grid_lines
44
+ def grid_lines=(v); Axlsx::validate_boolean(v); @grid_lines = v; end
45
+ # @see headings
46
+ def headings=(v); Axlsx::validate_boolean(v); @headings = v; end
47
+ # @see horizontal_centered
48
+ def horizontal_centered=(v); Axlsx::validate_boolean(v); @horizontal_centered = v; end
49
+ # @see vertical_centered
50
+ def vertical_centered=(v); Axlsx::validate_boolean(v); @vertical_centered = v; end
51
+
52
+ # Serializes the page options element.
53
+ # @note As all attributes default to "false" according to the xml schema definition, the generated xml includes only those attributes that are set to true.
54
+ # @param [String] str
55
+ # @return [String]
56
+ def to_xml_string(str = '')
57
+ str << '<printOptions '
58
+ #
59
+ str << instance_values.select{ |k,v| v == true }.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ')
60
+ str << '/>'
61
+ end
62
+ end
63
+ end
@@ -5,7 +5,9 @@ module Axlsx
5
5
  # @see Worksheet#add_row
6
6
  class Row
7
7
 
8
+ # A list of serilizable attributes.
8
9
  SERIALIZABLE_ATTRIBUTES = [:hidden, :outlineLevel, :collapsed, :style]
10
+
9
11
  # The worksheet this row belongs to
10
12
  # @return [Worksheet]
11
13
  attr_reader :worksheet
@@ -35,10 +37,8 @@ module Axlsx
35
37
  attr_reader :style
36
38
 
37
39
  # TODO 18.3.1.73
38
- # # collapsed
39
40
  # customFormat
40
41
  # # hidden
41
- # # outlineLevel
42
42
  # ph
43
43
  # # s (style)
44
44
  # spans
@@ -16,6 +16,8 @@ module Axlsx
16
16
  # @return [Array] of Table
17
17
  attr_reader :tables
18
18
 
19
+ attr_reader :comments
20
+
19
21
  # The rows in this worksheet
20
22
  # @note The recommended way to manage rows is Worksheet#add_row
21
23
  # @return [SimpleTypedList]
@@ -81,6 +83,51 @@ module Axlsx
81
83
 
82
84
  end
83
85
 
86
+ # Page setup settings for printing the worksheet.
87
+ # @example
88
+ # wb = Axlsx::Package.new.workbook
89
+ #
90
+ # # using options when creating the worksheet.
91
+ # ws = wb.add_worksheet :page_setup => {:fit_to_width => 1, :orientation => :landscape}
92
+ #
93
+ # # use the set method of the page_setup object
94
+ # ws.page_setup.set(:paper_width => "297mm", :paper_height => "210mm")
95
+ #
96
+ # # setup page in a block
97
+ # ws.page_setup do |page|
98
+ # page.scale = 80
99
+ # page.orientation = :portrait
100
+ # end
101
+ # @see PageSetup#initialize
102
+ # @return [PageSetup]
103
+ def page_setup
104
+ @page_setup ||= PageSetup.new
105
+ yield @page_setup if block_given?
106
+ @page_setup
107
+ end
108
+
109
+ # Options for printing the worksheet.
110
+ # @example
111
+ # wb = Axlsx::Package.new.workbook
112
+ # # using options when creating the worksheet.
113
+ # ws = wb.add_worksheet :print_options => {:gridLines => true, :horizontalCentered => true}
114
+ #
115
+ # # use the set method of the page_margins object
116
+ # ws.print_options.set(:headings => true)
117
+ #
118
+ # # set page margins in a block
119
+ # ws.print_options do |options|
120
+ # options.horizontalCentered = true
121
+ # options.verticalCentered = true
122
+ # end
123
+ # @see PrintOptions#initialize
124
+ # @return [PrintOptions]
125
+ def print_options
126
+ @print_options ||= PrintOptions.new
127
+ yield @print_options if block_given?
128
+ @print_options
129
+ end
130
+
84
131
  # definition of characters which are less than the maximum width of 0-9 in the default font for use in String#count.
85
132
  # This is used for autowidth calculations
86
133
  # @return [String]
@@ -93,21 +140,23 @@ module Axlsx
93
140
  # @see Workbook#add_worksheet
94
141
  # @option options [String] name The name of this worksheet.
95
142
  # @option options [Hash] page_margins A hash containing page margins for this worksheet. @see PageMargins
143
+ # @option options [Hash] print_options A hash containing print options for this worksheet. @see PrintOptions
96
144
  # @option options [Boolean] show_gridlines indicates if gridlines should be shown for this sheet.
97
145
  def initialize(wb, options={})
98
146
  self.workbook = wb
99
147
  @workbook.worksheets << self
100
-
148
+ @page_marging = @page_setup = @print_options = nil
101
149
  @drawing = @page_margins = @auto_filter = nil
102
150
  @merged_cells = []
103
151
  @auto_fit_data = []
104
152
  @conditional_formattings = []
105
-
153
+ @comments = Comments.new(self)
106
154
  @selected = false
107
155
  @show_gridlines = true
108
156
  self.name = "Sheet" + (index+1).to_s
109
157
  @page_margins = PageMargins.new options[:page_margins] if options[:page_margins]
110
-
158
+ @page_setup = PageSetup.new options[:page_setup] if options[:page_setup]
159
+ @print_options = PrintOptions.new options[:print_options] if options[:print_options]
111
160
  @rows = SimpleTypedList.new Row
112
161
  @column_info = SimpleTypedList.new Col
113
162
  # @cols = SimpleTypedList.new Cell
@@ -394,6 +443,12 @@ module Axlsx
394
443
  table
395
444
  end
396
445
 
446
+
447
+ # Shortcut to comments#add_comment
448
+ def add_comment(options={})
449
+ @comments.add_comment(options)
450
+ end
451
+
397
452
  # Adds a media item to the worksheets drawing
398
453
  # @param [Class] media_type
399
454
  # @option options [] unknown
@@ -423,7 +478,9 @@ module Axlsx
423
478
  str.concat '</sheetData>'
424
479
  str.concat "<autoFilter ref='%s'></autoFilter>" % @auto_filter if @auto_filter
425
480
  str.concat "<mergeCells count='%s'>%s</mergeCells>" % [@merged_cells.size, @merged_cells.reduce('') { |memo, obj| memo += "<mergeCell ref='%s'></mergeCell>" % obj } ] unless @merged_cells.empty?
481
+ print_options.to_xml_string(str) if @print_options
426
482
  page_margins.to_xml_string(str) if @page_margins
483
+ page_setup.to_xml_string(str) if @page_setup
427
484
  str.concat "<drawing r:id='rId1'></drawing>" if @drawing
428
485
  unless @tables.empty?
429
486
  str.concat "<tableParts count='%s'>%s</tableParts>" % [@tables.size, @tables.reduce('') { |memo, obj| memo += "<tablePart r:id='%s'/>" % obj.rId }]
@@ -431,18 +488,24 @@ module Axlsx
431
488
  @conditional_formattings.each do |cf|
432
489
  str.concat cf.to_xml_string
433
490
  end
491
+ str << '<legacyDrawing r:id="rId1"/>' if @comments.size > 0
434
492
  str + '</worksheet>'
435
493
  end
436
494
 
437
495
  # The worksheet relationships. This is managed automatically by the worksheet
438
496
  # @return [Relationships]
439
497
  def relationships
440
- r = Relationships.new
441
- @tables.each do |table|
442
- r << Relationship.new(TABLE_R, "../#{table.pn}")
443
- end
444
- r << Relationship.new(DRAWING_R, "../#{@drawing.pn}") if @drawing
445
- r
498
+ r = Relationships.new
499
+ @tables.each do |table|
500
+ r << Relationship.new(TABLE_R, "../#{table.pn}")
501
+ end
502
+
503
+ r << Relationship.new(VML_DRAWING_R, "../#{@comments.vml_drawing.pn}") if @comments.size > 0
504
+ r << Relationship.new(COMMENT_R, "../#{@comments.pn}") if @comments.size > 0
505
+ r << Relationship.new(COMMENT_R_NULL, "NULL") if @comments.size > 0
506
+
507
+ r << Relationship.new(DRAWING_R, "../#{@drawing.pn}") if @drawing
508
+ r
446
509
  end
447
510
 
448
511
  # Returns the cell or cells defined using excel style A1:B3 references.