mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 15:55:14 +00:00
craft-xlsx: preserve spacing in simple structured references
This commit is contained in:
1 parent
45ad9df637
commit
fb2b27b1f0
2 files changed
+26
-1
No files matched your search
@@ -681,17 +681,22 @@ fn list(t: &mut Bytes<'_>, links: &Links) -> Result<String, Unsupported> {
|
||||
2 if first <= last => Some((column(first)?, Some(column(last)?))),
|
||||
_ => return Err(Unsupported("invalid structured reference columns")),
|
||||
};
|
||||
let pad = if bits & 0x80 != 0 { " " } else { "" };
|
||||
let mut s = table.name.clone();
|
||||
match (rows, &columns) {
|
||||
([], None) => s.push_str("[]"),
|
||||
([], Some((c, None))) => {
|
||||
s.push('[');
|
||||
s.push_str(pad);
|
||||
s.push_str(c);
|
||||
s.push_str(pad);
|
||||
s.push(']');
|
||||
}
|
||||
([row], None) => {
|
||||
s.push('[');
|
||||
s.push_str(pad);
|
||||
s.push_str(row);
|
||||
s.push_str(pad);
|
||||
s.push(']');
|
||||
}
|
||||
_ => {
|
||||
@@ -701,7 +706,6 @@ fn list(t: &mut Bytes<'_>, links: &Links) -> Result<String, Unsupported> {
|
||||
Some((a, None)) => items.push(format!("[{a}]")),
|
||||
None => {}
|
||||
}
|
||||
let pad = if bits & 0x80 != 0 { " " } else { "" };
|
||||
let comma = if bits & 0x100 != 0 { ", " } else { "," };
|
||||
s.push('[');
|
||||
s.push_str(pad);
|
||||
|
||||
@@ -1839,6 +1839,27 @@ fn a_name_using_a_structured_reference_is_decoded_after_tables_are_indexed() {
|
||||
assert_eq!(wb.sheets[0].formula(CellRef::new(0, 1)), Some("Vals"), "{:?}", wb.warnings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_table_references_preserve_square_bracket_spacing() {
|
||||
let cases = [
|
||||
(1, "Sales[Val]"),
|
||||
(1 | 0x80, "Sales[ Val ]"),
|
||||
(rows(1), "Sales[#All]"),
|
||||
(rows(1) | 0x80, "Sales[ #All ]"),
|
||||
(1 | 0x100, "Sales[Val]"),
|
||||
(rows(1) | 0x100, "Sales[#All]"),
|
||||
];
|
||||
let mut data = row(0);
|
||||
for (i, (bits, _)) in cases.iter().enumerate() {
|
||||
data.extend(formula_cell(i as u32 + 1, &ptg_list(0, *bits, 1, 1, 1), &[]));
|
||||
}
|
||||
let bytes = book_with_tables(&data, &[sales(&sales_filters())]);
|
||||
let wb = read(&bytes).unwrap();
|
||||
for (i, (_, want)) in cases.iter().enumerate() {
|
||||
assert_eq!(wb.sheets[0].formula(CellRef::new(0, i as u32 + 1)), Some(*want), "{:?}", wb.warnings);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tables_are_read_as_their_xlsx_spelling() {
|
||||
// Spacing flags: 0x80 inside the outer brackets, 0x100 after commas.
|
||||
|
||||
Reference in new issue
Block a user