fast_xlsx 1.1.0 → 1.2.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/CHANGELOG.md +16 -0
- data/Cargo.lock +2 -2
- data/README.md +1 -1
- data/SECURITY.md +3 -3
- data/ext/fast_xlsx/Cargo.toml +1 -1
- data/ext/fast_xlsx/src/lib.rs +117 -22
- data/lib/fast_xlsx/version.rb +1 -1
- data/lib/fast_xlsx.rb +5 -2
- data/sig/fast_xlsx.rbs +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2c67527d71affcbc069c4b9516aeca478a50824cc102319509b4793d217794e4
|
|
4
|
+
data.tar.gz: e539469f97cdd27ca642e9fc64270ce4909134cb82047f187c198f4126de2c68
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee745f9fb7a1ccdbc4aca1387c675258e1878841a632739987131b8358819ab04b35a11d035174969a2e87902a6c11865e523a9172ad67f8c5f9a5848710f7b4
|
|
7
|
+
data.tar.gz: d3b4d68ea19941088b656cb133b07eb4b1f854bfb55ff1d1e20f03b05644b3cba4fb2062e9a9c3ead9ec6d5f464c53b169c415e1e274f8192ceefab7014c0363
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.2.0] - 2026-11-19
|
|
4
|
+
|
|
5
|
+
Upgrading is recommended: 1.1.0 and earlier are affected by the issues under Security. A chart `title:`, `x_axis:`, `y_axis:` or series `name:` written as a cell reference String (`"Sheet1!$A$1"`) now raises; pass `FastXlsx::Formula.new("Sheet1!$A$1")` instead.
|
|
6
|
+
|
|
7
|
+
### Security
|
|
8
|
+
|
|
9
|
+
- `insert_image` raises `FastXlsx::Error` for an image that would be larger than a worksheet. The size comes from the image's own header, so a file of a few bytes could keep `save` and `to_xlsx` busy for minutes, and a `Timeout` could not interrupt it.
|
|
10
|
+
- Control characters (below U+0020 other than tab, newline and carriage return) now raise `ArgumentError` in worksheet names, table headers and `total_label:`, data validation titles and messages, `insert_image`'s `alt_text:`, `:text` conditional format values, `num_format:`, `font_name:`, URLs and `unprotect_range`'s `name:`. They were written into the file as is, and Excel could not open it. Cell text is not affected.
|
|
11
|
+
- A chart's `title:`, `x_axis:`, `y_axis:` and series `name:` are always text. A String such as `"Sheet1!A1"` or `"=(Sheet1!$A$1)"` was read as a cell reference or written as a formula; it now raises `ArgumentError`. To show a cell's content, pass a `FastXlsx::Formula`.
|
|
12
|
+
- A `:cell` conditional format value that starts and ends with a double quote and has another one inside (`'"x"&A2&"y"'`) is compared as that text, instead of continuing as formula text.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- `write` with a Hash format, and `conditional_format` called natively, keep their own copy of the format while the value is converted. The value's `to_s` (or another thread) could push the format out of the cache of Hash formats and let it be freed before it was used. No crash was reproduced.
|
|
17
|
+
- Updated rust_xlsxwriter to 0.102, which doubles a double quote in a `:text` conditional format value instead of ending the rule's formula there.
|
|
18
|
+
|
|
3
19
|
## [1.1.0] - 2026-11-03
|
|
4
20
|
|
|
5
21
|
### Added
|
data/Cargo.lock
CHANGED
|
@@ -353,9 +353,9 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
|
|
353
353
|
|
|
354
354
|
[[package]]
|
|
355
355
|
name = "rust_xlsxwriter"
|
|
356
|
-
version = "0.
|
|
356
|
+
version = "0.102.0"
|
|
357
357
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
358
|
-
checksum = "
|
|
358
|
+
checksum = "6ca3d0e879a578c1313c2800ab0c6c029d38eed18098675e50341a30d32372ed"
|
|
359
359
|
dependencies = [
|
|
360
360
|
"tempfile",
|
|
361
361
|
"zip",
|
data/README.md
CHANGED
|
@@ -395,7 +395,7 @@ ws.insert_chart(1, 4, type: :column,
|
|
|
395
395
|
title: "Q1", x_axis: "Month", y_axis: "Amount", width: 600, height: 360)
|
|
396
396
|
```
|
|
397
397
|
|
|
398
|
-
`type`: `:column`, `:column_stacked`, `:bar`, `:bar_stacked`, `:line`, `:line_stacked`, `:area`, `:area_stacked`, `:pie`, `:doughnut`, `:radar`, `:scatter`. Ranges use Excel syntax, so a chart can plot data from another worksheet. Sizes are in pixels (default 480 × 288).
|
|
398
|
+
`type`: `:column`, `:column_stacked`, `:bar`, `:bar_stacked`, `:line`, `:line_stacked`, `:area`, `:area_stacked`, `:pie`, `:doughnut`, `:radar`, `:scatter`. Ranges use Excel syntax, so a chart can plot data from another worksheet. `title:`, `x_axis:`, `y_axis:` and a series `name:` are text; pass a `FastXlsx::Formula` such as `FastXlsx::Formula.new("Sheet1!$A$1")` to show a cell's content instead. Sizes are in pixels (default 480 × 288).
|
|
399
399
|
|
|
400
400
|
Values are mapped by type:
|
|
401
401
|
|
data/SECURITY.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Supported versions
|
|
4
4
|
|
|
5
|
-
Security fixes go into the latest release of the newest minor version.
|
|
5
|
+
Security fixes go into the latest release of the newest minor version.
|
|
6
6
|
|
|
7
7
|
| Version | Supported |
|
|
8
8
|
|---|---|
|
|
9
|
-
|
|
|
10
|
-
| <
|
|
9
|
+
| 1.2.x | ✅ |
|
|
10
|
+
| < 1.2 | ❌ (upgrade to 1.2.x; the [changelog](CHANGELOG.md) lists every change) |
|
|
11
11
|
|
|
12
12
|
## Reporting a vulnerability
|
|
13
13
|
|
data/ext/fast_xlsx/Cargo.toml
CHANGED
|
@@ -14,7 +14,7 @@ magnus = { version = "0.9", features = ["rb-sys"] }
|
|
|
14
14
|
rb-sys = { version = "0.9", features = ["stable-api-compiled-fallback"] }
|
|
15
15
|
# No "zlib" feature: without it zip compresses with zlib-rs, which saves
|
|
16
16
|
# 20-30% faster than the system zlib (and needs no C library).
|
|
17
|
-
rust_xlsxwriter = { version = "0.
|
|
17
|
+
rust_xlsxwriter = { version = "0.102.0", features = ["constant_memory"] }
|
|
18
18
|
|
|
19
19
|
[build-dependencies]
|
|
20
20
|
rb-sys-env = "0.2.2"
|
data/ext/fast_xlsx/src/lib.rs
CHANGED
|
@@ -89,6 +89,62 @@ fn check_positive(ruby: &Ruby, what: &str, size: f64) -> Result<f64, Error> {
|
|
|
89
89
|
))
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
// Characters XML 1.0 forbids. rust_xlsxwriter escapes them in cell text but
|
|
93
|
+
// writes them as is into attributes, which makes the file unreadable.
|
|
94
|
+
fn check_xml(what: &str, text: &str) -> Result<(), Error> {
|
|
95
|
+
let illegal = |c: char| {
|
|
96
|
+
(c < ' ' && !matches!(c, '\t' | '\n' | '\r')) || matches!(c, '\u{FFFE}' | '\u{FFFF}')
|
|
97
|
+
};
|
|
98
|
+
if text.chars().any(illegal) {
|
|
99
|
+
return Err(Error::new(
|
|
100
|
+
Ruby::get().unwrap().exception_arg_error(),
|
|
101
|
+
format!("invalid {what} {text:?}: control characters are not allowed"),
|
|
102
|
+
));
|
|
103
|
+
}
|
|
104
|
+
Ok(())
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// A chart title, axis name or series name. rust_xlsxwriter reads "Sheet1!A1"
|
|
108
|
+
// and "=(...)" / "=Table[...]" strings as references, so a plain String must
|
|
109
|
+
// not look like one; a FastXlsx::Formula asks for the reference.
|
|
110
|
+
fn chart_label(ruby: &Ruby, v: Value) -> Result<String, Error> {
|
|
111
|
+
if v.is_kind_of(ruby.get_inner(&FORMULA)) {
|
|
112
|
+
let expression: String = v.funcall("expression", ())?;
|
|
113
|
+
let reference = expression.strip_prefix('=').unwrap_or(&expression);
|
|
114
|
+
return Ok(if reference.starts_with('(') || reference.contains('[') {
|
|
115
|
+
format!("={reference}")
|
|
116
|
+
} else {
|
|
117
|
+
reference.to_string()
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
let text = String::try_convert(v)?;
|
|
121
|
+
let unparsed = text.starts_with("=(") || (text.starts_with('=') && text.contains('['));
|
|
122
|
+
// The same test as rust_xlsxwriter's is_valid_range().
|
|
123
|
+
let range = text.find('!').is_some_and(|at| {
|
|
124
|
+
let range = text[at + 1..].replace('$', "");
|
|
125
|
+
range.starts_with(|c: char| c.is_ascii_uppercase())
|
|
126
|
+
&& range.ends_with(|c: char| c.is_ascii_digit())
|
|
127
|
+
&& range
|
|
128
|
+
.chars()
|
|
129
|
+
.all(|c| c.is_ascii_uppercase() || c.is_ascii_digit() || c == ':')
|
|
130
|
+
});
|
|
131
|
+
if unparsed || range {
|
|
132
|
+
return Err(Error::new(
|
|
133
|
+
ruby.exception_arg_error(),
|
|
134
|
+
format!(
|
|
135
|
+
"chart text {text:?} would be read as a cell reference: \
|
|
136
|
+
pass a FastXlsx::Formula to reference a cell"
|
|
137
|
+
),
|
|
138
|
+
));
|
|
139
|
+
}
|
|
140
|
+
Ok(text)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// The largest area a sheet can cover, in pixels: every column at 255
|
|
144
|
+
// characters wide and every row at 409 points high.
|
|
145
|
+
const MAX_IMAGE_WIDTH: f64 = 16_384.0 * 1_790.0;
|
|
146
|
+
const MAX_IMAGE_HEIGHT: f64 = 1_048_576.0 * 546.0;
|
|
147
|
+
|
|
92
148
|
// A range of rows is checked before any row changes, so it is all or nothing.
|
|
93
149
|
fn check_last_row(last: u32) -> Result<(), Error> {
|
|
94
150
|
if last < MAX_ROWS {
|
|
@@ -221,6 +277,7 @@ impl Workbook {
|
|
|
221
277
|
Some(name) => {
|
|
222
278
|
// Validate the name before adding: rust_xlsxwriter adds the
|
|
223
279
|
// sheet first, so a bad name would leave a "SheetN" behind.
|
|
280
|
+
check_xml("worksheet name", &name)?;
|
|
224
281
|
rust_xlsxwriter::Worksheet::new()
|
|
225
282
|
.set_name(&name)
|
|
226
283
|
.map_err(xerr)?;
|
|
@@ -431,7 +488,9 @@ impl CellValue {
|
|
|
431
488
|
} else if v.is_kind_of(ruby.get_inner(&FORMULA)) {
|
|
432
489
|
CellValue::Formula(v.funcall("expression", ())?)
|
|
433
490
|
} else if v.is_kind_of(ruby.get_inner(&URL)) {
|
|
434
|
-
|
|
491
|
+
let url: String = v.funcall("url", ())?;
|
|
492
|
+
check_xml("URL", &url)?;
|
|
493
|
+
CellValue::Url(url, v.funcall("text", ())?)
|
|
435
494
|
} else if v.is_kind_of(ruby.get_inner(&RICH_STRING)) {
|
|
436
495
|
let segments: RArray = v.funcall("segments", ())?;
|
|
437
496
|
let mut parts = Vec::with_capacity(segments.len());
|
|
@@ -579,7 +638,14 @@ fn choice<T: Clone>(
|
|
|
579
638
|
// A number or string compared against in a conditional format rule.
|
|
580
639
|
fn cf_value(ruby: &Ruby, v: Value) -> Result<ConditionalFormatValue, Error> {
|
|
581
640
|
if let Some(s) = RString::from_value(v) {
|
|
582
|
-
|
|
641
|
+
let s = s.to_string()?;
|
|
642
|
+
// rust_xlsxwriter writes a "quoted" string as is, so one with a lone
|
|
643
|
+
// quote inside would continue as formula text: quote it here instead.
|
|
644
|
+
let inner = s.strip_prefix('"').and_then(|s| s.strip_suffix('"'));
|
|
645
|
+
if inner.is_some_and(|inner| inner.replace("\"\"", "").contains('"')) {
|
|
646
|
+
return Ok(format!("\"{}\"", s.replace('"', "\"\"")).into());
|
|
647
|
+
}
|
|
648
|
+
Ok(s.into())
|
|
583
649
|
} else if v.is_kind_of(ruby.class_numeric()) {
|
|
584
650
|
Ok(f64::try_convert(v)?.into())
|
|
585
651
|
} else {
|
|
@@ -821,7 +887,9 @@ const TABLE_TOTALS: &[(&str, TableFunction)] = &[
|
|
|
821
887
|
// Also returns a copy of the column's format, if any, for later writes.
|
|
822
888
|
fn table_column(ruby: &Ruby, v: Value) -> Result<(TableColumn, Option<Arc<Style>>), Error> {
|
|
823
889
|
let Some(spec) = RHash::from_value(v) else {
|
|
824
|
-
|
|
890
|
+
let header = String::try_convert(v)?;
|
|
891
|
+
check_xml("table header", &header)?;
|
|
892
|
+
return Ok((TableColumn::new().set_header(header), None));
|
|
825
893
|
};
|
|
826
894
|
check_keys(
|
|
827
895
|
ruby,
|
|
@@ -830,11 +898,13 @@ fn table_column(ruby: &Ruby, v: Value) -> Result<(TableColumn, Option<Arc<Style>
|
|
|
830
898
|
"table column",
|
|
831
899
|
)?;
|
|
832
900
|
let header = String::try_convert(raw_opt(ruby, spec, "header"))?;
|
|
901
|
+
check_xml("table header", &header)?;
|
|
833
902
|
let mut column = TableColumn::new().set_header(header);
|
|
834
903
|
if let Some(total) = opt::<Value>(ruby, spec, "total")? {
|
|
835
904
|
column = column.set_total_function(choice(ruby, "table total", total, TABLE_TOTALS)?);
|
|
836
905
|
}
|
|
837
906
|
if let Some(label) = opt::<String>(ruby, spec, "total_label")? {
|
|
907
|
+
check_xml("total_label", &label)?;
|
|
838
908
|
column = column.set_total_label(label);
|
|
839
909
|
}
|
|
840
910
|
let format = opt::<&Format>(ruby, spec, "format")?.map(|f| f.0.clone());
|
|
@@ -1002,14 +1072,20 @@ impl Format {
|
|
|
1002
1072
|
"border_color" => taken.set_border_color(color(ruby, value)?),
|
|
1003
1073
|
"num_format" => {
|
|
1004
1074
|
has_num_format = true;
|
|
1005
|
-
|
|
1075
|
+
let num_format = String::try_convert(value)?;
|
|
1076
|
+
check_xml("num_format", &num_format)?;
|
|
1077
|
+
taken.set_num_format(num_format)
|
|
1006
1078
|
}
|
|
1007
1079
|
"font_size" => taken.set_font_size(check_positive(
|
|
1008
1080
|
ruby,
|
|
1009
1081
|
"font_size",
|
|
1010
1082
|
f64::try_convert(value)?,
|
|
1011
1083
|
)?),
|
|
1012
|
-
"font_name" =>
|
|
1084
|
+
"font_name" => {
|
|
1085
|
+
let font_name = String::try_convert(value)?;
|
|
1086
|
+
check_xml("font_name", &font_name)?;
|
|
1087
|
+
taken.set_font_name(font_name)
|
|
1088
|
+
}
|
|
1013
1089
|
"font_color" => taken.set_font_color(color(ruby, value)?),
|
|
1014
1090
|
"bg_color" => taken.set_background_color(color(ruby, value)?),
|
|
1015
1091
|
"align" => taken.set_align(choice(
|
|
@@ -1279,6 +1355,9 @@ impl Worksheet {
|
|
|
1279
1355
|
format: Option<&Format>,
|
|
1280
1356
|
) -> Result<(), Error> {
|
|
1281
1357
|
rb_self.check_not_flushed(ruby, row)?;
|
|
1358
|
+
// Converting the value can run Ruby code, and a Format made from a
|
|
1359
|
+
// Hash is only kept alive by Format._coerce's cache: keep our own copy.
|
|
1360
|
+
let style = format.map(|f| f.0.clone());
|
|
1282
1361
|
let value = CellValue::from_ruby(ruby, v)?;
|
|
1283
1362
|
let tables = rb_self.table_formats.borrow();
|
|
1284
1363
|
let rows = rb_self.formatted_rows.borrow();
|
|
@@ -1294,7 +1373,7 @@ impl Worksheet {
|
|
|
1294
1373
|
&columns,
|
|
1295
1374
|
row,
|
|
1296
1375
|
col,
|
|
1297
|
-
|
|
1376
|
+
style.as_deref(),
|
|
1298
1377
|
&value,
|
|
1299
1378
|
),
|
|
1300
1379
|
)
|
|
@@ -1407,6 +1486,7 @@ impl Worksheet {
|
|
|
1407
1486
|
name: Option<String>,
|
|
1408
1487
|
password: Option<String>,
|
|
1409
1488
|
) -> Result<Obj<Self>, Error> {
|
|
1489
|
+
check_xml("range name", name.as_deref().unwrap_or(""))?;
|
|
1410
1490
|
rb_self.with_ws(|ws| {
|
|
1411
1491
|
ws.unprotect_range_with_options(
|
|
1412
1492
|
fr,
|
|
@@ -1717,7 +1797,8 @@ impl Worksheet {
|
|
|
1717
1797
|
_ => &["type", "criteria", "value", "format", "colors"],
|
|
1718
1798
|
};
|
|
1719
1799
|
check_keys(ruby, options, allowed, &format!("conditional_format :{kind}"))?;
|
|
1720
|
-
|
|
1800
|
+
// A copy, as in write(): the options below are converted by Ruby code.
|
|
1801
|
+
let format = opt::<&Format>(ruby, options, "format")?.map(|f| f.0.clone());
|
|
1721
1802
|
let value = raw_opt(ruby, options, "value");
|
|
1722
1803
|
let criteria = raw_opt(ruby, options, "criteria");
|
|
1723
1804
|
// A whole number in `range`: other numbers raise ArgumentError with
|
|
@@ -1769,8 +1850,8 @@ impl Worksheet {
|
|
|
1769
1850
|
($cf:expr) => {
|
|
1770
1851
|
rule(
|
|
1771
1852
|
range,
|
|
1772
|
-
match format {
|
|
1773
|
-
Some(f) => $cf.set_format(&f.
|
|
1853
|
+
match &format {
|
|
1854
|
+
Some(f) => $cf.set_format(&f.format),
|
|
1774
1855
|
None => $cf,
|
|
1775
1856
|
},
|
|
1776
1857
|
)
|
|
@@ -1782,6 +1863,7 @@ impl Worksheet {
|
|
|
1782
1863
|
}
|
|
1783
1864
|
"text" => {
|
|
1784
1865
|
let text = String::try_convert(value)?;
|
|
1866
|
+
check_xml("conditional format text", &text)?;
|
|
1785
1867
|
let text_rule = match choice(
|
|
1786
1868
|
ruby,
|
|
1787
1869
|
"text criteria",
|
|
@@ -2067,6 +2149,7 @@ impl Worksheet {
|
|
|
2067
2149
|
("error_message", DataValidation::set_error_message),
|
|
2068
2150
|
] {
|
|
2069
2151
|
if let Some(text) = opt::<String>(ruby, options, name)? {
|
|
2152
|
+
check_xml(name, &text)?;
|
|
2070
2153
|
dv = set(dv, text).map_err(xerr)?;
|
|
2071
2154
|
}
|
|
2072
2155
|
}
|
|
@@ -2119,6 +2202,7 @@ impl Worksheet {
|
|
|
2119
2202
|
};
|
|
2120
2203
|
let width = positive("width")?;
|
|
2121
2204
|
let height = positive("height")?;
|
|
2205
|
+
let (mut scale_w, mut scale_h) = (1.0, 1.0);
|
|
2122
2206
|
if let Some(scale) = positive("scale")? {
|
|
2123
2207
|
if width.is_some() || height.is_some() {
|
|
2124
2208
|
return Err(Error::new(
|
|
@@ -2126,18 +2210,29 @@ impl Worksheet {
|
|
|
2126
2210
|
"pass either scale: or width:/height:, not both",
|
|
2127
2211
|
));
|
|
2128
2212
|
}
|
|
2129
|
-
|
|
2213
|
+
(scale_w, scale_h) = (scale, scale);
|
|
2130
2214
|
} else if width.is_some() || height.is_some() {
|
|
2131
2215
|
// Displayed size at scale 1, as rust_xlsxwriter computes it from the DPI.
|
|
2132
2216
|
let natural_w = image.width() * 96.0 / image.width_dpi();
|
|
2133
2217
|
let natural_h = image.height() * 96.0 / image.height_dpi();
|
|
2134
|
-
let
|
|
2135
|
-
let
|
|
2218
|
+
let sw = width.map(|w| w / natural_w);
|
|
2219
|
+
let sh = height.map(|h| h / natural_h);
|
|
2136
2220
|
// With only one dimension, scale the other by the same factor.
|
|
2137
|
-
|
|
2138
|
-
|
|
2221
|
+
(scale_w, scale_h) = (sw.or(sh).unwrap(), sh.or(sw).unwrap());
|
|
2222
|
+
}
|
|
2223
|
+
// The size comes from the image's own header, and saving walks every
|
|
2224
|
+
// row and column the image covers, with no way to interrupt it.
|
|
2225
|
+
let shown_w = image.width() * 96.0 / image.width_dpi() * scale_w;
|
|
2226
|
+
let shown_h = image.height() * 96.0 / image.height_dpi() * scale_h;
|
|
2227
|
+
if !(shown_w <= MAX_IMAGE_WIDTH && shown_h <= MAX_IMAGE_HEIGHT) {
|
|
2228
|
+
return Err(Error::new(
|
|
2229
|
+
ruby.get_inner(&ERROR),
|
|
2230
|
+
format!("image is too large for a worksheet: {shown_w} x {shown_h} pixels"),
|
|
2231
|
+
));
|
|
2139
2232
|
}
|
|
2233
|
+
image = image.set_scale_width(scale_w).set_scale_height(scale_h);
|
|
2140
2234
|
if let Some(alt_text) = opt::<String>(ruby, options, "alt_text")? {
|
|
2235
|
+
check_xml("alt_text", &alt_text)?;
|
|
2141
2236
|
image = image.set_alt_text(alt_text);
|
|
2142
2237
|
}
|
|
2143
2238
|
let x = opt::<u32>(ruby, options, "x_offset")?.unwrap_or(0);
|
|
@@ -2237,19 +2332,19 @@ impl Worksheet {
|
|
|
2237
2332
|
if let Some(categories) = opt::<String>(ruby, s, "categories")? {
|
|
2238
2333
|
cs.set_categories(categories.as_str());
|
|
2239
2334
|
}
|
|
2240
|
-
if let Some(name) = opt::<
|
|
2241
|
-
cs.set_name(name
|
|
2335
|
+
if let Some(name) = opt::<Value>(ruby, s, "name")? {
|
|
2336
|
+
cs.set_name(chart_label(ruby, name)?.as_str());
|
|
2242
2337
|
}
|
|
2243
2338
|
Ok(())
|
|
2244
2339
|
})?;
|
|
2245
|
-
if let Some(title) = opt::<
|
|
2246
|
-
chart.title().set_name(title
|
|
2340
|
+
if let Some(title) = opt::<Value>(ruby, options, "title")? {
|
|
2341
|
+
chart.title().set_name(chart_label(ruby, title)?.as_str());
|
|
2247
2342
|
}
|
|
2248
|
-
if let Some(name) = opt::<
|
|
2249
|
-
chart.x_axis().set_name(name
|
|
2343
|
+
if let Some(name) = opt::<Value>(ruby, options, "x_axis")? {
|
|
2344
|
+
chart.x_axis().set_name(chart_label(ruby, name)?.as_str());
|
|
2250
2345
|
}
|
|
2251
|
-
if let Some(name) = opt::<
|
|
2252
|
-
chart.y_axis().set_name(name
|
|
2346
|
+
if let Some(name) = opt::<Value>(ruby, options, "y_axis")? {
|
|
2347
|
+
chart.y_axis().set_name(chart_label(ruby, name)?.as_str());
|
|
2253
2348
|
}
|
|
2254
2349
|
if let Some(width) = opt::<u32>(ruby, options, "width")? {
|
|
2255
2350
|
chart.set_width(width);
|
data/lib/fast_xlsx/version.rb
CHANGED
data/lib/fast_xlsx.rb
CHANGED
|
@@ -391,7 +391,8 @@ module FastXlsx
|
|
|
391
391
|
# @option options [Integer] :x_offset, :y_offset pixels
|
|
392
392
|
# @option options [String] :alt_text
|
|
393
393
|
# @return [self]
|
|
394
|
-
# @raise [FastXlsx::Error] for data that isn't a supported image
|
|
394
|
+
# @raise [FastXlsx::Error] for data that isn't a supported image, or an
|
|
395
|
+
# image that would be larger than a worksheet
|
|
395
396
|
def insert_image(*args, **)
|
|
396
397
|
_insert_image(*image_args(args), { ** })
|
|
397
398
|
end
|
|
@@ -415,7 +416,9 @@ module FastXlsx
|
|
|
415
416
|
# :radar, :scatter, and the stacked variants
|
|
416
417
|
# @param series [Array<Hash>] { values:, categories:, name: } with ranges
|
|
417
418
|
# such as "Sheet1!$B$2:$B$13"
|
|
418
|
-
# @option options [String] :title, :x_axis, :y_axis
|
|
419
|
+
# @option options [String, Formula] :title, :x_axis, :y_axis text; these and a
|
|
420
|
+
# series name: take a {Formula} such as "Sheet1!$A$1" to show a cell instead
|
|
421
|
+
# @raise [ArgumentError] for text that Excel would read as a cell reference
|
|
419
422
|
# @option options [Integer] :width, :height pixels
|
|
420
423
|
# @return [self]
|
|
421
424
|
def insert_chart(*cell, type:, series:, **)
|
data/sig/fast_xlsx.rbs
CHANGED
|
@@ -149,13 +149,13 @@ module FastXlsx
|
|
|
149
149
|
?x_offset: Integer, ?y_offset: Integer, ?alt_text: String) -> self
|
|
150
150
|
def embed_image: (Integer row, Integer col, String | _Reader source, ?alt_text: String?, ?format: format?) -> self
|
|
151
151
|
| (String cell, String | _Reader source, ?alt_text: String?, ?format: format?) -> self
|
|
152
|
-
type chart_series = { values: String, ?categories: String, ?name: String }
|
|
152
|
+
type chart_series = { values: String, ?categories: String, ?name: String | Formula }
|
|
153
153
|
|
|
154
154
|
def insert_chart: (Integer row, Integer col, type: Symbol, series: Array[chart_series],
|
|
155
|
-
?title: String, ?x_axis: String, ?y_axis: String,
|
|
155
|
+
?title: String | Formula, ?x_axis: String | Formula, ?y_axis: String | Formula,
|
|
156
156
|
?width: Integer, ?height: Integer) -> self
|
|
157
157
|
| (String cell, type: Symbol, series: Array[chart_series],
|
|
158
|
-
?title: String, ?x_axis: String, ?y_axis: String,
|
|
158
|
+
?title: String | Formula, ?x_axis: String | Formula, ?y_axis: String | Formula,
|
|
159
159
|
?width: Integer, ?height: Integer) -> self
|
|
160
160
|
type table_column = String | { header: String, ?total: Symbol, ?total_label: String, ?format: format }
|
|
161
161
|
|