rubyXL 1.1.11 → 1.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rubyXL/cell.rb +53 -44
- data/lib/rubyXL/private_class.rb +111 -28
- data/lib/rubyXL/worksheet.rb +198 -101
- data/rubyXL.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.12
|
data/lib/rubyXL/cell.rb
CHANGED
@@ -101,82 +101,91 @@ module RubyXL
|
|
101
101
|
@style_index = modify_fill(@workbook, @style_index,rgb)
|
102
102
|
end
|
103
103
|
|
104
|
-
#
|
104
|
+
# Changes font name of cell
|
105
105
|
def change_font_name(font_name='Verdana')
|
106
106
|
validate_worksheet
|
107
|
-
|
108
|
-
|
107
|
+
# Get copy of font object with modified name
|
108
|
+
font = deep_copy(workbook.fonts[font_id().to_s][:font])
|
109
|
+
font[:name][:attributes][:val] = font_name.to_s
|
110
|
+
# Update font and xf array
|
111
|
+
change_font(font)
|
109
112
|
end
|
110
113
|
|
111
|
-
#
|
114
|
+
# Changes font size of cell
|
112
115
|
def change_font_size(font_size=10)
|
113
116
|
validate_worksheet
|
114
117
|
if font_size.is_a?(Integer) || font_size.is_a?(Float)
|
115
|
-
|
116
|
-
|
118
|
+
# Get copy of font object with modified size
|
119
|
+
font = deep_copy(workbook.fonts[font_id().to_s][:font])
|
120
|
+
font[:sz][:attributes][:val] = font_size
|
121
|
+
# Update font and xf array
|
122
|
+
change_font(font)
|
117
123
|
else
|
118
124
|
raise 'Argument must be a number'
|
119
125
|
end
|
120
126
|
end
|
121
127
|
|
122
|
-
#
|
128
|
+
# Changes font color of cell
|
123
129
|
def change_font_color(font_color='000000')
|
124
130
|
validate_worksheet
|
125
131
|
#if arg is a color name, convert to integer
|
126
132
|
Color.validate_color(font_color)
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
133
|
-
@workbook.fonts[font_id][:font][:color][:attributes][:rgb] = font_color.to_s
|
133
|
+
# Get copy of font object with modified color
|
134
|
+
font = deep_copy(workbook.fonts[font_id().to_s][:font])
|
135
|
+
font = modify_font_color(font, font_color.to_s)
|
136
|
+
# Update font and xf array
|
137
|
+
change_font(font)
|
134
138
|
end
|
135
139
|
|
136
|
-
#
|
140
|
+
# Changes font italics settings of cell
|
137
141
|
def change_font_italics(italicized=false)
|
138
142
|
validate_worksheet
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
143
|
+
# Get copy of font object with modified italics settings
|
144
|
+
font = deep_copy(workbook.fonts[font_id().to_s][:font])
|
145
|
+
font = modify_font_italics(font, italicized)
|
146
|
+
# Update font and xf array
|
147
|
+
change_font(font)
|
145
148
|
end
|
146
149
|
|
147
|
-
#
|
150
|
+
# Changes font bold settings of cell
|
148
151
|
def change_font_bold(bolded=false)
|
149
152
|
validate_worksheet
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
153
|
+
# Get copy of font object with modified bold settings
|
154
|
+
font = deep_copy(workbook.fonts[font_id().to_s][:font])
|
155
|
+
font = modify_font_bold(font, bolded)
|
156
|
+
# Update font and xf array
|
157
|
+
change_font(font)
|
156
158
|
end
|
157
159
|
|
158
|
-
#
|
160
|
+
# Changes font underline settings of cell
|
159
161
|
def change_font_underline(underlined=false)
|
160
162
|
validate_worksheet
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
@workbook.fonts[font_id()][:font][:u] = nil
|
167
|
-
end
|
163
|
+
# Get copy of font object with modified underline settings
|
164
|
+
font = deep_copy(workbook.fonts[font_id().to_s][:font])
|
165
|
+
font = modify_font_underline(font, underlined)
|
166
|
+
# Update font and xf array
|
167
|
+
change_font(font)
|
168
168
|
end
|
169
169
|
|
170
|
-
#
|
170
|
+
# Changes font strikethrough settings of cell
|
171
171
|
def change_font_strikethrough(struckthrough=false)
|
172
172
|
validate_worksheet
|
173
|
-
|
173
|
+
# Get copy of font object with modified strikethrough settings
|
174
|
+
font = deep_copy(workbook.fonts[font_id().to_s][:font])
|
175
|
+
font = modify_font_strikethrough(font, struckthrough)
|
176
|
+
# Update font and xf array
|
177
|
+
change_font(font)
|
178
|
+
end
|
174
179
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
+
# Helper method to update the font array and xf array
|
181
|
+
def change_font(font)
|
182
|
+
# Modify font array and retrieve new font id
|
183
|
+
font_id = modify_font(@workbook, font, font_id())
|
184
|
+
# Get copy of xf object with modified font id
|
185
|
+
xf = deep_copy(xf_id())
|
186
|
+
xf[:fontId] = Integer(font_id.to_i)
|
187
|
+
# Modify xf array and retrieve new xf id
|
188
|
+
@style_index = modify_xf(@workbook, xf)
|
180
189
|
end
|
181
190
|
|
182
191
|
# changes horizontal alignment of cell
|
@@ -385,7 +394,7 @@ module RubyXL
|
|
385
394
|
end
|
386
395
|
|
387
396
|
def inspect
|
388
|
-
str = "(#{@row},#{@column}): #{@value}"
|
397
|
+
str = "(#{@row},#{@column}): #{@value}"
|
389
398
|
str += " =#{@formula}" if @formula
|
390
399
|
str += ", datatype = #{@datatype}, style_index = #{@style_index}"
|
391
400
|
return str
|
data/lib/rubyXL/private_class.rb
CHANGED
@@ -30,42 +30,125 @@ module RubyXL
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
workbook.fonts[old_size][:font] = deep_copy(font)
|
49
|
-
workbook.fonts[old_size][:count] = 1
|
50
|
-
workbook.fonts[font_id.to_s][:count] -= 1
|
33
|
+
# This method checks to see if there is an equivalent font that exists
|
34
|
+
def find_font(workbook, font)
|
35
|
+
workbook.fonts.each {|font_id, f|
|
36
|
+
if f[:font][:i] == font[:i] &&
|
37
|
+
f[:font][:b] == font[:b] &&
|
38
|
+
f[:font][:u] == font[:u] &&
|
39
|
+
f[:font][:strike] == font[:strike] &&
|
40
|
+
f[:font][:name][:attributes][:val] == font[:name][:attributes][:val] &&
|
41
|
+
f[:font][:sz][:attributes][:val] == font[:sz][:attributes][:val] &&
|
42
|
+
(f[:font][:color] && f[:font][:color][:attributes][:rgb]) == (font[:color] && font[:color][:attributes][:rgb])
|
43
|
+
return font_id
|
44
|
+
end
|
45
|
+
}
|
46
|
+
return nil
|
47
|
+
end
|
51
48
|
|
52
|
-
|
53
|
-
|
49
|
+
# Helper method to modify the font color
|
50
|
+
def modify_font_color(font, font_color)
|
51
|
+
if font[:color].nil?
|
52
|
+
font[:color] = {:attributes => {:rgb => ''}}
|
53
|
+
end
|
54
|
+
font[:color][:attributes][:rgb] = font_color.to_s
|
55
|
+
return font
|
56
|
+
end
|
57
|
+
|
58
|
+
# Helper method to modify the font's italics settings
|
59
|
+
def modify_font_italics(font, italicized)
|
60
|
+
if italicized
|
61
|
+
font[:i] = {}
|
62
|
+
else
|
63
|
+
font[:i] = nil
|
64
|
+
end
|
65
|
+
return font
|
66
|
+
end
|
54
67
|
|
68
|
+
# Helper method to modify the font's bold settings
|
69
|
+
def modify_font_bold(font, bolded)
|
70
|
+
if bolded
|
71
|
+
font[:b] = {}
|
72
|
+
else
|
73
|
+
font[:b] = nil
|
74
|
+
end
|
75
|
+
return font
|
76
|
+
end
|
77
|
+
|
78
|
+
# Helper method to modify the font's underline settings
|
79
|
+
def modify_font_underline(font, underlined)
|
80
|
+
if underlined
|
81
|
+
font[:u] = {}
|
82
|
+
else
|
83
|
+
font[:u] = nil
|
84
|
+
end
|
85
|
+
return font
|
86
|
+
end
|
87
|
+
|
88
|
+
# Helper method to modify the font's strikethrough settings
|
89
|
+
def modify_font_strikethrough(font, struckthrough)
|
90
|
+
if struckthrough
|
91
|
+
font[:strike] = {}
|
92
|
+
else
|
93
|
+
font[:strike] = nil
|
94
|
+
end
|
95
|
+
return font
|
96
|
+
end
|
97
|
+
|
98
|
+
# Determines if font exists
|
99
|
+
# If yes, return id of existing font
|
100
|
+
# If no, appends font to font array
|
101
|
+
def modify_font(workbook, font, old_font_id)
|
102
|
+
font_id = old_font_id
|
103
|
+
existing_font_id = find_font(workbook, font)
|
104
|
+
if !existing_font_id.nil?
|
105
|
+
font_id = existing_font_id
|
106
|
+
workbook.fonts[font_id][:count] += 1
|
107
|
+
workbook.fonts[old_font_id][:count] -= 1
|
108
|
+
elsif workbook.fonts[old_font_id.to_s][:count] > 1 || old_font_id == '0'
|
109
|
+
font_id = workbook.fonts.size.to_s
|
110
|
+
workbook.fonts[font_id] = {}
|
111
|
+
workbook.fonts[font_id][:font] = font
|
112
|
+
workbook.fonts[font_id][:count] = 1
|
113
|
+
workbook.fonts[old_font_id][:count] -= 1
|
114
|
+
else
|
115
|
+
workbook.fonts[font_id][:font] = font
|
116
|
+
end
|
117
|
+
return font_id
|
118
|
+
end
|
119
|
+
|
120
|
+
# This method checks to see if there is an equivalent xf that exists
|
121
|
+
def find_xf(workbook, xf)
|
122
|
+
workbook.cell_xfs[:xf].each_with_index {|xfs, index|
|
123
|
+
if xfs[:attributes][:borderId] == xf[:borderId] &&
|
124
|
+
xfs[:attributes][:xfId] == xf[:xfId] &&
|
125
|
+
xfs[:attributes][:fillId] == xf[:fillId] &&
|
126
|
+
xfs[:attributes][:numFmtId] == xf[:numFmtId] &&
|
127
|
+
xfs[:attributes][:fontId] == xf[:fontId]
|
128
|
+
return index
|
129
|
+
end
|
130
|
+
}
|
131
|
+
return nil
|
132
|
+
end
|
133
|
+
|
134
|
+
# Determines if xf exists
|
135
|
+
# If yes, return id of existing xf
|
136
|
+
# If no, appends xf to xf array
|
137
|
+
def modify_xf(workbook, xf)
|
138
|
+
existing_xf_id = find_xf(workbook, xf)
|
139
|
+
if !existing_xf_id.nil?
|
140
|
+
xf_id = existing_xf_id
|
141
|
+
else
|
55
142
|
if workbook.cell_xfs[:xf].is_a?Array
|
56
|
-
workbook.cell_xfs[:xf] <<
|
143
|
+
workbook.cell_xfs[:xf] << {:attributes=>xf}
|
57
144
|
else
|
58
|
-
workbook.cell_xfs[:xf] = [workbook.cell_xfs[:xf],
|
145
|
+
workbook.cell_xfs[:xf] = [workbook.cell_xfs[:xf], {:attributes=>xf}]
|
59
146
|
end
|
60
|
-
|
61
|
-
xf = workbook.get_style_attributes(workbook.cell_xfs[:xf].last)
|
62
|
-
xf[:fontId] = font_id
|
63
147
|
xf[:applyFont] = '1'
|
64
148
|
workbook.cell_xfs[:attributes][:count] += 1
|
65
|
-
|
66
|
-
else
|
67
|
-
return style_index
|
149
|
+
xf_id = workbook.cell_xfs[:xf].size - 1
|
68
150
|
end
|
151
|
+
return xf_id
|
69
152
|
end
|
70
153
|
|
71
154
|
#modifies fill array (copies, appends, adds color and solid attribute)
|
data/lib/rubyXL/worksheet.rb
CHANGED
@@ -103,46 +103,82 @@ class Worksheet < PrivateClass
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
106
|
+
# Changes font name of row
|
107
|
+
def change_row_font_name(row=0, font_name='Verdana')
|
108
|
+
# Get style object
|
109
|
+
xf_id = xf_id(get_row_style(row))
|
110
|
+
# Get copy of font object with modified name
|
111
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
112
|
+
font[:name][:attributes][:val] = font_name.to_s
|
113
|
+
# Update font and xf array
|
114
|
+
change_row_font(row, Worksheet::NAME, font_name, font, xf_id)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Changes font size of row
|
118
|
+
def change_row_font_size(row=0, font_size=10)
|
119
|
+
# Get style object
|
120
|
+
xf_id = xf_id(get_row_style(row))
|
121
|
+
# Get copy of font object with modified size
|
122
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
123
|
+
font[:sz][:attributes][:val] = font_size
|
124
|
+
# Update font and xf array
|
125
|
+
change_row_font(row, Worksheet::SIZE, font_size, font, xf_id)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Changes font color of row
|
129
|
+
def change_row_font_color(row=0, font_color='000000')
|
117
130
|
Color.validate_color(font_color)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
font = @workbook.fonts[
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
def change_row_italics(row=0,italicized=false)
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
131
|
+
# Get style object
|
132
|
+
xf_id = xf_id(get_row_style(row))
|
133
|
+
# Get copy of font object with modified color
|
134
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
135
|
+
font = modify_font_color(font, font_color.to_s)
|
136
|
+
# Update font and xf array
|
137
|
+
change_row_font(row, Worksheet::COLOR, font_color, font, xf_id)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Changes font italics settings of row
|
141
|
+
def change_row_italics(row=0, italicized=false)
|
142
|
+
# Get style object
|
143
|
+
xf_id = xf_id(get_row_style(row))
|
144
|
+
# Get copy of font object with modified italics settings
|
145
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
146
|
+
font = modify_font_italics(font, italicized)
|
147
|
+
# Update font and xf array
|
148
|
+
change_row_font(row, Worksheet::ITALICS, italicized, font, xf_id)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Changes font bold settings of row
|
152
|
+
def change_row_bold(row=0, bolded=false)
|
153
|
+
# Get style object
|
154
|
+
xf_id = xf_id(get_row_style(row))
|
155
|
+
# Get copy of font object with modified bold settings
|
156
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
157
|
+
font = modify_font_bold(font, bolded)
|
158
|
+
# Update font and xf array
|
159
|
+
change_row_font(row, Worksheet::BOLD, bolded, font, xf_id)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Changes font underline settings of row
|
163
|
+
def change_row_underline(row=0, underlined=false)
|
164
|
+
# Get style object
|
165
|
+
xf_id = xf_id(get_row_style(row))
|
166
|
+
# Get copy of font object with modified underline settings
|
167
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
168
|
+
font = modify_font_underline(font, underlined)
|
169
|
+
# Update font and xf array
|
170
|
+
change_row_font(row, Worksheet::UNDERLINE, underlined, font, xf_id)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Changes font strikethrough settings of row
|
174
|
+
def change_row_strikethrough(row=0, struckthrough=false)
|
175
|
+
# Get style object
|
176
|
+
xf_id = xf_id(get_row_style(row))
|
177
|
+
# Get copy of font object with modified strikethrough settings
|
178
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
179
|
+
font = modify_font_strikethrough(font, struckthrough)
|
180
|
+
# Update font and xf array
|
181
|
+
change_row_font(row, Worksheet::STRIKETHROUGH, struckthrough, font, xf_id)
|
146
182
|
end
|
147
183
|
|
148
184
|
def change_row_height(row=0,height=10)
|
@@ -201,46 +237,82 @@ class Worksheet < PrivateClass
|
|
201
237
|
change_row_border(row, :diagonal, weight)
|
202
238
|
end
|
203
239
|
|
204
|
-
|
205
|
-
|
206
|
-
|
240
|
+
# Changes font name of column
|
241
|
+
def change_column_font_name(col=0, font_name='Verdana')
|
242
|
+
# Get style object
|
243
|
+
xf_id = xf_id(get_col_style(col))
|
244
|
+
# Get copy of font object with modified name
|
245
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
246
|
+
font[:name][:attributes][:val] = font_name.to_s
|
247
|
+
# Update font and xf array
|
248
|
+
change_column_font(col, Worksheet::NAME, font_name, font, xf_id)
|
207
249
|
end
|
208
250
|
|
209
|
-
|
210
|
-
|
211
|
-
|
251
|
+
# Changes font size of column
|
252
|
+
def change_column_font_size(col=0, font_size=10)
|
253
|
+
# Get style object
|
254
|
+
xf_id = xf_id(get_col_style(col))
|
255
|
+
# Get copy of font object with modified size
|
256
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
257
|
+
font[:sz][:attributes][:val] = font_size
|
258
|
+
# Update font and xf array
|
259
|
+
change_column_font(col, Worksheet::SIZE, font_size, font, xf_id)
|
212
260
|
end
|
213
261
|
|
214
|
-
|
262
|
+
# Changes font color of column
|
263
|
+
def change_column_font_color(col=0, font_color='000000')
|
215
264
|
Color.validate_color(font_color)
|
216
|
-
|
217
|
-
|
218
|
-
font
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
def change_column_italics(col=0,italicized=false)
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
265
|
+
# Get style object
|
266
|
+
xf_id = xf_id(get_col_style(col))
|
267
|
+
# Get copy of font object with modified color
|
268
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
269
|
+
font = modify_font_color(font, font_color.to_s)
|
270
|
+
# Update font and xf array
|
271
|
+
change_column_font(col, Worksheet::COLOR, font_color, font, xf_id)
|
272
|
+
end
|
273
|
+
|
274
|
+
# Changes font italics settings of column
|
275
|
+
def change_column_italics(col=0, italicized=false)
|
276
|
+
# Get style object
|
277
|
+
xf_id = xf_id(get_col_style(col))
|
278
|
+
# Get copy of font object with modified italics settings
|
279
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
280
|
+
font = modify_font_italics(font, italicized)
|
281
|
+
# Update font and xf array
|
282
|
+
change_column_font(col, Worksheet::ITALICS, italicized, font, xf_id)
|
283
|
+
end
|
284
|
+
|
285
|
+
# Changes font bold settings of column
|
286
|
+
def change_column_bold(col=0, bolded=false)
|
287
|
+
# Get style object
|
288
|
+
xf_id = xf_id(get_col_style(col))
|
289
|
+
# Get copy of font object with modified bold settings
|
290
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
291
|
+
font = modify_font_bold(font, bolded)
|
292
|
+
# Update font and xf array
|
293
|
+
change_column_font(col, Worksheet::BOLD, bolded, font, xf_id)
|
294
|
+
end
|
295
|
+
|
296
|
+
# Changes font underline settings of column
|
297
|
+
def change_column_underline(col=0, underlined=false)
|
298
|
+
# Get style object
|
299
|
+
xf_id = xf_id(get_col_style(col))
|
300
|
+
# Get copy of font object with modified underline settings
|
301
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
302
|
+
font = modify_font_underline(font, underlined)
|
303
|
+
# Update font and xf array
|
304
|
+
change_column_font(col, Worksheet::UNDERLINE, underlined, font, xf_id)
|
305
|
+
end
|
306
|
+
|
307
|
+
# Changes font strikethrough settings of column
|
308
|
+
def change_column_strikethrough(col=0, struckthrough=false)
|
309
|
+
# Get style object
|
310
|
+
xf_id = xf_id(get_col_style(col))
|
311
|
+
# Get copy of font object with modified strikethrough settings
|
312
|
+
font = deep_copy(@workbook.fonts[xf_id[:fontId].to_s][:font])
|
313
|
+
font = modify_font_strikethrough(font, struckthrough)
|
314
|
+
# Update font and xf array
|
315
|
+
change_column_font(col, Worksheet::STRIKETHROUGH, struckthrough, font, xf_id)
|
244
316
|
end
|
245
317
|
|
246
318
|
def change_column_width(col=0,width=13)
|
@@ -1100,60 +1172,58 @@ class Worksheet < PrivateClass
|
|
1100
1172
|
@cols.last[:attributes][:customWidth] = '0'
|
1101
1173
|
end
|
1102
1174
|
|
1103
|
-
#
|
1175
|
+
# Helper method to update the row styles array
|
1104
1176
|
# change_type - NAME or SIZE or COLOR etc
|
1105
1177
|
# main method to change font, called from each separate font mutator method
|
1106
|
-
def change_row_font(row,change_type,arg)
|
1178
|
+
def change_row_font(row, change_type, arg, font, xf_id)
|
1107
1179
|
validate_workbook
|
1108
1180
|
validate_nonnegative(row)
|
1109
|
-
|
1110
1181
|
increase_rows(row)
|
1111
1182
|
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1183
|
+
# Modify font array and retrieve new font id
|
1184
|
+
font_id = modify_font(@workbook, font, xf_id[:fontId].to_s)
|
1185
|
+
# Get copy of xf object with modified font id
|
1186
|
+
xf = deep_copy(xf_id)
|
1187
|
+
xf[:fontId] = Integer(font_id)
|
1188
|
+
# Modify xf array and retrieve new xf id
|
1189
|
+
@row_styles[(row+1).to_s][:style] = modify_xf(@workbook, xf)
|
1118
1190
|
|
1119
1191
|
if @sheet_data[row].nil?
|
1120
1192
|
@sheet_data[row] = []
|
1121
1193
|
end
|
1194
|
+
|
1122
1195
|
@sheet_data[Integer(row)].each do |c|
|
1123
1196
|
unless c.nil?
|
1124
|
-
font_switch(c,change_type,arg)
|
1197
|
+
font_switch(c, change_type, arg)
|
1125
1198
|
end
|
1126
1199
|
end
|
1127
1200
|
end
|
1128
1201
|
|
1129
|
-
#
|
1130
|
-
|
1202
|
+
# Helper method to update the fonts and cell styles array
|
1203
|
+
# main method to change font, called from each separate font mutator method
|
1204
|
+
def change_column_font(col, change_type, arg, font, xf_id)
|
1131
1205
|
validate_workbook
|
1132
1206
|
validate_nonnegative(col)
|
1133
|
-
|
1134
1207
|
increase_columns(col)
|
1135
1208
|
|
1136
1209
|
i = get_cols_index(col)
|
1137
1210
|
|
1138
|
-
#
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1211
|
+
# Modify font array and retrieve new font id
|
1212
|
+
font_id = modify_font(@workbook, font, xf_id[:fontId].to_s)
|
1213
|
+
# Get copy of xf object with modified font id
|
1214
|
+
xf = deep_copy(xf_id)
|
1215
|
+
xf[:fontId] = Integer(font_id)
|
1216
|
+
# Modify xf array and retrieve new xf id
|
1217
|
+
modify_xf(@workbook, xf)
|
1145
1218
|
|
1146
|
-
|
1219
|
+
change_cols(i, col)
|
1147
1220
|
|
1148
|
-
|
1149
|
-
|
1150
|
-
@sheet_data.each_with_index do |row,i|
|
1221
|
+
@sheet_data.each_with_index do |row, i|
|
1151
1222
|
c = row[col]
|
1152
1223
|
unless c.nil?
|
1153
|
-
font_switch(c,change_type,arg)
|
1224
|
+
font_switch(c, change_type, arg)
|
1154
1225
|
end
|
1155
1226
|
end
|
1156
|
-
style_index
|
1157
1227
|
end
|
1158
1228
|
|
1159
1229
|
#performs correct modification based on what type of change_type is specified
|
@@ -1213,8 +1283,35 @@ class Worksheet < PrivateClass
|
|
1213
1283
|
end
|
1214
1284
|
end
|
1215
1285
|
|
1286
|
+
# Helper method to get the font id for a style index
|
1216
1287
|
def font_id(style_index)
|
1217
|
-
|
1288
|
+
xf_id(style_index)[:fontId]
|
1289
|
+
end
|
1290
|
+
|
1291
|
+
# Helper method to get the style attributes for a style index
|
1292
|
+
def xf_id(style_index)
|
1293
|
+
@workbook.get_style_attributes(@workbook.get_style(style_index))
|
1294
|
+
end
|
1295
|
+
|
1296
|
+
# Helper method to get the style index for a row
|
1297
|
+
def get_row_style(row)
|
1298
|
+
if @row_styles[(row+1).to_s].nil?
|
1299
|
+
@row_styles[(row+1).to_s] = {}
|
1300
|
+
@row_styles[(row+1).to_s][:style] = '0'
|
1301
|
+
@workbook.fonts['0'][:count] += 1
|
1302
|
+
end
|
1303
|
+
return @row_styles[(row+1).to_s][:style]
|
1304
|
+
end
|
1305
|
+
|
1306
|
+
# Helper method to get the style index for a column
|
1307
|
+
def get_col_style(col)
|
1308
|
+
i = get_cols_index(col)
|
1309
|
+
if @cols[i].nil?
|
1310
|
+
@workbook.fonts['0'][:count] += 1
|
1311
|
+
return 0
|
1312
|
+
else
|
1313
|
+
return Integer(@cols[i][:attributes][:style])
|
1314
|
+
end
|
1218
1315
|
end
|
1219
1316
|
|
1220
1317
|
def change_row_alignment(row,alignment,is_horizontal)
|
data/rubyXL.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rubyXL}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.12"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Vivek Bhagwat"]
|
12
|
-
s.date = %q{2011-11-
|
12
|
+
s.date = %q{2011-11-29}
|
13
13
|
s.description = %q{rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx/.xlsm) Documents}
|
14
14
|
s.email = %q{bhagwat.vivek@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyXL
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 12
|
10
|
+
version: 1.1.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vivek Bhagwat
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-29 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|