Skip to content

Commit

Permalink
Merge pull request #421 from jlondonobo/fix-parsing-error
Browse files Browse the repository at this point in the history
Fixes #420
  • Loading branch information
tafia authored Apr 23, 2024
2 parents 4ad426b + 95c6e39 commit 276fb61
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/xlsx/cells_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ fn read_v<'s>(
) -> Result<DataRef<'s>, XlsxError> {
let cell_format = match get_attribute(c_element.attributes(), QName(b"s")) {
Ok(Some(style)) => {
let id: usize = std::str::from_utf8(style).unwrap_or("0").parse()?;
let id: usize = match std::str::from_utf8(style).unwrap_or("0").parse() {
Ok(parsed_id) => parsed_id,
Err(_) => 0,
};
formats.get(id)
}
_ => Some(&CellFormat::Other),
Expand Down
Binary file added tests/empty_s_attribute.xlsx
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,3 +1897,26 @@ fn issue_391_shared_formula() {
assert_eq!(expect.end(), res.end());
assert!(expect.cells().eq(res.cells()));
}

#[test]
fn issue_420_empty_s_attribute() {
setup();

let path = format!(
"{}/tests/empty_s_attribute.xlsx",
env!("CARGO_MANIFEST_DIR")
);
let mut excel: Xlsx<_> = open_workbook(&path).unwrap();

let range = excel.worksheet_range("Sheet1").unwrap();
range_eq!(
range,
[
[String("Name".to_string()), String("Value".to_string())],
[String("John".to_string()), Float(1.)],
[String("Sophia".to_string()), Float(2.)],
[String("Peter".to_string()), Float(3.)],
[String("Sam".to_string()), Float(4.)],
]
);
}

0 comments on commit 276fb61

Please sign in to comment.