tafia / calamine

A pure Rust Excel/OpenDocument SpreadSheets file reader: rust on metal sheets
MIT License
1.69k stars 158 forks source link

calamine: xls wrong value for referenced String cells #334

Closed ahah43 closed 1 year ago

ahah43 commented 1 year ago

Description

for .XLS files, it is found that wrong value is returned for any cell referencing other string cell.

Note

this error is NOT found when reading from .XLSX files processed by the exact same code (see the rust code attached below). This error occurred using Calamine 0.21.1

Attachments

  1. xlsx_ref_String.xlsx
  2. xls_ref_String.xls
use calamine::{open_workbook_auto, Reader};
use std::io::Error;
fn main() -> Result<(), Error> {
    let this_sheet = "Sheet1";
    println!("\n======================================================================\n");
    // try both the xls and xlsx versions
    for excel_file in ["xls_ref_String.xls", "xlsx_ref_String.xlsx"] {
        let mut workbook = open_workbook_auto(excel_file).expect("Cannot open file");
        println!("File: {:?} are: \n", excel_file);
        // extracting values
        if let Some(Ok(r)) = workbook.worksheet_range(this_sheet) {
            for used_cell in r.used_cells() {
                println!(
                    "\tValue: A{:?} = {:?}",
                    used_cell.0, used_cell.2
                );
            }
        }
        println!("\n======================================================================\n");
    }
    Ok(())
}

See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies] calamine = "0.21.1"


- screenshots of the excel files (same for both the xls and xlsx versions)
![excel screenshot](https://github.com/tafia/calamine/assets/5351850/0e818f2d-2e29-4479-b20b-59a99d287199)

- A snapshot of the program results.
![output scrrenshot](https://github.com/tafia/calamine/assets/5351850/71e603f7-a213-4705-bf7f-efa39674ee5b)
tafia commented 1 year ago

Thanks for the report, I'll have a look ASAP.

tafia commented 1 year ago

Should be fixed now, deployed in v0.21.2

ahah43 commented 1 year ago

Should be fixed now, deployed in v0.21.2

Works like a charm!

Thank you very much!

tafia commented 1 year ago

Thanks for the detailed issues. Very helpful!