axlsx 1.0.12 → 1.0.14

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 (77) hide show
  1. data/README.md +165 -134
  2. data/examples/example.rb +133 -153
  3. data/lib/axlsx/#cfb.xlsx# +0 -0
  4. data/lib/axlsx/content_type/content_type.rb +23 -0
  5. data/lib/axlsx/content_type/default.rb +37 -0
  6. data/lib/axlsx/content_type/override.rb +37 -0
  7. data/lib/axlsx/doc_props/app.rb +178 -0
  8. data/lib/axlsx/doc_props/core.rb +34 -0
  9. data/lib/axlsx/drawing/axis.rb +93 -0
  10. data/lib/axlsx/drawing/bar_3D_chart.rb +136 -0
  11. data/lib/axlsx/drawing/bar_series.rb +64 -0
  12. data/lib/axlsx/drawing/cat_axis.rb +63 -0
  13. data/lib/axlsx/drawing/cat_axis_data.rb +35 -0
  14. data/lib/axlsx/drawing/chart.rb +193 -0
  15. data/lib/axlsx/drawing/drawing.rb +137 -0
  16. data/lib/axlsx/drawing/graphic_frame.rb +52 -0
  17. data/lib/axlsx/drawing/line_3D_chart.rb +114 -0
  18. data/lib/axlsx/drawing/line_series.rb +46 -0
  19. data/lib/axlsx/drawing/marker.rb +61 -0
  20. data/lib/axlsx/drawing/one_cell_anchor.rb +89 -0
  21. data/lib/axlsx/drawing/pic.rb +153 -0
  22. data/lib/axlsx/drawing/picture_locking.rb +72 -0
  23. data/lib/axlsx/drawing/picture_locking.rb~ +36 -0
  24. data/lib/axlsx/drawing/pie_3D_chart.rb +41 -0
  25. data/lib/axlsx/drawing/pie_series.rb +56 -0
  26. data/lib/axlsx/drawing/scaling.rb +59 -0
  27. data/lib/axlsx/drawing/ser_axis.rb +45 -0
  28. data/lib/axlsx/drawing/series.rb +71 -0
  29. data/lib/axlsx/drawing/series_title.rb +22 -0
  30. data/lib/axlsx/drawing/title.rb +65 -0
  31. data/lib/axlsx/drawing/two_cell_anchor.rb +76 -0
  32. data/lib/axlsx/drawing/val_axis.rb +34 -0
  33. data/lib/axlsx/drawing/val_axis_data.rb +26 -0
  34. data/lib/axlsx/drawing/view_3D.rb +85 -0
  35. data/lib/axlsx/package.rb +223 -0
  36. data/lib/axlsx/rels/relationship.rb +44 -0
  37. data/lib/axlsx/rels/relationships.rb +25 -0
  38. data/lib/axlsx/stylesheet/border.rb +57 -0
  39. data/lib/axlsx/stylesheet/border_pr.rb +68 -0
  40. data/lib/axlsx/stylesheet/cell_alignment.rb +105 -0
  41. data/lib/axlsx/stylesheet/cell_protection.rb +36 -0
  42. data/lib/axlsx/stylesheet/cell_style.rb +65 -0
  43. data/lib/axlsx/stylesheet/color.rb +69 -0
  44. data/lib/axlsx/stylesheet/fill.rb +32 -0
  45. data/lib/axlsx/stylesheet/font.rb +139 -0
  46. data/lib/axlsx/stylesheet/gradient_fill.rb +76 -0
  47. data/lib/axlsx/stylesheet/gradient_stop.rb +33 -0
  48. data/lib/axlsx/stylesheet/num_fmt.rb +63 -0
  49. data/lib/axlsx/stylesheet/pattern_fill.rb +66 -0
  50. data/lib/axlsx/stylesheet/styles.rb +298 -0
  51. data/lib/axlsx/stylesheet/table_style.rb +47 -0
  52. data/lib/axlsx/stylesheet/table_style_element.rb +71 -0
  53. data/lib/axlsx/stylesheet/table_styles.rb +39 -0
  54. data/lib/axlsx/stylesheet/xf.rb +138 -0
  55. data/lib/axlsx/util/constants.rb +216 -0
  56. data/lib/axlsx/util/ms_off_crypto.rb +88 -0
  57. data/lib/axlsx/util/ms_off_crypto.rb~ +3 -0
  58. data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
  59. data/lib/axlsx/util/parser.rb +43 -0
  60. data/lib/axlsx/util/parser.rb~ +6 -0
  61. data/lib/axlsx/util/simple_typed_list.rb +160 -0
  62. data/lib/axlsx/util/validators.rb +132 -0
  63. data/lib/axlsx/version.rb +4 -0
  64. data/lib/axlsx/workbook/workbook.rb +161 -0
  65. data/lib/axlsx/workbook/worksheet/cell.rb +350 -0
  66. data/lib/axlsx/workbook/worksheet/row.rb +107 -0
  67. data/lib/axlsx/workbook/worksheet/worksheet.rb +335 -0
  68. data/lib/axlsx.rb +59 -0
  69. data/test/drawing/tc_axis.rb +1 -1
  70. data/test/drawing/tc_cat_axis.rb +1 -1
  71. data/test/drawing/tc_line_series.tc~ +34 -0
  72. data/test/drawing/tc_picture_locking.rb~ +77 -0
  73. data/test/tc_package.rb +10 -0
  74. data/test/workbook/worksheet/tc_cell.rb +15 -0
  75. data/test/workbook/worksheet/tc_worksheet.rb +22 -1
  76. metadata +117 -5
  77. data/examples/follow_20111202.xlsx +0 -0
@@ -0,0 +1,298 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Axlsx
3
+ require 'axlsx/stylesheet/border.rb'
4
+ require 'axlsx/stylesheet/border_pr.rb'
5
+ require 'axlsx/stylesheet/cell_alignment.rb'
6
+ require 'axlsx/stylesheet/cell_style.rb'
7
+ require 'axlsx/stylesheet/color.rb'
8
+ require 'axlsx/stylesheet/fill.rb'
9
+ require 'axlsx/stylesheet/font.rb'
10
+ require 'axlsx/stylesheet/gradient_fill.rb'
11
+ require 'axlsx/stylesheet/gradient_stop.rb'
12
+ require 'axlsx/stylesheet/num_fmt.rb'
13
+ require 'axlsx/stylesheet/pattern_fill.rb'
14
+ require 'axlsx/stylesheet/table_style.rb'
15
+ require 'axlsx/stylesheet/table_styles.rb'
16
+ require 'axlsx/stylesheet/table_style_element.rb'
17
+ require 'axlsx/stylesheet/xf.rb'
18
+ require 'axlsx/stylesheet/cell_protection.rb'
19
+
20
+ #The Styles class manages worksheet styles
21
+ # In addition to creating the require style objects for a valid xlsx package, this class provides the key mechanism for adding styles to your workbook, and safely applying them to the cells of your worksheet.
22
+ # All portions of the stylesheet are implemented here exception colors, which specify legacy and modified pallete colors, and exLst, whic is used as a future feature data storage area.
23
+ # @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
24
+ # @see Styles#add_style
25
+ # @note The recommended way to manage styles is with add_style
26
+ class Styles
27
+ # numFmts for your styles.
28
+ # The default styles, which change based on the system local, are as follows.
29
+ # id formatCode
30
+ # 0 General
31
+ # 1 0
32
+ # 2 0.00
33
+ # 3 #,##0
34
+ # 4 #,##0.00
35
+ # 9 0%
36
+ # 10 0.00%
37
+ # 11 0.00E+00
38
+ # 12 # ?/?
39
+ # 13 # ??/??
40
+ # 14 mm-dd-yy
41
+ # 15 d-mmm-yy
42
+ # 16 d-mmm
43
+ # 17 mmm-yy
44
+ # 18 h:mm AM/PM
45
+ # 19 h:mm:ss AM/PM
46
+ # 20 h:mm
47
+ # 21 h:mm:ss
48
+ # 22 m/d/yy h:mm
49
+ # 37 #,##0 ;(#,##0)
50
+ # 38 #,##0 ;[Red](#,##0)
51
+ # 39 #,##0.00;(#,##0.00)
52
+ # 40 #,##0.00;[Red](#,##0.00)
53
+ # 45 mm:ss
54
+ # 46 [h]:mm:ss
55
+ # 47 mmss.0
56
+ # 48 ##0.0E+0
57
+ # 49 @
58
+ # Axlsx also defines the following constants which you can use in add_style.
59
+ # NUM_FMT_PERCENT formats to "0%"
60
+ # NUM_FMT_YYYYMMDD formats to "yyyy/mm/dd"
61
+ # NUM_FMT_YYYYMMDDHHMMSS formats to "yyyy/mm/dd hh:mm:ss"
62
+ # @see Office Open XML Part 1 - 18.8.31 for more information on creating number formats
63
+ # @return [SimpleTypedList]
64
+ # @note The recommended way to manage styles is with add_style
65
+ # @see Styles#add_style
66
+ attr_reader :numFmts
67
+
68
+ # The collection of fonts used in this workbook
69
+ # @return [SimpleTypedList]
70
+ # @note The recommended way to manage styles is with add_style
71
+ # @see Styles#add_style
72
+ attr_reader :fonts
73
+
74
+ # The collection of fills used in this workbook
75
+ # @return [SimpleTypedList]
76
+ # @note The recommended way to manage styles is with add_style
77
+ # @see Styles#add_style
78
+ attr_reader :fills
79
+
80
+ # The collection of borders used in this workbook
81
+ # Axlsx predefines THIN_BORDER which can be used to put a border around all of your cells.
82
+ # @return [SimpleTypedList]
83
+ # @note The recommended way to manage styles is with add_style
84
+ # @see Styles#add_style
85
+ attr_reader :borders
86
+
87
+ # The collection of master formatting records for named cell styles, which means records defined in cellStyles, in the workbook
88
+ # @return [SimpleTypedList]
89
+ # @note The recommended way to manage styles is with add_style
90
+ # @see Styles#add_style
91
+ attr_reader :cellStyleXfs
92
+
93
+ # The collection of named styles, referencing cellStyleXfs items in the workbook.
94
+ # @return [SimpleTypedList]
95
+ # @note The recommended way to manage styles is with add_style
96
+ # @see Styles#add_style
97
+ attr_reader :cellStyles
98
+
99
+ # The collection of master formatting records. This is the list that you will actually use in styling a workbook.
100
+ # @return [SimpleTypedList]
101
+ # @note The recommended way to manage styles is with add_style
102
+ # @see Styles#add_style
103
+ attr_reader :cellXfs
104
+
105
+ # The collection of non-cell formatting records used in the worksheet.
106
+ # @return [SimpleTypedList]
107
+ # @note The recommended way to manage styles is with add_style
108
+ # @see Styles#add_style
109
+ attr_reader :dxfs
110
+
111
+ # The collection of table styles that will be available to the user in the excel UI
112
+ # @return [SimpleTypedList]
113
+ # @note The recommended way to manage styles is with add_style
114
+ # @see Styles#add_style
115
+ attr_reader :tableStyles
116
+
117
+ # Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part.
118
+ def initialize()
119
+ load_default_styles
120
+ end
121
+
122
+ # Drastically simplifies style creation and management.
123
+ # @return [Integer]
124
+ # @option options [String] fg_color The text color
125
+ # @option options [Integer] sz The text size
126
+ # @option options [Boolean] b Indicates if the text should be bold
127
+ # @option options [Boolean] i Indicates if the text should be italicised
128
+ # @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
129
+ # @option options [Boolean] strike Indicates if the text should be rendered with a shadow
130
+ # @option options [Integer] charset The character set to use.
131
+ # @option options [Integer] family The font family to use.
132
+ # @option options [String] name The name of the font to use
133
+ # @option options [Integer] num_fmt The number format to apply
134
+ # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored.
135
+ # @option options [Integer] border The border style to use.
136
+ # @option options [String] bg_color The background color to apply to the cell
137
+ # @option options [Boolean] hidden Indicates if the cell should be hidden
138
+ # @option options [Boolean] locked Indicates if the cell should be locked
139
+ # @option options [Hash] alignment A hash defining any of the attributes used in CellAlignment
140
+ # @see CellAlignment
141
+ #
142
+ # @example You Got Style
143
+ # require "rubygems" # if that is your preferred way to manage gems!
144
+ # require "axlsx"
145
+ #
146
+ # p = Axlsx::Package.new
147
+ # ws = p.workbook.add_worksheet
148
+ #
149
+ # # black text on a white background at 14pt with thin borders!
150
+ # title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=>Axlsx::STYLE_THIN_BORDER
151
+ #
152
+ # ws.add_row :values => ["Least Popular Pets"]
153
+ # ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
154
+ # ws.add_row :values => ["Votes", 6, 4, 1], :style=>Axlsx::STYLE_THIN_BORDER
155
+ # f = File.open('example_you_got_style.xlsx', 'w')
156
+ # p.serialize(f)
157
+ #
158
+ # @example Styling specifically
159
+ # # an example of applying specific styles to specific cells
160
+ # require "rubygems" # if that is your preferred way to manage gems!
161
+ # require "axlsx"
162
+ #
163
+ # p = Axlsx::Package.new
164
+ # ws = p.workbook.add_worksheet
165
+ #
166
+ # # define your styles
167
+ # title = ws.style.add_style(:bg_color => "FFFF0000",
168
+ # :fg_color=>"#FF000000",
169
+ # :border=>Axlsx::STYLE_THIN_BORDER,
170
+ # :alignment=>{:horizontal => :center})
171
+ #
172
+ # date_time = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
173
+ # :border=>Axlsx::STYLE_THIN_BORDER)
174
+ #
175
+ # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
176
+ # :border=>Axlsx::STYLE_THIN_BORDER)
177
+ #
178
+ # currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
179
+ # :border=>Axlsx::STYLE_THIN_BORDER)
180
+ #
181
+ # # build your rows
182
+ # ws.add_row :values => ["Genreated At:", Time.now], :styles=>[nil, date_time]
183
+ # ws.add_row :values => ["Previous Year Quarterly Profits (JPY)"], :style=>title
184
+ # ws.add_row :values => ["Quarter", "Profit", "% of Total"], :style=>title
185
+ # ws.add_row :values => ["Q1", 4000, 40], :style=>[title, currency, percent]
186
+ # ws.add_row :values => ["Q2", 3000, 30], :style=>[title, currency, percent]
187
+ # ws.add_row :values => ["Q3", 1000, 10], :style=>[title, currency, percent]
188
+ # ws.add_row :values => ["Q4", 2000, 20], :style=>[title, currency, percent]
189
+ # f = File.open('example_you_got_style.xlsx', 'w')
190
+ # p.serialize(f)
191
+ def add_style(options={})
192
+
193
+ numFmtId = if options[:format_code]
194
+ n = @numFmts.map{ |f| f.numFmtId }.max + 1
195
+ numFmts << NumFmt.new(:numFmtId => n, :formatCode=> options[:format_code])
196
+ n
197
+ else
198
+ options[:num_fmt] || 0
199
+ end
200
+
201
+ borderId = options[:border] || 0
202
+ raise ArgumentError, "Invalid borderId" unless borderId < borders.size
203
+
204
+ fill = if options[:bg_color]
205
+ color = Color.new(:rgb=>options[:bg_color])
206
+ pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color)
207
+ fills << Fill.new(pattern)
208
+ else
209
+ 0
210
+ end
211
+
212
+ fontId = if (options.values_at(:fg_color, :sz, :b, :i, :strike, :outline, :shadow, :charset, :family, :font_name).length)
213
+ font = Font.new()
214
+ [:b, :i, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
215
+ font.color = Color.new(:rgb => options[:fg_color]) unless options[:fg_color].nil?
216
+ font.name = options[:font_name] unless options[:font_name].nil?
217
+ fonts << font
218
+ else
219
+ 0
220
+ end
221
+
222
+ applyProtection = (options[:hidden] || options[:locked]) ? 1 : 0
223
+
224
+ xf = Xf.new(:fillId => fill, :fontId=>fontId, :applyFill=>1, :applyFont=>1, :numFmtId=>numFmtId, :borderId=>borderId, :applyProtection=>applyProtection)
225
+
226
+ if options[:alignment]
227
+ xf.alignment = CellAlignment.new(options[:alignment])
228
+ end
229
+
230
+ if applyProtection
231
+ xf.protection = CellProtection.new(options)
232
+ end
233
+
234
+ cellXfs << xf
235
+ end
236
+
237
+ # Serializes the styles document
238
+ # @return [String]
239
+ def to_xml()
240
+ builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
241
+ xml.styleSheet(:xmlns => XML_NS) {
242
+ [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
243
+ self.instance_values[key.to_s].to_xml(xml) unless self.instance_values[key.to_s].nil?
244
+ end
245
+ }
246
+ end
247
+ builder.to_xml
248
+ end
249
+
250
+ private
251
+ # Creates the default set of styles the exel requires to be valid as well as setting up the
252
+ # Axlsx::STYLE_THIN_BORDER
253
+ def load_default_styles
254
+ @numFmts = SimpleTypedList.new NumFmt
255
+ @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode=> "yyyy/mm/dd")
256
+ @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode=> "yyyy/mm/dd hh:mm:ss")
257
+
258
+ @numFmts.lock
259
+
260
+ @fonts = SimpleTypedList.new Font
261
+ @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
262
+ @fonts.lock
263
+
264
+ @fills = SimpleTypedList.new Fill
265
+ @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:none))
266
+ @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:gray125))
267
+ @fills.lock
268
+
269
+ @borders = SimpleTypedList.new Border
270
+ @borders << Border.new
271
+ black_border = Border.new
272
+ [:left, :right, :top, :bottom].each do |item|
273
+ black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
274
+ end
275
+ @borders << black_border
276
+ @borders.lock
277
+
278
+ @cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
279
+ @cellStyleXfs << Xf.new(:borderId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
280
+ @cellStyleXfs.lock
281
+
282
+ @cellStyles = SimpleTypedList.new CellStyle
283
+ @cellStyles << CellStyle.new(:name =>"Normal", :builtinId =>0, :xfId=>0)
284
+ @cellStyles.lock
285
+
286
+ @cellXfs = SimpleTypedList.new Xf, "cellXfs"
287
+ @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
288
+ @cellXfs << Xf.new(:borderId=>1, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
289
+ # default date formatting
290
+ @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>14, :fontId=>0, :fillId=>0, :applyNumberFormat=>1)
291
+ @cellXfs.lock
292
+
293
+ @dxfs = SimpleTypedList.new(Xf, "dxfs"); @dxfs.lock
294
+ @tableStyles = TableStyles.new(:defaultTableStyle => "TableStyleMedium9", :defaultPivotStyle => "PivotStyleLight16"); @tableStyles.lock
295
+ end
296
+ end
297
+ end
298
+
@@ -0,0 +1,47 @@
1
+ module Axlsx
2
+ # A single table style definition and is a collection for tableStyleElements
3
+ # @note Table are not supported in this version and only the defaults required for a valid workbook are created.
4
+ class TableStyle < SimpleTypedList
5
+
6
+ # The name of this table style
7
+ # @return [string]
8
+ attr_reader :name
9
+
10
+ # indicates if this style should be applied to pivot tables
11
+ # @return [Boolean]
12
+ attr_reader :pivot
13
+
14
+ # indicates if this style should be applied to tables
15
+ # @return [Boolean]
16
+ attr_reader :table
17
+
18
+ # creates a new TableStyle object
19
+ # @raise [ArgumentError] if name option is not provided.
20
+ # @param [String] name
21
+ # @option options [Boolean] pivot
22
+ # @option options [Boolean] table
23
+ def initialize(name, options={})
24
+ self.name = name
25
+ options.each do |o|
26
+ self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
27
+ end
28
+ super TableStyleElement
29
+ end
30
+
31
+ # @see name
32
+ def name=(v) Axlsx::validate_string v; @name=v end
33
+ # @see pivot
34
+ def pivot=(v) Axlsx::validate_boolean v; @pivot=v end
35
+ # @see table
36
+ def table=(v) Axlsx::validate_boolean v; @table=v end
37
+
38
+ # Serializes the table style
39
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
40
+ # @return [String]
41
+ def to_xml(xml)
42
+ attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k }
43
+ attr[:count] = self.size
44
+ xml.tableStyle(attr) { self.each { |table_style_el| table_style_el.to_xml(xml) } }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,71 @@
1
+ module Axlsx
2
+ # an element of style that belongs to a table style.
3
+ # @note tables and table styles are not supported in this version. This class exists in preparation for that support.
4
+ class TableStyleElement
5
+ # The type of style element. The following type are allowed
6
+ # :wholeTable
7
+ # :headerRow
8
+ # :totalRow
9
+ # :firstColumn
10
+ # :lastColumn
11
+ # :firstRowStripe
12
+ # :secondRowStripe
13
+ # :firstColumnStripe
14
+ # :secondColumnStripe
15
+ # :firstHeaderCell
16
+ # :lastHeaderCell
17
+ # :firstTotalCell
18
+ # :lastTotalCell
19
+ # :firstSubtotalColumn
20
+ # :secondSubtotalColumn
21
+ # :thirdSubtotalColumn
22
+ # :firstSubtotalRow
23
+ # :secondSubtotalRow
24
+ # :thirdSubtotalRow
25
+ # :blankRow
26
+ # :firstColumnSubheading
27
+ # :secondColumnSubheading
28
+ # :thirdColumnSubheading
29
+ # :firstRowSubheading
30
+ # :secondRowSubheading
31
+ # :thirdRowSubheading
32
+ # :pageFieldLabels
33
+ # :pageFieldValues
34
+ # @return [Symbol]
35
+ attr_reader :type
36
+
37
+ # Number of rows or columns used in striping when the type is firstRowStripe, secondRowStripe, firstColumnStripe, or secondColumnStripe.
38
+ # @return [Integer]
39
+ attr_reader :size
40
+
41
+ # The dxfId this style element points to
42
+ # @return [Integer]
43
+ attr_reader :dxfId
44
+
45
+ # creates a new TableStyleElement object
46
+ # @option options [Symbol] type
47
+ # @option options [Integer] size
48
+ # @option options [Integer] dxfId
49
+ def initialize(options={})
50
+ options.each do |o|
51
+ self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
52
+ end
53
+ end
54
+
55
+ # @see type
56
+ def type=(v) Axlsx::validate_table_element_type v; @type = v end
57
+
58
+ # @see size
59
+ def size=(v) Axlsx::validate_unsigned_int v; @size = v end
60
+
61
+ # @see dxfId
62
+ def dxfId=(v) Axlsx::validate_unsigned_int v; @dxfId = v end
63
+
64
+ # Serializes the table style element
65
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
66
+ # @return [String]
67
+ def to_xml(xml)
68
+ xml.tableStyleElement self.instance_values
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,39 @@
1
+ module Axlsx
2
+ # TableStyles represents a collection of style definitions for table styles and pivot table styles.
3
+ # @note Support for custom table styles does not exist in this version. Many of the classes required are defined in preparation for future release. Please do not attempt to add custom table styles.
4
+ class TableStyles < SimpleTypedList
5
+
6
+ # The default table style. The default value is 'TableStyleMedium9'
7
+ # @return [String]
8
+ attr_reader :defaultTableStyle
9
+
10
+ # The default pivot table style. The default value is 'PivotStyleLight6'
11
+ # @return [String]
12
+ attr_reader :defaultPivotStyle
13
+
14
+ # Creates a new TableStyles object that is a container for TableStyle objects
15
+ # @option options [String] defaultTableStyle
16
+ # @option options [String] defaultPivotStyle
17
+ def initialize(options={})
18
+ @defaultTableStyle = options[:defaultTableStyle] || "TableStyleMedium9"
19
+ @defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
20
+ super TableStyle
21
+ end
22
+ # @see defaultTableStyle
23
+ def defaultTableStyle=(v) Axlsx::validate_string(v); @defaultTableStyle = v; end
24
+ # @see defaultPivotStyle
25
+ def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end
26
+
27
+ # Serializes the table styles element
28
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
29
+ # @return [String]
30
+ def to_xml(xml)
31
+ attr = self.instance_values.reject {|k, v| ![:defaultTableStyle, :defaultPivotStyle].include?(k.to_sym) }
32
+ attr[:count] = self.size
33
+ xml.tableStyles(attr) {
34
+ self.each { |table_style| table_style.to_xml(xml) }
35
+ }
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,138 @@
1
+ module Axlsx
2
+ # The Xf class defines a formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
3
+ # @see Styles#add_style
4
+ class Xf
5
+ #does not support extList (ExtensionList)
6
+
7
+ # The cell alignment for this style
8
+ # @return [CellAlignment]
9
+ # @see CellAlignment
10
+ attr_reader :alignment
11
+
12
+ # The cell protection for this style
13
+ # @return [CellProtection]
14
+ # @see CellProtection
15
+ attr_reader :protection
16
+
17
+ # id of the numFmt to apply to this style
18
+ # @return [Integer]
19
+ attr_reader :numFmtId
20
+
21
+ # index (0 based) of the font to be used in this style
22
+ # @return [Integer]
23
+ attr_reader :fontId
24
+
25
+ # index (0 based) of the fill to be used in this style
26
+ # @return [Integer]
27
+ attr_reader :fillId
28
+
29
+ # index (0 based) of the border to be used in this style
30
+ # @return [Integer]
31
+ attr_reader :borderId
32
+
33
+ # index (0 based) of cellStylesXfs item to be used in this style. Only applies to cellXfs items
34
+ # @return [Integer]
35
+ attr_reader :xfId
36
+
37
+ # indecates if text should be prefixed by a single quote in the cell
38
+ # @return [Boolean]
39
+ attr_reader :quotePrefix
40
+
41
+ # indicates if the cell has a pivot table drop down button
42
+ # @return [Boolean]
43
+ attr_reader :pivotButton
44
+
45
+ # indicates if the numFmtId should be applied
46
+ # @return [Boolean]
47
+ attr_reader :applyNumberFormat
48
+
49
+ # indicates if the fontId should be applied
50
+ # @return [Boolean]
51
+ attr_reader :applyFont
52
+
53
+ # indicates if the fillId should be applied
54
+ # @return [Boolean]
55
+ attr_reader :applyFill
56
+
57
+ # indicates if the borderId should be applied
58
+ # @return [Boolean]
59
+ attr_reader :applyBorder
60
+
61
+ # Indicates if the alignment options should be applied
62
+ # @return [Boolean]
63
+ attr_reader :applyAlignment
64
+
65
+ # Indicates if the protection options should be applied
66
+ # @return [Boolean]
67
+ attr_reader :applyProtection
68
+
69
+ # Creates a new Xf object
70
+ # @option options [Integer] numFmtId
71
+ # @option options [Integer] fontId
72
+ # @option options [Integer] fillId
73
+ # @option options [Integer] borderId
74
+ # @option options [Integer] xfId
75
+ # @option options [Boolean] quotePrefix
76
+ # @option options [Boolean] pivotButton
77
+ # @option options [Boolean] applyNumberFormat
78
+ # @option options [Boolean] applyFont
79
+ # @option options [Boolean] applyFill
80
+ # @option options [Boolean] applyBorder
81
+ # @option options [Boolean] applyAlignment
82
+ # @option options [Boolean] applyProtection
83
+ # @option options [CellAlignment] alignment
84
+ # @option options [CellProtection] protection
85
+ def initialize(options={})
86
+ options.each do |o|
87
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
88
+ end
89
+ end
90
+
91
+ # @see Xf#alignment
92
+ def alignment=(v) DataTypeValidator.validate "Xf.alignment", CellAlignment, v; @alignment = v end
93
+
94
+ # @see protection
95
+ def protection=(v) DataTypeValidator.validate "Xf.protection", CellProtection, v; @protection = v end
96
+
97
+ # @see numFmtId
98
+ def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
99
+
100
+ # @see fontId
101
+ def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
102
+ # @see fillId
103
+ def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
104
+ # @see borderId
105
+ def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
106
+ # @see xfId
107
+ def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
108
+ # @see quotePrefix
109
+ def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
110
+ # @see pivotButton
111
+ def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
112
+ # @see applyNumberFormat
113
+ def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
114
+ # @see applyFont
115
+ def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
116
+ # @see applyFill
117
+ def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
118
+
119
+ # @see applyBorder
120
+ def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
121
+
122
+ # @see applyAlignment
123
+ def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
124
+
125
+ # @see applyProtection
126
+ def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
127
+
128
+ # Serializes the xf elemen
129
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
130
+ # @return [String]
131
+ def to_xml(xml)
132
+ xml.xf(self.instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym}) {
133
+ alignment.to_xml(xml) if self.alignment
134
+ protection.to_xml(xml) if self.protection
135
+ }
136
+ end
137
+ end
138
+ end