axlsx 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +3 -2
  3. data/.yardopts_guide +19 -0
  4. data/CHANGELOG.md +64 -1
  5. data/README.md +105 -87
  6. data/Rakefile +0 -5
  7. data/examples/2010_comments.rb +17 -0
  8. data/examples/anchor_swapping.rb +28 -0
  9. data/examples/auto_filter.rb +16 -0
  10. data/examples/basic_charts.rb +4 -0
  11. data/examples/colored_links.rb +59 -0
  12. data/examples/conditional_formatting/example_conditional_formatting.rb +4 -2
  13. data/examples/example.rb +569 -258
  14. data/examples/ios_preview.rb +14 -0
  15. data/examples/page_setup.rb +11 -0
  16. data/examples/pivot_table.rb +39 -0
  17. data/examples/skydrive/real_example.rb +8 -8
  18. data/examples/styles.rb +66 -0
  19. data/examples/underline.rb +13 -0
  20. data/examples/wrap_text.rb +21 -0
  21. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  22. data/lib/axlsx/content_type/content_type.rb +1 -1
  23. data/lib/axlsx/content_type/default.rb +6 -37
  24. data/lib/axlsx/content_type/override.rb +6 -38
  25. data/lib/axlsx/doc_props/app.rb +10 -7
  26. data/lib/axlsx/doc_props/core.rb +6 -1
  27. data/lib/axlsx/drawing/axes.rb +61 -0
  28. data/lib/axlsx/drawing/axis.rb +20 -17
  29. data/lib/axlsx/drawing/bar_3D_chart.rb +31 -22
  30. data/lib/axlsx/drawing/cat_axis.rb +2 -10
  31. data/lib/axlsx/drawing/chart.rb +33 -6
  32. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  33. data/lib/axlsx/drawing/drawing.rb +11 -17
  34. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  35. data/lib/axlsx/drawing/hyperlink.rb +42 -36
  36. data/lib/axlsx/drawing/line_3D_chart.rb +28 -70
  37. data/lib/axlsx/drawing/line_chart.rb +99 -0
  38. data/lib/axlsx/drawing/line_series.rb +20 -2
  39. data/lib/axlsx/drawing/marker.rb +38 -18
  40. data/lib/axlsx/drawing/num_data.rb +6 -6
  41. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  42. data/lib/axlsx/drawing/one_cell_anchor.rb +28 -21
  43. data/lib/axlsx/drawing/pic.rb +43 -45
  44. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  45. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -1
  46. data/lib/axlsx/drawing/scaling.rb +13 -13
  47. data/lib/axlsx/drawing/scatter_chart.rb +32 -21
  48. data/lib/axlsx/drawing/ser_axis.rb +15 -16
  49. data/lib/axlsx/drawing/series.rb +3 -6
  50. data/lib/axlsx/drawing/str_data.rb +3 -3
  51. data/lib/axlsx/drawing/str_val.rb +7 -8
  52. data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
  53. data/lib/axlsx/drawing/val_axis.rb +14 -13
  54. data/lib/axlsx/drawing/view_3D.rb +52 -38
  55. data/lib/axlsx/drawing/vml_shape.rb +20 -79
  56. data/lib/axlsx/package.rb +58 -28
  57. data/lib/axlsx/rels/relationship.rb +75 -9
  58. data/lib/axlsx/rels/relationships.rb +8 -1
  59. data/lib/axlsx/stylesheet/border.rb +29 -20
  60. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  61. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  62. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  63. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  64. data/lib/axlsx/stylesheet/color.rb +20 -17
  65. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  66. data/lib/axlsx/stylesheet/font.rb +22 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  68. data/lib/axlsx/stylesheet/num_fmt.rb +23 -14
  69. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  70. data/lib/axlsx/stylesheet/styles.rb +37 -22
  71. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  72. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  73. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  74. data/lib/axlsx/stylesheet/xf.rb +28 -26
  75. data/lib/axlsx/util/accessors.rb +64 -0
  76. data/lib/axlsx/util/constants.rb +127 -6
  77. data/lib/axlsx/util/options_parser.rb +15 -0
  78. data/lib/axlsx/util/serialized_attributes.rb +79 -0
  79. data/lib/axlsx/util/simple_typed_list.rb +50 -15
  80. data/lib/axlsx/util/validators.rb +51 -16
  81. data/lib/axlsx/version.rb +2 -2
  82. data/lib/axlsx/workbook/defined_name.rb +14 -59
  83. data/lib/axlsx/workbook/shared_strings_table.rb +13 -4
  84. data/lib/axlsx/workbook/workbook.rb +85 -6
  85. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  86. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  87. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
  88. data/lib/axlsx/workbook/worksheet/break.rb +37 -0
  89. data/lib/axlsx/workbook/worksheet/cell.rb +109 -107
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +144 -0
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  92. data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
  93. data/lib/axlsx/workbook/worksheet/col.rb +43 -29
  94. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
  95. data/lib/axlsx/workbook/worksheet/color_scale.rb +62 -28
  96. data/lib/axlsx/workbook/worksheet/comment.rb +28 -37
  97. data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  99. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +31 -27
  100. data/lib/axlsx/workbook/worksheet/data_bar.rb +75 -41
  101. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  102. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
  103. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  104. data/lib/axlsx/workbook/worksheet/header_footer.rb +54 -0
  105. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  106. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  107. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  108. data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
  109. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  110. data/lib/axlsx/workbook/worksheet/pivot_table.rb +273 -0
  111. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
  112. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
  113. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  114. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  115. data/lib/axlsx/workbook/worksheet/row.rb +59 -83
  116. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
  117. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  118. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  119. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
  120. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
  121. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  122. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  123. data/lib/axlsx/workbook/worksheet/table.rb +25 -19
  124. data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
  125. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  126. data/lib/axlsx/workbook/worksheet/worksheet.rb +174 -35
  127. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +4 -10
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  131. data/lib/axlsx.rb +55 -5
  132. data/lib/schema/sml.xsd +4 -0
  133. data/test/axlsx.qcachegrind +2226 -0
  134. data/test/benchmark.rb +2 -3
  135. data/test/content_type/tc_default.rb +0 -11
  136. data/test/content_type/tc_override.rb +0 -13
  137. data/test/doc_props/tc_core.rb +7 -0
  138. data/test/drawing/tc_axes.rb +8 -0
  139. data/test/drawing/tc_axis.rb +15 -17
  140. data/test/drawing/tc_bar_3D_chart.rb +6 -0
  141. data/test/drawing/tc_cat_axis.rb +9 -9
  142. data/test/drawing/tc_chart.rb +20 -0
  143. data/test/drawing/tc_d_lbls.rb +14 -4
  144. data/test/drawing/tc_drawing.rb +0 -5
  145. data/test/drawing/tc_graphic_frame.rb +5 -3
  146. data/test/drawing/tc_hyperlink.rb +0 -4
  147. data/test/drawing/tc_line_chart.rb +39 -0
  148. data/test/drawing/tc_line_series.rb +8 -2
  149. data/test/drawing/tc_pic.rb +14 -3
  150. data/test/drawing/tc_ser_axis.rb +13 -12
  151. data/test/drawing/tc_two_cell_anchor.rb +3 -3
  152. data/test/drawing/tc_val_axis.rb +6 -6
  153. data/test/drawing/tc_vml_shape.rb +9 -3
  154. data/test/profile.rb +11 -21
  155. data/test/rels/tc_relationship.rb +32 -9
  156. data/test/rels/tc_relationships.rb +12 -1
  157. data/test/stylesheet/tc_color.rb +6 -0
  158. data/test/stylesheet/tc_styles.rb +15 -2
  159. data/test/tc_axlsx.rb +35 -2
  160. data/test/tc_helper.rb +7 -1
  161. data/test/tc_package.rb +44 -5
  162. data/test/util/tc_serialized_attributes.rb +19 -0
  163. data/test/util/tc_validators.rb +26 -1
  164. data/test/workbook/tc_defined_name.rb +2 -2
  165. data/test/workbook/tc_shared_strings_table.rb +6 -0
  166. data/test/workbook/tc_workbook.rb +38 -1
  167. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  168. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  169. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  170. data/test/workbook/worksheet/tc_break.rb +49 -0
  171. data/test/workbook/worksheet/tc_cell.rb +40 -6
  172. data/test/workbook/worksheet/tc_col.rb +11 -1
  173. data/test/workbook/worksheet/tc_color_scale.rb +31 -2
  174. data/test/workbook/worksheet/tc_comment.rb +21 -6
  175. data/test/workbook/worksheet/tc_comments.rb +2 -2
  176. data/test/workbook/worksheet/tc_conditional_formatting.rb +7 -0
  177. data/test/workbook/worksheet/tc_data_bar.rb +7 -0
  178. data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
  179. data/test/workbook/worksheet/tc_header_footer.rb +151 -0
  180. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  181. data/test/workbook/worksheet/tc_page_setup.rb +6 -1
  182. data/test/workbook/worksheet/tc_pane.rb +5 -45
  183. data/test/workbook/worksheet/tc_pivot_table.rb +120 -0
  184. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
  185. data/test/workbook/worksheet/tc_row.rb +4 -4
  186. data/test/workbook/worksheet/tc_selection.rb +9 -48
  187. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  188. data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
  189. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  190. data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
  191. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +8 -3
  192. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  193. data/test/workbook/worksheet/tc_worksheet.rb +131 -16
  194. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
  195. metadata +97 -64
  196. data/examples/example.xlsx +0 -0
  197. data/examples/example_streamed.xlsx +0 -0
  198. data/examples/extractive.pdf +0 -0
  199. data/examples/image1.gif +0 -0
  200. data/examples/image1.jpg +0 -0
  201. data/examples/image1.png +0 -0
  202. data/examples/no-use_autowidth.xlsx +0 -0
  203. data/examples/sample.png +0 -0
  204. data/examples/scraping_html.rb +0 -91
  205. data/examples/shared_strings_example.xlsx +0 -0
  206. data/examples/sheet_view.rb +0 -34
  207. data/examples/two_cell_anchor_image.rb +0 -11
  208. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
@@ -5,6 +5,32 @@ module Axlsx
5
5
  class Xf
6
6
  #does not support extList (ExtensionList)
7
7
 
8
+ include Axlsx::SerializedAttributes
9
+ include Axlsx::OptionsParser
10
+ # Creates a new Xf object
11
+ # @option options [Integer] numFmtId
12
+ # @option options [Integer] fontId
13
+ # @option options [Integer] fillId
14
+ # @option options [Integer] borderId
15
+ # @option options [Integer] xfId
16
+ # @option options [Boolean] quotePrefix
17
+ # @option options [Boolean] pivotButton
18
+ # @option options [Boolean] applyNumberFormat
19
+ # @option options [Boolean] applyFont
20
+ # @option options [Boolean] applyFill
21
+ # @option options [Boolean] applyBorder
22
+ # @option options [Boolean] applyAlignment
23
+ # @option options [Boolean] applyProtection
24
+ # @option options [CellAlignment] alignment
25
+ # @option options [CellProtection] protection
26
+ def initialize(options={})
27
+ parse_options options
28
+ end
29
+
30
+ serializable_attributes :numFmtId, :fontId, :fillId, :borderId, :xfId, :quotePrefix,
31
+ :pivotButton, :applyNumberFormat, :applyFont, :applyFill, :applyBorder, :applyAlignment,
32
+ :applyProtection
33
+
8
34
  # The cell alignment for this style
9
35
  # @return [CellAlignment]
10
36
  # @see CellAlignment
@@ -67,30 +93,7 @@ module Axlsx
67
93
  # @return [Boolean]
68
94
  attr_reader :applyProtection
69
95
 
70
- # Creates a new Xf object
71
- # @option options [Integer] numFmtId
72
- # @option options [Integer] fontId
73
- # @option options [Integer] fillId
74
- # @option options [Integer] borderId
75
- # @option options [Integer] xfId
76
- # @option options [Boolean] quotePrefix
77
- # @option options [Boolean] pivotButton
78
- # @option options [Boolean] applyNumberFormat
79
- # @option options [Boolean] applyFont
80
- # @option options [Boolean] applyFill
81
- # @option options [Boolean] applyBorder
82
- # @option options [Boolean] applyAlignment
83
- # @option options [Boolean] applyProtection
84
- # @option options [CellAlignment] alignment
85
- # @option options [CellProtection] protection
86
- def initialize(options={})
87
- options.each do |o|
88
- next if o[1].nil?
89
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
90
- end
91
- end
92
-
93
- # @see Xf#alignment
96
+ # @see Xf#alignment
94
97
  def alignment=(v) DataTypeValidator.validate "Xf.alignment", CellAlignment, v; @alignment = v end
95
98
 
96
99
  # @see protection
@@ -132,8 +135,7 @@ module Axlsx
132
135
  # @return [String]
133
136
  def to_xml_string(str = '')
134
137
  str << '<xf '
135
- h = instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym}
136
- str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
138
+ serialized_attributes str
137
139
  str << '>'
138
140
  alignment.to_xml_string(str) if self.alignment
139
141
  protection.to_xml_string(str) if self.protection
@@ -0,0 +1,64 @@
1
+ module Axlsx
2
+ # This module defines some of the more common validating attribute
3
+ # accessors that we use in Axlsx
4
+ #
5
+ # When this module is included in your class you can simply call
6
+ #
7
+ # string_attr_access :foo
8
+ #
9
+ # To generate a new, validating set of accessors for foo.
10
+ module Accessors
11
+ def self.included(base)
12
+ base.send :extend, ClassMethods
13
+ end
14
+
15
+ # Defines the class level xxx_attr_accessor methods
16
+ module ClassMethods
17
+
18
+ # Creates one or more string validated attr_accessors
19
+ # @param [Array] symbols An array of symbols representing the
20
+ # names of the attributes you will add to your class.
21
+ def string_attr_accessor(*symbols)
22
+ validated_attr_accessor(symbols, 'validate_string')
23
+ end
24
+
25
+
26
+ # Creates one or more usigned integer attr_accessors
27
+ # @param [Array] symbols An array of symbols representing the
28
+ # names of the attributes you will add to your class
29
+ def unsigned_int_attr_accessor(*symbols)
30
+ validated_attr_accessor(symbols, 'validate_unsigned_int')
31
+ end
32
+
33
+ # Creates one or more float (double?) attr_accessors
34
+ # @param [Array] symbols An array of symbols representing the
35
+ # names of the attributes you will add to your class
36
+ def float_attr_accessor(*symbols)
37
+ validated_attr_accessor(symbols, 'validate_float')
38
+ end
39
+
40
+ # Creates on or more boolean validated attr_accessors
41
+ # @param [Array] symbols An array of symbols representing the
42
+ # names of the attributes you will add to your class.
43
+ def boolean_attr_accessor(*symbols)
44
+ validated_attr_accessor(symbols, 'validate_boolean')
45
+ end
46
+
47
+ # Template for defining validated write accessors
48
+ SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end"
49
+
50
+ # Creates the reader and writer access methods
51
+ # @param [Array] symbols The names of the attributes to create
52
+ # @param [String] validator The axlsx validation method to use when
53
+ # validating assignation.
54
+ # @see lib/axlsx/util/validators.rb
55
+ def validated_attr_accessor(symbols, validator)
56
+ symbols.each do |symbol|
57
+ attr_reader symbol
58
+ module_eval(SETTER % [symbol.to_s, validator, symbol.to_s], __FILE__, __LINE__)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
@@ -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
 
@@ -49,6 +51,12 @@ module Axlsx
49
51
  # table rels namespace
50
52
  TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
51
53
 
54
+ # pivot table rels namespace
55
+ PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"
56
+
57
+ # pivot table cache definition namespace
58
+ PIVOT_TABLE_CACHE_DEFINITION_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"
59
+
52
60
  # workbook rels namespace
53
61
  WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
54
62
 
@@ -61,6 +69,9 @@ module Axlsx
61
69
  # core rels namespace
62
70
  CORE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/metadata/core-properties"
63
71
 
72
+ # digital signature rels namespace
73
+ DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature"
74
+
64
75
  # styles rels namespace
65
76
  STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
66
77
 
@@ -76,7 +87,7 @@ module Axlsx
76
87
  # image rels namespace
77
88
  IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
78
89
 
79
- # image rels namespace
90
+ # hyperlink rels namespace
80
91
  HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
81
92
 
82
93
  # comment rels namespace
@@ -94,6 +105,12 @@ module Axlsx
94
105
  # table content type
95
106
  TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
96
107
 
108
+ # pivot table content type
109
+ PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
110
+
111
+ # pivot table cache definition content type
112
+ PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"
113
+
97
114
  # workbook content type
98
115
  WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
99
116
 
@@ -118,6 +135,15 @@ module Axlsx
118
135
  # core content type
119
136
  CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"
120
137
 
138
+ # digital signature xml content type
139
+ DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
140
+
141
+ # digital signature origin content type
142
+ DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"
143
+
144
+ # digital signature certificate content type
145
+ DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"
146
+
121
147
  # chart content type
122
148
  CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
123
149
 
@@ -136,6 +162,7 @@ module Axlsx
136
162
  #drawing content type
137
163
  DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
138
164
 
165
+
139
166
  # xml content type extensions
140
167
  XML_EX = "xml"
141
168
 
@@ -193,6 +220,15 @@ module Axlsx
193
220
  # drawing part
194
221
  TABLE_PN = "tables/table%d.xml"
195
222
 
223
+ # pivot table parts
224
+ PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml"
225
+
226
+ # pivot table cache definition part name
227
+ PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml"
228
+
229
+ # pivot table rels parts
230
+ PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"
231
+
196
232
  # chart part
197
233
  CHART_PN = "charts/chart%d.xml"
198
234
 
@@ -247,12 +283,14 @@ module Axlsx
247
283
  # error message for RegexValidator
248
284
  ERR_REGEX = "Invalid Data. %s does not match %s."
249
285
 
286
+ # error message for RangeValidator
287
+ ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s"
288
+
250
289
  # error message for sheets that use a name which is longer than 31 bytes
251
290
  ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less"
252
-
253
- # error message for sheets that use a name which includes a colon
254
-
255
- 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."
291
+
292
+ # error message for sheets that use a name which include invalid characters
293
+ ERR_SHEET_NAME_CHARACTER_FORBIDDEN = "Your worksheet name '%s' contains a character which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet."
256
294
 
257
295
  # error message for duplicate sheet names
258
296
  ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
@@ -268,4 +306,87 @@ module Axlsx
268
306
 
269
307
  # error message for non 'integerish' value
270
308
  ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s"
309
+
310
+ # Regex to match forbidden control characters
311
+ # The following will be automatically stripped from worksheets.
312
+ #
313
+ # x00 Null
314
+ # x01 Start Of Heading
315
+ # x02 Start Of Text
316
+ # x03End Of Text
317
+ # x04 End Of Transmission
318
+ # x05 Enquiry
319
+ # x06 Acknowledge
320
+ # x07 Bell
321
+ # x08 Backspace
322
+ # x0B Line Tabulation
323
+ # x0C Form Feed
324
+ # x0E Shift Out
325
+ # x0F Shift In
326
+ # x10 Data Link Escape
327
+ # x11 Device Control One
328
+ # x12 Device Control Two
329
+ # x13 Device Control Three
330
+ # x14 Device Control Four
331
+ # x15 Negative Acknowledge
332
+ # x16 Synchronous Idle
333
+ # x17 End Of Transmission Block
334
+ # x18 Cancel
335
+ # x19 End Of Medium
336
+ # x1A Substitute
337
+ # x1B Escape
338
+ # x1C Information Separator Four
339
+ # x1D Information Separator Three
340
+ # x1E Information Separator Two
341
+ # x1F Information Separator One
342
+ #
343
+ # The following are not dealt with.
344
+ # If you have this in your data, expect excel to blow up!
345
+ #
346
+ # x7F Delete
347
+ # x80 Control 0080
348
+ # x81 Control 0081
349
+ # x82 Break Permitted Here
350
+ # x83 No Break Here
351
+ # x84 Control 0084
352
+ # x85 Next Line (Nel)
353
+ # x86 Start Of Selected Area
354
+ # x87 End Of Selected Area
355
+ # x88 Character Tabulation Set
356
+ # x89 Character Tabulation With Justification
357
+ # x8A Line Tabulation Set
358
+ # x8B Partial Line Forward
359
+ # x8C Partial Line Backward
360
+ # x8D Reverse Line Feed
361
+ # x8E Single Shift Two
362
+ # x8F Single Shift Three
363
+ # x90 Device Control String
364
+ # x91 Private Use One
365
+ # x92 Private Use Two
366
+ # x93 Set Transmit State
367
+ # x94 Cancel Character
368
+ # x95 Message Waiting
369
+ # x96 Start Of Guarded Area
370
+ # x97 End Of Guarded Area
371
+ # x98 Start Of String
372
+ # x99 Control 0099
373
+ # x9A Single Character Introducer
374
+ # x9B Control Sequence Introducer
375
+ # x9C String Terminator
376
+ # x9D Operating System Command
377
+ # x9E Privacy Message
378
+ # x9F Application Program Command
379
+ #
380
+ # The following are allowed:
381
+ #
382
+ # x0A Line Feed (Lf)
383
+ # x0D Carriage Return (Cr)
384
+ # x09 Character Tabulation
385
+ # @see http://www.codetable.net/asciikeycodes
386
+ pattern = "[\x0-\x08\x0B\x0C\x0E-\x1F]"
387
+ pattern= pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
388
+
389
+ # The regular expression used to remove control characters from worksheets
390
+ CONTROL_CHAR_REGEX = Regexp.new(pattern, 'n')
391
+
271
392
  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,79 @@
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
+
25
+ # This helper registers the attributes that will be formatted as elements.
26
+ def serializable_element_attributes(*symbols)
27
+ @xml_element_attributes = symbols
28
+ end
29
+
30
+ # attr reader for element attributes
31
+ def xml_element_attributes
32
+ @xml_element_attributes
33
+ end
34
+ end
35
+
36
+ # serializes the instance values of the defining object based on the
37
+ # list of serializable attributes.
38
+ # @param [String] str The string instance to append this
39
+ # serialization to.
40
+ # @param [Hash] additional_attributes An option key value hash for
41
+ # defining values that are not serializable attributes list.
42
+ def serialized_attributes(str = '', additional_attributes = {})
43
+ attributes = declared_attributes.merge! additional_attributes
44
+ attributes.each do |key, value|
45
+ str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(value, false)}\" "
46
+ end
47
+ str
48
+ end
49
+
50
+ # A hash of instance variables that have been declared with
51
+ # seraialized_attributes and are not nil.
52
+ # This requires ruby 1.9.3 or higher
53
+ def declared_attributes
54
+ instance_values.select do |key, value|
55
+ value != nil && self.class.xml_attributes.include?(key.to_sym)
56
+ end
57
+ end
58
+
59
+ # serialized instance values at text nodes on a camelized element of the
60
+ # attribute name. You may pass in a block for evaluation against non nil
61
+ # values. We use an array for element attributes becuase misordering will
62
+ # break the xml and 1.8.7 does not support ordered hashes.
63
+ # @param [String] str The string instance to which serialized data is appended
64
+ # @param [Array] additional_attributes An array of additional attribute names.
65
+ # @return [String] The serialized output.
66
+ def serialized_element_attributes(str='', additional_attributes=[], &block)
67
+ attrs = self.class.xml_element_attributes + additional_attributes
68
+ values = instance_values
69
+ attrs.each do |attribute_name|
70
+ value = values[attribute_name.to_s]
71
+ next if value.nil?
72
+ value = yield value if block_given?
73
+ element_name = Axlsx.camel(attribute_name, false)
74
+ str << "<#{element_name}>#{value}</#{element_name}>"
75
+ end
76
+ str
77
+ end
78
+ end
79
+ end
@@ -1,21 +1,9 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  # A SimpleTypedList is a type restrictive collection that allows some of the methods from Array and supports basic xml serialization.
4
5
  # @private
5
6
  class SimpleTypedList
6
- # The class constants of allowed types
7
- # @return [Array]
8
- attr_reader :allowed_types
9
-
10
- # The index below which items cannot be removed
11
- # @return [Integer]
12
- attr_reader :locked_at
13
-
14
- # The tag name to use when serializing this object
15
- # by default the parent node for all items in the list is the classname of the first allowed type with the first letter in lowercase.
16
- # @return [String]
17
- attr_reader :serialize_as
18
-
19
7
  # Creats a new typed list
20
8
  # @param [Array, Class] type An array of Class objects or a single Class object
21
9
  # @param [String] serialize_as The tag name to use in serialization
@@ -33,6 +21,39 @@ module Axlsx
33
21
  @serialize_as = serialize_as
34
22
  end
35
23
 
24
+ # The class constants of allowed types
25
+ # @return [Array]
26
+ attr_reader :allowed_types
27
+
28
+ # The index below which items cannot be removed
29
+ # @return [Integer]
30
+ attr_reader :locked_at
31
+
32
+ # The tag name to use when serializing this object
33
+ # by default the parent node for all items in the list is the classname of the first allowed type with the first letter in lowercase.
34
+ # @return [String]
35
+ attr_reader :serialize_as
36
+
37
+ # Transposes the list (without blowing up like ruby does)
38
+ # any non populated cell in the matrix will be a nil value
39
+ def transpose
40
+ return @list.clone if @list.size == 0
41
+ row_count = @list.size
42
+ max_column_count = @list.map{|row| row.cells.size}.max
43
+ result = Array.new(max_column_count) { Array.new(row_count) }
44
+ # yes, I know it is silly, but that warning is really annoying
45
+ row_count.times do |row_index|
46
+ max_column_count.times do |column_index|
47
+ datum = if @list[row_index].cells.size >= max_column_count
48
+ @list[row_index].cells[column_index]
49
+ elsif block_given?
50
+ yield(column_index, row_index)
51
+ end
52
+ result[column_index][row_index] = datum
53
+ end
54
+ end
55
+ result
56
+ end
36
57
  # Lock this list at the current size
37
58
  # @return [self]
38
59
  def lock
@@ -44,13 +65,15 @@ module Axlsx
44
65
  @list
45
66
  end
46
67
 
68
+ alias :to_a :to_ary
69
+
47
70
  # Unlock the list
48
71
  # @return [self]
49
72
  def unlock
50
73
  @locked_at = nil
51
74
  self
52
75
  end
53
-
76
+
54
77
  # join operator
55
78
  # @param [Array] v the array to join
56
79
  # @raise [ArgumentError] if any of the values being joined are not
@@ -60,7 +83,7 @@ module Axlsx
60
83
  v.each do |item|
61
84
  DataTypeValidator.validate "SimpleTypedList.+", @allowed_types, item
62
85
  @list << item
63
- end
86
+ end
64
87
  end
65
88
 
66
89
  # Concat operator
@@ -105,6 +128,18 @@ module Axlsx
105
128
  v
106
129
  end
107
130
 
131
+ # inserts an item at the index specfied
132
+ # @param [Integer] index
133
+ # @param [Any] v
134
+ # @raise [ArgumentError] if the index is protected by locking
135
+ # @raise [ArgumentError] if the index is not one of the allowed types
136
+ def insert(index, v)
137
+ DataTypeValidator.validate "SimpleTypedList.<<", @allowed_types, v
138
+ raise ArgumentError, "Item is protected and cannot be changed" if protected? index
139
+ @list.insert(index, v)
140
+ v
141
+ end
142
+
108
143
  # determines if the index is protected
109
144
  # @param [Integer] index
110
145
  def protected? index