axlsx 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/LICENSE +22 -0
  2. data/README.md +70 -0
  3. data/lib/axlsx.rb~ +67 -0
  4. data/lib/axlsx/content_type/content_type.rb~ +20 -0
  5. data/lib/axlsx/content_type/default.rb~ +32 -0
  6. data/lib/axlsx/content_type/override.rb~ +30 -0
  7. data/lib/axlsx/doc_props/app.rb~ +127 -0
  8. data/lib/axlsx/doc_props/core.rb~ +25 -0
  9. data/lib/axlsx/drawing/axis.rb~ +0 -0
  10. data/lib/axlsx/drawing/bar_3D_chart.rb~ +64 -0
  11. data/lib/axlsx/drawing/bar_series.rb~ +92 -0
  12. data/lib/axlsx/drawing/cat_axis.rb~ +32 -0
  13. data/lib/axlsx/drawing/chart.rb~ +0 -0
  14. data/lib/axlsx/drawing/drawing.rb~ +102 -0
  15. data/lib/axlsx/drawing/graphic_frame.rb~ +40 -0
  16. data/lib/axlsx/drawing/marker.rb~ +50 -0
  17. data/lib/axlsx/drawing/pie_3D_chart.rb~ +132 -0
  18. data/lib/axlsx/drawing/pie_series.rb~ +0 -0
  19. data/lib/axlsx/drawing/scaling.rb~ +0 -0
  20. data/lib/axlsx/drawing/series.rb~ +114 -0
  21. data/lib/axlsx/drawing/title.rb~ +69 -0
  22. data/lib/axlsx/drawing/two_cell_anchor.rb~ +70 -0
  23. data/lib/axlsx/drawing/val_axis.rb~ +34 -0
  24. data/lib/axlsx/drawing/view_3D.rb~ +21 -0
  25. data/lib/axlsx/package.rb +3 -3
  26. data/lib/axlsx/package.rb~ +181 -0
  27. data/lib/axlsx/rels/relationship.rb~ +18 -0
  28. data/lib/axlsx/rels/relationships.rb~ +23 -0
  29. data/lib/axlsx/stylesheet/border.rb~ +24 -0
  30. data/lib/axlsx/stylesheet/border_pr.rb~ +64 -0
  31. data/lib/axlsx/stylesheet/cell_alignment.rb~ +93 -0
  32. data/lib/axlsx/stylesheet/cell_protection.rb~ +16 -0
  33. data/lib/axlsx/stylesheet/cell_style.rb~ +61 -0
  34. data/lib/axlsx/stylesheet/color.rb~ +56 -0
  35. data/lib/axlsx/stylesheet/fill.rb~ +31 -0
  36. data/lib/axlsx/stylesheet/font.rb~ +33 -0
  37. data/lib/axlsx/stylesheet/gradient_fill.rb~ +70 -0
  38. data/lib/axlsx/stylesheet/gradient_stop.rb~ +15 -0
  39. data/lib/axlsx/stylesheet/num_fmt.rb~ +60 -0
  40. data/lib/axlsx/stylesheet/pattern_fill.rb~ +63 -0
  41. data/lib/axlsx/stylesheet/styles.rb~ +279 -0
  42. data/lib/axlsx/stylesheet/table_style.rb~ +43 -0
  43. data/lib/axlsx/stylesheet/table_style_element.rb~ +66 -0
  44. data/lib/axlsx/stylesheet/table_styles.rb~ +36 -0
  45. data/lib/axlsx/stylesheet/xf.rb~ +37 -0
  46. data/lib/axlsx/util/constants.rb +1 -1
  47. data/lib/axlsx/util/constants.rb~ +187 -0
  48. data/lib/axlsx/util/monkey_patches_for_true_zip_stream.rb~ +61 -0
  49. data/lib/axlsx/util/simple_typed_list.rb~ +79 -0
  50. data/lib/axlsx/util/validators.rb +3 -3
  51. data/lib/axlsx/util/validators.rb~ +132 -0
  52. data/lib/axlsx/util/xml_escape.rb~ +6 -0
  53. data/lib/axlsx/workbook/workbook.rb +1 -0
  54. data/lib/axlsx/workbook/workbook.rb~ +130 -0
  55. data/lib/axlsx/workbook/worksheet/cell.rb~ +185 -0
  56. data/lib/axlsx/workbook/worksheet/row.rb +4 -4
  57. data/lib/axlsx/workbook/worksheet/row.rb~ +92 -0
  58. data/lib/axlsx/workbook/worksheet/worksheet.rb +3 -4
  59. data/lib/axlsx/workbook/worksheet/worksheet.rb~ +194 -0
  60. data/lib/schema/dc.xsd~ +118 -0
  61. data/lib/schema/dcterms.xsd~ +331 -0
  62. data/lib/schema/opc-coreProperties.xsd~ +50 -0
  63. data/test/drawing/tc_bar_3D_chart.rb +1 -1
  64. data/test/drawing/tc_bar_3D_chart.rb~ +62 -0
  65. data/test/drawing/tc_chart.rb +1 -1
  66. data/test/drawing/tc_chart.rb~ +1 -0
  67. data/test/drawing/tc_pie_3D_chart.rb +1 -1
  68. data/test/drawing/tc_pie_3D_chart.rb~ +3 -28
  69. data/test/drawing/tc_title.rb +1 -1
  70. data/test/drawing/tc_title.rb~ +16 -19
  71. data/test/drawing/tc_two_cell_anchor.rb +1 -1
  72. data/test/drawing/tc_two_cell_anchor.rb~ +16 -14
  73. data/test/tc_package.rb +1 -1
  74. data/test/workbook/worksheet/tc_row.rb +1 -1
  75. data/test/workbook/worksheet/tc_row.rb~ +30 -0
  76. data/test/workbook/worksheet/tc_worksheet.rb +3 -3
  77. data/test/workbook/worksheet/tc_worksheet.rb~ +85 -0
  78. metadata +84 -102
@@ -0,0 +1,15 @@
1
+ module Axlsx
2
+ class GradientStop
3
+ attr_accessor :color, :position
4
+ def initialize(options={})
5
+ raise ArugumentError, "postion is required" unless options[:position]
6
+ raise ArugumentError, "color is required" unless options[:color]
7
+ options.each do |o|
8
+ self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
9
+ end
10
+ end
11
+ def color=(v) raise ArgumentError, "#{v.inspect} is not a Axlsx::Color" unless v.is_a? Axlsx::Color; @color=v end
12
+ def position=(v) Axlsx::validate_float v; @position = v end
13
+ def to_xml(xml) xml.stop(:position => self.position) {self.color.to_xml(xml)} end
14
+ end
15
+ end
@@ -0,0 +1,60 @@
1
+ module Axlsx
2
+ # A NumFmt object defines an identifier and formatting code for data in cells.
3
+ # @note The recommended way to manage styles is Styles#add_style
4
+ class NumFmt
5
+ # @return [Integer] An unsinged integer referencing a standard or custom number format.
6
+ # @note
7
+ # These are the known formats I can dig up. The constant NUM_FMT_PERCENT is 9, and uses the default % formatting. Axlsx also defines a few formats for date and time that are commonly used in asia as NUM_FMT_YYYYMMDD and NUM_FRM_YYYYMMDDHHMMSS.
8
+ # 1 0
9
+ # 2 0.00
10
+ # 3 #,##0
11
+ # 4 #,##0.00
12
+ # 5 $#,##0_);($#,##0)
13
+ # 6 $#,##0_);[Red]($#,##0)
14
+ # 7 $#,##0.00_);($#,##0.00)
15
+ # 8 $#,##0.00_);[Red]($#,##0.00)
16
+ # 9 0%
17
+ # 10 0.00%
18
+ # 11 0.00E+00
19
+ # 12 # ?/?
20
+ # 13 # ??/??
21
+ # 14 m/d/yyyy
22
+ # 15 d-mmm-yy
23
+ # 16 d-mmm
24
+ # 17 mmm-yy
25
+ # 18 h:mm AM/PM
26
+ # 19 h:mm:ss AM/PM
27
+ # 20 h:mm
28
+ # 21 h:mm:ss
29
+ # 22 m/d/yyyy h:mm
30
+ # 37 #,##0_);(#,##0)
31
+ # 38 #,##0_);[Red](#,##0)
32
+ # 39 #,##0.00_);(#,##0.00)
33
+ # 40 #,##0.00_);[Red](#,##0.00)
34
+ # 45 mm:ss
35
+ # 46 [h]:mm:ss
36
+ # 47 mm:ss.0
37
+ # 48 ##0.0E+0
38
+ # 49 @
39
+ # @see Axlsx
40
+ attr_accessor :numFmtId
41
+
42
+ # @return [String] The formatting to use for this number format.
43
+ # @see http://support.microsoft.com/kb/264372
44
+ attr_accessor :formatCode
45
+ def initialize(options={})
46
+ raise ArgumentError, "numFmtId:Integer, formatCode:String required. #{options.inspect}" unless options[:numFmtId] && options[:formatCode]
47
+ options.each do |o|
48
+ self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
49
+ end
50
+ end
51
+
52
+ def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
53
+ def formatCode=(v) Axlsx::validate_string v; @formatCode = v end
54
+
55
+ # Creates a numFmt element applying the instance values of this object as attributes.
56
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
57
+ def to_xml(xml) xml.numFmt(self.instance_values) end
58
+
59
+ end
60
+ end
@@ -0,0 +1,63 @@
1
+ module Axlsx
2
+ # A PatternFill is the pattern and solid fill styling for a cell.
3
+ # @note The recommended way to manage styles is with Styles#add_style
4
+ # @see Style#add_style
5
+ class PatternFill
6
+
7
+ # The color to use for the the background in solid fills.
8
+ # @return [Color]
9
+ attr_accessor :fgColor
10
+
11
+ # The color to use for the background of the fill when the type is not solid.
12
+ # @return [Color]
13
+ attr_accessor :bgColor
14
+
15
+ # The pattern type to use
16
+ # @note
17
+ # patternType must be one of
18
+ # :none
19
+ # :solid
20
+ # :mediumGray
21
+ # :darkGray
22
+ # :lightGray
23
+ # :darkHorizontal
24
+ # :darkVertical
25
+ # :darkDown
26
+ # :darkUp
27
+ # :darkGrid
28
+ # :darkTrellis
29
+ # :lightHorizontal
30
+ # :lightVertical
31
+ # :lightDown
32
+ # :lightUp
33
+ # :lightGrid
34
+ # :lightTrellis
35
+ # :gray125
36
+ # :gray0625
37
+ # @see Office Open XML Part 1 18.18.55
38
+ attr_accessor :patternType
39
+
40
+ # Creates a new PatternFill Object
41
+ # @option options [Symbol] patternType
42
+ # @option options [Color] fgColor
43
+ # @option options [Color] bgColor
44
+ def initialize(options={})
45
+ options.each do |o|
46
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
47
+ end
48
+ end
49
+
50
+ def fgColor=(v) DataTypeValidator.validate "PatternFill.fgColor", Color, v; @fgColor=v end
51
+ def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor=v end
52
+ def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
53
+
54
+ # Serializes the pattern fill
55
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
56
+ # @return [String]
57
+ def to_xml(xml)
58
+ xml.patternFill(:patternType => self.patternType) {
59
+ self.instance_values.reject { |k,v| k.to_sym == :patternType }.each { |k,v| xml.send(k, v.instance_values) }
60
+ }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,279 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Axlsx
3
+ #The Styles class manages worksheet styles
4
+ # 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.
5
+ # 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.
6
+ # @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
7
+ # @see Styles#add_style
8
+ # @note The recommended way to manage styles is with add_style
9
+ class Styles
10
+ # numFmts for your styles.
11
+ # The default styles, which change based on the system local, are as follows.
12
+ # id formatCode
13
+ # 0 General
14
+ # 1 0
15
+ # 2 0.00
16
+ # 3 #,##0
17
+ # 4 #,##0.00
18
+ # 9 0%
19
+ # 10 0.00%
20
+ # 11 0.00E+00
21
+ # 12 # ?/?
22
+ # 13 # ??/??
23
+ # 14 mm-dd-yy
24
+ # 15 d-mmm-yy
25
+ # 16 d-mmm
26
+ # 17 mmm-yy
27
+ # 18 h:mm AM/PM
28
+ # 19 h:mm:ss AM/PM
29
+ # 20 h:mm
30
+ # 21 h:mm:ss
31
+ # 22 m/d/yy h:mm
32
+ # 37 #,##0 ;(#,##0)
33
+ # 38 #,##0 ;[Red](#,##0)
34
+ # 39 #,##0.00;(#,##0.00)
35
+ # 40 #,##0.00;[Red](#,##0.00)
36
+ # 45 mm:ss
37
+ # 46 [h]:mm:ss
38
+ # 47 mmss.0
39
+ # 48 ##0.0E+0
40
+ # 49 @
41
+ # Axlsx also defines the following constants which you can use in add_style.
42
+ # NUM_FMT_PERCENT formats to "0%"
43
+ # NUM_FMT_YYYYMMDD formats to "yyyy/mm/dd"
44
+ # NUM_FMT_YYYYMMDDHHMMSS formats to "yyyy/mm/dd hh:mm:ss"
45
+ # @see Office Open XML Part 1 - 18.8.31 for more information on creating number formats
46
+ # @return [SimpleTypedList]
47
+ # @note The recommended way to manage styles is with add_style
48
+ # @see Styles#add_style
49
+ attr_reader :numFmts
50
+
51
+ # The collection of fonts used in this workbook
52
+ # @return [SimpleTypedList]
53
+ # @note The recommended way to manage styles is with add_style
54
+ # @see Styles#add_style
55
+ attr_reader :fonts
56
+
57
+ # The collection of fills used in this workbook
58
+ # @return [SimpleTypedList]
59
+ # @note The recommended way to manage styles is with add_style
60
+ # @see Styles#add_style
61
+ attr_reader :fills
62
+
63
+ # The collection of borders used in this workbook
64
+ # Axlsx predefines THIN_BORDER which can be used to put a border around all of your cells.
65
+ # @return [SimpleTypedList]
66
+ # @note The recommended way to manage styles is with add_style
67
+ # @see Styles#add_style
68
+ attr_reader :borders
69
+
70
+ # The collection of master formatting records for named cell styles, which means records defined in cellStyles, in the workbook
71
+ # @return [SimpleTypedList]
72
+ # @note The recommended way to manage styles is with add_style
73
+ # @see Styles#add_style
74
+ attr_reader :cellStyleXfs
75
+
76
+ # The collection of named styles, referencing cellStyleXfs items in the workbook.
77
+ # @return [SimpleTypedList]
78
+ # @note The recommended way to manage styles is with add_style
79
+ # @see Styles#add_style
80
+ attr_reader :cellStyles
81
+
82
+ # The collection of master formatting records. This is the list that you will actually use in styling a workbook.
83
+ # @return [SimpleTypedList]
84
+ # @note The recommended way to manage styles is with add_style
85
+ # @see Styles#add_style
86
+ attr_reader :cellXfs
87
+
88
+ # The collection of non-cell formatting records used in the worksheet.
89
+ # @return [SimpleTypedList]
90
+ # @note The recommended way to manage styles is with add_style
91
+ # @see Styles#add_style
92
+ attr_reader :dxfs
93
+
94
+ # The collection of table styles that will be available to the user in the excel UI
95
+ # @return [SimpleTypedList]
96
+ # @note The recommended way to manage styles is with add_style
97
+ # @see Styles#add_style
98
+ attr_reader :tableStyles
99
+
100
+ # Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part.
101
+ def initialize()
102
+ load_default_styles
103
+ end
104
+
105
+ # Drastically simplifies style creation and management.
106
+ # @return [Integer]
107
+ # @option options [String] fg_color The text color
108
+ # @option options [Integer] sz The text size
109
+ # @option options [Boolean] b Indicates if the text should be bold
110
+ # @option options [Boolean] i Indicates if the text should be italicised
111
+ # @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
112
+ # @option options [Boolean] strike Indicates if the text should be rendered with a shadow
113
+ # @option options [Integer] charset The character set to use.
114
+ # @option options [Integer] family The font family to use.
115
+ # @option options [String] name The name of the font to use
116
+ # @option options [Integer] num_fmt The number format to apply
117
+ # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored.
118
+ # @option options [Integer] border The border style to use.
119
+ # @option options [String] bg_color The background color to apply to the cell
120
+ # @option options [Boolean] hidden Indicates if the cell should be hidden
121
+ # @option options [Boolean] locked Indicates if the cell should be locked
122
+ # @option options [Hash] alignment A hash defining any of the attributes used in CellAlignment
123
+ # @see CellAlignment
124
+ #
125
+ # @example You Got Style
126
+ # require "rubygems" # if that is your preferred way to manage gems!
127
+ # require "axlsx"
128
+ #
129
+ # p = Axlsx::Package.new
130
+ # ws = p.workbook.add_worksheet
131
+ #
132
+ # # black text on a white background at 14pt with thin borders!
133
+ # title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=>Axlsx::STYLE_THIN_BORDER
134
+ #
135
+ # ws.add_row :values => ["Least Popular Pets"]
136
+ # ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
137
+ # ws.add_row :values => ["Votes", 6, 4, 1], :style=>Axlsx::STYLE_THIN_BORDER
138
+ # f = File.open('example_you_got_style.xlsx', 'w')
139
+ # p.serialize(f)
140
+ #
141
+ # @example Styling specifically
142
+ # # an example of applying specific styles to specific cells
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
+ # # define your styles
150
+ # title = ws.style.add_style(:bg_color => "FFFF0000",
151
+ # :fg_color=>"#FF000000",
152
+ # :border=>Axlsx::STYLE_THIN_BORDER,
153
+ # :alignment=>{:horizontal => :center})
154
+ #
155
+ # date_time = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
156
+ # :border=>Axlsx::STYLE_THIN_BORDER)
157
+ #
158
+ # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
159
+ # :border=>Axlsx::STYLE_THIN_BORDER)
160
+ #
161
+ # currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
162
+ # :border=>Axlsx::STYLE_THIN_BORDER)
163
+ #
164
+ # # build your rows
165
+ # ws.add_row :values => ["Genreated At:", Time.now], :styles=>[nil, date_time]
166
+ # ws.add_row :values => ["Previous Year Quarterly Profits (JPY)"], :style=>title
167
+ # ws.add_row :values => ["Quarter", "Profit", "% of Total"], :style=>title
168
+ # ws.add_row :values => ["Q1", 4000, 40], :style=>[title, currency, percent]
169
+ # ws.add_row :values => ["Q2", 3000, 30], :style=>[title, currency, percent]
170
+ # ws.add_row :values => ["Q3", 1000, 10], :style=>[title, currency, percent]
171
+ # ws.add_row :values => ["Q4", 2000, 20], :style=>[title, currency, percent]
172
+ # f = File.open('example_you_got_style.xlsx', 'w')
173
+ # p.serialize(f)
174
+ def add_style(options={})
175
+
176
+ numFmtId = if options[:format_code]
177
+ n = @numFmts.map{ |f| f.numFmtId }.max + 1
178
+ numFmts << NumFmt.new(:numFmtId => n, :formatCode=> options[:format_code])
179
+ n
180
+ else
181
+ options[:num_fmt] || 0
182
+ end
183
+
184
+ borderId = options[:border] || 0
185
+ raise ArgumentError, "Invalid borderId" unless borderId < borders.size
186
+
187
+ fill = if options[:bg_color]
188
+ color = Color.new(:rgb=>options[:bg_color])
189
+ pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color)
190
+ fills << Fill.new(pattern)
191
+ else
192
+ 0
193
+ end
194
+
195
+ fontId = if (options.values_at(:fg_color, :sz, :b, :i, :strike, :outline, :shadow, :charset, :family, :font_name).length)
196
+ font = Font.new()
197
+ [:b, :i, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
198
+ font.color = Color.new(:rgb => options[:fg_color]) unless options[:fg_color].nil?
199
+ font.name = options[:font_name] unless options[:font_name].nil?
200
+ fonts << font
201
+ else
202
+ 0
203
+ end
204
+
205
+ applyProtection = (options[:hidden] || options[:locked]) ? 1 : 0
206
+
207
+ xf = Xf.new(:fillId => fill, :fontId=>fontId, :applyFill=>1, :applyFont=>1, :numFmtId=>numFmtId, :borderId=>borderId, :applyProtection=>applyProtection)
208
+
209
+ if options[:alignment]
210
+ xf.alignment = CellAlignment.new(options[:alignment])
211
+ end
212
+
213
+ if applyProtection
214
+ xf.protection = CellProtection.new(options)
215
+ end
216
+
217
+ cellXfs << xf
218
+ end
219
+
220
+ # Serializes the styles document
221
+ # @return [String]
222
+ def to_xml()
223
+ builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
224
+ xml.styleSheet(:xmlns => XML_NS) {
225
+ [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :dxfs, :tableStyles].each do |key|
226
+ self.instance_values[key.to_s].to_xml(xml)
227
+ end
228
+ }
229
+ end
230
+ builder.to_xml
231
+ end
232
+
233
+ private
234
+ # Creates the default set of styles the exel requires to be valid as well as setting up the
235
+ # Axlsx::STYLE_THIN_BORDER
236
+ def load_default_styles
237
+ @numFmts = SimpleTypedList.new NumFmt
238
+ @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode=> "yyyy/mm/dd")
239
+ @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode=> "yyyy/mm/dd hh:mm:ss")
240
+
241
+ @numFmts.lock
242
+
243
+ @fonts = SimpleTypedList.new Font
244
+ @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
245
+ @fonts.lock
246
+
247
+ @fills = SimpleTypedList.new Fill
248
+ @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:none))
249
+ @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:gray125))
250
+ @fills.lock
251
+
252
+ @borders = SimpleTypedList.new Border
253
+ @borders << Border.new
254
+ black_border = Border.new
255
+ [:left, :right, :top, :bottom].each do |item|
256
+ black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
257
+ end
258
+ @borders << black_border
259
+ @borders.lock
260
+
261
+ @cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
262
+ @cellStyleXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
263
+ @cellStyleXfs.lock
264
+
265
+ @cellStyles = SimpleTypedList.new CellStyle
266
+ @cellStyles << CellStyle.new(:name =>"標準", :builtinId =>0, :xfId=>0)
267
+ @cellStyles.lock
268
+
269
+ @cellXfs = SimpleTypedList.new Xf, "cellXfs"
270
+ @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
271
+ @cellXfs << Xf.new(:borderId=>1, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
272
+ @cellXfs.lock
273
+
274
+ @dxfs = SimpleTypedList.new(Xf, "dxfs"); @dxfs.lock
275
+ @tableStyles = TableStyles.new(:defaultTableStyle => "TableStyleMedium9", :defaultPivotStyle => "PivotStyleLight16"); @tableStyles.lock
276
+ end
277
+ end
278
+ end
279
+
@@ -0,0 +1,43 @@
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_accessor :name
9
+
10
+ # indicates if this style should be applied to pivot tables
11
+ # @return [Boolean]
12
+ attr_accessor :pivot
13
+
14
+ # indicates if this style should be applied to tables
15
+ # @return [Boolean]
16
+ attr_accessor :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
+ options.each do |o|
25
+ self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
26
+ end
27
+ super TableStyleElement
28
+ end
29
+
30
+ def name=(v) Axlsx::validate_string v; @name=v end
31
+ def pivot=(v) Axlsx::validate_boolean v; @pivot=v end
32
+ def table=(v) Axlsx::validate_boolean v; @table=v end
33
+
34
+ # Serializes the table style
35
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
36
+ # @return [String]
37
+ def to_xml(xml)
38
+ attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k }
39
+ attr[:count] = self.size
40
+ xml.tableStyle(attr) { self.each { |table_style_el| table_style_el.to_xml(xml) } }
41
+ end
42
+ end
43
+ end