axlsx 1.0.16 → 1.0.18
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.
- data/.yardopts +1 -0
- data/CHANGELOG.md +7 -0
- data/README.md +105 -46
- data/examples/example.rb +172 -142
- data/lib/axlsx/content_type/content_type.rb +4 -3
- data/lib/axlsx/content_type/default.rb +1 -0
- data/lib/axlsx/content_type/override.rb +1 -0
- data/lib/axlsx/doc_props/app.rb +1 -1
- data/lib/axlsx/doc_props/core.rb +1 -0
- data/lib/axlsx/drawing/axis.rb +1 -0
- data/lib/axlsx/drawing/bar_3D_chart.rb +1 -0
- data/lib/axlsx/drawing/bar_series.rb +1 -0
- data/lib/axlsx/drawing/cat_axis.rb +1 -0
- data/lib/axlsx/drawing/cat_axis_data.rb +1 -0
- data/lib/axlsx/drawing/chart.rb +4 -4
- data/lib/axlsx/drawing/drawing.rb +1 -0
- data/lib/axlsx/drawing/graphic_frame.rb +1 -0
- data/lib/axlsx/drawing/hyperlink.rb +1 -1
- data/lib/axlsx/drawing/line_3D_chart.rb +1 -0
- data/lib/axlsx/drawing/line_series.rb +1 -0
- data/lib/axlsx/drawing/marker.rb +1 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +1 -0
- data/lib/axlsx/drawing/pic.rb +2 -1
- data/lib/axlsx/drawing/picture_locking.rb +1 -0
- data/lib/axlsx/drawing/pie_3D_chart.rb +1 -0
- data/lib/axlsx/drawing/pie_series.rb +1 -0
- data/lib/axlsx/drawing/scaling.rb +1 -0
- data/lib/axlsx/drawing/ser_axis.rb +1 -0
- data/lib/axlsx/drawing/series.rb +1 -0
- data/lib/axlsx/drawing/series_title.rb +1 -0
- data/lib/axlsx/drawing/title.rb +1 -0
- data/lib/axlsx/drawing/two_cell_anchor.rb +1 -0
- data/lib/axlsx/drawing/val_axis.rb +1 -0
- data/lib/axlsx/drawing/val_axis_data.rb +1 -0
- data/lib/axlsx/drawing/view_3D.rb +1 -0
- data/lib/axlsx/package.rb +86 -38
- data/lib/axlsx/rels/relationship.rb +4 -3
- data/lib/axlsx/rels/relationships.rb +1 -0
- data/lib/axlsx/stylesheet/border.rb +1 -0
- data/lib/axlsx/stylesheet/border_pr.rb +1 -0
- data/lib/axlsx/stylesheet/cell_alignment.rb +1 -0
- data/lib/axlsx/stylesheet/cell_protection.rb +1 -0
- data/lib/axlsx/stylesheet/cell_style.rb +1 -0
- data/lib/axlsx/stylesheet/color.rb +1 -0
- data/lib/axlsx/stylesheet/fill.rb +1 -0
- data/lib/axlsx/stylesheet/font.rb +8 -0
- data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
- data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
- data/lib/axlsx/stylesheet/num_fmt.rb +1 -0
- data/lib/axlsx/stylesheet/pattern_fill.rb +1 -0
- data/lib/axlsx/stylesheet/styles.rb +12 -9
- data/lib/axlsx/stylesheet/table_style.rb +1 -0
- data/lib/axlsx/stylesheet/table_style_element.rb +1 -0
- data/lib/axlsx/stylesheet/table_styles.rb +1 -0
- data/lib/axlsx/stylesheet/xf.rb +1 -0
- data/lib/axlsx/util/cbf.rb +1 -0
- data/lib/axlsx/util/constants.rb +23 -14
- data/lib/axlsx/util/ms_off_crypto.rb +1 -1
- data/lib/axlsx/util/parser.rb +1 -0
- data/lib/axlsx/util/simple_typed_list.rb +2 -1
- data/lib/axlsx/util/storage.rb +1 -0
- data/lib/axlsx/util/validators.rb +11 -2
- data/lib/axlsx/version.rb +2 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +71 -0
- data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
- data/lib/axlsx/workbook/workbook.rb +47 -25
- data/lib/axlsx/workbook/worksheet/cell.rb +131 -78
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +94 -0
- data/lib/axlsx/workbook/worksheet/row.rb +44 -12
- data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +158 -44
- data/lib/axlsx.rb +16 -10
- data/test/content_type/tc_content_type.rb +2 -0
- data/test/content_type/tc_default.rb +2 -0
- data/test/content_type/tc_override.rb +1 -0
- data/test/drawing/tc_chart.rb +2 -2
- data/test/stylesheet/tc_cell_alignment.rb +8 -3
- data/test/stylesheet/tc_font.rb +8 -0
- data/test/stylesheet/tc_styles.rb +6 -2
- data/test/tc_package.rb +31 -0
- data/test/workbook/tc_shared_strings_table.rb +39 -0
- data/test/workbook/tc_shared_strings_table.rb~ +8 -0
- data/test/workbook/tc_workbook.rb +8 -0
- data/test/workbook/worksheet/tc_cell.rb +52 -9
- data/test/workbook/worksheet/tc_date_time_converter.rb +127 -0
- data/test/workbook/worksheet/tc_date_time_converter.rb~ +69 -0
- data/test/workbook/worksheet/tc_page_margins.rb +100 -0
- data/test/workbook/worksheet/tc_row.rb +36 -0
- data/test/workbook/worksheet/tc_worksheet.rb +97 -3
- metadata +33 -40
data/lib/axlsx/package.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# encoding: UTF-8
|
|
2
2
|
module Axlsx
|
|
3
3
|
# Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
|
|
4
4
|
# xlsx document including valdation and serialization.
|
|
5
5
|
class Package
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
# provides access to the app doc properties for this package
|
|
9
9
|
# see App
|
|
10
10
|
attr_reader :app
|
|
@@ -17,18 +17,35 @@ module Axlsx
|
|
|
17
17
|
#
|
|
18
18
|
# @param [Hash] options A hash that you can use to specify the author and workbook for this package.
|
|
19
19
|
# @option options [String] :author The author of the document
|
|
20
|
+
# @option options [Boolean] :use_shared_strings This is passed to the workbook to specify that shared strings should be used when serializing the package.
|
|
20
21
|
# @example Package.new :author => 'you!', :workbook => Workbook.new
|
|
21
22
|
def initialize(options={})
|
|
22
23
|
@workbook = nil
|
|
23
24
|
@core, @app = Core.new, App.new
|
|
24
25
|
@core.creator = options[:author] || @core.creator
|
|
26
|
+
options.each do |o|
|
|
27
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
28
|
+
end
|
|
25
29
|
yield self if block_given?
|
|
26
30
|
end
|
|
27
31
|
|
|
32
|
+
# Shortcut to specify that the workbook should use shared strings
|
|
33
|
+
# @see Workbook#use_shared_strings
|
|
34
|
+
def use_shared_strings=(v)
|
|
35
|
+
Axlsx::validate_boolean(v);
|
|
36
|
+
workbook.use_shared_strings = v
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Shortcut to determine if the workbook is configured to use shared strings
|
|
40
|
+
# @see Workbook#use_shared_strings
|
|
41
|
+
def use_shared_strings
|
|
42
|
+
workbook.use_shared_strings
|
|
43
|
+
end
|
|
44
|
+
|
|
28
45
|
# The workbook this package will serialize or validate.
|
|
29
46
|
# @return [Workbook] If no workbook instance has been assigned with this package a new Workbook instance is returned.
|
|
30
47
|
# @raise ArgumentError if workbook parameter is not a Workbook instance.
|
|
31
|
-
# @note As there are multiple ways to instantiate a workbook for the package,
|
|
48
|
+
# @note As there are multiple ways to instantiate a workbook for the package,
|
|
32
49
|
# here are a few examples:
|
|
33
50
|
# # assign directly during package instanciation
|
|
34
51
|
# wb = Package.new(:workbook => Workbook.new).workbook
|
|
@@ -42,13 +59,13 @@ module Axlsx
|
|
|
42
59
|
yield @workbook if block_given?
|
|
43
60
|
@workbook
|
|
44
61
|
end
|
|
45
|
-
|
|
62
|
+
|
|
46
63
|
#def self.parse(input, confirm_valid = false)
|
|
47
64
|
# p = Package.new
|
|
48
65
|
# z = Zip::ZipFile.open(input)
|
|
49
66
|
# p.workbook = Workbook.parse z.get_entry(WORKBOOK_PN)
|
|
50
67
|
# p
|
|
51
|
-
#end
|
|
68
|
+
#end
|
|
52
69
|
|
|
53
70
|
# @see workbook
|
|
54
71
|
def workbook=(workbook) DataTypeValidator.validate "Package.workbook", Workbook, workbook; @workbook = workbook; end
|
|
@@ -57,9 +74,10 @@ module Axlsx
|
|
|
57
74
|
#
|
|
58
75
|
# @param [File] output The file you want to serialize your package to
|
|
59
76
|
# @param [Boolean] confirm_valid Validate the package prior to serialization.
|
|
77
|
+
# @option options stream indicates if we should be writing to a stream or a file. True for stream, nil for file
|
|
60
78
|
# @return [Boolean] False if confirm_valid and validation errors exist. True if the package was serialized
|
|
61
79
|
# @note A tremendous amount of effort has gone into ensuring that you cannot create invalid xlsx documents.
|
|
62
|
-
# confirm_valid should be used in the rare case that you cannot open the serialized file.
|
|
80
|
+
# confirm_valid should be used in the rare case that you cannot open the serialized file.
|
|
63
81
|
# @see Package#validate
|
|
64
82
|
# @example
|
|
65
83
|
# # 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.
|
|
@@ -70,35 +88,37 @@ module Axlsx
|
|
|
70
88
|
# # You will find a file called test.xlsx
|
|
71
89
|
def serialize(output, confirm_valid=false)
|
|
72
90
|
return false unless !confirm_valid || self.validate.empty?
|
|
73
|
-
p = parts
|
|
74
91
|
Zip::ZipOutputStream.open(output) do |zip|
|
|
75
|
-
|
|
76
|
-
unless part[:doc].nil?
|
|
77
|
-
zip.put_next_entry(part[:entry]);
|
|
78
|
-
entry = ['1.9.2', '1.9.3'].include?(RUBY_VERSION) ? part[:doc].force_encoding('BINARY') : part[:doc]
|
|
79
|
-
zip.puts(entry)
|
|
80
|
-
end
|
|
81
|
-
unless part[:path].nil?
|
|
82
|
-
zip.put_next_entry(part[:entry]);
|
|
83
|
-
# binread for 1.9.3
|
|
84
|
-
zip.write IO.respond_to?(:binread) ? IO.binread(part[:path]) : IO.read(part[:path])
|
|
85
|
-
end
|
|
86
|
-
end
|
|
92
|
+
write_parts(zip)
|
|
87
93
|
end
|
|
88
94
|
true
|
|
89
95
|
end
|
|
90
|
-
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# Serialize your workbook to a StringIO instance
|
|
99
|
+
# @param [Boolean] confirm_valid Validate the package prior to serialization.
|
|
100
|
+
# @return [StringIO|Boolean] False if confirm_valid and validation errors exist. rewound string IO if not.
|
|
101
|
+
def to_stream(confirm_valid=false)
|
|
102
|
+
return false unless !confirm_valid || self.validate.empty?
|
|
103
|
+
zip = write_parts(Zip::ZipOutputStream.new("streamed", true))
|
|
104
|
+
stream = zip.close_buffer
|
|
105
|
+
stream.rewind
|
|
106
|
+
stream
|
|
107
|
+
end
|
|
108
|
+
|
|
91
109
|
# Encrypt the package into a CFB using the password provided
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
# This is not ready yet
|
|
111
|
+
def encrypt(file_name, password)
|
|
112
|
+
return false
|
|
113
|
+
# moc = MsOffCrypto.new(file_name, password)
|
|
114
|
+
# moc.save
|
|
95
115
|
end
|
|
96
|
-
|
|
97
|
-
# Validate all parts of the package against xsd schema.
|
|
116
|
+
|
|
117
|
+
# Validate all parts of the package against xsd schema.
|
|
98
118
|
# @return [Array] An array of all validation errors found.
|
|
99
119
|
# @note This gem includes all schema from OfficeOpenXML-XMLSchema-Transitional.zip and OpenPackagingConventions-XMLSchema.zip
|
|
100
120
|
# as per ECMA-376, Third edition. opc schema require an internet connection to import remote schema from dublin core for dc,
|
|
101
|
-
# dcterms and xml namespaces. Those remote schema are included in this gem, and the original files have been altered to
|
|
121
|
+
# dcterms and xml namespaces. Those remote schema are included in this gem, and the original files have been altered to
|
|
102
122
|
# refer to the local versions.
|
|
103
123
|
#
|
|
104
124
|
# If by chance you are able to creat a package that does not validate it indicates that the internal
|
|
@@ -115,10 +135,30 @@ module Axlsx
|
|
|
115
135
|
errors
|
|
116
136
|
end
|
|
117
137
|
|
|
118
|
-
private
|
|
138
|
+
private
|
|
139
|
+
|
|
140
|
+
# Writes the package parts to a zip archive.
|
|
141
|
+
# @param [Zip::ZipOutputStream] zip
|
|
142
|
+
# @return [Zip::ZipOutputStream]
|
|
143
|
+
def write_parts(zip)
|
|
144
|
+
p = parts
|
|
145
|
+
p.each do |part|
|
|
146
|
+
unless part[:doc].nil?
|
|
147
|
+
zip.put_next_entry(part[:entry]);
|
|
148
|
+
entry = ['1.9.2', '1.9.3'].include?(RUBY_VERSION) ? part[:doc].force_encoding('BINARY') : part[:doc]
|
|
149
|
+
zip.puts(entry)
|
|
150
|
+
end
|
|
151
|
+
unless part[:path].nil?
|
|
152
|
+
zip.put_next_entry(part[:entry]);
|
|
153
|
+
# binread for 1.9.3
|
|
154
|
+
zip.write IO.respond_to?(:binread) ? IO.binread(part[:path]) : IO.read(part[:path])
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
zip
|
|
158
|
+
end
|
|
119
159
|
|
|
120
160
|
# The parts of a package
|
|
121
|
-
# @return [Array] An array of hashes that define the entry, document and schema for each part of the package.
|
|
161
|
+
# @return [Array] An array of hashes that define the entry, document and schema for each part of the package.
|
|
122
162
|
# @private
|
|
123
163
|
def parts
|
|
124
164
|
@parts = [
|
|
@@ -134,18 +174,22 @@ module Axlsx
|
|
|
134
174
|
@parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml, :schema => RELS_XSD}
|
|
135
175
|
@parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml, :schema => DRAWING_XSD}
|
|
136
176
|
end
|
|
137
|
-
|
|
138
|
-
workbook.charts.each do |chart|
|
|
177
|
+
|
|
178
|
+
workbook.charts.each do |chart|
|
|
139
179
|
@parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml, :schema => DRAWING_XSD}
|
|
140
|
-
end
|
|
180
|
+
end
|
|
141
181
|
|
|
142
182
|
workbook.images.each do |image|
|
|
143
183
|
@parts << {:entry => "xl/#{image.pn}", :path => image.image_src}
|
|
144
184
|
end
|
|
145
185
|
|
|
146
|
-
|
|
186
|
+
if use_shared_strings
|
|
187
|
+
@parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings.to_xml, :schema => SML_XSD}
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
workbook.worksheets.each do |sheet|
|
|
147
191
|
@parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml, :schema => RELS_XSD}
|
|
148
|
-
@parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml, :schema => SML_XSD}
|
|
192
|
+
@parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml, :schema => SML_XSD}
|
|
149
193
|
end
|
|
150
194
|
@parts
|
|
151
195
|
end
|
|
@@ -173,15 +217,15 @@ module Axlsx
|
|
|
173
217
|
def content_types
|
|
174
218
|
c_types = base_content_types
|
|
175
219
|
workbook.drawings.each do |drawing|
|
|
176
|
-
c_types << Axlsx::Override.new(:PartName => "/xl/#{drawing.pn}",
|
|
220
|
+
c_types << Axlsx::Override.new(:PartName => "/xl/#{drawing.pn}",
|
|
177
221
|
:ContentType => DRAWING_CT)
|
|
178
222
|
end
|
|
179
223
|
workbook.charts.each do |chart|
|
|
180
|
-
c_types << Axlsx::Override.new(:PartName => "/xl/#{chart.pn}",
|
|
181
|
-
:ContentType => CHART_CT)
|
|
224
|
+
c_types << Axlsx::Override.new(:PartName => "/xl/#{chart.pn}",
|
|
225
|
+
:ContentType => CHART_CT)
|
|
182
226
|
end
|
|
183
227
|
workbook.worksheets.each do |sheet|
|
|
184
|
-
c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}",
|
|
228
|
+
c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}",
|
|
185
229
|
:ContentType => WORKSHEET_CT)
|
|
186
230
|
end
|
|
187
231
|
exts = workbook.images.map { |image| image.extname }
|
|
@@ -195,6 +239,10 @@ module Axlsx
|
|
|
195
239
|
end
|
|
196
240
|
c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext )
|
|
197
241
|
end
|
|
242
|
+
if use_shared_strings
|
|
243
|
+
c_types << Axlsx::Override.new(:PartName => "/xl/#{SHARED_STRINGS_PN}",
|
|
244
|
+
:ContentType => SHARED_STRINGS_CT)
|
|
245
|
+
end
|
|
198
246
|
c_types
|
|
199
247
|
end
|
|
200
248
|
|
|
@@ -208,7 +256,7 @@ module Axlsx
|
|
|
208
256
|
c_types << Override.new(:PartName => "/#{APP_PN}", :ContentType => APP_CT)
|
|
209
257
|
c_types << Override.new(:PartName => "/#{CORE_PN}", :ContentType => CORE_CT)
|
|
210
258
|
c_types << Override.new(:PartName => "/xl/#{STYLES_PN}", :ContentType => STYLES_CT)
|
|
211
|
-
c_types << Axlsx::Override.new(:PartName => "/#{WORKBOOK_PN}", :ContentType => WORKBOOK_CT)
|
|
259
|
+
c_types << Axlsx::Override.new(:PartName => "/#{WORKBOOK_PN}", :ContentType => WORKBOOK_CT)
|
|
212
260
|
c_types.lock
|
|
213
261
|
c_types
|
|
214
262
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
1
2
|
module Axlsx
|
|
2
3
|
# A relationship defines a reference between package parts.
|
|
3
|
-
# @note Packages
|
|
4
|
+
# @note Packages automatically manage relationships.
|
|
4
5
|
class Relationship
|
|
5
6
|
|
|
6
7
|
# The location of the relationship target
|
|
@@ -31,7 +32,7 @@ module Axlsx
|
|
|
31
32
|
# creates a new relationship
|
|
32
33
|
# @param [String] Type The type of the relationship
|
|
33
34
|
# @param [String] Target The target for the relationship
|
|
34
|
-
# @option [Symbol] target_mode only accepts :external.
|
|
35
|
+
# @option [Symbol] target_mode only accepts :external.
|
|
35
36
|
def initialize(type, target, options={})
|
|
36
37
|
self.Target=target
|
|
37
38
|
self.Type=type
|
|
@@ -46,7 +47,7 @@ module Axlsx
|
|
|
46
47
|
# @see TargetMode
|
|
47
48
|
def TargetMode=(v) RestrictionValidator.validate 'Relationship.TargetMode', [:External, :Internal], v; @TargetMode = v; end
|
|
48
49
|
|
|
49
|
-
# Serializes the relationship
|
|
50
|
+
# Serializes the relationship
|
|
50
51
|
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
|
51
52
|
# @param [String] rId the reference id of the object.
|
|
52
53
|
# @return [String]
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
1
2
|
module Axlsx
|
|
2
3
|
# The Font class details a font instance for use in styling cells.
|
|
3
4
|
# @note The recommended way to manage fonts, and other styles is Styles#add_style
|
|
@@ -53,6 +54,10 @@ module Axlsx
|
|
|
53
54
|
# @return [Boolean]
|
|
54
55
|
attr_reader :i
|
|
55
56
|
|
|
57
|
+
# Indicates if the font should be rendered underlined
|
|
58
|
+
# @return [Boolean]
|
|
59
|
+
attr_reader :u
|
|
60
|
+
|
|
56
61
|
# Indicates if the font should be rendered with a strikthrough
|
|
57
62
|
# @return [Boolean]
|
|
58
63
|
attr_reader :strike
|
|
@@ -88,6 +93,7 @@ module Axlsx
|
|
|
88
93
|
# @option options [Integer] family
|
|
89
94
|
# @option options [Boolean] b
|
|
90
95
|
# @option options [Boolean] i
|
|
96
|
+
# @option options [Boolean] u
|
|
91
97
|
# @option options [Boolean] strike
|
|
92
98
|
# @option options [Boolean] outline
|
|
93
99
|
# @option options [Boolean] shadow
|
|
@@ -110,6 +116,8 @@ module Axlsx
|
|
|
110
116
|
def b=(v) Axlsx::validate_boolean v; @b = v end
|
|
111
117
|
# @see i
|
|
112
118
|
def i=(v) Axlsx::validate_boolean v; @i = v end
|
|
119
|
+
# @see u
|
|
120
|
+
def u=(v) Axlsx::validate_boolean v; @u = v end
|
|
113
121
|
# @see strike
|
|
114
122
|
def strike=(v) Axlsx::validate_boolean v; @strike = v end
|
|
115
123
|
# @see outline
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# encoding: UTF-8
|
|
2
2
|
module Axlsx
|
|
3
3
|
require 'axlsx/stylesheet/border.rb'
|
|
4
4
|
require 'axlsx/stylesheet/border_pr.rb'
|
|
@@ -125,11 +125,12 @@ module Axlsx
|
|
|
125
125
|
# @option options [Integer] sz The text size
|
|
126
126
|
# @option options [Boolean] b Indicates if the text should be bold
|
|
127
127
|
# @option options [Boolean] i Indicates if the text should be italicised
|
|
128
|
+
# @option options [Boolean] u Indicates if the text should be underlined
|
|
128
129
|
# @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
|
|
129
130
|
# @option options [Boolean] strike Indicates if the text should be rendered with a shadow
|
|
130
131
|
# @option options [Integer] charset The character set to use.
|
|
131
132
|
# @option options [Integer] family The font family to use.
|
|
132
|
-
# @option options [String]
|
|
133
|
+
# @option options [String] font_name The name of the font to use
|
|
133
134
|
# @option options [Integer] num_fmt The number format to apply
|
|
134
135
|
# @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored.
|
|
135
136
|
# @option options [Integer] border The border style to use.
|
|
@@ -199,6 +200,7 @@ module Axlsx
|
|
|
199
200
|
end
|
|
200
201
|
|
|
201
202
|
borderId = options[:border] || 0
|
|
203
|
+
|
|
202
204
|
raise ArgumentError, "Invalid borderId" unless borderId < borders.size
|
|
203
205
|
|
|
204
206
|
fill = if options[:bg_color]
|
|
@@ -209,9 +211,9 @@ module Axlsx
|
|
|
209
211
|
0
|
|
210
212
|
end
|
|
211
213
|
|
|
212
|
-
fontId = if (options.values_at(:fg_color, :sz, :b, :i, :strike, :outline, :shadow, :charset, :family, :font_name).length)
|
|
214
|
+
fontId = if (options.values_at(:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name).length)
|
|
213
215
|
font = Font.new()
|
|
214
|
-
[:b, :i, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
|
|
216
|
+
[:b, :i, :u, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
|
|
215
217
|
font.color = Color.new(:rgb => options[:fg_color]) unless options[:fg_color].nil?
|
|
216
218
|
font.name = options[:font_name] unless options[:font_name].nil?
|
|
217
219
|
fonts << font
|
|
@@ -224,6 +226,7 @@ module Axlsx
|
|
|
224
226
|
xf = Xf.new(:fillId => fill, :fontId=>fontId, :applyFill=>1, :applyFont=>1, :numFmtId=>numFmtId, :borderId=>borderId, :applyProtection=>applyProtection)
|
|
225
227
|
|
|
226
228
|
xf.applyNumberFormat = true if xf.numFmtId > 0
|
|
229
|
+
xf.applyBorder = true if borderId > 0
|
|
227
230
|
|
|
228
231
|
if options[:alignment]
|
|
229
232
|
xf.alignment = CellAlignment.new(options[:alignment])
|
|
@@ -253,22 +256,22 @@ module Axlsx
|
|
|
253
256
|
# Creates the default set of styles the exel requires to be valid as well as setting up the
|
|
254
257
|
# Axlsx::STYLE_THIN_BORDER
|
|
255
258
|
def load_default_styles
|
|
256
|
-
@numFmts = SimpleTypedList.new NumFmt
|
|
259
|
+
@numFmts = SimpleTypedList.new NumFmt, 'numFmts'
|
|
257
260
|
@numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode=> "yyyy/mm/dd")
|
|
258
261
|
@numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode=> "yyyy/mm/dd hh:mm:ss")
|
|
259
262
|
|
|
260
263
|
@numFmts.lock
|
|
261
264
|
|
|
262
|
-
@fonts = SimpleTypedList.new Font
|
|
265
|
+
@fonts = SimpleTypedList.new Font, 'fonts'
|
|
263
266
|
@fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
|
|
264
267
|
@fonts.lock
|
|
265
268
|
|
|
266
|
-
@fills = SimpleTypedList.new Fill
|
|
269
|
+
@fills = SimpleTypedList.new Fill, 'fills'
|
|
267
270
|
@fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:none))
|
|
268
271
|
@fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:gray125))
|
|
269
272
|
@fills.lock
|
|
270
273
|
|
|
271
|
-
@borders = SimpleTypedList.new Border
|
|
274
|
+
@borders = SimpleTypedList.new Border, 'borders'
|
|
272
275
|
@borders << Border.new
|
|
273
276
|
black_border = Border.new
|
|
274
277
|
[:left, :right, :top, :bottom].each do |item|
|
|
@@ -281,7 +284,7 @@ module Axlsx
|
|
|
281
284
|
@cellStyleXfs << Xf.new(:borderId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
|
|
282
285
|
@cellStyleXfs.lock
|
|
283
286
|
|
|
284
|
-
@cellStyles = SimpleTypedList.new CellStyle
|
|
287
|
+
@cellStyles = SimpleTypedList.new CellStyle, 'cellStyles'
|
|
285
288
|
@cellStyles << CellStyle.new(:name =>"Normal", :builtinId =>0, :xfId=>0)
|
|
286
289
|
@cellStyles.lock
|
|
287
290
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
1
2
|
module Axlsx
|
|
2
3
|
# TableStyles represents a collection of style definitions for table styles and pivot table styles.
|
|
3
4
|
# @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.
|
data/lib/axlsx/stylesheet/xf.rb
CHANGED
data/lib/axlsx/util/cbf.rb
CHANGED
data/lib/axlsx/util/constants.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
1
2
|
module Axlsx
|
|
2
3
|
|
|
3
4
|
# XML Encoding
|
|
@@ -20,7 +21,7 @@ module Axlsx
|
|
|
20
21
|
|
|
21
22
|
# dc elements (core) namespace
|
|
22
23
|
CORE_NS_DC = "http://purl.org/dc/elements/1.1/"
|
|
23
|
-
|
|
24
|
+
|
|
24
25
|
# dcmit (core) namespcace
|
|
25
26
|
CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/"
|
|
26
27
|
|
|
@@ -29,10 +30,10 @@ module Axlsx
|
|
|
29
30
|
|
|
30
31
|
# xml schema namespace
|
|
31
32
|
CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
|
|
32
|
-
|
|
33
|
+
|
|
33
34
|
# spreadsheet drawing namespace
|
|
34
35
|
XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
|
|
35
|
-
|
|
36
|
+
|
|
36
37
|
# drawing namespace
|
|
37
38
|
XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main"
|
|
38
39
|
|
|
@@ -42,13 +43,12 @@ module Axlsx
|
|
|
42
43
|
# relationships namespace
|
|
43
44
|
XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
|
44
45
|
|
|
45
|
-
|
|
46
46
|
# relationships name space
|
|
47
47
|
RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships"
|
|
48
48
|
|
|
49
49
|
# table rels namespace
|
|
50
50
|
TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
# workbook rels namespace
|
|
53
53
|
WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
|
|
54
54
|
|
|
@@ -64,6 +64,9 @@ module Axlsx
|
|
|
64
64
|
# styles rels namespace
|
|
65
65
|
STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
|
|
66
66
|
|
|
67
|
+
# shared strings namespace
|
|
68
|
+
SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
|
|
69
|
+
|
|
67
70
|
# drawing rels namespace
|
|
68
71
|
DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
|
|
69
72
|
|
|
@@ -76,7 +79,7 @@ module Axlsx
|
|
|
76
79
|
# image rels namespace
|
|
77
80
|
HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
|
|
78
81
|
|
|
79
|
-
# table content type
|
|
82
|
+
# table content type
|
|
80
83
|
TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
|
|
81
84
|
|
|
82
85
|
# workbook content type
|
|
@@ -86,14 +89,14 @@ module Axlsx
|
|
|
86
89
|
APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"
|
|
87
90
|
|
|
88
91
|
# rels content type
|
|
89
|
-
RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
|
|
92
|
+
RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
|
|
90
93
|
|
|
91
94
|
# styles content type
|
|
92
95
|
STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
|
|
93
96
|
|
|
94
97
|
# xml content type
|
|
95
98
|
XML_CT = "application/xml"
|
|
96
|
-
|
|
99
|
+
|
|
97
100
|
# worksheet content type
|
|
98
101
|
WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
|
99
102
|
|
|
@@ -123,7 +126,7 @@ module Axlsx
|
|
|
123
126
|
|
|
124
127
|
# jpeg extension
|
|
125
128
|
JPEG_EX = "jpeg"
|
|
126
|
-
|
|
129
|
+
|
|
127
130
|
# gif extension
|
|
128
131
|
GIF_EX = "gif"
|
|
129
132
|
|
|
@@ -138,10 +141,13 @@ module Axlsx
|
|
|
138
141
|
|
|
139
142
|
# styles part
|
|
140
143
|
STYLES_PN = "styles.xml"
|
|
141
|
-
|
|
144
|
+
|
|
145
|
+
# shared_strings part
|
|
146
|
+
SHARED_STRINGS_PN = "sharedStrings.xml"
|
|
147
|
+
|
|
142
148
|
# app part
|
|
143
149
|
APP_PN = "docProps/app.xml"
|
|
144
|
-
|
|
150
|
+
|
|
145
151
|
# core part
|
|
146
152
|
CORE_PN = "docProps/core.xml"
|
|
147
153
|
|
|
@@ -189,12 +195,12 @@ module Axlsx
|
|
|
189
195
|
|
|
190
196
|
# spreadsheetML validation schema
|
|
191
197
|
SML_XSD = SCHEMA_BASE + "sml.xsd"
|
|
192
|
-
|
|
198
|
+
|
|
193
199
|
# drawing validation schema
|
|
194
200
|
DRAWING_XSD = SCHEMA_BASE + "dml-spreadsheetDrawing.xsd"
|
|
195
201
|
|
|
196
202
|
# number format id for pecentage formatting using the default formatting id.
|
|
197
|
-
NUM_FMT_PERCENT = 9
|
|
203
|
+
NUM_FMT_PERCENT = 9
|
|
198
204
|
|
|
199
205
|
# number format id for date format like 2011/11/13
|
|
200
206
|
NUM_FMT_YYYYMMDD = 100
|
|
@@ -209,7 +215,7 @@ module Axlsx
|
|
|
209
215
|
STYLE_DATE = 2
|
|
210
216
|
|
|
211
217
|
# error messages RestrictionValidor
|
|
212
|
-
ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
|
|
218
|
+
ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
|
|
213
219
|
|
|
214
220
|
# error message DataTypeValidator
|
|
215
221
|
ERR_TYPE = "Invalid Data %s for %s. must be %s."
|
|
@@ -217,6 +223,9 @@ module Axlsx
|
|
|
217
223
|
# error message for RegexValidator
|
|
218
224
|
ERR_REGEX = "Invalid Data. %s does not match %s."
|
|
219
225
|
|
|
226
|
+
# error message for sheets that use a name which is longer than 31 bytes
|
|
227
|
+
ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less"
|
|
228
|
+
|
|
220
229
|
# error message for duplicate sheet names
|
|
221
230
|
ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
|
|
222
231
|
end
|
data/lib/axlsx/util/parser.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
1
2
|
module Axlsx
|
|
2
3
|
# A SimpleTypedList is a type restrictive collection that allows some of the methods from Array and supports basic xml serialization.
|
|
3
4
|
# @private
|
|
@@ -153,7 +154,7 @@ module Axlsx
|
|
|
153
154
|
# @return [String]
|
|
154
155
|
def to_xml(xml)
|
|
155
156
|
classname = @allowed_types[0].name.split('::').last
|
|
156
|
-
el_name = serialize_as || (classname[0,1].downcase + classname[1..-1])
|
|
157
|
+
el_name = serialize_as || (classname[0,1].downcase + classname[1..-1])
|
|
157
158
|
xml.send(el_name, :count=>@list.size) {
|
|
158
159
|
@list.each { |item| item.to_xml(xml) }
|
|
159
160
|
}
|
data/lib/axlsx/util/storage.rb
CHANGED