axlsx 1.2.0 → 1.3.3

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 (161) hide show
  1. data/.yardopts +3 -2
  2. data/CHANGELOG.md +34 -1
  3. data/README.md +47 -33
  4. data/Rakefile +1 -1
  5. data/examples/auto_filter.rb +16 -0
  6. data/examples/basic_charts.rb +4 -0
  7. data/examples/colored_links.rb +59 -0
  8. data/examples/doc/_index.html +88 -0
  9. data/examples/doc/class_list.html +53 -0
  10. data/examples/doc/css/common.css +1 -0
  11. data/examples/doc/css/full_list.css +57 -0
  12. data/examples/doc/css/style.css +328 -0
  13. data/examples/doc/file_list.html +52 -0
  14. data/examples/doc/frames.html +28 -0
  15. data/examples/doc/index.html +88 -0
  16. data/examples/doc/js/app.js +214 -0
  17. data/examples/doc/js/full_list.js +173 -0
  18. data/examples/doc/js/jquery.js +4 -0
  19. data/examples/doc/method_list.html +52 -0
  20. data/examples/doc/top-level-namespace.html +102 -0
  21. data/examples/example.rb +447 -257
  22. data/examples/finance.rb +82 -0
  23. data/examples/hyperlinks.rb +23 -0
  24. data/examples/page_setup.rb +11 -0
  25. data/examples/skydrive/axlsx.csv +1 -0
  26. data/examples/skydrive/axlsx.xlsx +0 -0
  27. data/examples/skydrive/real_example.rb +8 -8
  28. data/examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png +0 -0
  29. data/examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png +0 -0
  30. data/examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png +0 -0
  31. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png +0 -0
  32. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png +0 -0
  33. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png +0 -0
  34. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png +0 -0
  35. data/examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png +0 -0
  36. data/examples/sprk2012/basics.rb +11 -0
  37. data/examples/sprk2012/basics.xlsx +0 -0
  38. data/examples/sprk2012/gravatar.jpeg +0 -0
  39. data/examples/sprk2012/hair_club.jpg +0 -0
  40. data/examples/sprk2012/images.rb +9 -0
  41. data/examples/{example.xlsx → sprk2012/images.xlsx} +0 -0
  42. data/examples/sprk2012/line_chart.rb +56 -0
  43. data/examples/sprk2012/line_chart.xlsx +0 -0
  44. data/examples/sprk2012/sprk2012.key +0 -0
  45. data/examples/sprk2012/styles.rb +20 -0
  46. data/examples/sprk2012/styles.xlsx +0 -0
  47. data/examples/styles.rb +62 -0
  48. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  49. data/lib/axlsx/content_type/content_type.rb +1 -1
  50. data/lib/axlsx/content_type/default.rb +6 -37
  51. data/lib/axlsx/content_type/override.rb +6 -38
  52. data/lib/axlsx/doc_props/app.rb +10 -7
  53. data/lib/axlsx/drawing/axis.rb +4 -4
  54. data/lib/axlsx/drawing/chart.rb +2 -3
  55. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  56. data/lib/axlsx/drawing/drawing.rb +6 -0
  57. data/lib/axlsx/drawing/hyperlink.rb +40 -32
  58. data/lib/axlsx/drawing/marker.rb +13 -13
  59. data/lib/axlsx/drawing/num_data.rb +6 -6
  60. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  61. data/lib/axlsx/drawing/one_cell_anchor.rb +20 -22
  62. data/lib/axlsx/drawing/pic.rb +25 -27
  63. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  64. data/lib/axlsx/drawing/scaling.rb +13 -13
  65. data/lib/axlsx/drawing/scatter_chart.rb +3 -3
  66. data/lib/axlsx/drawing/series.rb +3 -6
  67. data/lib/axlsx/drawing/str_data.rb +3 -3
  68. data/lib/axlsx/drawing/str_val.rb +7 -8
  69. data/lib/axlsx/drawing/view_3D.rb +52 -38
  70. data/lib/axlsx/drawing/vml_shape.rb +23 -23
  71. data/lib/axlsx/package.rb +14 -17
  72. data/lib/axlsx/stylesheet/border.rb +29 -20
  73. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  74. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  75. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  76. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  77. data/lib/axlsx/stylesheet/color.rb +19 -16
  78. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  79. data/lib/axlsx/stylesheet/font.rb +22 -22
  80. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  81. data/lib/axlsx/stylesheet/num_fmt.rb +22 -13
  82. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  83. data/lib/axlsx/stylesheet/styles.rb +11 -2
  84. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  85. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  86. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  87. data/lib/axlsx/stylesheet/xf.rb +28 -26
  88. data/lib/axlsx/util/accessors.rb +49 -0
  89. data/lib/axlsx/util/constants.rb +105 -4
  90. data/lib/axlsx/util/options_parser.rb +15 -0
  91. data/lib/axlsx/util/serialized_attributes.rb +46 -0
  92. data/lib/axlsx/util/simple_typed_list.rb +16 -2
  93. data/lib/axlsx/util/validators.rb +33 -8
  94. data/lib/axlsx/version.rb +2 -2
  95. data/lib/axlsx/workbook/defined_name.rb +13 -58
  96. data/lib/axlsx/workbook/workbook.rb +33 -2
  97. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  98. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
  100. data/lib/axlsx/workbook/worksheet/cell.rb +82 -45
  101. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  102. data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -0
  103. data/lib/axlsx/workbook/worksheet/col.rb +34 -27
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +7 -13
  105. data/lib/axlsx/workbook/worksheet/comment.rb +14 -11
  106. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  107. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +27 -25
  108. data/lib/axlsx/workbook/worksheet/data_bar.rb +44 -34
  109. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  110. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -1
  111. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  112. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  113. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  114. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  115. data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
  116. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  117. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  118. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  119. data/lib/axlsx/workbook/worksheet/row.rb +48 -81
  120. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  121. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  122. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
  123. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  124. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  125. data/lib/axlsx/workbook/worksheet/table.rb +22 -17
  126. data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
  127. data/lib/axlsx/workbook/worksheet/worksheet.rb +51 -14
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +79 -0
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  131. data/lib/axlsx.rb +19 -5
  132. data/test/content_type/tc_default.rb +0 -11
  133. data/test/content_type/tc_override.rb +0 -13
  134. data/test/drawing/tc_d_lbls.rb +14 -4
  135. data/test/stylesheet/tc_styles.rb +13 -0
  136. data/test/tc_axlsx.rb +20 -2
  137. data/test/tc_package.rb +1 -0
  138. data/test/util/tc_validators.rb +22 -1
  139. data/test/workbook/tc_defined_name.rb +2 -2
  140. data/test/workbook/tc_workbook.rb +15 -0
  141. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  142. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  143. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  144. data/test/workbook/worksheet/tc_cell.rb +35 -5
  145. data/test/workbook/worksheet/tc_col.rb +11 -1
  146. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  147. data/test/workbook/worksheet/tc_page_setup.rb +6 -1
  148. data/test/workbook/worksheet/tc_pane.rb +5 -45
  149. data/test/workbook/worksheet/tc_row.rb +4 -4
  150. data/test/workbook/worksheet/tc_selection.rb +9 -48
  151. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  152. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  153. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +6 -1
  154. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  155. data/test/workbook/worksheet/tc_worksheet.rb +17 -3
  156. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +64 -0
  157. metadata +74 -10
  158. data/examples/example_streamed.xlsx +0 -0
  159. data/examples/no-use_autowidth.xlsx +0 -0
  160. data/examples/shared_strings_example.xlsx +0 -0
  161. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
 
4
3
  # XML Encoding
@@ -31,6 +30,9 @@ module Axlsx
31
30
  # xml schema namespace
32
31
  CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
33
32
 
33
+ # Digital signature namespace
34
+ DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature"
35
+
34
36
  # spreadsheet drawing namespace
35
37
  XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
36
38
 
@@ -61,6 +63,9 @@ module Axlsx
61
63
  # core rels namespace
62
64
  CORE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/metadata/core-properties"
63
65
 
66
+ # digital signature rels namespace
67
+ DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature"
68
+
64
69
  # styles rels namespace
65
70
  STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
66
71
 
@@ -76,7 +81,7 @@ module Axlsx
76
81
  # image rels namespace
77
82
  IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
78
83
 
79
- # image rels namespace
84
+ # hyperlink rels namespace
80
85
  HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
81
86
 
82
87
  # comment rels namespace
@@ -118,6 +123,15 @@ module Axlsx
118
123
  # core content type
119
124
  CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"
120
125
 
126
+ # digital signature xml content type
127
+ DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
128
+
129
+ # digital signature origin content type
130
+ DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"
131
+
132
+ # digital signature certificate content type
133
+ DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"
134
+
121
135
  # chart content type
122
136
  CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
123
137
 
@@ -136,6 +150,7 @@ module Axlsx
136
150
  #drawing content type
137
151
  DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
138
152
 
153
+
139
154
  # xml content type extensions
140
155
  XML_EX = "xml"
141
156
 
@@ -247,11 +262,14 @@ module Axlsx
247
262
  # error message for RegexValidator
248
263
  ERR_REGEX = "Invalid Data. %s does not match %s."
249
264
 
265
+ # error message for RangeValidator
266
+ ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s"
267
+
250
268
  # error message for sheets that use a name which is longer than 31 bytes
251
269
  ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less"
252
-
270
+
253
271
  # error message for sheets that use a name which includes a colon
254
-
272
+
255
273
  ERR_SHEET_NAME_COLON_FORBIDDEN = "Your worksheet name '%s' contains a colon, which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet."
256
274
 
257
275
  # error message for duplicate sheet names
@@ -268,4 +286,87 @@ module Axlsx
268
286
 
269
287
  # error message for non 'integerish' value
270
288
  ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s"
289
+
290
+ # Regex to match forbidden control characters
291
+ # The following will be automatically stripped from worksheets.
292
+ #
293
+ # x00 Null
294
+ # x01 Start Of Heading
295
+ # x02 Start Of Text
296
+ # x03End Of Text
297
+ # x04 End Of Transmission
298
+ # x05 Enquiry
299
+ # x06 Acknowledge
300
+ # x07 Bell
301
+ # x08 Backspace
302
+ # x0B Line Tabulation
303
+ # x0C Form Feed
304
+ # x0E Shift Out
305
+ # x0F Shift In
306
+ # x10 Data Link Escape
307
+ # x11 Device Control One
308
+ # x12 Device Control Two
309
+ # x13 Device Control Three
310
+ # x14 Device Control Four
311
+ # x15 Negative Acknowledge
312
+ # x16 Synchronous Idle
313
+ # x17 End Of Transmission Block
314
+ # x18 Cancel
315
+ # x19 End Of Medium
316
+ # x1A Substitute
317
+ # x1B Escape
318
+ # x1C Information Separator Four
319
+ # x1D Information Separator Three
320
+ # x1E Information Separator Two
321
+ # x1F Information Separator One
322
+ #
323
+ # The following are not dealt with.
324
+ # If you have this in your data, expect excel to blow up!
325
+ #
326
+ # x7F Delete
327
+ # x80 Control 0080
328
+ # x81 Control 0081
329
+ # x82 Break Permitted Here
330
+ # x83 No Break Here
331
+ # x84 Control 0084
332
+ # x85 Next Line (Nel)
333
+ # x86 Start Of Selected Area
334
+ # x87 End Of Selected Area
335
+ # x88 Character Tabulation Set
336
+ # x89 Character Tabulation With Justification
337
+ # x8A Line Tabulation Set
338
+ # x8B Partial Line Forward
339
+ # x8C Partial Line Backward
340
+ # x8D Reverse Line Feed
341
+ # x8E Single Shift Two
342
+ # x8F Single Shift Three
343
+ # x90 Device Control String
344
+ # x91 Private Use One
345
+ # x92 Private Use Two
346
+ # x93 Set Transmit State
347
+ # x94 Cancel Character
348
+ # x95 Message Waiting
349
+ # x96 Start Of Guarded Area
350
+ # x97 End Of Guarded Area
351
+ # x98 Start Of String
352
+ # x99 Control 0099
353
+ # x9A Single Character Introducer
354
+ # x9B Control Sequence Introducer
355
+ # x9C String Terminator
356
+ # x9D Operating System Command
357
+ # x9E Privacy Message
358
+ # x9F Application Program Command
359
+ #
360
+ # The following are allowed:
361
+ #
362
+ # x0A Line Feed (Lf)
363
+ # x0D Carriage Return (Cr)
364
+ # x09 Character Tabulation
365
+ # @see http://www.codetable.net/asciikeycodes
366
+ pattern = "[\x0-\x08\x0B\x0C\x0E-\x1F]"
367
+ pattern= pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
368
+
369
+ # The regular expression used to remove control characters from worksheets
370
+ CONTROL_CHAR_REGEX = Regexp.new(pattern, 'n')
371
+
271
372
  end
@@ -0,0 +1,15 @@
1
+ module Axlsx
2
+ # This module defines a single method for parsing options in class
3
+ # initializers.
4
+ module OptionsParser
5
+
6
+ # Parses an options hash by calling any defined method by the same
7
+ # name of the key postfixed with an '='
8
+ # @param [Hash] options Options to parse.
9
+ def parse_options(options={})
10
+ options.each do |key, value|
11
+ self.send("#{key}=", value) if self.respond_to?("#{key}=") && value != nil
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ module Axlsx
2
+ # This module allows us to define a list of symbols defining which
3
+ # attributes will be serialized for a class.
4
+ module SerializedAttributes
5
+
6
+ # Extend with class methods
7
+ def self.included(base)
8
+ base.send :extend, ClassMethods
9
+ end
10
+
11
+ # class methods applied to all includers
12
+ module ClassMethods
13
+
14
+ # This is the method to be used in inheriting classes to specify
15
+ # which of the instance values are serializable
16
+ def serializable_attributes(*symbols)
17
+ @xml_attributes = symbols
18
+ end
19
+
20
+ # a reader for those attributes
21
+ def xml_attributes
22
+ @xml_attributes
23
+ end
24
+ end
25
+
26
+ # serializes the instance values of the defining object based on the
27
+ # list of serializable attributes.
28
+ # @param [String] str The string instance to append this
29
+ # serialization to.
30
+ # @param [Hash] additional_attributes An option key value hash for
31
+ # defining values that are not serializable attributes list.
32
+ def serialized_attributes(str = '', additional_attributes = {})
33
+ key_value_pairs = instance_values
34
+ key_value_pairs.each do |key, value|
35
+ key_value_pairs.delete(key) if value == nil
36
+ key_value_pairs.delete(key) unless self.class.xml_attributes.include?(key.to_sym)
37
+ end
38
+ key_value_pairs.merge! additional_attributes
39
+
40
+ key_value_pairs.each do |key, value|
41
+ str << "#{Axlsx.camel(key, false)}=\"#{value}\" "
42
+ end
43
+ str
44
+ end
45
+ end
46
+ end
@@ -44,13 +44,15 @@ module Axlsx
44
44
  @list
45
45
  end
46
46
 
47
+ alias :to_a :to_ary
48
+
47
49
  # Unlock the list
48
50
  # @return [self]
49
51
  def unlock
50
52
  @locked_at = nil
51
53
  self
52
54
  end
53
-
55
+
54
56
  # join operator
55
57
  # @param [Array] v the array to join
56
58
  # @raise [ArgumentError] if any of the values being joined are not
@@ -60,7 +62,7 @@ module Axlsx
60
62
  v.each do |item|
61
63
  DataTypeValidator.validate "SimpleTypedList.+", @allowed_types, item
62
64
  @list << item
63
- end
65
+ end
64
66
  end
65
67
 
66
68
  # Concat operator
@@ -105,6 +107,18 @@ module Axlsx
105
107
  v
106
108
  end
107
109
 
110
+ # inserts an item at the index specfied
111
+ # @param [Integer] index
112
+ # @param [Any] v
113
+ # @raise [ArgumentError] if the index is protected by locking
114
+ # @raise [ArgumentError] if the index is not one of the allowed types
115
+ def insert(index, v)
116
+ DataTypeValidator.validate "SimpleTypedList.<<", @allowed_types, v
117
+ raise ArgumentError, "Item is protected and cannot be changed" if protected? index
118
+ @list.insert(index, v)
119
+ v
120
+ end
121
+
108
122
  # determines if the index is protected
109
123
  # @param [Integer] index
110
124
  def protected? index
@@ -14,6 +14,24 @@ module Axlsx
14
14
  end
15
15
  end
16
16
 
17
+ # Validate that the value provided is between a specific range
18
+ # Note that no data conversions will be done for you!
19
+ # Comparisons will be made using < and > or <= and <= when the inclusive parameter is true
20
+ class RangeValidator
21
+ # @param [String] name The name of what is being validated
22
+ # @param [Any] min The minimum allowed value
23
+ # @param [Any] max The maximum allowed value
24
+ # @param [Any] value The value to be validated
25
+ # @param [Boolean] inclusive Flag indicating if the comparison should be inclusive.
26
+ def self.validate(name, min, max, value, inclusive = true)
27
+ passes = if inclusive
28
+ min <= value && value <= max
29
+ else
30
+ min < value && value < max
31
+ end
32
+ raise ArgumentError, (ERR_RANGE % [value.inspect, min.to_s, max.to_s, inclusive]) unless passes
33
+ end
34
+ end
17
35
  # Validates the value against the regular expression provided.
18
36
  class RegexValidator
19
37
  # @param [String] name The name of what is being validated. This is included in the output when the value is invalid
@@ -73,7 +91,7 @@ module Axlsx
73
91
  # @raise [ArgumentError] raised if the value is not a Fixnun, Integer, Float value greater or equal to 0
74
92
  # @return [Boolean] true if the data is valid
75
93
  def self.validate_unsigned_numeric(v)
76
- DataTypeValidator.validate("Invalid column width", [Fixnum, Integer, Float], v, lambda { |arg| arg.respond_to?(:>=) && arg >= 0 })
94
+ DataTypeValidator.validate("Invalid column width", [Fixnum, Integer, Float], v, lambda { |arg| arg.respond_to?(:>=) && arg.to_i >= 0 })
77
95
  end
78
96
 
79
97
  # Requires that the value is a Fixnum or Integer
@@ -112,7 +130,7 @@ module Axlsx
112
130
  def self.validate_scale_10_400(v)
113
131
  DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg >= 10 && arg <= 400 }
114
132
  end
115
-
133
+
116
134
  # Requires that the value is an integer ranging from 10 to 400 or 0.
117
135
  def self.validate_scale_0_10_400(v)
118
136
  DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg == 0 || (arg >= 10 && arg <= 400) }
@@ -122,14 +140,21 @@ module Axlsx
122
140
  def self.validate_page_orientation(v)
123
141
  RestrictionValidator.validate "page_orientation", [:default, :landscape, :portrait], v
124
142
  end
143
+ # Requires that the value is one of :none, :single, :double, :singleAccounting, :doubleAccounting
144
+ def self.validate_cell_u(v)
145
+ RestrictionValidator.validate "cell run style u", [:none, :single, :double, :singleAccounting, :doubleAccounting], v
146
+ end
125
147
 
148
+ def self.validate_family(v)
149
+ RestrictionValidator.validate "cell run style family", 1..5, v
150
+ end
126
151
  # Requires that the value is valid pattern type.
127
152
  # valid pattern types must be one of :none, :solid, :mediumGray, :darkGray, :lightGray, :darkHorizontal, :darkVertical, :darkDown,
128
153
  # :darkUp, :darkGrid, :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, or :gray0625.
129
154
  # @param [Any] v The value validated
130
155
  def self.validate_pattern_type(v)
131
156
  RestrictionValidator.validate :pattern_type, [:none, :solid, :mediumGray, :darkGray, :lightGray, :darkHorizontal, :darkVertical, :darkDown, :darkUp, :darkGrid,
132
- :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, :gray0625], v
157
+ :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, :gray0625], v
133
158
  end
134
159
 
135
160
  # Requires that the value is one of the ST_TimePeriod types
@@ -226,7 +251,7 @@ module Axlsx
226
251
  def self.validate_data_validation_error_style(v)
227
252
  RestrictionValidator.validate :validate_data_validation_error_style, [:information, :stop, :warning], v
228
253
  end
229
-
254
+
230
255
  # Requires that the value is valid data validation operator.
231
256
  # valid operators must be one of lessThan, lessThanOrEqual, equal,
232
257
  # notEqual, greaterThanOrEqual, greaterThan, between, notBetween
@@ -234,28 +259,28 @@ module Axlsx
234
259
  def self.validate_data_validation_operator(v)
235
260
  RestrictionValidator.validate :data_validation_operator, [:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween], v
236
261
  end
237
-
262
+
238
263
  # Requires that the value is valid data validation type.
239
264
  # valid types must be one of custom, data, decimal, list, none, textLength, time, whole
240
265
  # @param [Any] v The value validated
241
266
  def self.validate_data_validation_type(v)
242
267
  RestrictionValidator.validate :data_validation_type, [:custom, :data, :decimal, :list, :none, :textLength, :time, :whole], v
243
268
  end
244
-
269
+
245
270
  # Requires that the value is a valid sheet view type.
246
271
  # valid types must be one of normal, page_break_preview, page_layout
247
272
  # @param [Any] v The value validated
248
273
  def self.validate_sheet_view_type(v)
249
274
  RestrictionValidator.validate :sheet_view_type, [:normal, :page_break_preview, :page_layout], v
250
275
  end
251
-
276
+
252
277
  # Requires that the value is a valid active pane type.
253
278
  # valid types must be one of bottom_left, bottom_right, top_left, top_right
254
279
  # @param [Any] v The value validated
255
280
  def self.validate_pane_type(v)
256
281
  RestrictionValidator.validate :active_pane_type, [:bottom_left, :bottom_right, :top_left, :top_right], v
257
282
  end
258
-
283
+
259
284
  # Requires that the value is a valid split state type.
260
285
  # valid types must be one of frozen, frozen_split, split
261
286
  # @param [Any] v The value validated
data/lib/axlsx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
2
+
3
3
  # The current version
4
- VERSION="1.2.0"
4
+ VERSION = "1.3.3"
5
5
  end
@@ -49,12 +49,15 @@ module Axlsx
49
49
  # @example
50
50
  # For clarification: LOG10 is always a cell reference, LOG10() is always formula, LOGO1000 can be a defined name that overrides a cell reference.
51
51
  class DefinedName
52
+ include Axlsx::SerializedAttributes
53
+ include Axlsx::OptionsParser
54
+ include Axlsx::Accessors
52
55
  # creates a new DefinedName.
53
56
  # @param [String] formula - the formula the defined name references
54
57
  # @param [Hash] options - A hash of key/value pairs that will be mapped to this instances attributes.
55
- #
58
+ #
56
59
  # @option [String] name - Specifies the name that appears in the user interface for the defined name.
57
- # This attribute is required.
60
+ # This attribute is required.
58
61
  # The following built-in names are defined in this SpreadsheetML specification:
59
62
  # Print
60
63
  # _xlnm.Print_Area: this defined name specifies the workbook's print area.
@@ -96,10 +99,9 @@ module Axlsx
96
99
  # version of the workbook that is published to or rendered on a Web or application server.
97
100
  def initialize(formula, options={})
98
101
  @formula = formula
99
- options.each do |o|
100
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
101
- end
102
+ parse_options options
102
103
  end
104
+
103
105
  attr_reader :local_sheet_id
104
106
 
105
107
  # The local sheet index (0-based)
@@ -109,64 +111,17 @@ module Axlsx
109
111
  @local_sheet_id = value
110
112
  end
111
113
 
112
- # string attributes that will be added when this class is evaluated
113
- STRING_ATTRIBUTES = [:short_cut_key, :status_bar, :help, :description, :custom_menu, :comment]
114
-
115
- # boolean attributes that will be added when this class is evaluated
116
- BOOLEAN_ATTRIBUTES = [:workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden]
117
-
118
- # Dynamically create string attribute accessors
119
- STRING_ATTRIBUTES.each do |attr|
120
- class_eval %{
121
- # The #{attr} attribute reader
122
- # @return [String]
123
- attr_reader :#{attr}
124
-
125
- # The #{attr} writer
126
- # @param [String] value The value to assign to #{attr}
127
- # @return [String]
128
- def #{attr}=(value)
129
- Axlsx::validate_string(value)
130
- @#{attr}= value
131
- end
132
- }
133
- end
134
-
135
- # Dynamically create boolean attribute accessors
136
- BOOLEAN_ATTRIBUTES.each do |attr|
137
- class_eval %{
138
- # The #{attr} attribute reader
139
- # @return [Boolean]
140
- attr_reader :#{attr}
114
+ string_attr_accessor :short_cut_key, :status_bar, :help, :description, :custom_menu, :comment, :name, :formula
141
115
 
142
- # The #{attr} writer
143
- # @param [Boolean] value The value to assign to #{attr}
144
- # @return [Boolean]
145
- def #{attr}=(value)
146
- Axlsx::validate_boolean(value)
147
- @#{attr} = value
148
- end
149
- }
150
- end
151
-
152
- attr_reader :name
153
- # The name of this defined name. Please refer to the class documentation for more information
154
- def name=(value)
155
- Axlsx::RestrictionValidator.validate 'DefinedName.name', %w(_xlnm.Print_Area _xlnm.Print_Titles _xlnm.Criteria _xlnm._FilterDatabase _xlnm.Extract _xlnm.Consolidate_Area _xlnm.Database _xlnm.Sheet_Title), value
156
- @name = value
157
- end
116
+ boolean_attr_accessor :workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden
158
117
 
159
- # The formula this defined name references
160
- attr_reader :formula
118
+ serializable_attributes :short_cut_key, :status_bar, :help, :description, :custom_menu, :comment,
119
+ :workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden, :name, :local_sheet_id
161
120
 
162
121
  def to_xml_string(str='')
163
122
  raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name
164
- str << '<definedName'
165
- instance_values.each do |name, value|
166
- unless name == 'formula'
167
- str << ' ' << Axlsx::camel(name, false) << "='#{value}'"
168
- end
169
- end
123
+ str << '<definedName '
124
+ serialized_attributes str
170
125
  str << '>' << @formula
171
126
  str << '</definedName>'
172
127
  end
@@ -1,14 +1,17 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Axlsx
3
- require 'axlsx/workbook/worksheet/auto_filter.rb'
3
+ require 'axlsx/workbook/worksheet/sheet_calc_pr.rb'
4
+ require 'axlsx/workbook/worksheet/auto_filter/auto_filter.rb'
4
5
  require 'axlsx/workbook/worksheet/date_time_converter.rb'
5
6
  require 'axlsx/workbook/worksheet/protected_range.rb'
6
7
  require 'axlsx/workbook/worksheet/protected_ranges.rb'
7
8
  require 'axlsx/workbook/worksheet/cell.rb'
8
9
  require 'axlsx/workbook/worksheet/page_margins.rb'
10
+ require 'axlsx/workbook/worksheet/page_set_up_pr.rb'
9
11
  require 'axlsx/workbook/worksheet/page_setup.rb'
10
12
  require 'axlsx/workbook/worksheet/print_options.rb'
11
13
  require 'axlsx/workbook/worksheet/cfvo.rb'
14
+ require 'axlsx/workbook/worksheet/cfvos.rb'
12
15
  require 'axlsx/workbook/worksheet/color_scale.rb'
13
16
  require 'axlsx/workbook/worksheet/data_bar.rb'
14
17
  require 'axlsx/workbook/worksheet/icon_set.rb'
@@ -27,10 +30,13 @@ require 'axlsx/workbook/worksheet/dimension.rb'
27
30
  require 'axlsx/workbook/worksheet/sheet_data.rb'
28
31
  require 'axlsx/workbook/worksheet/worksheet_drawing.rb'
29
32
  require 'axlsx/workbook/worksheet/worksheet_comments.rb'
33
+ require 'axlsx/workbook/worksheet/worksheet_hyperlink'
34
+ require 'axlsx/workbook/worksheet/worksheet_hyperlinks'
30
35
  require 'axlsx/workbook/worksheet/worksheet.rb'
31
36
  require 'axlsx/workbook/shared_strings_table.rb'
32
37
  require 'axlsx/workbook/defined_name.rb'
33
38
  require 'axlsx/workbook/defined_names.rb'
39
+ require 'axlsx/workbook/worksheet/table_style_info.rb'
34
40
  require 'axlsx/workbook/worksheet/table.rb'
35
41
  require 'axlsx/workbook/worksheet/tables.rb'
36
42
  require 'axlsx/workbook/worksheet/data_validation.rb'
@@ -147,6 +153,14 @@ require 'axlsx/workbook/worksheet/selection.rb'
147
153
  @@date1904 = false
148
154
 
149
155
 
156
+ # A quick helper to retrive a worksheet by name
157
+ # @param [String] name The name of the sheet you are looking for
158
+ # @return [Worksheet] The sheet found, or nil
159
+ def sheet_by_name(name)
160
+ index = @worksheets.index { |sheet| sheet.name == name }
161
+ @worksheets[index] if index
162
+ end
163
+
150
164
  # lets come back to this later when we are ready for parsing.
151
165
  #def self.parse entry
152
166
  # io = entry.get_input_stream
@@ -155,7 +169,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
155
169
  # w.parse_string :date1904, "//xmlns:workbookPr/@date1904"
156
170
  # w
157
171
  #end
158
-
172
+
159
173
  # Creates a new Workbook
160
174
  # The recomended way to work with workbooks is via Package#workbook
161
175
  # @option options [Boolean] date1904. If this is not specified, date1904 is set to false. Office 2011 for Mac defaults to false.
@@ -201,6 +215,23 @@ require 'axlsx/workbook/worksheet/selection.rb'
201
215
  # see @use_autowidth
202
216
  def use_autowidth=(v=true) Axlsx::validate_boolean v; @use_autowidth = v; end
203
217
 
218
+ # inserts a worksheet into this workbook at the position specified.
219
+ # It the index specified is out of range, the worksheet will be added to the end of the
220
+ # worksheets collection
221
+ # @return [Worksheet]
222
+ # @param index The zero based position to insert the newly created worksheet
223
+ # @param [Hash] options Options to pass into the worksheed during initialization.
224
+ # @option options [String] name The name of the worksheet
225
+ # @option options [Hash] page_margins The page margins for the worksheet
226
+ def insert_worksheet(index=0, options={})
227
+ worksheet = Worksheet.new(self, options)
228
+ @worksheets.delete_at(@worksheets.size - 1)
229
+ @worksheets.insert(index, worksheet)
230
+ yield worksheet if block_given?
231
+ worksheet
232
+ end
233
+
234
+ #
204
235
  # Adds a worksheet to this workbook
205
236
  # @return [Worksheet]
206
237
  # @option options [String] name The name of the worksheet.
@@ -0,0 +1,77 @@
1
+
2
+ require 'axlsx/workbook/worksheet/auto_filter/filter_column.rb'
3
+ require 'axlsx/workbook/worksheet/auto_filter/filters.rb'
4
+
5
+ module Axlsx
6
+
7
+ #This class represents an auto filter range in a worksheet
8
+ class AutoFilter
9
+
10
+ # creates a new Autofilter object
11
+ # @param [Worksheet] worksheet
12
+ def initialize(worksheet)
13
+ raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
14
+ @worksheet = worksheet
15
+ end
16
+
17
+ attr_reader :worksheet
18
+
19
+ # The range the autofilter should be applied to.
20
+ # This should be a string like 'A1:B8'
21
+ # @return [String]
22
+ attr_accessor :range
23
+
24
+ # the formula for the defined name required for this auto filter
25
+ # This prepends the worksheet name to the absolute cell reference
26
+ # e.g. A1:B2 -> 'Sheet1'!$A$1:$B$2
27
+ # @return [String]
28
+ def defined_name
29
+ return unless range
30
+ Axlsx.cell_range(range.split(':').collect { |name| worksheet.name_to_cell(name)})
31
+ end
32
+
33
+ # A collection of filterColumns for this auto_filter
34
+ # @return [SimpleTypedList]
35
+ def columns
36
+ @columns ||= SimpleTypedList.new FilterColumn
37
+ end
38
+
39
+ # Adds a filter column. This is the recommended way to create and manage filter columns for your autofilter.
40
+ # In addition to the require id and type parameters, options will be passed to the filter column during instantiation.
41
+ # @param [String] col_id Zero-based index indicating the AutoFilter column to which this filter information applies.
42
+ # @param [Symbol] filter_type A symbol representing one of the supported filter types.
43
+ # @param [Hash] options a hash of options to pass into the generated filter
44
+ # @return [FilterColumn]
45
+ def add_column(col_id, filter_type, options = {})
46
+ columns << FilterColumn.new(col_id, filter_type, options)
47
+ columns.last
48
+ end
49
+
50
+ # actually performs the filtering of rows who's cells do not
51
+ # match the filter.
52
+ def apply
53
+ first_cell, last_cell = range.split(':')
54
+ start_point = Axlsx::name_to_indices(first_cell)
55
+ end_point = Axlsx::name_to_indices(last_cell)
56
+ # The +1 is so we skip the header row with the filter drop downs
57
+ rows = worksheet.rows[(start_point.last+1)..end_point.last] || []
58
+
59
+ column_offset = start_point.first
60
+ columns.each do |column|
61
+ rows.each do |row|
62
+ next if row.hidden
63
+ column.apply(row, column_offset)
64
+ end
65
+ end
66
+ end
67
+ # serialize the object
68
+ # @return [String]
69
+ def to_xml_string(str='')
70
+ return unless range
71
+ str << "<autoFilter ref='#{range}'>"
72
+ columns.each { |filter_column| filter_column.to_xml_string(str) }
73
+ str << "</autoFilter>"
74
+ end
75
+
76
+ end
77
+ end