Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Integer Error from Excel files with empty s attributes #420

Closed
jlondonobo opened this issue Apr 7, 2024 · 0 comments · Fixed by #421
Closed

Parse Integer Error from Excel files with empty s attributes #420

jlondonobo opened this issue Apr 7, 2024 · 0 comments · Fixed by #421

Comments

@jlondonobo
Copy link
Contributor

Description

Reading an Excel file that contains empty s attributes (s="") results in a ParseIntError.

Steps to reproduce

  1. Download an example file from Colombia's National Tax and Customs Department: https://www.dian.gov.co/dian/cifras/Basesestadisticasimportaciones/01_Importaciones_2018_Enero.zip

  2. Attempt to parse the file:

    use calamine::{open_workbook, Reader, Xlsx};
    
    fn main() -> Result<(), Box<dyn std::error::Error>> {
        let path = "PATH_TO_FILE";
        let mut workbook: Xlsx<_> = open_workbook(path)?;
        dbg!(workbook.worksheet_range("Sheet1"));
        Ok(())
    }
    • Note: Directly opening and saving the file in Excel may auto-correct the s attributes, thus altering the test conditions.

Possible Cause

The issue likely stems from the read_v function, which attempts to convert style attributes into integers. When an s attribute is an empty string, the conversion fails, leading to the error.

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()?;
formats.get(id)
}
_ => Some(&CellFormat::Other),

Suggested fix

A potential fix could involve modifying the read_v function to handle empty s attributes gracefully, either by ignoring them or by assigning a default style value.

@jlondonobo jlondonobo changed the title Parse Integer Error from Excel files with empty s attributes. Parse Integer Error from Excel files with empty s attributes Apr 7, 2024
@jlondonobo jlondonobo mentioned this issue Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant