Skip to content
Merged
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
9 changes: 7 additions & 2 deletions src/xlsx/cells_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,14 @@ fn read_v<'s>(
};
match get_attribute(c_element.attributes(), QName(b"t"))? {
Some(b"s") => {
// shared string
// Cell value is an index into the shared string table.
let idx = atoi_simd::parse::<usize>(v.as_bytes()).unwrap_or(0);
Ok(DataRef::SharedString(&strings[idx]))
match strings.get(idx) {
Some(shared_string) => Ok(DataRef::SharedString(shared_string)),
None => Err(XlsxError::Unexpected(
"Cell string index not found in shared strings table",
)),
}
}
Some(b"b") => {
// boolean
Expand Down
6 changes: 6 additions & 0 deletions src/xlsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,12 @@ where
is_phonetic_text = true;
}
Ok(Event::End(ref e)) if e.name() == closing => {
if rich_buffer.is_none() {
// An empty <s></s> element, without <t> or other
// subelements, is treated as a valid empty string in Excel.
rich_buffer = Some(String::new());
}

return Ok(rich_buffer);
}
Ok(Event::End(ref e)) if e.local_name().as_ref() == b"rPh" => {
Expand Down
Binary file added tests/empty_shared_string.xlsx
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2264,3 +2264,16 @@ fn test_xlsb_case_insensitive_part_name() {
fn test_xlsx_backward_slash_part_name() {
let _: Xlsx<_> = wb("issue_530.xlsx");
}

// Test for issue #573 where a shared string doesn't have a <t> sub-element.
// This is unusual but valid according to the xlsx specification.
#[test]
fn test_xlsx_empty_shared_string() {
let mut excel: Xlsx<_> = wb("empty_shared_string.xlsx");
let range = excel.worksheet_range("Sheet1").unwrap();

range_eq!(
range,
[[String("abc".to_string())], [String("".to_string())]]
);
}