write_xlsx 0.65.1 → 0.69.0
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.
- checksums.yaml +4 -4
- data/README.rdoc +7 -0
- data/lib/write_xlsx/chart.rb +20 -2
- data/lib/write_xlsx/drawing.rb +4 -7
- data/lib/write_xlsx/package/comments.rb +13 -10
- data/lib/write_xlsx/package/conditional_format.rb +1 -1
- data/lib/write_xlsx/package/table.rb +4 -18
- data/lib/write_xlsx/package/vml.rb +2 -2
- data/lib/write_xlsx/sheets.rb +10 -4
- data/lib/write_xlsx/utility.rb +7 -10
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +73 -88
- data/lib/write_xlsx/worksheet.rb +39 -85
- data/lib/write_xlsx/worksheet/hyperlink.rb +2 -1
- data/test/drawing/test_write_c_chart.rb +1 -1
- data/test/package/table/test_table13.rb +69 -0
- data/test/regression/test_button08.rb +28 -0
- data/test/regression/test_chart_axis25.rb +45 -0
- data/test/regression/test_chart_axis26.rb +45 -0
- data/test/regression/test_chart_axis27.rb +45 -0
- data/test/regression/test_chart_axis28.rb +45 -0
- data/test/regression/test_chart_axis29.rb +44 -0
- data/test/regression/test_chart_scatter08.rb +57 -0
- data/test/regression/test_comment11.rb +33 -0
- data/test/regression/test_selection01.rb +23 -0
- data/test/regression/test_selection02.rb +33 -0
- data/test/regression/test_shape01.rb +25 -0
- data/test/regression/test_shape02.rb +42 -0
- data/test/regression/test_shape03.rb +45 -0
- data/test/regression/test_shape04.rb +43 -0
- data/test/regression/test_table15.rb +37 -0
- data/test/regression/test_utf8_01.rb +23 -0
- data/test/regression/test_utf8_03.rb +23 -0
- data/test/regression/test_utf8_04.rb +23 -0
- data/test/regression/test_utf8_05.rb +26 -0
- data/test/regression/test_utf8_06.rb +28 -0
- data/test/regression/test_utf8_07.rb +27 -0
- data/test/regression/test_utf8_08.rb +38 -0
- data/test/regression/test_utf8_09.rb +24 -0
- data/test/regression/test_utf8_10.rb +42 -0
- data/test/regression/xlsx_files/button08.xlsx +0 -0
- data/test/regression/xlsx_files/button09.xlsx +0 -0
- data/test/regression/xlsx_files/button10.xlsx +0 -0
- data/test/regression/xlsx_files/button11.xlsx +0 -0
- data/test/regression/xlsx_files/button12.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis25.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis26.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis27.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis28.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis29.xlsx +0 -0
- data/test/regression/xlsx_files/chart_scatter08.xlsx +0 -0
- data/test/regression/xlsx_files/comment11.xlsx +0 -0
- data/test/regression/xlsx_files/selection01.xlsx +0 -0
- data/test/regression/xlsx_files/selection02.xlsx +0 -0
- data/test/regression/xlsx_files/shape01.xlsx +0 -0
- data/test/regression/xlsx_files/shape02.xlsx +0 -0
- data/test/regression/xlsx_files/shape03.xlsx +0 -0
- data/test/regression/xlsx_files/shape04.xlsx +0 -0
- data/test/regression/xlsx_files/table15.xlsx +0 -0
- data/test/regression/xlsx_files/utf8_01.xlsx +0 -0
- data/test/regression/xlsx_files/utf8_03.xlsx +0 -0
- data/test/regression/xlsx_files/utf8_04.xlsx +0 -0
- data/test/regression/xlsx_files/utf8_05.xlsx +0 -0
- data/test/regression/xlsx_files/utf8_06.xlsx +0 -0
- data/test/regression/xlsx_files/utf8_07.xlsx +0 -0
- data/test/regression/xlsx_files/utf8_08.xlsx +0 -0
- data/test/regression/xlsx_files/utf8_09.xlsx +0 -0
- data/test/regression/xlsx_files/utf8_10.xlsx +0 -0
- data/test/workbook/test_define_name.rb +16 -0
- data/test/worksheet/test_cond_format_18.rb +1 -1
- data/test/worksheet/test_convert_date_time_04.rb +19 -0
- data/test/worksheet/test_write_row_element.rb +14 -14
- metadata +113 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0b64b508ff280aa34008fca70ef3554cfd2aae0f
|
|
4
|
+
data.tar.gz: e9ca4ef7d80c4bf39be76c842725fd08f71d22fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b857dd675e58f9f2bc4e064ad133d4237c87d27809852688bd2e2f58ea70fb520b239a1924b92a4856c866fbcdb73ece933808f1aa5380d6a31c3b91e3fd8ff
|
|
7
|
+
data.tar.gz: 6ea66fc1fe51560bde230f42a5d6b119b59285a321f86f7c7d9776fcd83b24f4b21afcedd8be954df17a173d113a0dd765b830e704309219a365454be34ad5b2
|
data/README.rdoc
CHANGED
|
@@ -75,6 +75,13 @@ the first worksheet in an Excel XML spreadsheet called ruby.xlsx:
|
|
|
75
75
|
workbook.close
|
|
76
76
|
|
|
77
77
|
== Recent change
|
|
78
|
+
2013-06-30 v0.69.0
|
|
79
|
+
Added chart font rotation property. Mainly for use with data axes to make the display more compact.
|
|
80
|
+
Fix for issue where shapes on one worksheet corrupted charts on a subsequent worksheet.
|
|
81
|
+
Fix for issue where add_button invalidated cell comments in the same workbook.
|
|
82
|
+
Fix for set_selection with cell range.
|
|
83
|
+
Fix for issue with image scaling.
|
|
84
|
+
|
|
78
85
|
2013-03-23 v0.65.1
|
|
79
86
|
Bug fix for non-integer image scaling.
|
|
80
87
|
Bug fix in Worksheet#set_first_sheet
|
data/lib/write_xlsx/chart.rb
CHANGED
|
@@ -1790,12 +1790,18 @@ def convert_font_args(params)
|
|
|
1790
1790
|
:_underline => params[:underline],
|
|
1791
1791
|
:_pitch_family => params[:pitch_family],
|
|
1792
1792
|
:_charset => params[:charset],
|
|
1793
|
-
:_baseline => params[:baseline] || 0
|
|
1793
|
+
:_baseline => params[:baseline] || 0,
|
|
1794
|
+
:_rotation => params[:rotation]
|
|
1794
1795
|
}
|
|
1795
1796
|
|
|
1796
1797
|
# Convert font size units.
|
|
1797
1798
|
font[:_size] *= 100 if font[:_size] && font[:_size] != 0
|
|
1798
1799
|
|
|
1800
|
+
# Convert rotation into 60,000ths of a degree.
|
|
1801
|
+
if ptrue?(font[:_rotation])
|
|
1802
|
+
font[:_rotation] = 60_000 * font[:_rotation].to_i
|
|
1803
|
+
end
|
|
1804
|
+
|
|
1799
1805
|
font
|
|
1800
1806
|
end
|
|
1801
1807
|
|
|
@@ -3427,6 +3433,18 @@ def write_a_body_pr(horiz) # :nodoc:
|
|
|
3427
3433
|
@writer.empty_tag('a:bodyPr', attributes)
|
|
3428
3434
|
end
|
|
3429
3435
|
|
|
3436
|
+
#
|
|
3437
|
+
# Write the <a:bodyPr> element for axis fonts.
|
|
3438
|
+
#
|
|
3439
|
+
def write_axis_body_pr(rot = nil, vert = nil)
|
|
3440
|
+
attributes = []
|
|
3441
|
+
|
|
3442
|
+
attributes << 'rot' << rot if rot
|
|
3443
|
+
attributes << 'vert' << vert if vert
|
|
3444
|
+
|
|
3445
|
+
@writer.empty_tag('a:bodyPr', attributes)
|
|
3446
|
+
end
|
|
3447
|
+
|
|
3430
3448
|
#
|
|
3431
3449
|
# Write the <a:lstStyle> element.
|
|
3432
3450
|
#
|
|
@@ -3989,7 +4007,7 @@ def write_axis_font(font) # :nodoc:
|
|
|
3989
4007
|
return unless font
|
|
3990
4008
|
|
|
3991
4009
|
@writer.tag_elements('c:txPr') do
|
|
3992
|
-
|
|
4010
|
+
write_axis_body_pr(font[:_rotation])
|
|
3993
4011
|
write_a_lst_style
|
|
3994
4012
|
@writer.tag_elements('a:p') do
|
|
3995
4013
|
write_a_p_pr_rich(font)
|
data/lib/write_xlsx/drawing.rb
CHANGED
|
@@ -367,24 +367,21 @@ def write_atag_graphic_data(index)
|
|
|
367
367
|
|
|
368
368
|
@writer.tag_elements('a:graphicData', attributes) do
|
|
369
369
|
# Write the c:chart element.
|
|
370
|
-
write_c_chart(
|
|
370
|
+
write_c_chart(index)
|
|
371
371
|
end
|
|
372
372
|
end
|
|
373
373
|
|
|
374
374
|
#
|
|
375
375
|
# Write the <c:chart> element.
|
|
376
376
|
#
|
|
377
|
-
def write_c_chart(
|
|
377
|
+
def write_c_chart(id)
|
|
378
378
|
schema = 'http://schemas.openxmlformats.org/'
|
|
379
379
|
xmlns_c = "#{schema}drawingml/2006/chart"
|
|
380
380
|
xmlns_r = "#{schema}officeDocument/2006/relationships"
|
|
381
381
|
|
|
382
382
|
|
|
383
|
-
attributes = [
|
|
384
|
-
|
|
385
|
-
'xmlns:r', xmlns_r,
|
|
386
|
-
'r:id', r_id
|
|
387
|
-
]
|
|
383
|
+
attributes = ['xmlns:c', xmlns_c, 'xmlns:r', xmlns_r]
|
|
384
|
+
attributes += r_id_attributes(id)
|
|
388
385
|
|
|
389
386
|
@writer.empty_tag('c:chart', attributes)
|
|
390
387
|
end
|
|
@@ -263,18 +263,21 @@ def assemble_xml_file
|
|
|
263
263
|
end
|
|
264
264
|
|
|
265
265
|
def sorted_comments
|
|
266
|
-
@sorted_comments
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
@comments
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
266
|
+
unless @sorted_comments
|
|
267
|
+
@sorted_comments = []
|
|
268
|
+
# We sort the comments by row and column but that isn't strictly required.
|
|
269
|
+
@comments.keys.sort.each do |row|
|
|
270
|
+
@comments[row].keys.sort.each do |col|
|
|
271
|
+
# Set comment visibility if required and not already user defined.
|
|
272
|
+
@comments[row][col].visible ||= 1 if comments_visible?
|
|
273
|
+
|
|
274
|
+
# Set comment author if not already user defined.
|
|
275
|
+
@comments[row][col].author ||= @worksheet.comments_author
|
|
276
|
+
@sorted_comments << @comments[row][col]
|
|
277
|
+
end
|
|
276
278
|
end
|
|
277
279
|
end
|
|
280
|
+
|
|
278
281
|
@sorted_comments
|
|
279
282
|
end
|
|
280
283
|
|
|
@@ -304,7 +304,7 @@ def row_col_param_for_conditional_formatting(*args)
|
|
|
304
304
|
# Check for a cell reference in A1 notation and substitute row and column
|
|
305
305
|
if args[0] =~ /^\D/
|
|
306
306
|
# Check for a user defined multiple range like B3:K6,B8:K11.
|
|
307
|
-
user_range = args[0].gsub(/\s*,\s*/, ' ').gsub(/\$/, '') if args[0] =~ /,/
|
|
307
|
+
user_range = args[0].sub(/^=/, '').gsub(/\s*,\s*/, ' ').gsub(/\$/, '') if args[0] =~ /,/
|
|
308
308
|
end
|
|
309
309
|
|
|
310
310
|
row1, col1, row2, col2, param = row_col_notation(args)
|
|
@@ -24,8 +24,6 @@ def initialize(id, param = {})
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
# attr_reader :id
|
|
28
|
-
|
|
29
27
|
def initialize(worksheet, id, *args)
|
|
30
28
|
@worksheet = worksheet
|
|
31
29
|
@writer = Package::XMLWriterSimple.new
|
|
@@ -204,25 +202,15 @@ def valid_table_parameter
|
|
|
204
202
|
def handle_the_column_formula(col_data, col_num, formula, format)
|
|
205
203
|
return unless formula
|
|
206
204
|
|
|
207
|
-
|
|
208
|
-
formula.sub!(/^=/, '')
|
|
209
|
-
# Covert Excel 2010 "@" ref to 2007 "#This Row".
|
|
210
|
-
formula.gsub!(/@/,'[#This Row],')
|
|
211
|
-
|
|
212
|
-
col_data.formula = formula
|
|
205
|
+
col_data.formula = formula.sub(/^=/, '').gsub(/@/,'[#This Row],')
|
|
213
206
|
|
|
214
207
|
(@first_data_row..@last_data_row).each do |row|
|
|
215
|
-
@worksheet.write_formula(row, col_num, formula, format)
|
|
208
|
+
@worksheet.write_formula(row, col_num, col_data.formula, format)
|
|
216
209
|
end
|
|
217
210
|
end
|
|
218
211
|
|
|
219
212
|
def handle_the_function_for_the_table_row(row2, col_data, col_num, total_function, format)
|
|
220
|
-
function = total_function
|
|
221
|
-
|
|
222
|
-
# Massage the function name.
|
|
223
|
-
function = function.downcase
|
|
224
|
-
function.gsub!(/_/, '')
|
|
225
|
-
function.gsub!(/\s/,'')
|
|
213
|
+
function = total_function.downcase.gsub(/[_\s]/, '')
|
|
226
214
|
|
|
227
215
|
function = 'countNums' if function == 'countnums'
|
|
228
216
|
function = 'stdDev' if function == 'stddev'
|
|
@@ -272,9 +260,7 @@ def set_the_table_options
|
|
|
272
260
|
|
|
273
261
|
def set_the_table_style
|
|
274
262
|
if @param[:style]
|
|
275
|
-
@style = @param[:style]
|
|
276
|
-
# Remove whitespace from style name.
|
|
277
|
-
@style.gsub!(/\s/, '')
|
|
263
|
+
@style = @param[:style].gsub(/\s/, '')
|
|
278
264
|
else
|
|
279
265
|
@style = "TableStyleMedium9"
|
|
280
266
|
end
|
|
@@ -33,9 +33,9 @@ def assemble_xml_file(worksheet)
|
|
|
33
33
|
write_button_shapetype
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
-
unless worksheet.
|
|
36
|
+
unless worksheet.sorted_comments.empty?
|
|
37
37
|
write_shape_type_and_shape(
|
|
38
|
-
worksheet.
|
|
38
|
+
worksheet.sorted_comments,
|
|
39
39
|
vml_shape_id, z_index) do
|
|
40
40
|
write_comment_shapetype
|
|
41
41
|
end
|
data/lib/write_xlsx/sheets.rb
CHANGED
|
@@ -100,8 +100,14 @@ def write_drawing_rels_files(package_dir)
|
|
|
100
100
|
|
|
101
101
|
# )
|
|
102
102
|
dir = "#{package_dir}/xl/drawings/_rels"
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
|
|
104
|
+
index = 0
|
|
105
|
+
self.each do |sheet|
|
|
106
|
+
if !sheet.drawing_links[0].empty? || sheet.has_shapes?
|
|
107
|
+
index += 1
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
next if sheet.drawing_links[0].empty?
|
|
105
111
|
|
|
106
112
|
FileUtils.mkdir_p(dir)
|
|
107
113
|
|
|
@@ -114,7 +120,7 @@ def write_drawing_rels_files(package_dir)
|
|
|
114
120
|
end
|
|
115
121
|
|
|
116
122
|
# Create the .rels file such as /xl/drawings/_rels/sheet1.xml.rels.
|
|
117
|
-
rels.set_xml_writer("#{dir}/drawing#{index
|
|
123
|
+
rels.set_xml_writer("#{dir}/drawing#{index}.xml.rels")
|
|
118
124
|
rels.assemble_xml_file
|
|
119
125
|
end
|
|
120
126
|
end
|
|
@@ -216,7 +222,7 @@ def write_sheet(writer, sheet, sheet_id) #:nodoc:
|
|
|
216
222
|
if sheet.hidden?
|
|
217
223
|
attributes << 'state' << 'hidden'
|
|
218
224
|
end
|
|
219
|
-
attributes
|
|
225
|
+
attributes += r_id_attributes(sheet_id)
|
|
220
226
|
writer.empty_tag_encoded('sheet', attributes)
|
|
221
227
|
end
|
|
222
228
|
end
|
data/lib/write_xlsx/utility.rb
CHANGED
|
@@ -119,14 +119,7 @@ def check_dimensions(row, col)
|
|
|
119
119
|
# nil if the date is invalid.
|
|
120
120
|
#
|
|
121
121
|
def convert_date_time(date_time_string) #:nodoc:
|
|
122
|
-
date_time = date_time_string
|
|
123
|
-
|
|
124
|
-
days = 0 # Number of days since epoch
|
|
125
|
-
seconds = 0 # Time expressed as fraction of 24h hours in seconds
|
|
126
|
-
|
|
127
|
-
# Strip leading and trailing whitespace.
|
|
128
|
-
date_time.sub!(/^\s+/, '')
|
|
129
|
-
date_time.sub!(/\s+$/, '')
|
|
122
|
+
date_time = date_time_string.sub(/^\s+/, '').sub(/\s+$/, '').sub(/Z$/, '')
|
|
130
123
|
|
|
131
124
|
# Check for invalid date char.
|
|
132
125
|
return nil if date_time =~ /[^0-9T:\-\.Z]/
|
|
@@ -134,8 +127,8 @@ def convert_date_time(date_time_string) #:nodoc:
|
|
|
134
127
|
# Check for "T" after date or before time.
|
|
135
128
|
return nil unless date_time =~ /\dT|T\d/
|
|
136
129
|
|
|
137
|
-
#
|
|
138
|
-
|
|
130
|
+
days = 0 # Number of days since epoch
|
|
131
|
+
seconds = 0 # Time expressed as fraction of 24h hours in seconds
|
|
139
132
|
|
|
140
133
|
# Split into date and time.
|
|
141
134
|
date, time = date_time.split(/T/)
|
|
@@ -495,5 +488,9 @@ def write_stroke
|
|
|
495
488
|
|
|
496
489
|
@writer.empty_tag('v:stroke', attributes)
|
|
497
490
|
end
|
|
491
|
+
|
|
492
|
+
def r_id_attributes(id)
|
|
493
|
+
['r:id', "rId#{id}"]
|
|
494
|
+
end
|
|
498
495
|
end
|
|
499
496
|
end
|
data/lib/write_xlsx/version.rb
CHANGED
data/lib/write_xlsx/workbook.rb
CHANGED
|
@@ -41,7 +41,7 @@ class Workbook
|
|
|
41
41
|
attr_writer :firstsheet # :nodoc:
|
|
42
42
|
attr_reader :palette # :nodoc:
|
|
43
43
|
attr_reader :worksheets, :charts, :drawings # :nodoc:
|
|
44
|
-
attr_reader :
|
|
44
|
+
attr_reader :named_ranges # :nodoc:
|
|
45
45
|
attr_reader :doc_properties # :nodoc:
|
|
46
46
|
attr_reader :image_types, :images # :nodoc:
|
|
47
47
|
attr_reader :shared_strings # :nodoc:
|
|
@@ -111,8 +111,6 @@ def initialize(file, default_formats = {})
|
|
|
111
111
|
@custom_colors = []
|
|
112
112
|
@doc_properties = {}
|
|
113
113
|
@local_time = Time.now
|
|
114
|
-
@num_vml_files = 0
|
|
115
|
-
@num_comment_files = 0
|
|
116
114
|
@optimization = 0
|
|
117
115
|
@x_window = 240
|
|
118
116
|
@y_window = 15
|
|
@@ -247,31 +245,29 @@ def assemble_xml_file #:nodoc:
|
|
|
247
245
|
write_xml_declaration
|
|
248
246
|
|
|
249
247
|
# Write the root workbook element.
|
|
250
|
-
write_workbook
|
|
248
|
+
write_workbook do
|
|
251
249
|
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
# Write the XLSX file version.
|
|
251
|
+
write_file_version
|
|
254
252
|
|
|
255
|
-
|
|
256
|
-
|
|
253
|
+
# Write the workbook properties.
|
|
254
|
+
write_workbook_pr
|
|
257
255
|
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
# Write the workbook view properties.
|
|
257
|
+
write_book_views
|
|
260
258
|
|
|
261
|
-
|
|
262
|
-
|
|
259
|
+
# Write the worksheet names and ids.
|
|
260
|
+
@worksheets.write_sheets(@writer)
|
|
263
261
|
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
# Write the workbook defined names.
|
|
263
|
+
write_defined_names
|
|
266
264
|
|
|
267
|
-
|
|
268
|
-
|
|
265
|
+
# Write the workbook calculation properties.
|
|
266
|
+
write_calc_pr
|
|
269
267
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
# Close the workbook tag.
|
|
274
|
-
write_workbook_end
|
|
268
|
+
# Write the workbook extension storage.
|
|
269
|
+
#write_ext_lst
|
|
270
|
+
end
|
|
275
271
|
|
|
276
272
|
# Close the XML writer object and filehandle.
|
|
277
273
|
@writer.crlf
|
|
@@ -655,7 +651,7 @@ def add_format(properties = {})
|
|
|
655
651
|
# This is not very useful for inserting multiple shapes,
|
|
656
652
|
# since the x/y coordinates also gets modified.
|
|
657
653
|
#
|
|
658
|
-
def add_shape(properties)
|
|
654
|
+
def add_shape(properties = {})
|
|
659
655
|
shape = Shape.new(properties)
|
|
660
656
|
shape.palette = @palette
|
|
661
657
|
|
|
@@ -693,10 +689,6 @@ def add_shape(properties)
|
|
|
693
689
|
def define_name(name, formula)
|
|
694
690
|
sheet_index = nil
|
|
695
691
|
sheetname = ''
|
|
696
|
-
full_name = name
|
|
697
|
-
|
|
698
|
-
# Remove the = sign from the formula if it exists.
|
|
699
|
-
formula.sub!(/^=/, '')
|
|
700
692
|
|
|
701
693
|
# Local defined names are formatted like "Sheet1!name".
|
|
702
694
|
if name =~ /^(.*)!(.*)$/
|
|
@@ -722,7 +714,7 @@ def define_name(name, formula)
|
|
|
722
714
|
raise "Invalid name '#{name}' looks like a cell name in defined_name()\n"
|
|
723
715
|
end
|
|
724
716
|
|
|
725
|
-
@defined_names.push([ name, sheet_index, formula])
|
|
717
|
+
@defined_names.push([ name, sheet_index, formula.sub(/^=/, '') ])
|
|
726
718
|
end
|
|
727
719
|
|
|
728
720
|
#
|
|
@@ -949,6 +941,14 @@ def style_properties
|
|
|
949
941
|
]
|
|
950
942
|
end
|
|
951
943
|
|
|
944
|
+
def num_vml_files
|
|
945
|
+
@worksheets.select { |sheet| sheet.has_vml? }.count
|
|
946
|
+
end
|
|
947
|
+
|
|
948
|
+
def num_comment_files
|
|
949
|
+
@worksheets.select { |sheet| sheet.has_comments? }.count
|
|
950
|
+
end
|
|
951
|
+
|
|
952
952
|
private
|
|
953
953
|
|
|
954
954
|
def setup_filename(file) #:nodoc:
|
|
@@ -1085,11 +1085,9 @@ def write_workbook #:nodoc:
|
|
|
1085
1085
|
'xmlns:r',
|
|
1086
1086
|
schema + '/officeDocument/2006/relationships'
|
|
1087
1087
|
]
|
|
1088
|
-
@writer.
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
def write_workbook_end #:nodoc:
|
|
1092
|
-
@writer.end_tag('workbook')
|
|
1088
|
+
@writer.tag_elements('workbook', attributes) do
|
|
1089
|
+
yield
|
|
1090
|
+
end
|
|
1093
1091
|
end
|
|
1094
1092
|
|
|
1095
1093
|
def write_file_version #:nodoc:
|
|
@@ -1144,18 +1142,15 @@ def write_calc_pr #:nodoc:
|
|
|
1144
1142
|
end
|
|
1145
1143
|
|
|
1146
1144
|
def write_ext_lst #:nodoc:
|
|
1147
|
-
|
|
1148
|
-
@writer.tag_elements(tag) { write_ext }
|
|
1145
|
+
@writer.tag_elements('extLst') { write_ext }
|
|
1149
1146
|
end
|
|
1150
1147
|
|
|
1151
1148
|
def write_ext #:nodoc:
|
|
1152
|
-
tag = 'ext'
|
|
1153
|
-
uri = "#{OFFICE_URL}mac/excel/2008/main"
|
|
1154
1149
|
attributes = [
|
|
1155
|
-
'xmlns:mx',
|
|
1150
|
+
'xmlns:mx', "#{OFFICE_URL}mac/excel/2008/main",
|
|
1156
1151
|
'uri', uri
|
|
1157
1152
|
]
|
|
1158
|
-
@writer.tag_elements(
|
|
1153
|
+
@writer.tag_elements('ext', attributes) { write_mx_arch_id }
|
|
1159
1154
|
end
|
|
1160
1155
|
|
|
1161
1156
|
def write_mx_arch_id #:nodoc:
|
|
@@ -1164,14 +1159,13 @@ def write_mx_arch_id #:nodoc:
|
|
|
1164
1159
|
|
|
1165
1160
|
def write_defined_names #:nodoc:
|
|
1166
1161
|
return if @defined_names.nil? || @defined_names.empty?
|
|
1167
|
-
|
|
1168
|
-
@writer.tag_elements(tag) do
|
|
1162
|
+
@writer.tag_elements('definedNames') do
|
|
1169
1163
|
@defined_names.each { |defined_name| write_defined_name(defined_name) }
|
|
1170
1164
|
end
|
|
1171
1165
|
end
|
|
1172
1166
|
|
|
1173
|
-
def write_defined_name(
|
|
1174
|
-
name, id, range, hidden =
|
|
1167
|
+
def write_defined_name(defined_name) #:nodoc:
|
|
1168
|
+
name, id, range, hidden = defined_name
|
|
1175
1169
|
|
|
1176
1170
|
attributes = ['name', name]
|
|
1177
1171
|
attributes << 'localSheetId' << "#{id}" unless id == -1
|
|
@@ -1424,30 +1418,28 @@ def ne_0?(val)
|
|
|
1424
1418
|
# the named ranges for App.xml.
|
|
1425
1419
|
#
|
|
1426
1420
|
def prepare_defined_names #:nodoc:
|
|
1427
|
-
defined_names = @defined_names
|
|
1428
|
-
|
|
1429
1421
|
@worksheets.each do |sheet|
|
|
1430
1422
|
# Check for Print Area settings.
|
|
1431
1423
|
if sheet.autofilter_area
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1424
|
+
@defined_names << [
|
|
1425
|
+
'_xlnm._FilterDatabase',
|
|
1426
|
+
sheet.index,
|
|
1427
|
+
sheet.autofilter_area,
|
|
1428
|
+
1
|
|
1429
|
+
]
|
|
1437
1430
|
end
|
|
1438
1431
|
|
|
1439
1432
|
# Check for Print Area settings.
|
|
1440
1433
|
if !sheet.print_area.empty?
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1434
|
+
@defined_names << [
|
|
1435
|
+
'_xlnm.Print_Area',
|
|
1436
|
+
sheet.index,
|
|
1437
|
+
sheet.print_area
|
|
1438
|
+
]
|
|
1445
1439
|
end
|
|
1446
1440
|
|
|
1447
1441
|
# Check for repeat rows/cols. aka, Print Titles.
|
|
1448
1442
|
if !sheet.print_repeat_cols.empty? || !sheet.print_repeat_rows.empty?
|
|
1449
|
-
range = ''
|
|
1450
|
-
|
|
1451
1443
|
if !sheet.print_repeat_cols.empty? && !sheet.print_repeat_rows.empty?
|
|
1452
1444
|
range = sheet.print_repeat_cols + ',' + sheet.print_repeat_rows
|
|
1453
1445
|
else
|
|
@@ -1455,55 +1447,49 @@ def prepare_defined_names #:nodoc:
|
|
|
1455
1447
|
end
|
|
1456
1448
|
|
|
1457
1449
|
# Store the defined names.
|
|
1458
|
-
defined_names << ['_xlnm.Print_Titles', sheet.index, range]
|
|
1450
|
+
@defined_names << ['_xlnm.Print_Titles', sheet.index, range]
|
|
1459
1451
|
end
|
|
1460
1452
|
end
|
|
1461
1453
|
|
|
1462
|
-
defined_names = sort_defined_names(defined_names)
|
|
1463
|
-
@
|
|
1464
|
-
@named_ranges = extract_named_ranges(defined_names)
|
|
1454
|
+
@defined_names = sort_defined_names(@defined_names)
|
|
1455
|
+
@named_ranges = extract_named_ranges(@defined_names)
|
|
1465
1456
|
end
|
|
1466
1457
|
|
|
1467
1458
|
#
|
|
1468
1459
|
# Iterate through the worksheets and set up the VML objects.
|
|
1469
1460
|
#
|
|
1470
1461
|
def prepare_vml_objects #:nodoc:
|
|
1471
|
-
comment_id
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
comment_files = 0
|
|
1462
|
+
comment_id = 0
|
|
1463
|
+
vml_drawing_id = 0
|
|
1464
|
+
vml_data_id = 1
|
|
1465
|
+
vml_shape_id = 1024
|
|
1476
1466
|
|
|
1477
|
-
@worksheets.each do |sheet|
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
comment_files += 1 if sheet.has_comments?
|
|
1467
|
+
@worksheets.select { |sheet| sheet.has_vml? }.each do |sheet|
|
|
1468
|
+
comment_id += 1 if sheet.has_comments?
|
|
1469
|
+
vml_drawing_id += 1
|
|
1481
1470
|
|
|
1482
|
-
|
|
1483
|
-
|
|
1471
|
+
sheet.prepare_vml_objects(vml_data_id, vml_shape_id,
|
|
1472
|
+
vml_drawing_id, comment_id)
|
|
1484
1473
|
|
|
1485
1474
|
# Each VML file should start with a shape id incremented by 1024.
|
|
1486
|
-
vml_data_id += 1 * (
|
|
1487
|
-
vml_shape_id += 1024 * (
|
|
1475
|
+
vml_data_id += 1 * ( 1 + sheet.num_comments_block )
|
|
1476
|
+
vml_shape_id += 1024 * ( 1 + sheet.num_comments_block )
|
|
1488
1477
|
end
|
|
1489
1478
|
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
# Add a font format for cell comments.
|
|
1494
|
-
if comment_files > 0
|
|
1495
|
-
format = Format.new(
|
|
1496
|
-
@formats,
|
|
1497
|
-
:font => 'Tahoma',
|
|
1498
|
-
:size => 8,
|
|
1499
|
-
:color_indexed => 81,
|
|
1500
|
-
:font_only => 1
|
|
1501
|
-
)
|
|
1479
|
+
add_font_format_for_cell_comments if num_comment_files > 0
|
|
1480
|
+
end
|
|
1502
1481
|
|
|
1503
|
-
|
|
1482
|
+
def add_font_format_for_cell_comments
|
|
1483
|
+
format = Format.new(
|
|
1484
|
+
@formats,
|
|
1485
|
+
:font => 'Tahoma',
|
|
1486
|
+
:size => 8,
|
|
1487
|
+
:color_indexed => 81,
|
|
1488
|
+
:font_only => 1
|
|
1489
|
+
)
|
|
1504
1490
|
|
|
1505
|
-
|
|
1506
|
-
|
|
1491
|
+
format.get_xf_index
|
|
1492
|
+
@formats.formats << format
|
|
1507
1493
|
end
|
|
1508
1494
|
|
|
1509
1495
|
#
|
|
@@ -1569,7 +1555,6 @@ def chart_data(worksheet, cells)
|
|
|
1569
1555
|
end
|
|
1570
1556
|
end
|
|
1571
1557
|
end
|
|
1572
|
-
private :chart_data
|
|
1573
1558
|
|
|
1574
1559
|
#
|
|
1575
1560
|
# Sort internal and user defined names in the same order as used by Excel.
|