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
data/lib/write_xlsx/formats.rb
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'digest/md5'
|
|
5
|
+
require 'write_xlsx/utility/common'
|
|
5
6
|
|
|
6
7
|
module Writexlsx
|
|
7
8
|
class ImageProperty
|
|
9
|
+
include Utility::Common
|
|
10
|
+
|
|
8
11
|
attr_reader :type, :width, :height, :name, :x_dpi, :y_dpi, :md5
|
|
9
12
|
attr_reader :filename, :description, :decorative
|
|
10
13
|
attr_accessor :ref_id, :body, :position
|
|
@@ -66,7 +69,7 @@ module Writexlsx
|
|
|
66
69
|
y_ppu = data[offset + 12, 4].unpack1("N")
|
|
67
70
|
units = data[offset + 16, 1].unpack1("C")
|
|
68
71
|
|
|
69
|
-
if units == 1
|
|
72
|
+
if units == 1 && ptrue?(x_ppu) && ptrue?(y_ppu)
|
|
70
73
|
@x_dpi = x_ppu * 0.0254
|
|
71
74
|
@y_dpi = y_ppu * 0.0254
|
|
72
75
|
end
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'write_xlsx/utility/cell_reference'
|
|
5
|
+
require 'write_xlsx/utility/chart_formatting'
|
|
6
|
+
require 'write_xlsx/utility/dimensions'
|
|
7
|
+
require 'write_xlsx/utility/date_time'
|
|
8
|
+
require 'write_xlsx/utility/url'
|
|
9
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
10
|
+
require 'write_xlsx/utility/sheetname_quoting'
|
|
11
|
+
|
|
12
|
+
module Writexlsx
|
|
13
|
+
module ObjectPositioning
|
|
14
|
+
include Writexlsx::Utility::CellReference
|
|
15
|
+
include Writexlsx::Utility::ChartFormatting
|
|
16
|
+
include Writexlsx::Utility::Dimensions
|
|
17
|
+
include Writexlsx::Utility::DateTime
|
|
18
|
+
include Writexlsx::Utility::Url
|
|
19
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
20
|
+
include Writexlsx::Utility::SheetnameQuoting
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# Calculate the vertices that define the position of a graphical object
|
|
24
|
+
# within the worksheet in pixels.
|
|
25
|
+
#
|
|
26
|
+
def position_object_pixels(col_start, row_start, x1, y1, width, height, anchor = nil) # :nodoc:
|
|
27
|
+
context = object_positioning_context(anchor)
|
|
28
|
+
|
|
29
|
+
position_object_pixels_with_context(
|
|
30
|
+
col_start, row_start, x1, y1, width, height, context
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
# def position_object_pixels(col_start, row_start, x1, y1, width, height, anchor = nil) # :nodoc:
|
|
34
|
+
# col_start, row_start, x1, y1 =
|
|
35
|
+
# adjust_start_position_for_negative_offsets(col_start, row_start, x1, y1)
|
|
36
|
+
|
|
37
|
+
# x_abs, y_abs =
|
|
38
|
+
# calculate_absolute_position(col_start, row_start, x1, y1, anchor)
|
|
39
|
+
|
|
40
|
+
# col_start, row_start, x1, y1 =
|
|
41
|
+
# adjust_start_position_for_cell_offsets(col_start, row_start, x1, y1, anchor)
|
|
42
|
+
|
|
43
|
+
# col_end, row_end, x2, y2 =
|
|
44
|
+
# calculate_object_end_position(col_start, row_start, x1, y1, width, height, anchor)
|
|
45
|
+
|
|
46
|
+
# [col_start, row_start, x1, y1, col_end, row_end, x2, y2, x_abs, y_abs]
|
|
47
|
+
# end
|
|
48
|
+
|
|
49
|
+
#
|
|
50
|
+
# Calculate the vertices that define the position of a graphical object
|
|
51
|
+
# within the worksheet in EMUs.
|
|
52
|
+
#
|
|
53
|
+
def position_object_emus(graphical_object) # :nodoc:
|
|
54
|
+
object = graphical_object
|
|
55
|
+
col_start, row_start, x1, y1, col_end, row_end, x2, y2, x_abs, y_abs =
|
|
56
|
+
position_object_pixels(
|
|
57
|
+
object.col, object.row, object.x_offset, object.y_offset,
|
|
58
|
+
object.scaled_width, object.scaled_height, object.anchor
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Convert the pixel values to EMUs. See above.
|
|
62
|
+
x1 = (0.5 + (9_525 * x1)).to_i
|
|
63
|
+
y1 = (0.5 + (9_525 * y1)).to_i
|
|
64
|
+
x2 = (0.5 + (9_525 * x2)).to_i
|
|
65
|
+
y2 = (0.5 + (9_525 * y2)).to_i
|
|
66
|
+
x_abs = (0.5 + (9_525 * x_abs)).to_i
|
|
67
|
+
y_abs = (0.5 + (9_525 * y_abs)).to_i
|
|
68
|
+
|
|
69
|
+
[col_start, row_start, x1, y1, col_end, row_end, x2, y2, x_abs, y_abs]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
#
|
|
73
|
+
# Convert the width of a cell from pixels to character units.
|
|
74
|
+
#
|
|
75
|
+
def pixels_to_width(pixels)
|
|
76
|
+
max_digit_width = 7.0
|
|
77
|
+
padding = 5.0
|
|
78
|
+
|
|
79
|
+
if pixels <= 12
|
|
80
|
+
pixels / (max_digit_width + padding)
|
|
81
|
+
else
|
|
82
|
+
(pixels - padding) / max_digit_width
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
#
|
|
87
|
+
# Convert the height of a cell from pixels to character units.
|
|
88
|
+
#
|
|
89
|
+
def pixels_to_height(pixels)
|
|
90
|
+
height = 0.75 * pixels
|
|
91
|
+
height = height.to_i if (height - height.to_i).abs < 0.1
|
|
92
|
+
height
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
private
|
|
96
|
+
|
|
97
|
+
def position_object_pixels_with_context(col_start, row_start, x1, y1, width, height, context)
|
|
98
|
+
col_start, row_start, x1, y1 =
|
|
99
|
+
adjust_start_position_for_negative_offsets(col_start, row_start, x1, y1, context)
|
|
100
|
+
|
|
101
|
+
x_abs, y_abs =
|
|
102
|
+
calculate_absolute_position(col_start, row_start, x1, y1, context)
|
|
103
|
+
|
|
104
|
+
col_start, row_start, x1, y1 =
|
|
105
|
+
adjust_start_position_for_cell_offsets(col_start, row_start, x1, y1, context)
|
|
106
|
+
|
|
107
|
+
col_end, row_end, x2, y2 =
|
|
108
|
+
calculate_object_end_position(col_start, row_start, x1, y1, width, height, context)
|
|
109
|
+
|
|
110
|
+
[col_start, row_start, x1, y1, col_end, row_end, x2, y2, x_abs, y_abs]
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def adjust_start_position_for_negative_offsets(col_start, row_start, x1, y1, context)
|
|
114
|
+
# Adjust start column for negative offsets.
|
|
115
|
+
while x1 < 0 && col_start > 0
|
|
116
|
+
x1 += context[:size_col].call(col_start - 1, 0)
|
|
117
|
+
col_start -= 1
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Adjust start row for negative offsets.
|
|
121
|
+
while y1 < 0 && row_start > 0
|
|
122
|
+
y1 += context[:size_row].call(row_start - 1, 0)
|
|
123
|
+
row_start -= 1
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Ensure that the image isn't shifted off the page at top left.
|
|
127
|
+
x1 = 0 if x1 < 0
|
|
128
|
+
y1 = 0 if y1 < 0
|
|
129
|
+
|
|
130
|
+
[col_start, row_start, x1, y1]
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def calculate_absolute_position(col_start, row_start, x1, y1, context)
|
|
134
|
+
# Calculate the absolute x offset of the top-left vertex.
|
|
135
|
+
x_abs = if context[:col_size_changed]
|
|
136
|
+
(0..(col_start - 1)).inject(0) do |sum, col|
|
|
137
|
+
sum + context[:size_col].call(col, context[:anchor])
|
|
138
|
+
end
|
|
139
|
+
else
|
|
140
|
+
# Optimisation for when the column widths haven't changed.
|
|
141
|
+
context[:default_col_pixels] * col_start
|
|
142
|
+
end
|
|
143
|
+
x_abs += x1
|
|
144
|
+
|
|
145
|
+
# Calculate the absolute y offset of the top-left vertex.
|
|
146
|
+
y_abs = if context[:row_size_changed]
|
|
147
|
+
(0..(row_start - 1)).inject(0) do |sum, row|
|
|
148
|
+
sum + context[:size_row].call(row, context[:anchor])
|
|
149
|
+
end
|
|
150
|
+
else
|
|
151
|
+
# Optimisation for when the row heights haven't changed.
|
|
152
|
+
context[:default_row_pixels] * row_start
|
|
153
|
+
end
|
|
154
|
+
y_abs += y1
|
|
155
|
+
|
|
156
|
+
[x_abs, y_abs]
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def adjust_start_position_for_cell_offsets(col_start, row_start, x1, y1, context)
|
|
160
|
+
# Adjust start column for offsets that are greater than the col width.
|
|
161
|
+
while x1 >= context[:size_col].call(col_start, context[:anchor])
|
|
162
|
+
x1 -= context[:size_col].call(col_start, 0)
|
|
163
|
+
col_start += 1
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Adjust start row for offsets that are greater than the row height.
|
|
167
|
+
while y1 >= context[:size_row].call(row_start, context[:anchor])
|
|
168
|
+
y1 -= context[:size_row].call(row_start, 0)
|
|
169
|
+
row_start += 1
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
[col_start, row_start, x1, y1]
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def calculate_object_end_position(col_start, row_start, x1, y1, width, height, context)
|
|
176
|
+
# Initialise end cell to the same as the start cell.
|
|
177
|
+
col_end = col_start
|
|
178
|
+
row_end = row_start
|
|
179
|
+
|
|
180
|
+
# Only offset the image in the cell if the row/col isn't hidden.
|
|
181
|
+
width += x1 if context[:size_col].call(col_start, context[:anchor]) > 0
|
|
182
|
+
height += y1 if context[:size_row].call(row_start, context[:anchor]) > 0
|
|
183
|
+
|
|
184
|
+
# Subtract the underlying cell widths to find the end cell of the object.
|
|
185
|
+
while width >= context[:size_col].call(col_end, context[:anchor])
|
|
186
|
+
width -= context[:size_col].call(col_end, context[:anchor])
|
|
187
|
+
col_end += 1
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Subtract the underlying cell heights to find the end cell of the object.
|
|
191
|
+
while height >= context[:size_row].call(row_end, context[:anchor])
|
|
192
|
+
height -= context[:size_row].call(row_end, context[:anchor])
|
|
193
|
+
row_end += 1
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# The end vertices are whatever is left from the width and height.
|
|
197
|
+
x2 = width
|
|
198
|
+
y2 = height
|
|
199
|
+
|
|
200
|
+
[col_end, row_end, x2, y2]
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
9
9
|
class App
|
|
10
|
-
include Writexlsx::Utility
|
|
10
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
11
11
|
|
|
12
12
|
attr_writer :doc_security
|
|
13
13
|
|
|
@@ -62,7 +62,7 @@ module Writexlsx
|
|
|
62
62
|
@workbook.worksheets
|
|
63
63
|
.reject { |sheet| sheet.is_chartsheet? || sheet.very_hidden? }
|
|
64
64
|
.each do |sheet|
|
|
65
|
-
|
|
65
|
+
add_part_name(sheet.name)
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require 'write_xlsx/utility'
|
|
4
|
+
require 'write_xlsx/utility/common'
|
|
5
|
+
require 'write_xlsx/utility/string_width'
|
|
6
|
+
require 'write_xlsx/utility/drawing'
|
|
5
7
|
|
|
6
8
|
module Writexlsx
|
|
7
9
|
module Package
|
|
8
10
|
class Button
|
|
9
|
-
include Writexlsx::Utility
|
|
11
|
+
include Writexlsx::Utility::Common
|
|
12
|
+
include Writexlsx::Utility::StringWidth
|
|
13
|
+
include Writexlsx::Utility::Drawing
|
|
10
14
|
|
|
11
15
|
def initialize(worksheet, row, col, params, default_row_pixels, button_number)
|
|
12
16
|
@worksheet = worksheet
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require 'write_xlsx/constants'
|
|
4
5
|
require 'write_xlsx/format'
|
|
5
6
|
require 'write_xlsx/package/xml_writer_simple'
|
|
6
|
-
require 'write_xlsx/utility'
|
|
7
|
+
require 'write_xlsx/utility/common'
|
|
8
|
+
require 'write_xlsx/utility/cell_reference'
|
|
9
|
+
require 'write_xlsx/utility/drawing'
|
|
7
10
|
|
|
8
11
|
module Writexlsx
|
|
9
12
|
module Package
|
|
10
13
|
class Comment
|
|
11
|
-
include
|
|
14
|
+
include Constants
|
|
15
|
+
include Writexlsx::Utility::Common
|
|
16
|
+
include Writexlsx::Utility::CellReference
|
|
17
|
+
include Writexlsx::Utility::Drawing
|
|
12
18
|
|
|
13
19
|
DEFAULT_COLOR = 81 # what color ?
|
|
14
20
|
DEFAULT_WIDTH = 128
|
|
@@ -243,7 +249,9 @@ module Writexlsx
|
|
|
243
249
|
end
|
|
244
250
|
|
|
245
251
|
class Comments
|
|
246
|
-
include Writexlsx::Utility
|
|
252
|
+
include Writexlsx::Utility::Common
|
|
253
|
+
include Writexlsx::Utility::CellReference
|
|
254
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
247
255
|
|
|
248
256
|
def initialize(worksheet)
|
|
249
257
|
@worksheet = worksheet
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
module Writexlsx
|
|
5
5
|
module Package
|
|
6
6
|
class ConditionalFormat
|
|
7
|
-
include Writexlsx::Utility
|
|
7
|
+
include Writexlsx::Utility::Common
|
|
8
|
+
include Writexlsx::Utility::CellReference
|
|
9
|
+
include Writexlsx::Utility::Dimensions
|
|
10
|
+
include Writexlsx::Utility::DateTime
|
|
11
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
8
12
|
|
|
9
13
|
def self.factory(worksheet, *args)
|
|
10
14
|
range, param =
|
|
@@ -481,7 +485,7 @@ module Writexlsx
|
|
|
481
485
|
param[:criteria] = valid_criteria_type_for_conditional_formatting[param[:criteria].downcase] if param.has_key?(:criteria) && valid_criteria_type_for_conditional_formatting.has_key?(param[:criteria].downcase)
|
|
482
486
|
|
|
483
487
|
# Convert date/times value if required.
|
|
484
|
-
if %w[date time
|
|
488
|
+
if %w[date time].include?(param[:type])
|
|
485
489
|
param[:type] = 'cellIs'
|
|
486
490
|
|
|
487
491
|
param[:value] = convert_date_time_if_required(param[:value])
|
|
@@ -744,7 +748,7 @@ module Writexlsx
|
|
|
744
748
|
quoted_value = value.to_s
|
|
745
749
|
numeric_regex = /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
|
|
746
750
|
# String "Cell" values must be quoted, apart from ranges.
|
|
747
|
-
if !(quoted_value =~
|
|
751
|
+
if !(quoted_value =~ /^(\$?)([A-Z]{1,3})(\$?)(\d+)/) &&
|
|
748
752
|
!(quoted_value =~ numeric_regex) &&
|
|
749
753
|
!(quoted_value =~ /^".*"$/)
|
|
750
754
|
quoted_value = %("#{value}")
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
9
9
|
class ContentTypes
|
|
10
|
-
include Writexlsx::Utility
|
|
10
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
11
11
|
|
|
12
12
|
App_package = 'application/vnd.openxmlformats-package.'
|
|
13
13
|
App_document = 'application/vnd.openxmlformats-officedocument.'
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
9
9
|
class Core
|
|
10
|
-
include Writexlsx::Utility
|
|
10
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
11
11
|
|
|
12
12
|
App_package = 'application/vnd.openxmlformats-package.'
|
|
13
13
|
App_document = 'application/vnd.openxmlformats-officedocument.'
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
9
9
|
class Custom
|
|
10
|
-
include Writexlsx::Utility
|
|
10
|
+
include Writexlsx::Utility::Common
|
|
11
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
11
12
|
|
|
12
13
|
def initialize
|
|
13
14
|
@writer = Package::XMLWriterSimple.new
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
@@ -10,7 +10,7 @@ module Writexlsx
|
|
|
10
10
|
# Metadata - A class for writing the Excel XLSX metadata.xml file.
|
|
11
11
|
#
|
|
12
12
|
class Metadata
|
|
13
|
-
include Writexlsx::Utility
|
|
13
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
14
14
|
|
|
15
15
|
attr_writer :has_dynamic_functions
|
|
16
16
|
attr_writer :num_embedded_images
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
6
5
|
require 'write_xlsx/package/app'
|
|
7
6
|
require 'write_xlsx/package/comments'
|
|
8
7
|
require 'write_xlsx/package/content_types'
|
|
@@ -23,8 +22,6 @@ require 'write_xlsx/package/vml'
|
|
|
23
22
|
module Writexlsx
|
|
24
23
|
module Package
|
|
25
24
|
class Packager
|
|
26
|
-
include Writexlsx::Utility
|
|
27
|
-
|
|
28
25
|
def initialize(workbook)
|
|
29
26
|
@workbook = workbook
|
|
30
27
|
@package_dir = ''
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
9
9
|
class Relationships
|
|
10
|
-
include Writexlsx::Utility
|
|
10
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
11
11
|
|
|
12
12
|
Schema_root = 'http://schemas.openxmlformats.org'
|
|
13
13
|
Package_schema = Schema_root + '/package/2006/relationships'
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/common'
|
|
6
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
7
|
|
|
7
8
|
module Writexlsx
|
|
8
9
|
module Package
|
|
9
10
|
class RichValue
|
|
10
|
-
include Writexlsx::Utility
|
|
11
|
+
include Writexlsx::Utility::Common
|
|
12
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
11
13
|
|
|
12
14
|
attr_accessor :embedded_images
|
|
13
15
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
@@ -16,7 +16,7 @@ module Writexlsx
|
|
|
16
16
|
# Convert to Ruby by Hideo Nakamura, nakamura.hideo@gmail.com
|
|
17
17
|
#
|
|
18
18
|
class RichValueRel
|
|
19
|
-
include Writexlsx::Utility
|
|
19
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
20
20
|
|
|
21
21
|
attr_writer :value_count
|
|
22
22
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
@@ -17,7 +17,7 @@ module Writexlsx
|
|
|
17
17
|
# Convert to Ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
|
18
18
|
#
|
|
19
19
|
class RichValueStructure
|
|
20
|
-
include Writexlsx::Utility
|
|
20
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
21
21
|
|
|
22
22
|
attr_writer :has_embedded_descriptions
|
|
23
23
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
@@ -16,10 +16,10 @@ module Writexlsx
|
|
|
16
16
|
# Convert to Ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
|
17
17
|
#
|
|
18
18
|
class RichValueTypes
|
|
19
|
-
include Writexlsx::Utility
|
|
19
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
20
20
|
|
|
21
21
|
def initialize
|
|
22
|
-
@writer
|
|
22
|
+
@writer = Package::XMLWriterSimple.new
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def set_xml_writer(filename)
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
9
9
|
class SharedStrings
|
|
10
|
-
include Writexlsx::Utility
|
|
10
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
11
11
|
|
|
12
12
|
PRESERVE_SPACE_ATTRIBUTES = ['xml:space', 'preserve'].freeze
|
|
13
13
|
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/common'
|
|
6
|
+
require 'write_xlsx/utility/chart_formatting'
|
|
7
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
8
|
|
|
7
9
|
module Writexlsx
|
|
8
10
|
module Package
|
|
9
11
|
class Styles
|
|
10
|
-
include Writexlsx::Utility
|
|
12
|
+
include Writexlsx::Utility::Common
|
|
13
|
+
include Writexlsx::Utility::ChartFormatting
|
|
14
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
11
15
|
|
|
12
16
|
def initialize
|
|
13
17
|
@writer = Package::XMLWriterSimple.new
|
|
@@ -247,7 +251,7 @@ module Writexlsx
|
|
|
247
251
|
def write_fill(format, dxf_format = nil)
|
|
248
252
|
# Special handling for pattern only case.
|
|
249
253
|
if pattern_only_case?(format, dxf_format)
|
|
250
|
-
write_default_fill(PATTERNS[format.pattern])
|
|
254
|
+
write_default_fill(PATTERNS[format.fill_style.pattern])
|
|
251
255
|
else
|
|
252
256
|
@writer.tag_elements('fill') do
|
|
253
257
|
write_fill_base(format, dxf_format)
|
|
@@ -258,15 +262,15 @@ module Writexlsx
|
|
|
258
262
|
def pattern_only_case?(format, dxf_format)
|
|
259
263
|
bg_color, fg_color = bg_and_fg_color(format, dxf_format)
|
|
260
264
|
|
|
261
|
-
!ptrue?(fg_color) && !ptrue?(bg_color) && ptrue?(format.pattern)
|
|
265
|
+
!ptrue?(fg_color) && !ptrue?(bg_color) && ptrue?(format.fill_style.pattern)
|
|
262
266
|
end
|
|
263
267
|
|
|
264
268
|
def write_fill_base(format, dxf_format)
|
|
265
269
|
# The "none" pattern is handled differently for dxf formats.
|
|
266
|
-
attributes = if dxf_format && format.pattern <= 1
|
|
270
|
+
attributes = if dxf_format && format.fill_style.pattern <= 1
|
|
267
271
|
[]
|
|
268
272
|
else
|
|
269
|
-
[['patternType', PATTERNS[format.pattern]]]
|
|
273
|
+
[['patternType', PATTERNS[format.fill_style.pattern]]]
|
|
270
274
|
end
|
|
271
275
|
|
|
272
276
|
@writer.tag_elements('patternFill', attributes) do
|
|
@@ -285,14 +289,14 @@ module Writexlsx
|
|
|
285
289
|
if bg_color != 0x40 # 'Automatic'
|
|
286
290
|
@writer.empty_tag('bgColor', [['rgb', palette_color(bg_color)]])
|
|
287
291
|
end
|
|
288
|
-
elsif !dxf_format && format.pattern <= 1
|
|
292
|
+
elsif !dxf_format && format.fill_style.pattern <= 1
|
|
289
293
|
@writer.empty_tag('bgColor', [['indexed', 64]])
|
|
290
294
|
end
|
|
291
295
|
end
|
|
292
296
|
|
|
293
297
|
def bg_and_fg_color(format, dxf_format)
|
|
294
|
-
bg_color = format.bg_color
|
|
295
|
-
fg_color = format.fg_color
|
|
298
|
+
bg_color = format.fill_style.bg_color
|
|
299
|
+
fg_color = format.fill_style.fg_color
|
|
296
300
|
|
|
297
301
|
# Colors for dxf formats are handled differently from normal formats since
|
|
298
302
|
# the normal format reverses the meaning of BG and FG for solid fills.
|
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/common'
|
|
6
|
+
require 'write_xlsx/utility/cell_reference'
|
|
7
|
+
require 'write_xlsx/utility/dimensions'
|
|
8
|
+
require 'write_xlsx/utility/xml_primitives'
|
|
6
9
|
|
|
7
10
|
module Writexlsx
|
|
8
11
|
module Package
|
|
9
12
|
class Table
|
|
10
|
-
include Writexlsx::Utility
|
|
13
|
+
include Writexlsx::Utility::Common
|
|
14
|
+
include Writexlsx::Utility::CellReference
|
|
15
|
+
include Writexlsx::Utility::Dimensions
|
|
16
|
+
include Writexlsx::Utility::XmlPrimitives
|
|
11
17
|
|
|
12
18
|
class ColumnData
|
|
13
19
|
attr_reader :id
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require 'write_xlsx/package/xml_writer_simple'
|
|
5
|
-
require 'write_xlsx/utility'
|
|
5
|
+
require 'write_xlsx/utility/drawing'
|
|
6
6
|
|
|
7
7
|
module Writexlsx
|
|
8
8
|
module Package
|
|
9
9
|
class Vml
|
|
10
|
-
include Writexlsx::Utility
|
|
10
|
+
include Writexlsx::Utility::Drawing
|
|
11
11
|
|
|
12
12
|
def initialize
|
|
13
13
|
@writer = Package::XMLWriterSimple.new
|