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
13 changes: 10 additions & 3 deletions src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,11 @@ impl<RS: Read + Seek> Xls<RS> {
}
let row = read_u16(r.data);
let col = read_u16(&r.data[2..]);
let format = self.formats.get(read_u16(&r.data[4..]) as usize);
fmla_pos = (row as u32, col as u32);
if let Some(val) = parse_formula_value(&r.data[6..14])? {
if let Some(val) =
parse_formula_value(&r.data[6..14], format, self.is_1904)?
{
// If the value is a string
// it will appear in 0x0207 record coming next
cells.push(Cell::new(fmla_pos, val));
Expand Down Expand Up @@ -1601,7 +1604,11 @@ fn parse_formula(
}

/// `FormulaValue` [MS-XLS 2.5.133]
fn parse_formula_value(r: &[u8]) -> Result<Option<Data>, XlsError> {
fn parse_formula_value(
r: &[u8],
format: Option<&CellFormat>,
is_1904: bool,
) -> Result<Option<Data>, XlsError> {
match *r {
// String, value should be in next record
[0x00, .., 0xFF, 0xFF] => Ok(None),
Expand All @@ -1613,7 +1620,7 @@ fn parse_formula_value(r: &[u8]) -> Result<Option<Data>, XlsError> {
typ: "error",
val: e,
}),
_ => Ok(Some(Data::Float(read_f64(r)))),
_ => Ok(Some(format_excel_f64(read_f64(r), format, is_1904))),
}
}

Expand Down
Binary file added tests/formula-date-format.xls
Binary file not shown.
24 changes: 24 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2882,3 +2882,27 @@ fn test_xlsx_inline_str_with_value() {
);
assert_eq!(range.get_value((1, 3)), Some(&String("1.".to_string())));
}

#[test]
fn test_xls_formula_date_format() {
let mut wb: Xls<_> = wb("formula-date-format.xls");
let range = wb.worksheet_range("Sheet1").unwrap();
// This date is a literal:
assert_eq!(
range.get_value((0, 0)),
Some(&DateTime(ExcelDateTime::new(
41331.,
ExcelDateTimeType::DateTime,
true
)))
);
// While this one is a formula result:
assert_eq!(
range.get_value((1, 0)),
Some(&DateTime(ExcelDateTime::new(
41332.,
ExcelDateTimeType::DateTime,
true
)))
);
}
Loading