tafia / calamine

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

ODS: incorrect range calculation if first row is empty and repeated #354

Closed dimastbk closed 9 months ago

dimastbk commented 10 months ago

If first row in ODS contains table:number-rows-repeated > 1, then row_min of Range is wrong.

number_rows_repeated.ods

#[test]
fn ods_number_rows_repeated() {
    setup();

    let path = format!(
        "{}/tests/number_rows_repeated.ods",
        env!("CARGO_MANIFEST_DIR")
    );
    let mut ods: Ods<_> = open_workbook(&path).unwrap();

    let range = ods.worksheet_range_at(0).unwrap().unwrap();
    let range = range.range((0, 0), range.end().unwrap());

    range_eq!(
        range,
        [
            [String("A".to_string()), String("B".to_string())],
            [String("C".to_string()), String("D".to_string())],
            [String("C".to_string()), String("D".to_string())],
            [Empty, Empty],
            [Empty, Empty],
            [String("C".to_string()), String("D".to_string())],
            [Empty, Empty],
            [String("C".to_string()), String("D".to_string())],
        ]
    );

    let range = ods.worksheet_range_at(1).unwrap().unwrap();
    let range = range.range((0, 0), range.end().unwrap());

    range_eq!(
        range,
        [
            [Empty, Empty],
            [String("A".to_string()), String("B".to_string())],
            [String("C".to_string()), String("D".to_string())],
            [String("C".to_string()), String("D".to_string())],
            [Empty, Empty],
            [Empty, Empty],
            [String("C".to_string()), String("D".to_string())],
            [Empty, Empty],
            [String("C".to_string()), String("D".to_string())],
        ]
    );

    let range = ods.worksheet_range_at(2).unwrap().unwrap();
    let range = range.range((0, 0), range.end().unwrap());

    range_eq!( // failed
        range,
        [
            [Empty, Empty],
            [Empty, Empty],
            [String("A".to_string()), String("B".to_string())],
            [String("C".to_string()), String("D".to_string())],
            [String("C".to_string()), String("D".to_string())],
            [Empty, Empty],
            [Empty, Empty],
            [String("C".to_string()), String("D".to_string())],
            [Empty, Empty],
            [String("C".to_string()), String("D".to_string())],
        ]
    );
}