axlsx 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +14 -0
- data/Gemfile +3 -7
- data/Gemfile.lock +17 -8
- data/README.md +88 -59
- data/axlsx.gemspec +9 -3
- data/doc/Axlsx.html +482 -248
- data/doc/Axlsx/App.html +237 -159
- data/doc/Axlsx/Axis.html +75 -51
- data/doc/Axlsx/Bar3DChart.html +75 -53
- data/doc/Axlsx/BarSeries.html +45 -31
- data/doc/Axlsx/Border.html +70 -50
- data/doc/Axlsx/BorderPr.html +80 -62
- data/doc/Axlsx/CatAxis.html +62 -43
- data/doc/Axlsx/CatAxisData.html +23 -16
- data/doc/Axlsx/Cell.html +2022 -393
- data/doc/Axlsx/CellAlignment.html +103 -75
- data/doc/Axlsx/CellProtection.html +44 -30
- data/doc/Axlsx/CellStyle.html +66 -46
- data/doc/Axlsx/Chart.html +159 -108
- data/doc/Axlsx/Color.html +73 -52
- data/doc/Axlsx/ContentType.html +20 -14
- data/doc/Axlsx/Core.html +29 -20
- data/doc/Axlsx/DataTypeValidator.html +27 -19
- data/doc/Axlsx/Default.html +39 -27
- data/doc/Axlsx/Drawing.html +104 -70
- data/doc/Axlsx/Fill.html +33 -23
- data/doc/Axlsx/Font.html +132 -98
- data/doc/Axlsx/GradientFill.html +70 -48
- data/doc/Axlsx/GradientStop.html +31 -21
- data/doc/Axlsx/GraphicFrame.html +40 -27
- data/doc/Axlsx/Line3DChart.html +62 -43
- data/doc/Axlsx/LineSeries.html +37 -25
- data/doc/Axlsx/Marker.html +63 -43
- data/doc/Axlsx/NumFmt.html +79 -65
- data/doc/Axlsx/OneCellAnchor.html +78 -54
- data/doc/Axlsx/Override.html +39 -27
- data/doc/Axlsx/Package.html +103 -163
- data/doc/Axlsx/Parser.html +549 -0
- data/doc/Axlsx/PatternFill.html +66 -51
- data/doc/Axlsx/Pic.html +230 -123
- data/doc/Axlsx/PictureLocking.html +1159 -0
- data/doc/Axlsx/Pie3DChart.html +23 -16
- data/doc/Axlsx/PieSeries.html +44 -30
- data/doc/Axlsx/RegexValidator.html +14 -10
- data/doc/Axlsx/Relationship.html +40 -27
- data/doc/Axlsx/Relationships.html +20 -14
- data/doc/Axlsx/RestrictionValidator.html +25 -17
- data/doc/Axlsx/Row.html +73 -53
- data/doc/Axlsx/Scaling.html +46 -31
- data/doc/Axlsx/SerAxis.html +49 -33
- data/doc/Axlsx/Series.html +51 -35
- data/doc/Axlsx/SeriesTitle.html +14 -10
- data/doc/Axlsx/Styles.html +210 -156
- data/doc/Axlsx/TableStyle.html +47 -32
- data/doc/Axlsx/TableStyleElement.html +75 -61
- data/doc/Axlsx/TableStyles.html +42 -28
- data/doc/Axlsx/Title.html +36 -25
- data/doc/Axlsx/TwoCellAnchor.html +83 -58
- data/doc/Axlsx/ValAxis.html +35 -24
- data/doc/Axlsx/ValAxisData.html +13 -9
- data/doc/Axlsx/View3D.html +64 -43
- data/doc/Axlsx/Workbook.html +305 -147
- data/doc/Axlsx/Worksheet.html +567 -271
- data/doc/Axlsx/Xf.html +114 -77
- data/doc/_index.html +15 -1
- data/doc/class_list.html +1 -1
- data/doc/css/style.css +1 -1
- data/doc/file.LICENSE.html +25 -21
- data/doc/file.README.html +89 -66
- data/doc/index.html +89 -66
- data/doc/js/app.js +4 -4
- data/doc/method_list.html +717 -413
- data/doc/top-level-namespace.html +1 -1
- data/examples/example.rb +52 -25
- data/examples/follow_20111202.xlsx +0 -0
- data/lib/axlsx.rb +14 -1
- data/lib/axlsx/drawing/chart.rb +20 -4
- data/lib/axlsx/drawing/drawing.rb +1 -1
- data/lib/axlsx/drawing/pic.rb +5 -2
- data/lib/axlsx/drawing/picture_locking.rb +72 -0
- data/lib/axlsx/package.rb +9 -7
- data/lib/axlsx/stylesheet/color.rb +19 -9
- data/lib/axlsx/stylesheet/styles.rb +2 -0
- data/lib/axlsx/util/constants.rb +6 -0
- data/lib/axlsx/util/parser.rb +43 -0
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/workbook.rb +21 -1
- data/lib/axlsx/workbook/worksheet/cell.rb +159 -7
- data/lib/axlsx/workbook/worksheet/row.rb +4 -2
- data/lib/axlsx/workbook/worksheet/worksheet.rb +38 -4
- data/test/drawing/tc_picture_locking.rb +73 -0
- data/test/rels/tc_relationships.rb +0 -1
- data/test/stylesheet/tc_styles.rb +0 -12
- data/test/tc_package.rb +5 -3
- data/test/workbook/tc_workbook.rb +7 -0
- data/test/workbook/worksheet/tc_cell.rb +102 -1
- data/test/workbook/worksheet/tc_worksheet.rb +17 -0
- metadata +79 -19
- data/doc/Axlsx/Ar.html +0 -196
- data/doc/Axlsx/Ar/ClassMethods.html +0 -188
- data/doc/Axlsx/Ar/InstanceMethods.html +0 -108
- data/doc/Axlsx/Ar/SingletonMethods.html +0 -312
@@ -286,6 +286,8 @@ module Axlsx
|
|
286
286
|
@cellXfs = SimpleTypedList.new Xf, "cellXfs"
|
287
287
|
@cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
|
288
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)
|
289
291
|
@cellXfs.lock
|
290
292
|
|
291
293
|
@dxfs = SimpleTypedList.new(Xf, "dxfs"); @dxfs.lock
|
data/lib/axlsx/util/constants.rb
CHANGED
@@ -199,6 +199,9 @@ module Axlsx
|
|
199
199
|
# cellXfs id for thin borders around the cell
|
200
200
|
STYLE_THIN_BORDER = 1
|
201
201
|
|
202
|
+
# cellXfs id for default date styling
|
203
|
+
STYLE_DATE = 2
|
204
|
+
|
202
205
|
# error messages RestrictionValidor
|
203
206
|
ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
|
204
207
|
|
@@ -207,4 +210,7 @@ module Axlsx
|
|
207
210
|
|
208
211
|
# error message for RegexValidator
|
209
212
|
ERR_REGEX = "Invalid Data. %s does not match %s."
|
213
|
+
|
214
|
+
# error message for duplicate sheet names
|
215
|
+
ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
|
210
216
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# The Parser module mixes in a number of methods to help in generating a model from xml
|
3
|
+
# This module is not included in the axlsx library at this time. It is for future development only,
|
4
|
+
module Parser
|
5
|
+
|
6
|
+
# The xml to be parsed
|
7
|
+
attr_accessor :parser_xml
|
8
|
+
|
9
|
+
# parse and assign string attribute
|
10
|
+
def parse_string attr_name, xpath
|
11
|
+
send("#{attr_name.to_s}=", parse_value(xpath))
|
12
|
+
end
|
13
|
+
|
14
|
+
# parse convert and assign node text to symbol
|
15
|
+
def parse_symbol attr_name, xpath
|
16
|
+
v = parse_value xpath
|
17
|
+
v = v.to_sym unless v.nil?
|
18
|
+
send("#{attr_name.to_s}=", v)
|
19
|
+
end
|
20
|
+
|
21
|
+
# parse, convert and assign note text to integer
|
22
|
+
def parse_integer attr_name, xpath
|
23
|
+
v = parse_value xpath
|
24
|
+
v = v.to_i if v.respond_to?(:to_i)
|
25
|
+
send("#{attr_name.to_s}=", v)
|
26
|
+
end
|
27
|
+
|
28
|
+
# parse, convert and assign node text to float
|
29
|
+
def parse_float attr_name, xpath
|
30
|
+
v = parse_value xpath
|
31
|
+
v = v.to_f if v.respond_to?(:to_f)
|
32
|
+
send("#{attr_name.to_s}=", v)
|
33
|
+
end
|
34
|
+
|
35
|
+
# return node text based on xpath
|
36
|
+
def parse_value xpath
|
37
|
+
node = parser_xml.xpath(xpath)
|
38
|
+
return nil if node.empty?
|
39
|
+
node.text.strip
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/axlsx/version.rb
CHANGED
@@ -71,7 +71,16 @@ require 'axlsx/workbook/worksheet/worksheet.rb'
|
|
71
71
|
|
72
72
|
# Indicates if the epoc date for serialization should be 1904. If false, 1900 is used.
|
73
73
|
@@date1904 = false
|
74
|
-
|
74
|
+
|
75
|
+
# lets come back to this later when we are ready for parsing.
|
76
|
+
#def self.parse entry
|
77
|
+
# io = entry.get_input_stream
|
78
|
+
# w = self.new
|
79
|
+
# w.parser_xml = Nokogiri::XML(io.read)
|
80
|
+
# w.parse_string :date1904, "//xmlns:workbookPr/@date1904"
|
81
|
+
# w
|
82
|
+
#end
|
83
|
+
|
75
84
|
# Creates a new Workbook
|
76
85
|
# @option options [Boolean] date1904
|
77
86
|
def initialize(options={})
|
@@ -120,6 +129,17 @@ require 'axlsx/workbook/worksheet/worksheet.rb'
|
|
120
129
|
r
|
121
130
|
end
|
122
131
|
|
132
|
+
# returns a range of cells in a worksheet
|
133
|
+
# @param [String] cell_def The excel style reference defining the worksheet and cells. The range must specify the sheet to
|
134
|
+
# retrieve the cells from. e.g. range('Sheet1!A1:B2') will return an array of four cells [A1, A2, B1, B2] while range('Sheet1!A1') will return a single Cell.
|
135
|
+
# @return [Cell, Array]
|
136
|
+
def [](cell_def)
|
137
|
+
sheet_name = cell_def.split('!')[0] if cell_def.match('!')
|
138
|
+
worksheet = self.worksheets.select { |s| s.name == sheet_name }.first
|
139
|
+
raise ArgumentError, 'Unknown Sheet' unless sheet_name && worksheet.is_a?(Worksheet)
|
140
|
+
worksheet[cell_def.gsub(/.+!/,"")]
|
141
|
+
end
|
142
|
+
|
123
143
|
# Serializes the workbook document
|
124
144
|
# @return [String]
|
125
145
|
def to_xml()
|
@@ -53,27 +53,137 @@ module Axlsx
|
|
53
53
|
|
54
54
|
|
55
55
|
# The value of this cell.
|
56
|
-
# @return casted value based on cell's type attribute.
|
56
|
+
# @return [String, Integer, Float, Time] casted value based on cell's type attribute.
|
57
57
|
attr_reader :value
|
58
58
|
# @see value
|
59
59
|
def value=(v)
|
60
60
|
#TODO: consider doing value based type determination first?
|
61
61
|
@value = cast_value(v)
|
62
62
|
end
|
63
|
+
|
64
|
+
# The inline font_name property for the cell
|
65
|
+
# @return [String]
|
66
|
+
attr_reader :font_name
|
67
|
+
# @see font_name
|
68
|
+
def font_name=(v) Axlsx::validate_string(v); @font_name = v; end
|
69
|
+
|
70
|
+
# The inline charset property for the cell
|
71
|
+
# @return [String]
|
72
|
+
attr_reader :charset
|
73
|
+
# @see charset
|
74
|
+
def charset=(v) Axlsx::validate_unsigned_int(v); @charset = v; end
|
75
|
+
|
76
|
+
# The inline family property for the cell
|
77
|
+
# @return [String]
|
78
|
+
attr_reader :family
|
79
|
+
# @see family
|
80
|
+
def family=(v) Axlsx::validate_string(v); @family = v; end
|
81
|
+
|
82
|
+
# The inline bold property for the cell
|
83
|
+
# @return [Boolean]
|
84
|
+
attr_reader :b
|
85
|
+
# @see b
|
86
|
+
def b=(v) Axlsx::validate_boolean(v); @b = v; end
|
87
|
+
|
88
|
+
# The inline italic property for the cell
|
89
|
+
# @return [Boolean]
|
90
|
+
attr_reader :i
|
91
|
+
# @see i
|
92
|
+
def i=(v) Axlsx::validate_boolean(v); @i = v; end
|
93
|
+
|
94
|
+
# The inline strike property for the cell
|
95
|
+
# @return [Boolean]
|
96
|
+
attr_reader :strike
|
97
|
+
# @see strike
|
98
|
+
def strike=(v) Axlsx::validate_boolean(v); @strike = v; end
|
99
|
+
|
100
|
+
# The inline outline property for the cell
|
101
|
+
# @return [Boolean]
|
102
|
+
attr_reader :outline
|
103
|
+
# @see outline
|
104
|
+
def outline=(v) Axlsx::validate_boolean(v); @outline = v; end
|
105
|
+
|
106
|
+
# The inline shadow property for the cell
|
107
|
+
# @return [Boolean]
|
108
|
+
attr_reader :shadow
|
109
|
+
# @see shadow
|
110
|
+
def shadow=(v) Axlsx::validate_boolean(v); @shadow = v; end
|
63
111
|
|
112
|
+
# The inline condense property for the cell
|
113
|
+
# @return [Boolean]
|
114
|
+
attr_reader :condense
|
115
|
+
# @see condense
|
116
|
+
def condense=(v) Axlsx::validate_boolean(v); @condense = v; end
|
117
|
+
|
118
|
+
# The inline extend property for the cell
|
119
|
+
# @return [Boolean]
|
120
|
+
attr_reader :extend
|
121
|
+
# @see extend
|
122
|
+
def extend=(v) Axlsx::validate_boolean(v); @extend = v; end
|
123
|
+
|
124
|
+
# The inline underline property for the cell
|
125
|
+
# @return [Boolean]
|
126
|
+
attr_reader :u
|
127
|
+
# @see u
|
128
|
+
def u=(v) Axlsx::validate_boolean(v); @u = v; end
|
129
|
+
|
130
|
+
# The inline color property for the cell
|
131
|
+
# @return [Color]
|
132
|
+
attr_reader :color
|
133
|
+
# @param [String] The 8 character representation for an rgb color #FFFFFFFF"
|
134
|
+
def color=(v)
|
135
|
+
@color = v.is_a?(Color) ? v : Color.new(:rgb=>v)
|
136
|
+
end
|
137
|
+
|
138
|
+
# The inline sz property for the cell
|
139
|
+
# @return [Boolean]
|
140
|
+
attr_reader :sz
|
141
|
+
# @see sz
|
142
|
+
def sz=(v) Axlsx::validate_unsigned_int(v); @sz = v; end
|
143
|
+
|
144
|
+
# The inline vertical alignment property for the cell
|
145
|
+
# this must be one of [:baseline, :subscript, :superscript]
|
146
|
+
# @return [Symbol]
|
147
|
+
attr_reader :vertAlign
|
148
|
+
# @see vertAlign
|
149
|
+
def vertAlign=(v) RestrictionValidator.validate "Cell.vertAlign", [:baseline, :subscript, :superscript], v; @vertAlign = v; end
|
150
|
+
|
151
|
+
# The inline scheme property for the cell
|
152
|
+
# this must be one of [:none, major, minor]
|
153
|
+
# @return [Symbol]
|
154
|
+
attr_reader :scheme
|
155
|
+
# @see scheme
|
156
|
+
def scheme=(v) RestrictionValidator.validate "Cell.schema", [:none, :major, :minor], v; @scheme = v; end
|
64
157
|
|
65
158
|
# @param [Row] row The row this cell belongs to.
|
66
159
|
# @param [Any] value The value associated with this cell.
|
67
160
|
# @option options [Symbol] type The intended data type for this cell. If not specified the data type will be determined internally based on the vlue provided.
|
68
161
|
# @option options [Integer] style The index of the cellXfs item to be applied to this cell. If not specified, the default style (0) will be applied.
|
162
|
+
# @option options [String] font_name
|
163
|
+
# @option options [Integer] charset
|
164
|
+
# @option options [String] family
|
165
|
+
# @option options [Boolean] b
|
166
|
+
# @option options [Boolean] i
|
167
|
+
# @option options [Boolean] strike
|
168
|
+
# @option options [Boolean] outline
|
169
|
+
# @option options [Boolean] shadow
|
170
|
+
# @option options [Boolean] condense
|
171
|
+
# @option options [Boolean] extend
|
172
|
+
# @option options [Boolean] u
|
173
|
+
# @option options [Symbol] vertAlign must be one of :baseline, :subscript, :superscript
|
174
|
+
# @option options [Integer] sz
|
175
|
+
# @option options [String] color an 8 letter rgb specification
|
176
|
+
# @option options [Symbol] scheme must be one of :none, major, :minor
|
69
177
|
def initialize(row, value="", options={})
|
70
178
|
self.row=row
|
71
|
-
#reference for validation
|
72
179
|
@styles = row.worksheet.workbook.styles
|
73
|
-
@
|
74
|
-
|
180
|
+
@style = 0
|
181
|
+
@type = cell_type_from_value(value)
|
182
|
+
@row.cells << self
|
183
|
+
options.each do |o|
|
184
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
185
|
+
end
|
75
186
|
@value = cast_value(value)
|
76
|
-
@row.cells << self
|
77
187
|
end
|
78
188
|
|
79
189
|
# @return [Integer] The index of the cell in the containing row.
|
@@ -104,7 +214,10 @@ module Axlsx
|
|
104
214
|
@style = v
|
105
215
|
end
|
106
216
|
|
107
|
-
|
217
|
+
# @return [Array] of x/y coordinates in the cheet for this cell.
|
218
|
+
def pos
|
219
|
+
[index, row.index]
|
220
|
+
end
|
108
221
|
|
109
222
|
# Serializes the cell
|
110
223
|
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
@@ -118,7 +231,45 @@ module Axlsx
|
|
118
231
|
|
119
232
|
# however nokogiri does a nice 'force_encoding' which we shall remove!
|
120
233
|
if @type == :string
|
121
|
-
|
234
|
+
#parse formula
|
235
|
+
if @value.start_with?('=')
|
236
|
+
xml.c(:r => r, :s=>style) {
|
237
|
+
xml.f @value.to_s.gsub('=', '')
|
238
|
+
}
|
239
|
+
else
|
240
|
+
#parse standard string
|
241
|
+
#xml.c(:r => r, :t=>:inlineStr, :s=>style) {
|
242
|
+
# xml.is { xml.t @value.to_s }
|
243
|
+
#}
|
244
|
+
#parse styled string
|
245
|
+
xml.c(:r => r, :s=>style) {
|
246
|
+
xml.is {
|
247
|
+
xml.r {
|
248
|
+
xml.rPr {
|
249
|
+
xml.rFont(:val=>@font_name) if @font_name
|
250
|
+
xml.charset(:val=>@charset) if @charset
|
251
|
+
xml.family(:val=>@family) if @family
|
252
|
+
xml.b(:val=>@b) if @b
|
253
|
+
xml.i(:val=>@i) if @i
|
254
|
+
xml.strike(:val=>@strike) if @strike
|
255
|
+
xml.outline(:val=>@outline) if @outline
|
256
|
+
xml.shadow(:val=>@shadow) if @shadow
|
257
|
+
xml.condense(:val=>@condense) if @condense
|
258
|
+
xml.extend(:val=>@extend) if @extend
|
259
|
+
@color.to_xml(xml) if @color
|
260
|
+
xml.sz(:val=>@sz) if @sz
|
261
|
+
xml.u(:val=>@u) if @u
|
262
|
+
# :baseline, :subscript, :superscript
|
263
|
+
xml.vertAlign(:val=>@vertAlign) if @verAlign
|
264
|
+
# :none, major, :minor
|
265
|
+
xml.scheme(:val=>@scheme) if @scheme
|
266
|
+
}
|
267
|
+
xml.t @value.to_s
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}
|
271
|
+
end
|
272
|
+
|
122
273
|
else
|
123
274
|
xml.c(:r => r, :s => style) { xml.v value }
|
124
275
|
end
|
@@ -169,6 +320,7 @@ module Axlsx
|
|
169
320
|
def cast_value(v)
|
170
321
|
if (@type == :time && v.is_a?(Time)) || (@type == :time && v.respond_to?(:to_time))
|
171
322
|
v = v.respond_to?(:to_time) ? v.to_time : v
|
323
|
+
self.style = STYLE_DATE if self.style == 0
|
172
324
|
# Using hardcoded offsets here as some operating systems will not except a 'negative' offset from the ruby epoc.
|
173
325
|
# (1970)
|
174
326
|
epoc1900 = -2209021200 #Time.local(1900, 1, 1)
|
@@ -93,11 +93,13 @@ module Axlsx
|
|
93
93
|
def array_to_cells(values, options={})
|
94
94
|
values = values
|
95
95
|
DataTypeValidator.validate 'Row.array_to_cells', Array, values
|
96
|
-
types, style = options
|
96
|
+
types, style = options.delete(:types), options.delete(:style)
|
97
97
|
values.each_with_index do |value, index|
|
98
98
|
cell_style = style.is_a?(Array) ? style[index] : style
|
99
|
+
options[:style] = cell_style if cell_style
|
99
100
|
cell_type = types.is_a?(Array)? types[index] : types
|
100
|
-
|
101
|
+
options[:type] = cell_type if cell_type
|
102
|
+
Cell.new(self, value, options)
|
101
103
|
end
|
102
104
|
end
|
103
105
|
end
|
@@ -42,9 +42,44 @@ module Axlsx
|
|
42
42
|
@cols = SimpleTypedList.new Cell
|
43
43
|
end
|
44
44
|
|
45
|
+
# Returns the cell or cells defined using excel style A1:B3 references.
|
46
|
+
# @param [String] cell_def the string defining the cell or range of cells
|
47
|
+
# @return [Cell, Array]
|
48
|
+
def [](cell_def)
|
49
|
+
parts = cell_def.split(':')
|
50
|
+
first = name_to_cell parts[0]
|
51
|
+
|
52
|
+
if parts.size == 1
|
53
|
+
first
|
54
|
+
else
|
55
|
+
cells = []
|
56
|
+
last = name_to_cell(parts[1])
|
57
|
+
rows[(first.row.index..last.row.index)].each do |r|
|
58
|
+
r.cells[(first.index..last.index)].each do |c|
|
59
|
+
cells << c
|
60
|
+
end
|
61
|
+
end
|
62
|
+
cells
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# returns the column and row index for a named based cell
|
67
|
+
# @param [String] name The cell or cell range to return. "A1" will return the first cell of the first row.
|
68
|
+
# @return [Cell]
|
69
|
+
def name_to_cell(name)
|
70
|
+
col_index, row_index = *Axlsx::name_to_indices(name)
|
71
|
+
r = rows[row_index]
|
72
|
+
r.cells[col_index] if r
|
73
|
+
end
|
74
|
+
|
45
75
|
# The name of the worksheet
|
46
76
|
# @param [String] v
|
47
|
-
def name=(v)
|
77
|
+
def name=(v)
|
78
|
+
DataTypeValidator.validate "Worksheet.name", String, v
|
79
|
+
sheet_names = @workbook.worksheets.map { |s| s.name }
|
80
|
+
raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % v) if sheet_names.include?(v)
|
81
|
+
@name=v
|
82
|
+
end
|
48
83
|
|
49
84
|
# The part name of this worksheet
|
50
85
|
# @return [String]
|
@@ -205,13 +240,12 @@ module Axlsx
|
|
205
240
|
styles = self.workbook.styles
|
206
241
|
cellXfs, fonts = styles.cellXfs, styles.fonts
|
207
242
|
sz = fonts[0].sz
|
208
|
-
|
209
243
|
cells.each_with_index do |item, index|
|
244
|
+
next if item.value.is_a?(String) && item.value.start_with?('=')
|
210
245
|
col = @auto_fit_data[index] || {:longest=>"", :sz=>sz}
|
211
246
|
cell_xf = cellXfs[item.style]
|
212
247
|
font = fonts[cell_xf.fontId || 0]
|
213
|
-
sz = font.sz || sz
|
214
|
-
|
248
|
+
sz = item.sz || font.sz || fonts[0].sz
|
215
249
|
if (col[:longest].scan(/./mu).size * col[:sz]) < (item.value.to_s.scan(/./mu).size * sz)
|
216
250
|
col[:sz] = sz
|
217
251
|
col[:longest] = item.value.to_s
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'axlsx.rb'
|
3
|
+
|
4
|
+
class TestPictureLocking < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@item = Axlsx::PictureLocking.new
|
7
|
+
end
|
8
|
+
def teardown
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_initialiation
|
12
|
+
assert_equal(@item.instance_values.size, 1)
|
13
|
+
assert_equal(@item.noChangeAspect, true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_noGrp
|
17
|
+
assert_raise(ArgumentError) { @item.noGrp = -1 }
|
18
|
+
assert_nothing_raised { @item.noGrp = false }
|
19
|
+
assert_equal(@item.noGrp, false )
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_noRot
|
23
|
+
assert_raise(ArgumentError) { @item.noRot = -1 }
|
24
|
+
assert_nothing_raised { @item.noRot = false }
|
25
|
+
assert_equal(@item.noRot, false )
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_noChangeAspect
|
29
|
+
assert_raise(ArgumentError) { @item.noChangeAspect = -1 }
|
30
|
+
assert_nothing_raised { @item.noChangeAspect = false }
|
31
|
+
assert_equal(@item.noChangeAspect, false )
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_noMove
|
35
|
+
assert_raise(ArgumentError) { @item.noMove = -1 }
|
36
|
+
assert_nothing_raised { @item.noMove = false }
|
37
|
+
assert_equal(@item.noMove, false )
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_noResize
|
41
|
+
assert_raise(ArgumentError) { @item.noResize = -1 }
|
42
|
+
assert_nothing_raised { @item.noResize = false }
|
43
|
+
assert_equal(@item.noResize, false )
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_noEditPoints
|
47
|
+
assert_raise(ArgumentError) { @item.noEditPoints = -1 }
|
48
|
+
assert_nothing_raised { @item.noEditPoints = false }
|
49
|
+
assert_equal(@item.noEditPoints, false )
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_noAdjustHandles
|
53
|
+
assert_raise(ArgumentError) { @item.noAdjustHandles = -1 }
|
54
|
+
assert_nothing_raised { @item.noAdjustHandles = false }
|
55
|
+
assert_equal(@item.noAdjustHandles, false )
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_noChangeArrowheads
|
59
|
+
assert_raise(ArgumentError) { @item.noChangeArrowheads = -1 }
|
60
|
+
assert_nothing_raised { @item.noChangeArrowheads = false }
|
61
|
+
assert_equal(@item.noChangeArrowheads, false )
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_noChangeShapeType
|
65
|
+
assert_raise(ArgumentError) { @item.noChangeShapeType = -1 }
|
66
|
+
assert_nothing_raised { @item.noChangeShapeType = false }
|
67
|
+
assert_equal(@item.noChangeShapeType, false )
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
end
|