diff --git a/src/xlsx/cells_reader.rs b/src/xlsx/cells_reader.rs index d4207688..ed5a4c17 100644 --- a/src/xlsx/cells_reader.rs +++ b/src/xlsx/cells_reader.rs @@ -333,7 +333,10 @@ fn read_v<'s>( ) -> Result, 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), diff --git a/tests/empty_s_attribute.xlsx b/tests/empty_s_attribute.xlsx new file mode 100644 index 00000000..b4e934b8 Binary files /dev/null and b/tests/empty_s_attribute.xlsx differ diff --git a/tests/test.rs b/tests/test.rs index 8370d13d..05d6e531 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -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.)], + ] + ); +}