xlsxrb 0.2.0 → 0.2.1
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/CHANGELOG.md +37 -0
- data/README.md +1 -1
- data/lib/xlsxrb/dsl_helpers.rb +49 -1
- data/lib/xlsxrb/elements/worksheet.rb +2 -2
- data/lib/xlsxrb/ooxml/utils.rb +13 -0
- data/lib/xlsxrb/ooxml/workbook_writer.rb +13 -2
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +302 -228
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +11 -4
- data/lib/xlsxrb/ooxml/writer.rb +1 -1
- data/lib/xlsxrb/ooxml/xml_builder.rb +18 -0
- data/lib/xlsxrb/stream_row.rb +2 -2
- data/lib/xlsxrb/stream_writer.rb +203 -80
- data/lib/xlsxrb/style_builder.rb +339 -0
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +239 -88
- data/lib/xlsxrb/worksheet_builder.rb +841 -134
- data/lib/xlsxrb.rb +19 -0
- data/sig/generated/xlsxrb/dsl_helpers.rbs +28 -0
- data/sig/generated/xlsxrb/ooxml/utils.rbs +10 -0
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +5 -0
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +53 -0
- data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/xml_builder.rbs +12 -0
- data/sig/generated/xlsxrb/stream_row.rbs +2 -2
- data/sig/generated/xlsxrb/stream_writer.rbs +40 -4
- data/sig/generated/xlsxrb/style_builder.rbs +261 -0
- data/sig/generated/xlsxrb/workbook_builder.rbs +42 -9
- data/sig/generated/xlsxrb/worksheet_builder.rbs +615 -3
- data/sig/generated/xlsxrb.rbs +15 -0
- metadata +1 -1
data/lib/xlsxrb.rb
CHANGED
|
@@ -77,6 +77,21 @@ module Xlsxrb
|
|
|
77
77
|
# Base class for all exceptions raised by Xlsxrb.
|
|
78
78
|
class Error < StandardError; end
|
|
79
79
|
|
|
80
|
+
# @api private
|
|
81
|
+
module Deprecation
|
|
82
|
+
LIB_DIR = File.expand_path(__dir__).freeze
|
|
83
|
+
private_constant :LIB_DIR
|
|
84
|
+
|
|
85
|
+
# Warns that a feature is deprecated, at the location +uplevel+ frames above the caller,
|
|
86
|
+
# or, with +uplevel: nil+, at the first caller outside this library, for methods that
|
|
87
|
+
# are reached both directly and through another xlsxrb method.
|
|
88
|
+
#: (String message, ?uplevel: Integer?) -> void
|
|
89
|
+
def self.warn(message, uplevel: 1)
|
|
90
|
+
uplevel ||= caller_locations(1)&.index { |location| !location.absolute_path.to_s.start_with?(LIB_DIR) } || 0
|
|
91
|
+
Kernel.warn("[Xlsxrb DEPRECATION] #{message}", uplevel: uplevel + 1)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
80
95
|
# Raised when parsing malformed or invalid XML structures.
|
|
81
96
|
class ParseError < Error; end
|
|
82
97
|
|
|
@@ -1258,6 +1273,10 @@ module Xlsxrb
|
|
|
1258
1273
|
# end
|
|
1259
1274
|
# end
|
|
1260
1275
|
#
|
|
1276
|
+
# @note Planned for version 0.3.0: Cell#format_code of the built cells will be the
|
|
1277
|
+
# number format of each cell's resolved style, as in a loaded workbook; cells styled
|
|
1278
|
+
# :default or :none will have style index 0; and a style index given in cell_styles
|
|
1279
|
+
# will be kept only in Cell#style_index.
|
|
1261
1280
|
# @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel specification limits.
|
|
1262
1281
|
# @param default_font [Hash, nil] Optional default font options.
|
|
1263
1282
|
# @yield [builder]
|
|
@@ -83,9 +83,24 @@ module Xlsxrb
|
|
|
83
83
|
#
|
|
84
84
|
# @param styles [untyped]
|
|
85
85
|
# @return [untyped]
|
|
86
|
+
# @raise [ArgumentError] If the Hash looks like an inline style rather than columns mapped to styles.
|
|
86
87
|
# : (untyped styles) -> untyped
|
|
87
88
|
def self.normalize_row_styles: (untyped styles) -> untyped
|
|
88
89
|
|
|
90
|
+
# Hint for a cell_styles Hash that reads like an inline style.
|
|
91
|
+
INLINE_CELL_STYLES_HINT: ::String
|
|
92
|
+
|
|
93
|
+
# Raises when an entry of a cell_styles Hash cannot be a column mapped to a style:
|
|
94
|
+
# a style option name as the key (a column name has at most three letters), or a
|
|
95
|
+
# value that is not a style name, a style index, an inline style, or nil.
|
|
96
|
+
#
|
|
97
|
+
# @param column [Object] The entry's key.
|
|
98
|
+
# @param style [Object] The entry's value.
|
|
99
|
+
# @return [void]
|
|
100
|
+
# @raise [ArgumentError]
|
|
101
|
+
# : (untyped column, untyped style) -> void
|
|
102
|
+
def self.check_column_style!: (untyped column, untyped style) -> void
|
|
103
|
+
|
|
89
104
|
# Style names that select the workbook's default cell format.
|
|
90
105
|
DEFAULT_STYLE_NAMES: untyped
|
|
91
106
|
|
|
@@ -260,6 +275,19 @@ module Xlsxrb
|
|
|
260
275
|
|
|
261
276
|
MAX_SHEET_NAME_LENGTH: ::Integer
|
|
262
277
|
|
|
278
|
+
MAX_CELL_TEXT_LENGTH: ::Integer
|
|
279
|
+
|
|
280
|
+
# Raises ArgumentError if +text+ is longer than a cell holds: 32,767 UTF-16 code units,
|
|
281
|
+
# as Excel counts it (ADR 0011). Text of N UTF-16 code units has at least N bytes, so
|
|
282
|
+
# callers on hot paths call this only for text longer than MAX_CELL_TEXT_LENGTH bytes,
|
|
283
|
+
# which bytesize tells in O(1).
|
|
284
|
+
#
|
|
285
|
+
# @param text [String]
|
|
286
|
+
# @return [void]
|
|
287
|
+
# @raise [ArgumentError]
|
|
288
|
+
# : (String text) -> void
|
|
289
|
+
def self.check_cell_text_length!: (String text) -> void
|
|
290
|
+
|
|
263
291
|
# Sanitizes a worksheet name to ensure it conforms to Excel constraints within 31 characters.
|
|
264
292
|
# Replaces forbidden characters (\ / ? * [ ] : and control characters),
|
|
265
293
|
# replaces leading/trailing apostrophes, and replaces reserved 'History' with 'History_'.
|
|
@@ -34,6 +34,16 @@ module Xlsxrb
|
|
|
34
34
|
# Default date-time format code used by Writer for Time cells.
|
|
35
35
|
DEFAULT_DATETIME_FORMAT: ::String
|
|
36
36
|
|
|
37
|
+
# First bytes of the four-byte UTF-8 sequences, which encode the characters outside
|
|
38
|
+
# the Basic Multilingual Plane: two UTF-16 code units each.
|
|
39
|
+
SUPPLEMENTARY_LEAD_BYTES: untyped
|
|
40
|
+
|
|
41
|
+
# The length of UTF-8 text in UTF-16 code units, the unit Excel counts its text
|
|
42
|
+
# limits in (ADR 0011): one per character, and one more for each character outside
|
|
43
|
+
# the Basic Multilingual Plane, such as an emoji.
|
|
44
|
+
# : (String text) -> Integer
|
|
45
|
+
def self.utf16_length: (String text) -> Integer
|
|
46
|
+
|
|
37
47
|
# Checks whether a serial number is a valid Excel date within the supported range.
|
|
38
48
|
# : (untyped serial, ?date1904: bool) -> bool
|
|
39
49
|
def self.valid_excel_date?: (untyped serial, ?date1904: bool) -> bool
|
|
@@ -90,6 +90,11 @@ module Xlsxrb
|
|
|
90
90
|
|
|
91
91
|
def escape_xml: (untyped value) -> untyped
|
|
92
92
|
|
|
93
|
+
# Escapes cell text: encodes it as ST_Xstring (XmlBuilder.encode_xstring), so that
|
|
94
|
+
# text that looks like _xHHHH_ and characters XML 1.0 cannot hold are read back as
|
|
95
|
+
# written, then escapes the XML special characters.
|
|
96
|
+
def escape_text: (untyped value) -> untyped
|
|
97
|
+
|
|
93
98
|
def write_shared_strings_xml: (untyped zip) -> untyped
|
|
94
99
|
|
|
95
100
|
def write_worksheet_xml: (untyped io, untyped sheet, ?drawing_rid: untyped, ?picture_rid: untyped, ?sheet_protection: untyped, ?protected_ranges: untyped, ?auto_filter: untyped, ?filter_columns: untyped, ?sort_state: untyped, ?merge_cells: untyped, ?conditional_formats: untyped, ?data_validations: untyped, ?hyperlinks: untyped, ?print_options: untyped, ?page_margins: untyped, ?page_setup: untyped, ?header_footer: untyped, ?row_breaks: untyped, ?col_breaks: untyped, ?column_breaks: untyped, ?cell_watches: untyped, ?ignored_errors: untyped, ?freeze_pane: untyped, ?split_pane: untyped, ?selection: untyped, ?sheet_view: untyped, ?sheet_properties: untyped, ?sheet_format: untyped, ?tables: untyped, ?table_start_rid: untyped, ?legacy_drawing_rid: untyped, ?sparkline_groups: untyped, ?phonetic_pr: untyped, ?sheet_calc_pr: untyped) -> untyped
|
|
@@ -13,10 +13,43 @@ module Xlsxrb
|
|
|
13
13
|
|
|
14
14
|
INTEGER_STRINGS: untyped
|
|
15
15
|
|
|
16
|
+
# Matches a value that claims to be a Time through is_a? without being one, such as
|
|
17
|
+
# ActiveSupport::TimeWithZone, which `when Time` does not match. The writers try it
|
|
18
|
+
# after their Time and Date branches, so other values never reach it. Such a value
|
|
19
|
+
# is written as the Time that to_time gives.
|
|
20
|
+
# @api private
|
|
21
|
+
module TimeLike
|
|
22
|
+
# : (untyped value) -> bool
|
|
23
|
+
def self.===: (untyped value) -> bool
|
|
24
|
+
|
|
25
|
+
# A Time with the value's year, month, day, hour, minute, second, and UTC offset,
|
|
26
|
+
# which keeps its wall clock.
|
|
27
|
+
# : (untyped value) -> Time
|
|
28
|
+
def self.to_time: (untyped value) -> Time
|
|
29
|
+
end
|
|
30
|
+
|
|
16
31
|
def initialize: (untyped io, ?date1904: untyped) -> untyped
|
|
17
32
|
|
|
33
|
+
# Makes the row writers reject text longer than a cell holds (32,767 characters),
|
|
34
|
+
# as the strict Excel mode of the caller asks.
|
|
35
|
+
# @api private
|
|
36
|
+
# : (bool strict) -> void
|
|
37
|
+
def strict_excel_mode=: (bool strict) -> void
|
|
38
|
+
|
|
39
|
+
# Sets what gives the style id for a Time-like value in a styled cell, so that a
|
|
40
|
+
# style without a number format can be given its date-time variant.
|
|
41
|
+
# @api private
|
|
42
|
+
# : (untyped resolver) -> void
|
|
43
|
+
attr_writer time_like_style_resolver: untyped
|
|
44
|
+
|
|
18
45
|
def set_column_style: (untyped col_index, untyped style_id) -> untyped
|
|
19
46
|
|
|
47
|
+
# Drops the resolved column style ids, for a caller that changed the style id a
|
|
48
|
+
# name in the style map stands for.
|
|
49
|
+
# @api private
|
|
50
|
+
# : () -> void
|
|
51
|
+
def forget_column_style_ids: () -> void
|
|
52
|
+
|
|
20
53
|
# Write the worksheet header. Call once before writing rows.
|
|
21
54
|
# Options for pre-sheetData elements:
|
|
22
55
|
# sheet_properties: Hash of sheet-level properties (:tab_color, etc.)
|
|
@@ -38,6 +71,21 @@ module Xlsxrb
|
|
|
38
71
|
|
|
39
72
|
private
|
|
40
73
|
|
|
74
|
+
# Writes the cells of a row that has cell styles, row attributes, or column styles.
|
|
75
|
+
# It is not inlined in write_row_values because YJIT ran the same loop there about
|
|
76
|
+
# 1.6 times slower, after the row attribute handling.
|
|
77
|
+
def write_styled_cells: (untyped buf, untyped values, untyped max_len, untyped row_num_str, untyped styles, untyped is_styles_collection, untyped single_style_id, untyped row_style_id, untyped style_map, untyped sst, untyped sst_index) -> untyped
|
|
78
|
+
|
|
79
|
+
# The style id of each column style, indexed by column, resolved once instead of
|
|
80
|
+
# for every cell. It is resolved again when the style map is another Hash, or after
|
|
81
|
+
# set_column_style or forget_column_style_ids.
|
|
82
|
+
# : (Hash[untyped, Integer]? style_map) -> Array[Integer?]
|
|
83
|
+
def column_style_ids: (Hash[untyped, Integer]? style_map) -> Array[Integer?]
|
|
84
|
+
|
|
85
|
+
# Writes a cell for write_styled_cells whose value is a formula, rich text, BigDecimal,
|
|
86
|
+
# cell error, or another value that write_styled_cells does not write itself.
|
|
87
|
+
def write_complex_cell: (untyped buf, untyped col_ref, untyped row_num_str, untyped value, untyped style_id, untyped sst, untyped sst_index) -> untyped
|
|
88
|
+
|
|
41
89
|
def resolve_style_id: (untyped style, untyped style_map) -> untyped
|
|
42
90
|
|
|
43
91
|
def write_sheet_properties: (untyped props) -> untyped
|
|
@@ -116,6 +164,11 @@ module Xlsxrb
|
|
|
116
164
|
ESCAPE_MAP: untyped
|
|
117
165
|
|
|
118
166
|
def escape_xml: (untyped value) -> untyped
|
|
167
|
+
|
|
168
|
+
# Escapes cell text: encodes it as ST_Xstring (XmlBuilder.encode_xstring), so that
|
|
169
|
+
# text that looks like _xHHHH_ and characters XML 1.0 cannot hold are read back as
|
|
170
|
+
# written, then escapes the XML special characters.
|
|
171
|
+
def escape_text: (untyped value) -> untyped
|
|
119
172
|
end
|
|
120
173
|
end
|
|
121
174
|
end
|
|
@@ -40,6 +40,9 @@ module Xlsxrb
|
|
|
40
40
|
def build_line_end_xml: (untyped element, untyped opts) -> untyped
|
|
41
41
|
|
|
42
42
|
# : (untyped value) -> untyped
|
|
43
|
+
# Escapes cell text: ST_Xstring (XmlBuilder.encode_xstring), then XML.
|
|
44
|
+
def xml_escape_text: (untyped value) -> untyped
|
|
45
|
+
|
|
43
46
|
def xml_escape: (untyped value) -> untyped
|
|
44
47
|
|
|
45
48
|
# : (untyped rich_text) -> untyped
|
|
@@ -46,6 +46,18 @@ module Xlsxrb
|
|
|
46
46
|
# : (untyped value) -> String
|
|
47
47
|
def self.escape: (untyped value) -> String
|
|
48
48
|
|
|
49
|
+
XSTRING_ENCODE_RE: ::Regexp
|
|
50
|
+
|
|
51
|
+
# Encodes cell text as ISO/IEC 29500-1 ST_Xstring, the inverse of the _xHHHH_ part
|
|
52
|
+
# of unescape: an underscore that starts an _xHHHH_ sequence becomes _x005F_, and a
|
|
53
|
+
# character that XML 1.0 cannot hold, such as U+0001 or U+FFFE, becomes _xHHHH_.
|
|
54
|
+
# Excel and unescape read the original text back. The value must be UTF-8.
|
|
55
|
+
#
|
|
56
|
+
# @param value [String]
|
|
57
|
+
# @return [String]
|
|
58
|
+
# : (String value) -> String
|
|
59
|
+
def self.encode_xstring: (String value) -> String
|
|
60
|
+
|
|
49
61
|
NUM_ENTITY_RE: ::Regexp
|
|
50
62
|
|
|
51
63
|
XSTRING_RE: ::Regexp
|
|
@@ -9,9 +9,9 @@ module Xlsxrb
|
|
|
9
9
|
# puts "#{cell.ref}: #{cell.value}"
|
|
10
10
|
# end
|
|
11
11
|
#
|
|
12
|
-
# @example Random access or
|
|
12
|
+
# @example Random access or the row's values (cached on-demand)
|
|
13
13
|
# cell = row[0]
|
|
14
|
-
# values = row.
|
|
14
|
+
# values = row.values
|
|
15
15
|
#
|
|
16
16
|
# @api public
|
|
17
17
|
class StreamRow
|
|
@@ -110,6 +110,8 @@ module Xlsxrb
|
|
|
110
110
|
# @yield [style_builder]
|
|
111
111
|
# @yieldparam style_builder [Xlsxrb::StyleBuilder]
|
|
112
112
|
# @return [StyleBuilder]
|
|
113
|
+
# Using the returned value is deprecated and warns; in version 0.3.0, this method
|
|
114
|
+
# will return nil. Configure the style with options or in the block.
|
|
113
115
|
# : (String | Symbol name, **untyped opts) ?{ (StyleBuilder) -> void } -> StyleBuilder
|
|
114
116
|
def style: (String | Symbol name, **untyped opts) ?{ (StyleBuilder) -> void } -> StyleBuilder
|
|
115
117
|
|
|
@@ -1029,6 +1031,13 @@ module Xlsxrb
|
|
|
1029
1031
|
# @api public
|
|
1030
1032
|
# : (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
|
|
1031
1033
|
def sheet_calc_properties=: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
|
|
1034
|
+
|
|
1035
|
+
private
|
|
1036
|
+
|
|
1037
|
+
# The error for writing through a proxy whose sheet is not the current sheet: an
|
|
1038
|
+
# earlier sheet, or a sheet that was never created.
|
|
1039
|
+
# : () -> Error
|
|
1040
|
+
def inactive_sheet_error: () -> Error
|
|
1032
1041
|
end
|
|
1033
1042
|
|
|
1034
1043
|
# Returns the list of worksheet names created in this workbook so far.
|
|
@@ -1052,8 +1061,13 @@ module Xlsxrb
|
|
|
1052
1061
|
# : (?String? name, ?state: Symbol | String | nil, ?tab_color: String | Hash[Symbol, untyped] | Symbol | nil, ?code_name: String | Symbol | nil, **untyped opts) ?{ (WorksheetProxy) -> void } -> String
|
|
1053
1062
|
def sheet: (?String? name, ?state: Symbol | String | nil, ?tab_color: String | Hash[Symbol, untyped] | Symbol | nil, ?code_name: String | Symbol | nil, **untyped opts) ?{ (WorksheetProxy) -> void } -> String
|
|
1054
1063
|
|
|
1064
|
+
UNKNOWN_SHEET_MESSAGE: ::String
|
|
1065
|
+
|
|
1055
1066
|
# Returns a WorksheetProxy for the current or named sheet.
|
|
1056
1067
|
#
|
|
1068
|
+
# Looking up a sheet that does not exist is deprecated and warns; in version 0.3.0 it
|
|
1069
|
+
# will raise ArgumentError.
|
|
1070
|
+
#
|
|
1057
1071
|
# @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
|
|
1058
1072
|
# @yield [proxy]
|
|
1059
1073
|
# @yieldparam proxy [WorksheetProxy]
|
|
@@ -1998,10 +2012,32 @@ module Xlsxrb
|
|
|
1998
2012
|
# : (untyped cell_styles) -> void
|
|
1999
2013
|
def check_style_names!: (untyped cell_styles) -> void
|
|
2000
2014
|
|
|
2001
|
-
#
|
|
2002
|
-
#
|
|
2003
|
-
#
|
|
2004
|
-
|
|
2015
|
+
# Raises ArgumentError if +name+ is a style name that has not been defined. Defined
|
|
2016
|
+
# names return before DslHelpers.check_style_name!, whose Symbol#to_s allocates a
|
|
2017
|
+
# String for every styled cell.
|
|
2018
|
+
# : (untyped name) -> void
|
|
2019
|
+
def check_style_name!: (untyped name) -> void
|
|
2020
|
+
|
|
2021
|
+
LATE_SHEET_SETTING_MESSAGE: ::String
|
|
2022
|
+
|
|
2023
|
+
# Warns when a setting that StreamWriter writes at the start of the sheet comes after
|
|
2024
|
+
# rows (or skipped rows) of the sheet. ADR 0010 makes it an error in 0.3.0.
|
|
2025
|
+
# : (String name) -> void
|
|
2026
|
+
def warn_late_sheet_setting: (String name) -> void
|
|
2027
|
+
|
|
2028
|
+
# The style id for a Time-like value (see Ooxml::WorksheetWriter::TimeLike) in a cell
|
|
2029
|
+
# whose style id is style_id: the date-time variant of that style when the style has no
|
|
2030
|
+
# number format, as a Time in the same cell gets from with_date_style_variants, and
|
|
2031
|
+
# style_id otherwise. Called by the worksheet writer only for such values.
|
|
2032
|
+
# : (Integer style_id) -> Integer
|
|
2033
|
+
def time_like_style_id: (Integer style_id) -> Integer
|
|
2034
|
+
|
|
2035
|
+
# Gives Date and Time values whose named style has no number format a variant of that
|
|
2036
|
+
# style with the default date or time format, registered on first use. A value without
|
|
2037
|
+
# a cell style gets a variant of the style it inherits: the row style, or the column
|
|
2038
|
+
# style in a row without one.
|
|
2039
|
+
# : (Array[untyped] values, untyped cell_styles, untyped row_style) -> untyped
|
|
2040
|
+
def with_date_style_variants: (Array[untyped] values, untyped cell_styles, untyped row_style) -> untyped
|
|
2005
2041
|
|
|
2006
2042
|
def ensure_sheet_started!: () -> untyped
|
|
2007
2043
|
|
|
@@ -572,6 +572,17 @@ module Xlsxrb
|
|
|
572
572
|
# : (untyped writer) -> Integer
|
|
573
573
|
def register_with: (untyped writer) -> Integer
|
|
574
574
|
|
|
575
|
+
# Returns whether +other+ describes the same cell format, whatever the names.
|
|
576
|
+
#
|
|
577
|
+
# @param other [StyleBuilder]
|
|
578
|
+
# @return [Boolean]
|
|
579
|
+
# @api private
|
|
580
|
+
# : (StyleBuilder other) -> bool
|
|
581
|
+
def same_format?: (StyleBuilder other) -> bool
|
|
582
|
+
|
|
583
|
+
# : () -> Array[untyped]
|
|
584
|
+
def format_signature: () -> Array[untyped]
|
|
585
|
+
|
|
575
586
|
private
|
|
576
587
|
|
|
577
588
|
# Raises ArgumentError for option keys #apply_options! does not know, and for a nested
|
|
@@ -583,4 +594,254 @@ module Xlsxrb
|
|
|
583
594
|
|
|
584
595
|
def resolve_color: (untyped color) -> untyped
|
|
585
596
|
end
|
|
597
|
+
|
|
598
|
+
# What +style+ returns in the 0.2 series, in place of the definition it records. It
|
|
599
|
+
# forwards every public method to that definition, so changes still reach it, and warns
|
|
600
|
+
# on first use at the caller's line.
|
|
601
|
+
#
|
|
602
|
+
# @deprecated Configure a style with options or in the block given to +style+. In version
|
|
603
|
+
# 0.3.0, +style+ will return nil (ADR 0010).
|
|
604
|
+
# @api public
|
|
605
|
+
class ReturnedStyleBuilder < StyleBuilder
|
|
606
|
+
DEPRECATION_MESSAGE: ::String
|
|
607
|
+
|
|
608
|
+
# @api private
|
|
609
|
+
# : (StyleBuilder definition) -> void
|
|
610
|
+
def initialize: (StyleBuilder definition) -> void
|
|
611
|
+
|
|
612
|
+
# : () -> (String | Symbol)?
|
|
613
|
+
def name: () -> (String | Symbol)?
|
|
614
|
+
|
|
615
|
+
# : () -> Hash[Symbol, untyped]
|
|
616
|
+
def font_props: () -> Hash[Symbol, untyped]
|
|
617
|
+
|
|
618
|
+
# : () -> Hash[Symbol, untyped]
|
|
619
|
+
def fill_props: () -> Hash[Symbol, untyped]
|
|
620
|
+
|
|
621
|
+
# : () -> Hash[Symbol, untyped]
|
|
622
|
+
def border_props: () -> Hash[Symbol, untyped]
|
|
623
|
+
|
|
624
|
+
# : (String name, String | Integer number_format) -> StyleBuilder
|
|
625
|
+
def with_number_format: (String name, String | Integer number_format) -> StyleBuilder
|
|
626
|
+
|
|
627
|
+
# : (**untyped) -> self
|
|
628
|
+
def apply_options!: (**untyped) -> self
|
|
629
|
+
|
|
630
|
+
# : (**untyped) -> void
|
|
631
|
+
def font: (**untyped) -> void
|
|
632
|
+
|
|
633
|
+
# : (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
634
|
+
def font=: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
635
|
+
|
|
636
|
+
# : (bool value) -> bool
|
|
637
|
+
def bold=: (bool value) -> bool
|
|
638
|
+
|
|
639
|
+
# : () -> bool
|
|
640
|
+
def bold?: () -> bool
|
|
641
|
+
|
|
642
|
+
# : (bool value) -> bool
|
|
643
|
+
def italic=: (bool value) -> bool
|
|
644
|
+
|
|
645
|
+
# : () -> bool
|
|
646
|
+
def italic?: () -> bool
|
|
647
|
+
|
|
648
|
+
# : () -> (Integer | Float | nil)
|
|
649
|
+
def font_size: () -> (Integer | Float | nil)
|
|
650
|
+
|
|
651
|
+
# : (Numeric size_value) -> Numeric
|
|
652
|
+
def font_size=: (Numeric size_value) -> Numeric
|
|
653
|
+
|
|
654
|
+
# : () -> String?
|
|
655
|
+
def font_name: () -> String?
|
|
656
|
+
|
|
657
|
+
# : (String name) -> String
|
|
658
|
+
def font_name=: (String name) -> String
|
|
659
|
+
|
|
660
|
+
# : () -> String?
|
|
661
|
+
def font_color: () -> String?
|
|
662
|
+
|
|
663
|
+
# : (String | Symbol color) -> (String | Symbol)
|
|
664
|
+
def font_color=: (String | Symbol color) -> (String | Symbol)
|
|
665
|
+
|
|
666
|
+
# : () -> (String | Symbol | bool | nil)
|
|
667
|
+
def underline: () -> (String | Symbol | bool | nil)
|
|
668
|
+
|
|
669
|
+
# : (String | Symbol | bool val) -> (String | Symbol | bool)
|
|
670
|
+
def underline=: (String | Symbol | bool val) -> (String | Symbol | bool)
|
|
671
|
+
|
|
672
|
+
# : () -> bool
|
|
673
|
+
def underline?: () -> bool
|
|
674
|
+
|
|
675
|
+
# : (bool value) -> bool
|
|
676
|
+
def strike=: (bool value) -> bool
|
|
677
|
+
|
|
678
|
+
# : () -> bool
|
|
679
|
+
def strike?: () -> bool
|
|
680
|
+
|
|
681
|
+
# : () -> String?
|
|
682
|
+
def vert_align: () -> String?
|
|
683
|
+
|
|
684
|
+
# : (untyped val) -> untyped
|
|
685
|
+
def vert_align=: (untyped val) -> untyped
|
|
686
|
+
|
|
687
|
+
# : (untyped val) -> untyped
|
|
688
|
+
def superscript=: (untyped val) -> untyped
|
|
689
|
+
|
|
690
|
+
# : () -> bool
|
|
691
|
+
def superscript?: () -> bool
|
|
692
|
+
|
|
693
|
+
# : (untyped val) -> untyped
|
|
694
|
+
def subscript=: (untyped val) -> untyped
|
|
695
|
+
|
|
696
|
+
# : () -> bool
|
|
697
|
+
def subscript?: () -> bool
|
|
698
|
+
|
|
699
|
+
# : (?untyped pattern, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> void
|
|
700
|
+
def fill_pattern: (?untyped pattern, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> void
|
|
701
|
+
|
|
702
|
+
# : (untyped pattern) -> untyped
|
|
703
|
+
def fill_pattern=: (untyped pattern) -> untyped
|
|
704
|
+
|
|
705
|
+
# : () -> String?
|
|
706
|
+
def fill_color: () -> String?
|
|
707
|
+
|
|
708
|
+
# : (String | Symbol color) -> (String | Symbol)
|
|
709
|
+
def fill_color=: (String | Symbol color) -> (String | Symbol)
|
|
710
|
+
|
|
711
|
+
# : (?pattern: untyped, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> void
|
|
712
|
+
def fill: (?pattern: untyped, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> void
|
|
713
|
+
|
|
714
|
+
# : (untyped opts) -> untyped
|
|
715
|
+
def fill=: (untyped opts) -> untyped
|
|
716
|
+
|
|
717
|
+
# : (?type: untyped, ?degree: Numeric | nil, ?stops: Array[untyped]) -> void
|
|
718
|
+
def fill_gradient: (?type: untyped, ?degree: Numeric | nil, ?stops: Array[untyped]) -> void
|
|
719
|
+
|
|
720
|
+
# : (?all: Hash[Symbol, untyped]?, ?left: Hash[Symbol, untyped]?, ?right: Hash[Symbol, untyped]?, ?top: Hash[Symbol, untyped]?, ?bottom: Hash[Symbol, untyped]?, ?diagonal: Hash[Symbol, untyped]?) -> void
|
|
721
|
+
def border: (?all: Hash[Symbol, untyped]?, ?left: Hash[Symbol, untyped]?, ?right: Hash[Symbol, untyped]?, ?top: Hash[Symbol, untyped]?, ?bottom: Hash[Symbol, untyped]?, ?diagonal: Hash[Symbol, untyped]?) -> void
|
|
722
|
+
|
|
723
|
+
# : (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
724
|
+
def border=: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
725
|
+
|
|
726
|
+
# : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
727
|
+
def border_all: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
728
|
+
|
|
729
|
+
# : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
730
|
+
def border_left: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
731
|
+
|
|
732
|
+
# : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
733
|
+
def border_right: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
734
|
+
|
|
735
|
+
# : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
736
|
+
def border_top: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
737
|
+
|
|
738
|
+
# : (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
739
|
+
def border_bottom: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
740
|
+
|
|
741
|
+
# : (?style: String | Symbol | Integer, ?color: String | Symbol | nil, ?up: bool, ?down: bool) -> void
|
|
742
|
+
def border_diagonal: (?style: String | Symbol | Integer, ?color: String | Symbol | nil, ?up: bool, ?down: bool) -> void
|
|
743
|
+
|
|
744
|
+
# : (?horizontal: (String | Symbol)?, ?vertical: (String | Symbol)?, ?wrap_text: bool?, ?text_rotation: Integer?, ?indent: Integer?, ?shrink_to_fit: bool?, ?reading_order: Integer?, ?justify_last_line: bool?, ?relative_indent: Integer?) -> void
|
|
745
|
+
def alignment: (?horizontal: (String | Symbol)?, ?vertical: (String | Symbol)?, ?wrap_text: bool?, ?text_rotation: Integer?, ?indent: Integer?, ?shrink_to_fit: bool?, ?reading_order: Integer?, ?justify_last_line: bool?, ?relative_indent: Integer?) -> void
|
|
746
|
+
|
|
747
|
+
# : (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
748
|
+
def alignment=: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
749
|
+
|
|
750
|
+
# : () -> (String | Symbol | nil)
|
|
751
|
+
def align_horizontal: () -> (String | Symbol | nil)
|
|
752
|
+
|
|
753
|
+
# : (String | Symbol value) -> (String | Symbol)
|
|
754
|
+
def align_horizontal=: (String | Symbol value) -> (String | Symbol)
|
|
755
|
+
|
|
756
|
+
# : () -> (String | Symbol | nil)
|
|
757
|
+
def align_vertical: () -> (String | Symbol | nil)
|
|
758
|
+
|
|
759
|
+
# : (String | Symbol value) -> (String | Symbol)
|
|
760
|
+
def align_vertical=: (String | Symbol value) -> (String | Symbol)
|
|
761
|
+
|
|
762
|
+
# : (bool value) -> bool
|
|
763
|
+
def wrap_text=: (bool value) -> bool
|
|
764
|
+
|
|
765
|
+
# : () -> bool
|
|
766
|
+
def wrap_text?: () -> bool
|
|
767
|
+
|
|
768
|
+
# : (bool value) -> bool
|
|
769
|
+
def shrink_to_fit=: (bool value) -> bool
|
|
770
|
+
|
|
771
|
+
# : () -> bool
|
|
772
|
+
def shrink_to_fit?: () -> bool
|
|
773
|
+
|
|
774
|
+
# : () -> (Numeric | nil)
|
|
775
|
+
def text_rotation: () -> (Numeric | nil)
|
|
776
|
+
|
|
777
|
+
# : (Numeric value) -> Numeric
|
|
778
|
+
def text_rotation=: (Numeric value) -> Numeric
|
|
779
|
+
|
|
780
|
+
# : () -> (Integer | nil)
|
|
781
|
+
def indent: () -> (Integer | nil)
|
|
782
|
+
|
|
783
|
+
# : (Numeric value) -> Numeric
|
|
784
|
+
def indent=: (Numeric value) -> Numeric
|
|
785
|
+
|
|
786
|
+
# : (?locked: bool?, ?hidden: bool?) -> void
|
|
787
|
+
def protection: (?locked: bool?, ?hidden: bool?) -> void
|
|
788
|
+
|
|
789
|
+
# : (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
790
|
+
def protection=: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
791
|
+
|
|
792
|
+
# : (bool value) -> bool
|
|
793
|
+
def locked=: (bool value) -> bool
|
|
794
|
+
|
|
795
|
+
# : () -> bool
|
|
796
|
+
def locked?: () -> bool
|
|
797
|
+
|
|
798
|
+
# : (bool value) -> bool
|
|
799
|
+
def hidden=: (bool value) -> bool
|
|
800
|
+
|
|
801
|
+
# : () -> bool
|
|
802
|
+
def hidden?: () -> bool
|
|
803
|
+
|
|
804
|
+
# : () -> (String | Integer | nil)
|
|
805
|
+
def number_format: () -> (String | Integer | nil)
|
|
806
|
+
|
|
807
|
+
# : (String | Integer num_fmt_id) -> (String | Integer)
|
|
808
|
+
def number_format=: (String | Integer num_fmt_id) -> (String | Integer)
|
|
809
|
+
|
|
810
|
+
# : (untyped writer) -> Integer
|
|
811
|
+
def register_with: (untyped writer) -> Integer
|
|
812
|
+
|
|
813
|
+
# : (StyleBuilder other) -> bool
|
|
814
|
+
def same_format?: (StyleBuilder other) -> bool
|
|
815
|
+
|
|
816
|
+
# Lets StyleBuilder#same_format? compare with the definition without a warning.
|
|
817
|
+
# : () -> Array[untyped]
|
|
818
|
+
def format_signature: () -> Array[untyped]
|
|
819
|
+
|
|
820
|
+
private
|
|
821
|
+
|
|
822
|
+
# : () -> StyleBuilder
|
|
823
|
+
def definition_for_use: () -> StyleBuilder
|
|
824
|
+
end
|
|
825
|
+
|
|
826
|
+
# The order in which the styles of an {Xlsxrb.build} workbook are defined, shared by
|
|
827
|
+
# the workbook builder and its sheet builders. A row records the clock when it is
|
|
828
|
+
# added, so that it uses the definitions made before it, as a row written by
|
|
829
|
+
# {StreamWriter} does.
|
|
830
|
+
#
|
|
831
|
+
# @api private
|
|
832
|
+
class StyleLog
|
|
833
|
+
# Number of definitions so far.
|
|
834
|
+
# : Integer
|
|
835
|
+
attr_reader clock: untyped
|
|
836
|
+
|
|
837
|
+
# Each name's definitions, as [clock, builder] pairs in the order they were made.
|
|
838
|
+
# : Hash[String, Array[[Integer, StyleBuilder]]]
|
|
839
|
+
attr_reader definitions: untyped
|
|
840
|
+
|
|
841
|
+
# : () -> void
|
|
842
|
+
def initialize: () -> void
|
|
843
|
+
|
|
844
|
+
# : (String name, StyleBuilder builder) -> void
|
|
845
|
+
def record: (String name, StyleBuilder builder) -> void
|
|
846
|
+
end
|
|
586
847
|
end
|
|
@@ -45,6 +45,8 @@ module Xlsxrb
|
|
|
45
45
|
# @yield [style_builder]
|
|
46
46
|
# @yieldparam style_builder [Xlsxrb::StyleBuilder]
|
|
47
47
|
# @return [StyleBuilder]
|
|
48
|
+
# Using the returned value is deprecated and warns; in version 0.3.0, this method
|
|
49
|
+
# will return nil. Configure the style with options or in the block.
|
|
48
50
|
# @api public
|
|
49
51
|
# : (String | Symbol name, **untyped opts) ?{ (StyleBuilder) -> void } -> StyleBuilder
|
|
50
52
|
def style: (String | Symbol name, **untyped opts) ?{ (StyleBuilder) -> void } -> StyleBuilder
|
|
@@ -190,20 +192,30 @@ module Xlsxrb
|
|
|
190
192
|
# @param opts [Hash] Additional sheet properties.
|
|
191
193
|
# @yield [sheet_builder]
|
|
192
194
|
# @yieldparam sheet_builder [Xlsxrb::WorksheetBuilder]
|
|
193
|
-
# @return [
|
|
195
|
+
# @return [DeferredWorksheet] The sheet as {WorksheetBuilder#build} returns it, with
|
|
196
|
+
# style names in its cells. It is built when first used.
|
|
194
197
|
# @raise [ArgumentError] If sheet name violates Excel limits in strict mode.
|
|
195
198
|
# @api public
|
|
196
|
-
# : (?String? name, ?state: Symbol | String | nil, ?tab_color: String | Hash[Symbol, untyped] | Symbol | nil, ?code_name: String | Symbol | nil, **untyped opts) ?{ (WorksheetBuilder) -> void } ->
|
|
197
|
-
def sheet: (?String? name, ?state: Symbol | String | nil, ?tab_color: String | Hash[Symbol, untyped] | Symbol | nil, ?code_name: String | Symbol | nil, **untyped opts) ?{ (WorksheetBuilder) -> void } ->
|
|
199
|
+
# : (?String? name, ?state: Symbol | String | nil, ?tab_color: String | Hash[Symbol, untyped] | Symbol | nil, ?code_name: String | Symbol | nil, **untyped opts) ?{ (WorksheetBuilder) -> void } -> DeferredWorksheet
|
|
200
|
+
def sheet: (?String? name, ?state: Symbol | String | nil, ?tab_color: String | Hash[Symbol, untyped] | Symbol | nil, ?code_name: String | Symbol | nil, **untyped opts) ?{ (WorksheetBuilder) -> void } -> DeferredWorksheet
|
|
198
201
|
|
|
199
|
-
#
|
|
202
|
+
# Adds a worksheet, as {#sheet} does.
|
|
203
|
+
#
|
|
204
|
+
# @deprecated Use {#sheet} to add a sheet. In version 0.3.0, this method will return the
|
|
205
|
+
# {WorksheetBuilder} of an existing sheet, or of the current sheet without an argument,
|
|
206
|
+
# and raise for a sheet that does not exist. Calling it with an argument, or without
|
|
207
|
+
# one after a sheet was added, warns.
|
|
200
208
|
#
|
|
201
209
|
# @param name_or_index [String, Symbol, Integer, nil]
|
|
202
210
|
# @yield [sheet_builder]
|
|
203
|
-
# @return [
|
|
211
|
+
# @return [DeferredWorksheet]
|
|
204
212
|
# @api public
|
|
205
|
-
# : (?String | Symbol | Integer | nil name_or_index) ?{ (WorksheetBuilder) -> void } ->
|
|
206
|
-
def []: (?String | Symbol | Integer | nil name_or_index) ?{ (WorksheetBuilder) -> void } ->
|
|
213
|
+
# : (?String | Symbol | Integer | nil name_or_index) ?{ (WorksheetBuilder) -> void } -> DeferredWorksheet
|
|
214
|
+
def []: (?String | Symbol | Integer | nil name_or_index) ?{ (WorksheetBuilder) -> void } -> DeferredWorksheet
|
|
215
|
+
|
|
216
|
+
INDEX_CREATES_SHEET_MESSAGE: ::String
|
|
217
|
+
|
|
218
|
+
INDEX_ADDS_SHEET_MESSAGE: ::String
|
|
207
219
|
|
|
208
220
|
# Adds a defined name (named range or formula) to the workbook.
|
|
209
221
|
# Bare cell references and coordinate keywords are automatically formatted with sheet quotes and absolute $ references.
|
|
@@ -397,8 +409,29 @@ module Xlsxrb
|
|
|
397
409
|
# : (untyped names, untyped sheets) -> untyped
|
|
398
410
|
def resolve_defined_names: (untyped names, untyped sheets) -> untyped
|
|
399
411
|
|
|
400
|
-
#
|
|
401
|
-
|
|
412
|
+
# Registers the styles of every sheet and builds the sheets' rows with their style
|
|
413
|
+
# names resolved to style indexes. Each cell is created once, here.
|
|
414
|
+
# : (Array[WorksheetBuilder::Snapshot] sheets) -> [Array[Elements::Worksheet], Hash[Symbol, untyped]]
|
|
415
|
+
def process_styles: (Array[WorksheetBuilder::Snapshot] sheets) -> [ Array[Elements::Worksheet], Hash[Symbol, untyped] ]
|
|
416
|
+
|
|
417
|
+
# Returns the key of the definition that the style +name+ stands for at style log
|
|
418
|
+
# +clock+: the last one made by then, or the first one if none was. A name defined
|
|
419
|
+
# once, or always with the same format, is its own key.
|
|
420
|
+
# : (String name, Integer? clock, Hash[String, Array[[Integer, String]]] versions) -> String
|
|
421
|
+
def style_version: (String name, Integer? clock, Hash[String, Array[[ Integer, String ]]] versions) -> String
|
|
422
|
+
|
|
423
|
+
# Marks the definition that the style +name+ stands for at style log +clock+ as used.
|
|
424
|
+
# : (untyped name, Integer? clock, Hash[String, Array[[Integer, String]]] versions, Hash[String, true] used_versions) -> void
|
|
425
|
+
def use_style_version: (untyped name, Integer? clock, Hash[String, Array[[ Integer, String ]]] versions, Hash[String, true] used_versions) -> void
|
|
426
|
+
|
|
427
|
+
# Records the date or time variant of the style named +style_key+ that a Date or
|
|
428
|
+
# Time +value+ in a row added at style log +clock+ needs, if any.
|
|
429
|
+
# : (untyped value, String style_key, Integer clock, Hash[String, Array[[Integer, String]]] versions, Hash[String, untyped] all_style_builders, Hash[String, StyleBuilder] version_builders, Hash[untyped, untyped] date_variants, Hash[String, untyped] variant_builders) -> void
|
|
430
|
+
def add_date_variant: (untyped value, String style_key, Integer clock, Hash[String, Array[[ Integer, String ]]] versions, Hash[String, untyped] all_style_builders, Hash[String, StyleBuilder] version_builders, Hash[untyped, untyped] date_variants, Hash[String, untyped] variant_builders) -> void
|
|
431
|
+
|
|
432
|
+
# Creates a cell whose style was resolved to +style+ (an index, or a name with no index).
|
|
433
|
+
# : (Integer row_index, Integer column_index, untyped value, untyped style, String? format_code, bool valid_coordinates) -> Elements::Cell
|
|
434
|
+
def resolved_cell: (Integer row_index, Integer column_index, untyped value, untyped style, String? format_code, bool valid_coordinates) -> Elements::Cell
|
|
402
435
|
|
|
403
436
|
# : (untyped writer) -> Hash[Symbol, untyped]
|
|
404
437
|
def extract_styles_from_writer: (untyped writer) -> Hash[Symbol, untyped]
|