write_xlsx 1.12.3 → 1.15.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/.rubocop.yml +22 -0
- data/Changes +23 -0
- data/README.md +1 -1
- data/lib/write_xlsx/chart/area.rb +2 -2
- data/lib/write_xlsx/chart/axis.rb +55 -32
- data/lib/write_xlsx/chart/axis_writer.rb +528 -0
- data/lib/write_xlsx/chart/bar.rb +2 -2
- data/lib/write_xlsx/chart/caption.rb +16 -9
- data/lib/write_xlsx/chart/chart_area.rb +121 -0
- data/lib/write_xlsx/chart/column.rb +2 -2
- data/lib/write_xlsx/chart/d_pt_point_writer.rb +14 -0
- data/lib/write_xlsx/chart/doughnut.rb +0 -3
- data/lib/write_xlsx/chart/formatting_writer.rb +652 -0
- data/lib/write_xlsx/chart/initialization.rb +100 -0
- data/lib/write_xlsx/chart/line.rb +4 -3
- data/lib/write_xlsx/chart/pie.rb +6 -2
- data/lib/write_xlsx/chart/radar.rb +2 -2
- data/lib/write_xlsx/chart/scatter.rb +4 -3
- data/lib/write_xlsx/chart/series.rb +35 -15
- data/lib/write_xlsx/chart/series_data.rb +132 -0
- data/lib/write_xlsx/chart/series_writer.rb +318 -0
- data/lib/write_xlsx/chart/settings.rb +226 -0
- data/lib/write_xlsx/chart/stock.rb +2 -2
- data/lib/write_xlsx/chart/table.rb +50 -0
- data/lib/write_xlsx/chart/xml_writer.rb +305 -0
- data/lib/write_xlsx/chart.rb +286 -2477
- data/lib/write_xlsx/chartsheet.rb +35 -83
- data/lib/write_xlsx/constants.rb +11 -0
- data/lib/write_xlsx/drawing.rb +5 -3
- data/lib/write_xlsx/format/alignment_state.rb +39 -0
- data/lib/write_xlsx/format/alignment_style.rb +92 -0
- data/lib/write_xlsx/format/border_state.rb +47 -0
- data/lib/write_xlsx/format/border_style.rb +116 -0
- data/lib/write_xlsx/format/fill_state.rb +26 -0
- data/lib/write_xlsx/format/fill_style.rb +52 -0
- data/lib/write_xlsx/format/font_state.rb +74 -0
- data/lib/write_xlsx/format/font_style.rb +172 -0
- data/lib/write_xlsx/format/format_state.rb +65 -0
- data/lib/write_xlsx/format/number_format_state.rb +20 -0
- data/lib/write_xlsx/format/number_format_style.rb +28 -0
- data/lib/write_xlsx/format/protection_state.rb +20 -0
- data/lib/write_xlsx/format/protection_style.rb +28 -0
- data/lib/write_xlsx/format.rb +1093 -426
- data/lib/write_xlsx/formats.rb +0 -2
- data/lib/write_xlsx/image_property.rb +4 -1
- data/lib/write_xlsx/inserted_chart.rb +1 -1
- data/lib/write_xlsx/object_positioning.rb +203 -0
- data/lib/write_xlsx/package/app.rb +3 -3
- data/lib/write_xlsx/package/button.rb +6 -2
- data/lib/write_xlsx/package/comments.rb +11 -3
- data/lib/write_xlsx/package/conditional_format.rb +7 -3
- data/lib/write_xlsx/package/content_types.rb +2 -2
- data/lib/write_xlsx/package/core.rb +2 -2
- data/lib/write_xlsx/package/custom.rb +3 -2
- data/lib/write_xlsx/package/metadata.rb +2 -2
- data/lib/write_xlsx/package/packager.rb +0 -3
- data/lib/write_xlsx/package/relationships.rb +2 -2
- data/lib/write_xlsx/package/rich_value.rb +4 -2
- data/lib/write_xlsx/package/rich_value_rel.rb +2 -2
- data/lib/write_xlsx/package/rich_value_structure.rb +2 -2
- data/lib/write_xlsx/package/rich_value_types.rb +3 -3
- data/lib/write_xlsx/package/shared_strings.rb +2 -2
- data/lib/write_xlsx/package/styles.rb +13 -9
- data/lib/write_xlsx/package/table.rb +8 -2
- data/lib/write_xlsx/package/theme.rb +0 -3
- data/lib/write_xlsx/package/vml.rb +2 -2
- data/lib/write_xlsx/page_setup.rb +192 -0
- data/lib/write_xlsx/shape.rb +97 -100
- data/lib/write_xlsx/sheets.rb +9 -4
- data/lib/write_xlsx/sparkline.rb +2 -2
- data/lib/write_xlsx/utility/cell_reference.rb +124 -0
- data/lib/write_xlsx/utility/chart_formatting.rb +262 -0
- data/lib/write_xlsx/utility/common.rb +44 -0
- data/lib/write_xlsx/utility/date_time.rb +113 -0
- data/lib/write_xlsx/utility/dimensions.rb +40 -0
- data/lib/write_xlsx/utility/drawing.rb +136 -0
- data/lib/write_xlsx/utility/rich_text.rb +184 -0
- data/lib/write_xlsx/utility/sheetname_quoting.rb +73 -0
- data/lib/write_xlsx/utility/string_width.rb +45 -0
- data/lib/write_xlsx/utility/url.rb +27 -0
- data/lib/write_xlsx/utility/xml_primitives.rb +32 -0
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook/chart_data.rb +188 -0
- data/lib/write_xlsx/workbook/format_preparation.rb +199 -0
- data/lib/write_xlsx/workbook/initialization.rb +223 -0
- data/lib/write_xlsx/workbook/package_preparation.rb +231 -0
- data/lib/write_xlsx/workbook/workbook_writer.rb +164 -0
- data/lib/write_xlsx/workbook.rb +143 -981
- data/lib/write_xlsx/worksheet/asset_manager.rb +60 -0
- data/lib/write_xlsx/worksheet/autofilter.rb +390 -0
- data/lib/write_xlsx/worksheet/cell_data.rb +13 -6
- data/lib/write_xlsx/worksheet/cell_data_manager.rb +47 -0
- data/lib/write_xlsx/worksheet/cell_data_store.rb +61 -0
- data/lib/write_xlsx/worksheet/columns.rb +204 -0
- data/lib/write_xlsx/worksheet/comments_support.rb +61 -0
- data/lib/write_xlsx/worksheet/conditional_formats.rb +30 -0
- data/lib/write_xlsx/worksheet/data_validation.rb +9 -1
- data/lib/write_xlsx/worksheet/data_writing.rb +1017 -0
- data/lib/write_xlsx/worksheet/drawing_methods.rb +308 -0
- data/lib/write_xlsx/worksheet/drawing_preparation.rb +290 -0
- data/lib/write_xlsx/worksheet/drawing_relations.rb +76 -0
- data/lib/write_xlsx/worksheet/drawing_xml_writer.rb +50 -0
- data/lib/write_xlsx/worksheet/formatting.rb +418 -0
- data/lib/write_xlsx/worksheet/hyperlink.rb +9 -1
- data/lib/write_xlsx/worksheet/initialization.rb +146 -0
- data/lib/write_xlsx/worksheet/panes.rb +64 -0
- data/lib/write_xlsx/worksheet/print_options.rb +72 -0
- data/lib/write_xlsx/worksheet/protection.rb +65 -0
- data/lib/write_xlsx/worksheet/rich_text_helpers.rb +78 -0
- data/lib/write_xlsx/worksheet/row_col_sizing.rb +69 -0
- data/lib/write_xlsx/worksheet/rows.rb +84 -0
- data/lib/write_xlsx/worksheet/selection.rb +41 -0
- data/lib/write_xlsx/worksheet/xml_writer.rb +1246 -0
- data/lib/write_xlsx/worksheet.rb +376 -4530
- metadata +66 -4
- data/lib/write_xlsx/utility.rb +0 -986
- data/lib/write_xlsx/worksheet/page_setup.rb +0 -192
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Writexlsx
|
|
5
|
+
class Worksheet
|
|
6
|
+
module DrawingXmlWriter
|
|
7
|
+
#
|
|
8
|
+
# Write the <drawing> elements.
|
|
9
|
+
#
|
|
10
|
+
def write_drawings # :nodoc:
|
|
11
|
+
increment_rel_id_and_write_r_id('drawing') if drawings?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Write the <legacyDrawing> element.
|
|
16
|
+
#
|
|
17
|
+
def write_legacy_drawing # :nodoc:
|
|
18
|
+
increment_rel_id_and_write_r_id('legacyDrawing') if has_vml?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Write the <legacyDrawingHF> element.
|
|
23
|
+
#
|
|
24
|
+
def write_legacy_drawing_hf # :nodoc:
|
|
25
|
+
return unless has_header_vml?
|
|
26
|
+
|
|
27
|
+
# Increment the relationship id for any drawings or comments.
|
|
28
|
+
@rel_count += 1
|
|
29
|
+
|
|
30
|
+
attributes = [['r:id', "rId#{@rel_count}"]]
|
|
31
|
+
@writer.empty_tag('legacyDrawingHF', attributes)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# Write the <picture> element.
|
|
36
|
+
#
|
|
37
|
+
def write_picture
|
|
38
|
+
return unless background_image
|
|
39
|
+
|
|
40
|
+
# Increment the relationship id.
|
|
41
|
+
@rel_count += 1
|
|
42
|
+
id = @rel_count
|
|
43
|
+
|
|
44
|
+
attributes = [['r:id', "rId#{id}"]]
|
|
45
|
+
|
|
46
|
+
@writer.empty_tag('picture', attributes)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'write_xlsx/constants'
|
|
5
|
+
|
|
6
|
+
###############################################################################
|
|
7
|
+
#
|
|
8
|
+
# Formatting - A module for worksheet layout and print/appearance settings.
|
|
9
|
+
#
|
|
10
|
+
# Used in conjunction with WriteXLSX
|
|
11
|
+
#
|
|
12
|
+
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
|
13
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
|
14
|
+
|
|
15
|
+
module Writexlsx
|
|
16
|
+
class Worksheet
|
|
17
|
+
module Formatting
|
|
18
|
+
include Constants
|
|
19
|
+
|
|
20
|
+
#
|
|
21
|
+
# Header/footer
|
|
22
|
+
#
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# Set the page header caption and optional margin.
|
|
26
|
+
#
|
|
27
|
+
def set_header(string = '', margin = 0.3, options = {})
|
|
28
|
+
raise 'Header string must be less than 255 characters' if string.length > 255
|
|
29
|
+
|
|
30
|
+
# Replace the Excel placeholder &[Picture] with the internal &G.
|
|
31
|
+
header_footer_string = string.gsub("&[Picture]", '&G')
|
|
32
|
+
# placeholeder /&G/ の数
|
|
33
|
+
placeholder_count = header_footer_string.scan("&G").count
|
|
34
|
+
@page_setup.header = header_footer_string
|
|
35
|
+
|
|
36
|
+
@page_setup.header_footer_aligns = options[:align_with_margins] if options[:align_with_margins]
|
|
37
|
+
|
|
38
|
+
@page_setup.header_footer_scales = options[:scale_with_doc] if options[:scale_with_doc]
|
|
39
|
+
|
|
40
|
+
# Reset the array in case the function is called more than once.
|
|
41
|
+
@assets.reset_header_images
|
|
42
|
+
|
|
43
|
+
[
|
|
44
|
+
[:image_left, 'LH'], [:image_center, 'CH'], [:image_right, 'RH']
|
|
45
|
+
].each do |p|
|
|
46
|
+
next unless options[p.first]
|
|
47
|
+
|
|
48
|
+
@assets.add_header_image(
|
|
49
|
+
ImageProperty.new(options[p.first], position: p.last)
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# # placeholeder /&G/ の数
|
|
54
|
+
# placeholder_count = @page_setup.header.scan("&G").count
|
|
55
|
+
|
|
56
|
+
raise "Number of header image (#{@assets.header_images.size}) doesn't match placeholder count (#{placeholder_count}) in string: #{@page_setup.header}" if @assets.header_images.size != placeholder_count
|
|
57
|
+
|
|
58
|
+
@page_setup.margin_header = margin || 0.3
|
|
59
|
+
@page_setup.header_footer_changed = true
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
#
|
|
63
|
+
# Set the page footer caption and optional margin.
|
|
64
|
+
#
|
|
65
|
+
def set_footer(string = '', margin = 0.3, options = {})
|
|
66
|
+
raise 'Footer string must be less than 255 characters' if string.length > 255
|
|
67
|
+
|
|
68
|
+
# Replace the Excel placeholder &[Picture] with the internal &G.
|
|
69
|
+
@page_setup.footer = string.gsub("&[Picture]", '&G')
|
|
70
|
+
|
|
71
|
+
@page_setup.header_footer_aligns = options[:align_with_margins] if options[:align_with_margins]
|
|
72
|
+
|
|
73
|
+
@page_setup.header_footer_scales = options[:scale_with_doc] if options[:scale_with_doc]
|
|
74
|
+
|
|
75
|
+
# Reset the array in case the function is called more than once.
|
|
76
|
+
@assets.reset_footer_images
|
|
77
|
+
|
|
78
|
+
[
|
|
79
|
+
[:image_left, 'LF'], [:image_center, 'CF'], [:image_right, 'RF']
|
|
80
|
+
].each do |p|
|
|
81
|
+
next unless options[p.first]
|
|
82
|
+
|
|
83
|
+
@assets.add_footer_image(
|
|
84
|
+
ImageProperty.new(options[p.first], position: p.last)
|
|
85
|
+
)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# placeholeder /&G/ の数
|
|
89
|
+
placeholder_count = @page_setup.footer.scan("&G").count
|
|
90
|
+
|
|
91
|
+
raise "Number of footer image (#{@assets.footer_images.size}) doesn't match placeholder count (#{placeholder_count}) in string: #{@page_setup.footer}" if @assets.footer_images.size != placeholder_count
|
|
92
|
+
|
|
93
|
+
@page_setup.margin_footer = margin
|
|
94
|
+
@page_setup.header_footer_changed = true
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
#
|
|
98
|
+
# Page margin helpers
|
|
99
|
+
#
|
|
100
|
+
|
|
101
|
+
#
|
|
102
|
+
# Center the worksheet data horizontally between the margins on the printed page:
|
|
103
|
+
#
|
|
104
|
+
def center_horizontally
|
|
105
|
+
@page_setup.center_horizontally
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
#
|
|
109
|
+
# Center the worksheet data vertically between the margins on the printed page:
|
|
110
|
+
#
|
|
111
|
+
def center_vertically
|
|
112
|
+
@page_setup.center_vertically
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
#
|
|
116
|
+
# Set all the page margins to the same value in inches.
|
|
117
|
+
#
|
|
118
|
+
def margins=(margin)
|
|
119
|
+
self.margin_left = margin
|
|
120
|
+
self.margin_right = margin
|
|
121
|
+
self.margin_top = margin
|
|
122
|
+
self.margin_bottom = margin
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
#
|
|
126
|
+
# Set the left and right margins to the same value in inches.
|
|
127
|
+
# See set_margins
|
|
128
|
+
#
|
|
129
|
+
def margins_left_right=(margin)
|
|
130
|
+
self.margin_left = margin
|
|
131
|
+
self.margin_right = margin
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
#
|
|
135
|
+
# Set the top and bottom margins to the same value in inches.
|
|
136
|
+
# See set_margins
|
|
137
|
+
#
|
|
138
|
+
def margins_top_bottom=(margin)
|
|
139
|
+
self.margin_top = margin
|
|
140
|
+
self.margin_bottom = margin
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
#
|
|
144
|
+
# Set the left margin in inches.
|
|
145
|
+
# See margins=()
|
|
146
|
+
#
|
|
147
|
+
def margin_left=(margin)
|
|
148
|
+
@page_setup.margin_left = remove_white_space(margin)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
#
|
|
152
|
+
# Set the right margin in inches.
|
|
153
|
+
# See margins=()
|
|
154
|
+
#
|
|
155
|
+
def margin_right=(margin)
|
|
156
|
+
@page_setup.margin_right = remove_white_space(margin)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
#
|
|
160
|
+
# Set the top margin in inches.
|
|
161
|
+
# See margins=()
|
|
162
|
+
#
|
|
163
|
+
def margin_top=(margin)
|
|
164
|
+
@page_setup.margin_top = remove_white_space(margin)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
#
|
|
168
|
+
# Set the bottom margin in inches.
|
|
169
|
+
# See margins=()
|
|
170
|
+
#
|
|
171
|
+
def margin_bottom=(margin)
|
|
172
|
+
@page_setup.margin_bottom = remove_white_space(margin)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# # deprecations for set_* wrapper methods
|
|
176
|
+
#
|
|
177
|
+
# set_margin_* methods are deprecated. use margin_*=().
|
|
178
|
+
#
|
|
179
|
+
def set_margins(margin)
|
|
180
|
+
put_deprecate_message("#{self}.set_margins")
|
|
181
|
+
self.margins = margin
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
#
|
|
185
|
+
# this method is deprecated. use margin_left_right=().
|
|
186
|
+
# Set the left and right margins to the same value in inches.
|
|
187
|
+
#
|
|
188
|
+
def set_margins_LR(margin)
|
|
189
|
+
put_deprecate_message("#{self}.set_margins_LR")
|
|
190
|
+
self.margins_left_right = margin
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
#
|
|
194
|
+
# this method is deprecated. use margin_top_bottom=().
|
|
195
|
+
# Set the top and bottom margins to the same value in inches.
|
|
196
|
+
#
|
|
197
|
+
def set_margins_TB(margin)
|
|
198
|
+
put_deprecate_message("#{self}.set_margins_TB")
|
|
199
|
+
self.margins_top_bottom = margin
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
#
|
|
203
|
+
# this method is deprecated. use margin_left=()
|
|
204
|
+
# Set the left margin in inches.
|
|
205
|
+
#
|
|
206
|
+
def set_margin_left(margin = 0.7)
|
|
207
|
+
put_deprecate_message("#{self}.set_margin_left")
|
|
208
|
+
self.margin_left = margin
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
#
|
|
212
|
+
# this method is deprecated. use margin_right=()
|
|
213
|
+
# Set the right margin in inches.
|
|
214
|
+
#
|
|
215
|
+
def set_margin_right(margin = 0.7)
|
|
216
|
+
put_deprecate_message("#{self}.set_margin_right")
|
|
217
|
+
self.margin_right = margin
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
#
|
|
221
|
+
# this method is deprecated. use margin_top=()
|
|
222
|
+
# Set the top margin in inches.
|
|
223
|
+
#
|
|
224
|
+
def set_margin_top(margin = 0.75)
|
|
225
|
+
put_deprecate_message("#{self}.set_margin_top")
|
|
226
|
+
self.margin_top = margin
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
#
|
|
230
|
+
# this method is deprecated. use margin_bottom=()
|
|
231
|
+
# Set the bottom margin in inches.
|
|
232
|
+
#
|
|
233
|
+
def set_margin_bottom(margin = 0.75)
|
|
234
|
+
put_deprecate_message("#{self}.set_margin_bottom")
|
|
235
|
+
self.margin_bottom = margin
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
#
|
|
239
|
+
# Repeat/print area
|
|
240
|
+
#
|
|
241
|
+
|
|
242
|
+
#
|
|
243
|
+
# Set the number of rows to repeat at the top of each printed page.
|
|
244
|
+
#
|
|
245
|
+
def repeat_rows(row_min, row_max = nil)
|
|
246
|
+
row_max ||= row_min
|
|
247
|
+
|
|
248
|
+
# Convert to 1 based.
|
|
249
|
+
row_min += 1
|
|
250
|
+
row_max += 1
|
|
251
|
+
|
|
252
|
+
area = "$#{row_min}:$#{row_max}"
|
|
253
|
+
|
|
254
|
+
# Build up the print titles "Sheet1!$1:$2"
|
|
255
|
+
sheetname = quote_sheetname(@name)
|
|
256
|
+
@page_setup.repeat_rows = "#{sheetname}!#{area}"
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def print_repeat_rows # :nodoc:
|
|
260
|
+
@page_setup.repeat_rows
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
#
|
|
264
|
+
# :call-seq:
|
|
265
|
+
# repeat_columns(first_col, last_col = nil)
|
|
266
|
+
#
|
|
267
|
+
# Set the columns to repeat at the left hand side of each printed page.
|
|
268
|
+
#
|
|
269
|
+
def repeat_columns(*args)
|
|
270
|
+
if args[0] =~ /^\D/
|
|
271
|
+
_dummy, first_col, _dummy, last_col = substitute_cellref(*args)
|
|
272
|
+
else
|
|
273
|
+
first_col, last_col = args
|
|
274
|
+
end
|
|
275
|
+
last_col ||= first_col
|
|
276
|
+
|
|
277
|
+
area = "#{xl_col_to_name(first_col, 1)}:#{xl_col_to_name(last_col, 1)}"
|
|
278
|
+
@page_setup.repeat_cols = "#{quote_sheetname(@name)}!#{area}"
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def print_repeat_cols # :nodoc:
|
|
282
|
+
@page_setup.repeat_cols
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
#
|
|
286
|
+
# :call-seq:
|
|
287
|
+
# print_area(first_row, first_col, last_row, last_col)
|
|
288
|
+
#
|
|
289
|
+
# This method is used to specify the area of the worksheet that will
|
|
290
|
+
# be printed. All four parameters must be specified. You can also use
|
|
291
|
+
# A1 notation.
|
|
292
|
+
#
|
|
293
|
+
def print_area(*args)
|
|
294
|
+
return @page_setup.print_area.dup if args.empty?
|
|
295
|
+
|
|
296
|
+
if (row_col_array = row_col_notation(args.first))
|
|
297
|
+
row1, col1, row2, col2 = row_col_array
|
|
298
|
+
else
|
|
299
|
+
row1, col1, row2, col2 = args
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
return if [row1, col1, row2, col2].include?(nil)
|
|
303
|
+
|
|
304
|
+
# Ignore max print area since this is the same as no print area for Excel.
|
|
305
|
+
return if row1 == 0 && col1 == 0 && row2 == ROW_MAX - 1 && col2 == COL_MAX - 1
|
|
306
|
+
|
|
307
|
+
# Build up the print area range "=Sheet2!R1C1:R2C1"
|
|
308
|
+
@page_setup.print_area = convert_name_area(row1, col1, row2, col2)
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
#
|
|
312
|
+
# Scale and view
|
|
313
|
+
#
|
|
314
|
+
|
|
315
|
+
#
|
|
316
|
+
# Set the worksheet zoom factor in the range <tt>10 <= scale <= 400</tt>:
|
|
317
|
+
#
|
|
318
|
+
def zoom=(scale)
|
|
319
|
+
# Confine the scale to Excel's range
|
|
320
|
+
@zoom = if scale < 10 || scale > 400
|
|
321
|
+
# carp "Zoom factor scale outside range: 10 <= zoom <= 400"
|
|
322
|
+
100
|
|
323
|
+
else
|
|
324
|
+
scale.to_i
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# This method is deprecated. use zoom=().
|
|
329
|
+
def set_zoom(scale)
|
|
330
|
+
put_deprecate_message("#{self}.set_zoom")
|
|
331
|
+
self.zoom = scale
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
#
|
|
335
|
+
# Set the scale factor of the printed page.
|
|
336
|
+
# Scale factors in the range 10 <= scale <= 400 are valid:
|
|
337
|
+
#
|
|
338
|
+
def print_scale=(scale = 100)
|
|
339
|
+
scale_val = scale.to_i
|
|
340
|
+
# Confine the scale to Excel's range
|
|
341
|
+
scale_val = 100 if scale_val < 10 || scale_val > 400
|
|
342
|
+
|
|
343
|
+
# Turn off "fit to page" option.
|
|
344
|
+
@page_setup.fit_page = false
|
|
345
|
+
|
|
346
|
+
@page_setup.scale = scale_val
|
|
347
|
+
@page_setup.page_setup_changed = true
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
#
|
|
351
|
+
# This method is deprecated. use print_scale=().
|
|
352
|
+
#
|
|
353
|
+
def set_print_scale(scale = 100)
|
|
354
|
+
put_deprecate_message("#{self}.set_print_scale")
|
|
355
|
+
self.print_scale = (scale)
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
#
|
|
359
|
+
# Set the option to print the worksheet in black and white.
|
|
360
|
+
#
|
|
361
|
+
def print_black_and_white
|
|
362
|
+
@page_setup.black_white = true
|
|
363
|
+
@page_setup.page_setup_changed = true
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
#
|
|
367
|
+
# Display the worksheet right to left for some eastern versions of Excel.
|
|
368
|
+
#
|
|
369
|
+
def right_to_left(flag = true)
|
|
370
|
+
@right_to_left = !!flag
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
#
|
|
374
|
+
# Hide cell zero values.
|
|
375
|
+
#
|
|
376
|
+
def hide_zero(flag = true)
|
|
377
|
+
@show_zeros = !flag
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
#
|
|
381
|
+
# Set the paper type. Ex. 1 = US Letter, 9 = A4
|
|
382
|
+
#
|
|
383
|
+
def paper=(paper_size)
|
|
384
|
+
@page_setup.paper = paper_size
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
def set_paper(paper_size)
|
|
388
|
+
put_deprecate_message("#{self}.set_paper")
|
|
389
|
+
self.paper = paper_size
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
#
|
|
393
|
+
# Set the order in which pages are printed.
|
|
394
|
+
#
|
|
395
|
+
def print_across(across = true)
|
|
396
|
+
if across
|
|
397
|
+
@page_setup.across = true
|
|
398
|
+
@page_setup.page_setup_changed = true
|
|
399
|
+
else
|
|
400
|
+
@page_setup.across = false
|
|
401
|
+
end
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
#
|
|
405
|
+
# The start_page=() method is used to set the number of the
|
|
406
|
+
# starting page when the worksheet is printed out.
|
|
407
|
+
#
|
|
408
|
+
def start_page=(page_start)
|
|
409
|
+
@page_setup.page_start = page_start
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
def set_start_page(page_start)
|
|
413
|
+
put_deprecate_message("#{self}.set_start_page")
|
|
414
|
+
self.start_page = page_start
|
|
415
|
+
end
|
|
416
|
+
end
|
|
417
|
+
end
|
|
418
|
+
end
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require 'write_xlsx/utility/common'
|
|
5
|
+
require 'write_xlsx/utility/cell_reference'
|
|
6
|
+
require 'write_xlsx/utility/url'
|
|
7
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
8
|
+
|
|
4
9
|
module Writexlsx
|
|
5
10
|
class Worksheet
|
|
6
11
|
class Hyperlink # :nodoc:
|
|
7
|
-
include Writexlsx::Utility
|
|
12
|
+
include Writexlsx::Utility::Common
|
|
13
|
+
include Writexlsx::Utility::CellReference
|
|
14
|
+
include Writexlsx::Utility::Url
|
|
15
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
8
16
|
|
|
9
17
|
attr_reader :str, :tip
|
|
10
18
|
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Writexlsx
|
|
5
|
+
class Worksheet
|
|
6
|
+
module Initialization
|
|
7
|
+
def setup_identity(workbook, index, name)
|
|
8
|
+
@workbook = workbook
|
|
9
|
+
@index = index
|
|
10
|
+
@name = name
|
|
11
|
+
|
|
12
|
+
@excel_version = 2007
|
|
13
|
+
@palette = workbook.palette
|
|
14
|
+
@default_url_format = workbook.default_url_format
|
|
15
|
+
@max_url_length = workbook.max_url_length
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def setup_limits
|
|
19
|
+
@xls_rowmax = 1_048_576
|
|
20
|
+
@xls_colmax = 16_384
|
|
21
|
+
@xls_strmax = 32_767
|
|
22
|
+
|
|
23
|
+
@dim_rowmin = nil
|
|
24
|
+
@dim_rowmax = nil
|
|
25
|
+
@dim_colmin = nil
|
|
26
|
+
@dim_colmax = nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def setup_dependencies
|
|
30
|
+
@page_setup = Writexlsx::PageSetup.new
|
|
31
|
+
@comments = Package::Comments.new(self)
|
|
32
|
+
@assets = AssetManager.new
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def setup_view_options
|
|
36
|
+
@screen_gridlines = true
|
|
37
|
+
@show_zeros = true
|
|
38
|
+
@hide_row_col_headers = 0
|
|
39
|
+
@top_left_cell = ''
|
|
40
|
+
|
|
41
|
+
@tab_color = 0
|
|
42
|
+
|
|
43
|
+
@zoom = 100
|
|
44
|
+
@zoom_scale_normal = true
|
|
45
|
+
@right_to_left = false
|
|
46
|
+
@leading_zeros = false
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def setup_sheet_geometry
|
|
50
|
+
@outline_row_level = 0
|
|
51
|
+
@outline_col_level = 0
|
|
52
|
+
|
|
53
|
+
@original_row_height = 15
|
|
54
|
+
@default_row_height = 15
|
|
55
|
+
@default_row_pixels = 20
|
|
56
|
+
@default_col_width = 8.43
|
|
57
|
+
@default_date_pixels = 68
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def setup_row_and_column_state
|
|
61
|
+
@col_info = {}
|
|
62
|
+
@cell_data_store = CellDataStore.new
|
|
63
|
+
|
|
64
|
+
@set_cols = {}
|
|
65
|
+
@set_rows = {}
|
|
66
|
+
@row_sizes = {}
|
|
67
|
+
|
|
68
|
+
@col_size_changed = false
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def setup_filter_and_selection_state
|
|
72
|
+
@selections = []
|
|
73
|
+
@panes = []
|
|
74
|
+
|
|
75
|
+
@autofilter_area = nil
|
|
76
|
+
@filter_on = false
|
|
77
|
+
@filter_range = []
|
|
78
|
+
@filter_cols = {}
|
|
79
|
+
@filter_cells = {}
|
|
80
|
+
@filter_type = {}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def setup_drawing_and_media
|
|
84
|
+
@last_shape_id = 1
|
|
85
|
+
@rel_count = 0
|
|
86
|
+
|
|
87
|
+
@external_hyper_links = []
|
|
88
|
+
@external_drawing_links = []
|
|
89
|
+
@external_comment_links = []
|
|
90
|
+
@external_vml_links = []
|
|
91
|
+
@external_background_links = []
|
|
92
|
+
@external_table_links = []
|
|
93
|
+
|
|
94
|
+
@drawing_links = []
|
|
95
|
+
@vml_drawing_links = []
|
|
96
|
+
|
|
97
|
+
@shape_hash = {}
|
|
98
|
+
@drawing_rels = {}
|
|
99
|
+
@drawing_rels_id = 0
|
|
100
|
+
@vml_drawing_rels = {}
|
|
101
|
+
@vml_drawing_rels_id = 0
|
|
102
|
+
|
|
103
|
+
@has_dynamic_functions = false
|
|
104
|
+
@has_embedded_images = false
|
|
105
|
+
@use_future_functions = false
|
|
106
|
+
@has_vml = false
|
|
107
|
+
|
|
108
|
+
@buttons_array = []
|
|
109
|
+
@header_images_array = []
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def setup_cell_features
|
|
113
|
+
@merge = []
|
|
114
|
+
|
|
115
|
+
@validations = []
|
|
116
|
+
@cond_formats = {}
|
|
117
|
+
@data_bars_2010 = []
|
|
118
|
+
@dxf_priority = 1
|
|
119
|
+
|
|
120
|
+
@ignore_errors = nil
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def setup_protection
|
|
124
|
+
@protected_ranges = []
|
|
125
|
+
@num_protected_ranges = 0
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def apply_excel2003_compatibility
|
|
129
|
+
@original_row_height = 12.75
|
|
130
|
+
@default_row_height = 12.75
|
|
131
|
+
@default_row_pixels = 17
|
|
132
|
+
|
|
133
|
+
self.margins_left_right = 0.75
|
|
134
|
+
self.margins_top_bottom = 1
|
|
135
|
+
|
|
136
|
+
@page_setup.margin_header = 0.5
|
|
137
|
+
@page_setup.margin_footer = 0.5
|
|
138
|
+
@page_setup.header_footer_aligns = false
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def setup_workbook_dependent_state
|
|
142
|
+
@embedded_image_indexes = @workbook.embedded_image_indexes
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Writexlsx
|
|
4
|
+
class Worksheet
|
|
5
|
+
# Pane-related operations extracted from Worksheet to slim the main class.
|
|
6
|
+
module Panes
|
|
7
|
+
###############################################################################
|
|
8
|
+
#
|
|
9
|
+
# set_top_left_cell()
|
|
10
|
+
#
|
|
11
|
+
# Set the first visible cell at the top left of the worksheet.
|
|
12
|
+
#
|
|
13
|
+
def set_top_left_cell(row, col = nil)
|
|
14
|
+
if (row_col_array = row_col_notation(row))
|
|
15
|
+
_row, _col = row_col_array
|
|
16
|
+
else
|
|
17
|
+
_row = row
|
|
18
|
+
_col = col
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
@top_left_cell = xl_rowcol_to_cell(_row, _col)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# :call-seq:
|
|
26
|
+
# freeze_panes(row, col [ , top_row, left_col ] )
|
|
27
|
+
#
|
|
28
|
+
# This method can be used to divide a worksheet into horizontal or
|
|
29
|
+
# vertical regions known as panes and to also "freeze" these panes so
|
|
30
|
+
# that the splitter bars are not visible. This is the same as the
|
|
31
|
+
# Window->Freeze Panes menu command in Excel
|
|
32
|
+
#
|
|
33
|
+
def freeze_panes(*args)
|
|
34
|
+
return if args.empty?
|
|
35
|
+
|
|
36
|
+
# Check for a cell reference in A1 notation and substitute row and column.
|
|
37
|
+
if (row_col_array = row_col_notation(args.first))
|
|
38
|
+
row, col, top_row, left_col = row_col_array
|
|
39
|
+
type = args[1]
|
|
40
|
+
else
|
|
41
|
+
row, col, top_row, left_col, type = args
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
col ||= 0
|
|
45
|
+
top_row ||= row
|
|
46
|
+
left_col ||= col
|
|
47
|
+
type ||= 0
|
|
48
|
+
|
|
49
|
+
@panes = [row, col, top_row, left_col, type]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
#
|
|
53
|
+
# :call-seq:
|
|
54
|
+
# split_panes(y, x, top_row, left_col)
|
|
55
|
+
#
|
|
56
|
+
# Set panes and mark them as split.
|
|
57
|
+
#
|
|
58
|
+
def split_panes(*args)
|
|
59
|
+
# Call freeze panes but add the type flag for split panes.
|
|
60
|
+
freeze_panes(args[0], args[1], args[2], args[3], 2)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|