calamine icon indicating copy to clipboard operation
calamine copied to clipboard

Still can not deserialize excel sheet

Open HosMercury opened this issue 8 months ago • 3 comments

` fn read_excel(file_path: &str) -> Result<(), Box<dyn std::error::Error>> { let mut wb = open_workbook::<Xlsx<_>, _>(file_path)?;

#[derive(Debug, Deserialize)]
struct Row {
    #[serde(rename = "Quantity")]
    quantity: u32,

    #[serde(rename = "Product Name")]
    product_name: String,

    #[serde(rename = "Condition")]
    condition: String,

    #[serde(rename = "Final condition")]
    final_condition: String,

    #[serde(rename = "Serial Tracking")]
    serial_tracking: String,

    #[serde(rename = "MFG Serial")]
    mfg_serial: String,

    #[serde(rename = "Serial")]
    serial: Option<String>,

    #[serde(rename = "Cost")]
    cost: u32,

    #[serde(rename = "Price")]
    price: Option<String>,

    #[serde(rename = "Location")]
    location: String,

    #[serde(rename = "Warranty")]
    warranty: Option<String>,

    #[serde(rename = "Color")]
    color: Option<String>,

    #[serde(rename = "Type")]
    the_type: Option<String>,

    #[serde(rename = "Form Factor")]
    form_factor: Option<String>,

    #[serde(rename = "Category")]
    category: String,

    #[serde(rename = "Brand")]
    brand: String,

    #[serde(rename = "Series")]
    series: Option<String>,

    #[serde(rename = "Model")]
    model: String,

    #[serde(rename = "Model No")]
    model_no: Option<String>,

    #[serde(rename = "CPU")]
    cpu: String,

    #[serde(rename = "GPU")]
    gpu: Option<String>,

    #[serde(rename = "TotalRam")]
    total_ram: String,

    #[serde(rename = "TotalStorage")]
    total_storage: Option<String>,

    #[serde(rename = "Storage Config")]
    storage_config: Option<String>,

    #[serde(rename = "Screen Size")]
    screen_size: Option<String>,

    #[serde(rename = "Screen Resolution")]
    screen_resolution: Option<String>,

    #[serde(rename = "Resolution Code")]
    resolution_code: Option<String>,

    #[serde(rename = "Refresh Rate")]
    refresh_rate: Option<String>,

    #[serde(rename = "Screen Panel")]
    screen_panel: Option<String>,

    #[serde(rename = "Touchscreen")]
    touch_screen: Option<String>,

    #[serde(rename = "Keyboard")]
    keyboard: Option<String>,

    #[serde(rename = "Cam")]
    cam: Option<String>,

    #[serde(rename = "Battery")]
    battery: String,

    #[serde(rename = "Hinge")]
    hinge: Option<String>,

    #[serde(rename = "Mouse")]
    mouse: Option<String>,

    #[serde(rename = "Audit Result")]
    audit_result: Option<String>,

    #[serde(rename = "Issues")]
    issues: Option<String>,

    #[serde(rename = "Notes")]
    notes: String,

    #[serde(rename = "SpacePro ID")]
    spacepro_id: Option<String>,

    #[serde(rename = "Images")]
    image: Option<String>,
}

let sh1 = wb.worksheet_range("Sheet1")?;

let deser1 = sh1.deserialize()?;
let mut rows1: Vec<Row> = Vec::new();
for row in deser1 {
    rows1.push(row?);
}
println!("sheet 1: {rows1:?}");
Ok(())

} `

I have this error Error processing Excel: missing field Quantity``

Although I have an Excel sheet with columns the same as the struct above

HosMercury avatar Apr 25 '25 20:04 HosMercury

try to use Option<u32> ? I suspect some cell are not integers?

tafia avatar Apr 30 '25 02:04 tafia

I get the same error if i changed the order of struct props . For example if the first prop is ( brand ) i got the error (Error processing Excel: missing field Brand ) So it is not about the column itself.

HosMercury avatar Apr 30 '25 13:04 HosMercury

Any reason

HosMercury avatar May 09 '25 16:05 HosMercury

have you tried to put Option?? Without the source file it is hard to guess.

tafia avatar Jun 19 '25 04:06 tafia

@HosMercury Could you please attach a sample file in order to debug this. It can contain sample (non-proprietary) data but it should be in the format that you expect and with the same headers.

Without a sample file it isn't possible to say what the issue is and this question will be closed.

jmcnamara avatar Jun 30 '25 14:06 jmcnamara

Closing due to a lack of a reproducible file. Will reopen/reinvestigate if a file is provided.

jmcnamara avatar Jul 04 '25 14:07 jmcnamara