Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,11 +1237,11 @@ fn parse_format(
found: r.data.len(),
});
}
// The specification restricts `ifmt` to a few ranges but some writers use
// other ids, for example ones that start their custom formats at 50. The
// format string in the record is used for any id so that it takes
// precedence over the built-in format with the same id.
let ifmt = read_u16(r.data);
match ifmt {
5..=8 | 23..=26 | 41..=44 | 63..=66 | 164..=382 => (),
_ => return Err(XlsError::InvalidFormat { ifmt }),
}

let s = parse_string(&r.data[2..], encoding, biff)?;
Ok((ifmt, detect_custom_number_format(&s)))
Expand Down
Binary file added tests/format_id_overrides_builtin.xls
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,20 @@ fn test_xlsx_date_east_asian_explicit_formats() {
}
}

#[test]
fn test_xls_format_id_overrides_builtin() {
// Test that a Format record with an id outside the ranges allowed by the
// specification takes precedence over the built-in date format with the
// same id. The file defines format 50 as `0.000` and format 51 as `0.0`.
// See issue #798.
let mut workbook: Xls<_> = wb("format_id_overrides_builtin.xls");
let range = workbook.worksheet_range_at(0).unwrap().unwrap();

assert_eq!(range.get_value((1, 1)), Some(&Float(3.505)));
assert_eq!(range.get_value((2, 1)), Some(&Float(286.5)));
assert_eq!(range.get_value((3, 1)), Some(&Int(5)));
}

// Test that a custom number format whose `formatCode` contains quoted literal
// text (e.g. `mmmm" "yyyy`) is detected as a date. The quotes are stored in
// styles.xml as `&quot;` XML entity references, so the format detection must
Expand Down
Loading