Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,15 @@ impl<RS: Read + Seek> Xls<RS> {
});
formulas.push(Cell::new(fmla_pos, fmla));
}
_ => (),
// tests/high_byte_string.xls contains a record type that
// cannot be found in the "By Number" 2.3.2 table
0x00D6 => {
let Ok(s) = parse_label(r.data, &encoding, biff) else {
continue;
};
cells.push(s);
}
_ => {}
}
}
let range = Range::from_sparse(cells);
Expand Down Expand Up @@ -1035,8 +1043,8 @@ fn read_dbcs(
Ok(s)
}

fn read_unicode_string_no_cch(encoding: &XlsEncoding, buf: &[u8], len: &usize, s: &mut String) {
encoding.decode_to(&buf[1..=*len], *len, s, Some(buf[0] & 0x1 != 0));
fn read_unicode_string_no_cch(enc: &XlsEncoding, buf: &[u8], len: &usize, s: &mut String) -> usize {
enc.decode_to(&buf[1..], *len, s, Some(buf[0] & 0x1 != 0)).1
}

struct Record<'a> {
Expand Down Expand Up @@ -1311,9 +1319,9 @@ fn parse_formula(
stack.push(formula.len());
formula.push('\"');
let cch = rgce[0] as usize;
read_unicode_string_no_cch(encoding, &rgce[1..], &cch, &mut formula);
let l = read_unicode_string_no_cch(encoding, &rgce[1..], &cch, &mut formula);
formula.push('\"');
rgce = &rgce[2 + cch..];
rgce = &rgce[2 + l..];
}
0x18 => {
rgce = &rgce[5..];
Expand Down
Binary file added tests/high_byte_string.xls
Binary file not shown.
22 changes: 22 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2264,3 +2264,25 @@ fn test_xlsb_case_insensitive_part_name() {
fn test_xlsx_backward_slash_part_name() {
let _: Xlsx<_> = wb("issue_530.xlsx");
}

#[test]
fn test_high_byte_strings() {
// file contains as well as record types that do not seem to be present in the spec
let mut xls: Xls<_> = wb("high_byte_string.xls");
for (_name, ws) in xls.worksheets() {
for (row, _col, cell) in ws.used_cells() {
if row == 3 {
assert_eq!(
cell.as_string().unwrap(),
"Inside FERC's Gas Market Report monthly bidweek price file. "
);
}
}
}
// FIXME: Libreoffice recognizes a REPT("O", I44) formula
let formulas = xls.worksheet_formula("Sheet1").unwrap();
assert_eq!(
"Unrecognised formula for cell (43, 9): Unrecognized { typ: \"ptg\", val: 192 }",
formulas.get_value((43, 9)).unwrap()
);
}