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,223 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Axlsx
3
+ # Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
4
+ # xlsx document including valdation and serialization.
5
+ class Package
6
+
7
+ # provides access to the app doc properties for this package
8
+ # see App
9
+ attr_reader :app
10
+
11
+ # provides access to the core doc properties for the package
12
+ # see Core
13
+ attr_reader :core
14
+
15
+ # Initializes your package
16
+ #
17
+ # @param [Hash] options A hash that you can use to specify the author and workbook for this package.
18
+ # @option options [String] :author The author of the document
19
+ # @example Package.new :author => 'you!', :workbook => Workbook.new
20
+ def initialize(options={})
21
+ @workbook = nil
22
+ @core, @app = Core.new, App.new
23
+ @core.creator = options[:author] || @core.creator
24
+ yield self if block_given?
25
+ end
26
+
27
+ # The workbook this package will serialize or validate.
28
+ # @return [Workbook] If no workbook instance has been assigned with this package a new Workbook instance is returned.
29
+ # @raise ArgumentError if workbook parameter is not a Workbook instance.
30
+ # @note As there are multiple ways to instantiate a workbook for the package,
31
+ # here are a few examples:
32
+ # # assign directly during package instanciation
33
+ # wb = Package.new(:workbook => Workbook.new).workbook
34
+ #
35
+ # # get a fresh workbook automatically from the package
36
+ # wb = Pacakge.new().workbook
37
+ # # # set the workbook after creating the package
38
+ # wb = Package.new().workbook = Workbook.new
39
+ def workbook
40
+ @workbook || @workbook = Workbook.new
41
+ yield @workbook if block_given?
42
+ @workbook
43
+ end
44
+
45
+ #def self.parse(input, confirm_valid = false)
46
+ # p = Package.new
47
+ # z = Zip::ZipFile.open(input)
48
+ # p.workbook = Workbook.parse z.get_entry(WORKBOOK_PN)
49
+ # p
50
+ #end
51
+
52
+ # @see workbook
53
+ def workbook=(workbook) DataTypeValidator.validate "Package.workbook", Workbook, workbook; @workbook = workbook; end
54
+
55
+ # Serialize your workbook to disk as an xlsx document.
56
+ #
57
+ # @param [File] output The file you want to serialize your package to
58
+ # @param [Boolean] confirm_valid Validate the package prior to serialization.
59
+ # @return [Boolean] False if confirm_valid and validation errors exist. True if the package was serialized
60
+ # @note A tremendous amount of effort has gone into ensuring that you cannot create invalid xlsx documents.
61
+ # confirm_valid should be used in the rare case that you cannot open the serialized file.
62
+ # @see Package#validate
63
+ # @example
64
+ # # This is how easy it is to create a valid xlsx file. Of course you might want to add a sheet or two, and maybe some data, styles and charts.
65
+ # # Take a look at the README for an example of how to do it!
66
+ # f = File.open('test.xlsx', 'w')
67
+ # Package.new.serialize(f)
68
+ #
69
+ # # You will find a file called test.xlsx
70
+ def serialize(output, confirm_valid=false)
71
+ return false unless !confirm_valid || self.validate.empty?
72
+ p = parts
73
+ Zip::ZipOutputStream.open(output) do |zip|
74
+ p.each do |part|
75
+ unless part[:doc].nil?
76
+ zip.put_next_entry(part[:entry]);
77
+ entry = ['1.9.2', '1.9.3'].include?(RUBY_VERSION) ? part[:doc].force_encoding('BINARY') : part[:doc]
78
+ zip.puts(entry)
79
+ end
80
+ unless part[:path].nil?
81
+ zip.put_next_entry(part[:entry]);
82
+ # binread for 1.9.3
83
+ zip.write IO.respond_to?(:binread) ? IO.binread(part[:path]) : IO.read(part[:path])
84
+ end
85
+ end
86
+ end
87
+ true
88
+ end
89
+
90
+
91
+ # Validate all parts of the package against xsd schema.
92
+ # @return [Array] An array of all validation errors found.
93
+ # @note This gem includes all schema from OfficeOpenXML-XMLSchema-Transitional.zip and OpenPackagingConventions-XMLSchema.zip
94
+ # as per ECMA-376, Third edition. opc schema require an internet connection to import remote schema from dublin core for dc,
95
+ # dcterms and xml namespaces. Those remote schema are included in this gem, and the original files have been altered to
96
+ # refer to the local versions.
97
+ #
98
+ # If by chance you are able to creat a package that does not validate it indicates that the internal
99
+ # validation is not robust enough and needs to be improved. Please report your errors to the gem author.
100
+ # @see http://www.ecma-international.org/publications/standards/Ecma-376.htm
101
+ # @example
102
+ # # The following will output any error messages found in serialization.
103
+ # p = Axlsx::Package.new
104
+ # # ... code to create sheets, charts, styles etc.
105
+ # p.validate.each { |error| puts error.message }
106
+ def validate
107
+ errors = []
108
+ parts.each { |part| errors.concat validate_single_doc(part[:schema], part[:doc]) unless part[:schema].nil? }
109
+ errors
110
+ end
111
+
112
+ private
113
+
114
+ # The parts of a package
115
+ # @return [Array] An array of hashes that define the entry, document and schema for each part of the package.
116
+ # @private
117
+ def parts
118
+ @parts = [
119
+ {:entry => RELS_PN, :doc => relationships.to_xml, :schema => RELS_XSD},
120
+ {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml, :schema => SML_XSD},
121
+ {:entry => CORE_PN, :doc => @core.to_xml, :schema => CORE_XSD},
122
+ {:entry => APP_PN, :doc => @app.to_xml, :schema => APP_XSD},
123
+ {:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships.to_xml, :schema => RELS_XSD},
124
+ {:entry => CONTENT_TYPES_PN, :doc => content_types.to_xml, :schema => CONTENT_TYPES_XSD},
125
+ {:entry => WORKBOOK_PN, :doc => workbook.to_xml, :schema => SML_XSD}
126
+ ]
127
+ workbook.drawings.each do |drawing|
128
+ @parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml, :schema => RELS_XSD}
129
+ @parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml, :schema => DRAWING_XSD}
130
+ end
131
+
132
+ workbook.charts.each do |chart|
133
+ @parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml, :schema => DRAWING_XSD}
134
+ end
135
+
136
+ workbook.images.each do |image|
137
+ @parts << {:entry => "xl/#{image.pn}", :path => image.image_src}
138
+ end
139
+
140
+ workbook.worksheets.each do |sheet|
141
+ @parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml, :schema => RELS_XSD}
142
+ @parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml, :schema => SML_XSD}
143
+ end
144
+ @parts
145
+ end
146
+
147
+ # Performs xsd validation for a signle document
148
+ #
149
+ # @param [String] schema path to the xsd schema to be used in validation.
150
+ # @param [String] doc The xml text to be validated
151
+ # @return [Array] An array of all validation errors encountered.
152
+ # @private
153
+ def validate_single_doc(schema, doc)
154
+ schema = Nokogiri::XML::Schema(File.open(schema))
155
+ doc = Nokogiri::XML(doc)
156
+
157
+ errors = []
158
+ schema.validate(doc).each do |error|
159
+ errors << error
160
+ end
161
+ errors
162
+ end
163
+
164
+ # Appends override objects for drawings, charts, and sheets as they exist in your workbook to the default content types.
165
+ # @return [ContentType]
166
+ # @private
167
+ def content_types
168
+ c_types = base_content_types
169
+ workbook.drawings.each do |drawing|
170
+ c_types << Axlsx::Override.new(:PartName => "/xl/#{drawing.pn}",
171
+ :ContentType => DRAWING_CT)
172
+ end
173
+ workbook.charts.each do |chart|
174
+ c_types << Axlsx::Override.new(:PartName => "/xl/#{chart.pn}",
175
+ :ContentType => CHART_CT)
176
+ end
177
+ workbook.worksheets.each do |sheet|
178
+ c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}",
179
+ :ContentType => WORKSHEET_CT)
180
+ end
181
+ exts = workbook.images.map { |image| image.extname }
182
+ exts.uniq.each do |ext|
183
+ ct = if ['jpeg', 'jpg'].include?(ext)
184
+ JPEG_CT
185
+ elsif ext == 'gif'
186
+ GIF_CT
187
+ elsif ext == 'png'
188
+ PNG_CT
189
+ end
190
+ c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext )
191
+ end
192
+ c_types
193
+ end
194
+
195
+ # Creates the minimum content types for generating a valid xlsx document.
196
+ # @return [ContentType]
197
+ # @private
198
+ def base_content_types
199
+ c_types = ContentType.new()
200
+ c_types << Default.new(:ContentType => RELS_CT, :Extension => RELS_EX)
201
+ c_types << Default.new(:Extension => XML_EX, :ContentType => XML_CT)
202
+ c_types << Override.new(:PartName => "/#{APP_PN}", :ContentType => APP_CT)
203
+ c_types << Override.new(:PartName => "/#{CORE_PN}", :ContentType => CORE_CT)
204
+ c_types << Override.new(:PartName => "/xl/#{STYLES_PN}", :ContentType => STYLES_CT)
205
+ c_types << Axlsx::Override.new(:PartName => "/#{WORKBOOK_PN}", :ContentType => WORKBOOK_CT)
206
+ c_types.lock
207
+ c_types
208
+ end
209
+
210
+ # Creates the relationships required for a valid xlsx document
211
+ # @return [Relationships]
212
+ # @private
213
+ def relationships
214
+ rels = Axlsx::Relationships.new
215
+ rels << Relationship.new(WORKBOOK_R, WORKBOOK_PN)
216
+ rels << Relationship.new(CORE_R, CORE_PN)
217
+ rels << Relationship.new(APP_R, APP_PN)
218
+ rels.lock
219
+ rels
220
+ end
221
+ end
222
+ end
223
+
@@ -0,0 +1,44 @@
1
+ module Axlsx
2
+ # A relationship defines a reference between package parts.
3
+ # @note Packages automatcially manage relationships.
4
+ class Relationship
5
+
6
+ # The location of the relationship target
7
+ # @return [String]
8
+ attr_reader :Target
9
+
10
+ # The type of relationship
11
+ # @note Supported types are defined as constants in Axlsx:
12
+ # @see XML_NS_R
13
+ # @see TABLE_R
14
+ # @see WORKBOOK_R
15
+ # @see WORKSHEET_R
16
+ # @see APP_R
17
+ # @see RELS_R
18
+ # @see CORE_R
19
+ # @see STYLES_R
20
+ # @see CHART_R
21
+ # @see DRAWING_R
22
+ # @return [String]
23
+ attr_reader :Type
24
+ def initialize(type, target)
25
+ self.Target=target
26
+ self.Type=type
27
+ end
28
+
29
+ # @see Target
30
+ def Target=(v) Axlsx::validate_string v; @Target = v end
31
+ # @see Type
32
+ def Type=(v) Axlsx::validate_relationship_type v; @Type = v end
33
+
34
+ # Serializes the relationship
35
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
36
+ # @param [String] rId the reference id of the object.
37
+ # @return [String]
38
+ def to_xml(xml, rId)
39
+ h = self.instance_values
40
+ h[:Id] = rId
41
+ xml.Relationship(h)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ module Axlsx
2
+ require 'axlsx/rels/relationship.rb'
3
+
4
+ # Relationships are a collection of Relations that define how package parts are related.
5
+ # @note The package automatically manages releationships.
6
+ class Relationships < SimpleTypedList
7
+
8
+ # Creates a new Relationships collection based on SimpleTypedList
9
+ def initialize
10
+ super Relationship
11
+ end
12
+
13
+ # Serializes the relationships document.
14
+ # @return [String]
15
+ def to_xml()
16
+ builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
17
+ xml.Relationships(:xmlns => Axlsx::RELS_R) {
18
+ each_with_index { |rel, index| rel.to_xml(xml, "rId#{index+1}") }
19
+ }
20
+ end
21
+ builder.to_xml
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,57 @@
1
+ module Axlsx
2
+ # This class details a border used in Office Open XML spreadsheet styles.
3
+ class Border
4
+
5
+ # @return [Boolean] The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell.
6
+ attr_reader :diagonalUp
7
+
8
+ # @return [Boolean] The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell.
9
+ attr_reader :diagonalDown
10
+
11
+ # @return [Boolean] The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells.
12
+ attr_reader :outline
13
+
14
+ # @return [SimpleTypedList] A list of BorderPr objects for this border.
15
+ attr_reader :prs
16
+
17
+ # Creates a new Border object
18
+ # @option options [Boolean] diagonalUp
19
+ # @option options [Boolean] diagonalDown
20
+ # @option options [Boolean] outline
21
+ # @example Making a border
22
+ # p = Package.new
23
+ # red_border = Border.new
24
+ # [:left, :right, :top, :bottom].each do |item|
25
+ # red_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FFFF0000")) #
26
+ # end
27
+ # # this sets red_border to be the index for the created border.
28
+ # red_border = p.workbook.styles.@borders << red_border
29
+ # #used in row creation as follows. This will add a red border to each of the cells in the row.
30
+ # p.workbook.add_worksheet.rows << :values=>[1,2,3] :style=>red_border
31
+ def initialize(options={})
32
+ @prs = SimpleTypedList.new BorderPr
33
+ options.each do |o|
34
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
35
+ end
36
+ end
37
+
38
+ # @see diagonalUp
39
+ def diagonalUp=(v) Axlsx::validate_boolean v; @diagonalUp = v end
40
+ # @see diagonalDown
41
+ def diagonalDown=(v) Axlsx::validate_boolean v; @diagonalDown = v end
42
+ # @see outline
43
+ def outline=(v) Axlsx::validate_boolean v; @outline = v end
44
+
45
+ # Serializes the border element
46
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
47
+ def to_xml(xml)
48
+ xml.border(self.instance_values.select{ |k,v| [:diagonalUp, :diagonalDown, :outline].include? k }) {
49
+ [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal].each do |k|
50
+ @prs.select { |pr| pr.name == k }.each do |part|
51
+ part.to_xml(xml)
52
+ end
53
+ end
54
+ }
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,68 @@
1
+ module Axlsx
2
+ # A border part.
3
+ class BorderPr
4
+
5
+ # @return [Color] The color of this border part.
6
+ attr_reader :color
7
+
8
+ # @return [Symbol] The syle of this border part.
9
+ # @note
10
+ # The following are allowed
11
+ # :none
12
+ # :thin
13
+ # :medium
14
+ # :dashed
15
+ # :dotted
16
+ # :thick
17
+ # :double
18
+ # :hair
19
+ # :mediumDashed
20
+ # :dashDot
21
+ # :mediumDashDot
22
+ # :dashDotDot
23
+ # :mediumDashDotDot
24
+ # :slantDashDot
25
+ attr_reader :style
26
+
27
+ # @return [Symbol] The name of this border part
28
+ # @note
29
+ # The following are allowed
30
+ # :start
31
+ # :end
32
+ # :left
33
+ # :right
34
+ # :top
35
+ # :bottom
36
+ # :diagonal
37
+ # :vertical
38
+ # :horizontal
39
+ attr_reader :name
40
+
41
+ # Creates a new Border Part Object
42
+ # @option options [Color] color
43
+ # @option options [Symbol] name
44
+ # @option options [Symbol] style
45
+ # @see Axlsx::Border
46
+ def initialize(options={})
47
+ options.each do |o|
48
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
49
+ end
50
+ end
51
+
52
+ # @see name
53
+ def name=(v) RestrictionValidator.validate "BorderPr.name", [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal], v; @name = v end
54
+ # @see color
55
+ def color=(v) DataTypeValidator.validate(:color, Color, v); @color = v end
56
+ # @see style
57
+ def style=(v) RestrictionValidator.validate "BorderPr.style", [:none, :thin, :medium, :dashed, :dotted, :thick, :double, :hair, :mediumDashed, :dashDot, :mediumDashDot, :dashDotDot, :mediumDashDotDot, :slantDashDot], v; @style = v end
58
+
59
+ # Serializes the border part
60
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
61
+ # @return [String]
62
+ def to_xml(xml)
63
+ xml.send(@name, :style => @style) {
64
+ @color.to_xml(xml) if @color.is_a? Color
65
+ }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,105 @@
1
+ module Axlsx
2
+ # CellAlignment stores information about the cell alignment of a style Xf Object.
3
+ # @note Using Styles#add_style is the recommended way to manage cell alignment.
4
+ # @see Styles#add_style
5
+ class CellAlignment
6
+ # The horizontal alignment of the cell.
7
+ # @note
8
+ # The horizontal cell alignement style must be one of
9
+ # :general
10
+ # :left
11
+ # :center
12
+ # :right
13
+ # :fill
14
+ # :justify
15
+ # :centerContinuous
16
+ # :distributed
17
+ # @return [Symbol]
18
+ attr_reader :horizontal
19
+
20
+ # The vertical alignment of the cell.
21
+ # @note
22
+ # The vertical cell allingment style must be one of the following:
23
+ # :top
24
+ # :center
25
+ # :bottom
26
+ # :justify
27
+ # :distributed
28
+ # @return [Symbol]
29
+ attr_reader :vertical
30
+
31
+ # The textRotation of the cell.
32
+ # @return [Integer]
33
+ attr_reader :textRotation
34
+
35
+ # Indicate if the text of the cell should wrap
36
+ # @return [Boolean]
37
+ attr_reader :wrapText
38
+
39
+ # The amount of indent
40
+ # @return [Integer]
41
+ attr_reader :indent
42
+
43
+ # The amount of relativeIndent
44
+ # @return [Integer]
45
+ attr_reader :relativeIndent
46
+
47
+ # Indicate if the last line should be justified.
48
+ # @return [Boolean]
49
+ attr_reader :justifyLastLine
50
+
51
+ # Indicate if the text should be shrunk to the fit in the cell.
52
+ # @return [Boolean]
53
+ attr_reader :shrinkToFit
54
+
55
+ # The reading order of the text
56
+ # 0 Context Dependent
57
+ # 1 Left-to-Right
58
+ # 2 Right-to-Left
59
+ # @return [Integer]
60
+ attr_reader :readingOrder
61
+
62
+ # Create a new cell_alignment object
63
+ # @option options [Symbol] horizontal
64
+ # @option options [Symbol] vertical
65
+ # @option options [Integer] textRotation
66
+ # @option options [Boolean] wrapText
67
+ # @option options [Integer] indent
68
+ # @option options [Integer] relativeIndent
69
+ # @option options [Boolean] justifyLastLine
70
+ # @option options [Boolean] shrinkToFit
71
+ # @option options [Integer] readingOrder
72
+ def initialize(options={})
73
+ options.each do |o|
74
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
75
+ end
76
+ end
77
+
78
+ # @see horizontal
79
+ def horizontal=(v) Axlsx::validate_horizontal_alignment v; @horizontal = v end
80
+ # @see vertical
81
+ def vertical=(v) Axlsx::validate_vertical_alignment v; @vertical = v end
82
+ # @see textRotation
83
+ def textRotation=(v) Axlsx::validate_unsigned_int v; @textRotation = v end
84
+ # @see wrapText
85
+ def wrapText=(v) Axlsx::validate_boolean v; @wrapText = v end
86
+ # @see indent
87
+ def indent=(v) Axlsx::validate_unsigned_int v; @indent = v end
88
+ # @see relativeIndent
89
+ def relativeIndent=(v) Axlsx::validate_int v; @relativeIndent = v end
90
+ # @see justifyLastLine
91
+ def justifyLastLine=(v) Axlsx::validate_boolean v; @justifyLastLine = v end
92
+ # @see shrinkToFit
93
+ def shrinkToFit=(v) Axlsx::validate_boolean v; @shrinkToFit = v end
94
+ # @see readingOrder
95
+ def readingOrder=(v) Axlsx::validate_unsigned_int v; @readingOrder = v end
96
+
97
+ # Serializes the cell alignment
98
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
99
+ # @return [String]
100
+ def to_xml(xml)
101
+ xml.alignment(self.instance_values)
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,36 @@
1
+ module Axlsx
2
+ # CellProtection stores information about locking or hiding cells in spreadsheet.
3
+ # @note Using Styles#add_style is the recommended way to manage cell protection.
4
+ # @see Styles#add_style
5
+ class CellProtection
6
+
7
+ # specifies locking for cells that have the style containing this protection
8
+ # @return [Boolean]
9
+ attr_reader :hidden
10
+
11
+ # specifies if the cells that have the style containing this protection
12
+ # @return [Boolean]
13
+ attr_reader :locked
14
+
15
+ # Creates a new CellProtection
16
+ # @option options [Boolean] hidden value for hidden protection
17
+ # @option options [Boolean] locked value for locked protection
18
+ def initialize(options={})
19
+ options.each do |o|
20
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
21
+ end
22
+ end
23
+
24
+ # @see hidden
25
+ def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
26
+ # @see locked
27
+ def locked=(v) Axlsx::validate_boolean v; @locked = v end
28
+
29
+ # Serializes the cell protection
30
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
31
+ # @return [String]
32
+ def to_xml(xml)
33
+ xml.protection(self.instance_values)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,65 @@
1
+ module Axlsx
2
+ # CellStyle defines named styles that reference defined formatting records and can be used in your worksheet.
3
+ # @note Using Styles#add_style is the recommended way to manage cell styling.
4
+ # @see Styles#add_style
5
+ class CellStyle
6
+ # The name of this cell style
7
+ # @return [String]
8
+ attr_reader :name
9
+
10
+ # The formatting record id this named style utilizes
11
+ # @return [Integer]
12
+ # @see Axlsx::Xf
13
+ attr_reader :xfId
14
+
15
+ # The buildinId to use when this named style is applied
16
+ # @return [Integer]
17
+ # @see Axlsx::NumFmt
18
+ attr_reader :builtinId
19
+
20
+ # Determines if this formatting is for an outline style, and what level of the outline it is to be applied to.
21
+ # @return [Integer]
22
+ attr_reader :iLevel
23
+
24
+ # Determines if this named style should show in the list of styles when using excel
25
+ # @return [Boolean]
26
+ attr_reader :hidden
27
+
28
+ # Indicates that the build in style reference has been customized.
29
+ # @return [Boolean]
30
+ attr_reader :customBuiltin
31
+
32
+ # Creats a new CellStyle object
33
+ # @option options [String] name
34
+ # @option options [Integer] xfId
35
+ # @option options [Integer] buildinId
36
+ # @option options [Integer] iLevel
37
+ # @option options [Boolean] hidden
38
+ # @option options [Boolean] customBuiltIn
39
+ def initialize(options={})
40
+ options.each do |o|
41
+ self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
42
+ end
43
+ end
44
+ # @see name
45
+ def name=(v) Axlsx::validate_string v; @name = v end
46
+ # @see xfId
47
+ def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
48
+ # @see builtinId
49
+ def builtinId=(v) Axlsx::validate_unsigned_int v; @builtinId = v end
50
+ # @see iLivel
51
+ def iLevel=(v) Axlsx::validate_unsigned_int v; @iLevel = v end
52
+ # @see hidden
53
+ def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
54
+ # @see customBuiltin
55
+ def customBuiltin=(v) Axlsx::validate_boolean v; @customBuiltin = v end
56
+
57
+ # Serializes the cell style
58
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
59
+ # @return [String]
60
+ def to_xml(xml)
61
+ xml.cellStyle(self.instance_values)
62
+ end
63
+ end
64
+
65
+ end