diff --git a/src/xlsb/mod.rs b/src/xlsb/mod.rs index 3de08a4..364bf6e 100644 --- a/src/xlsb/mod.rs +++ b/src/xlsb/mod.rs @@ -581,7 +581,7 @@ impl ReaderRef for Xlsb { // an empty cell at the beginning with row `header_row` and same column as the first non-empty cell. if cells.first().map_or(false, |c| c.pos.0 != header_row_idx) { cells.insert( - header_row_idx as usize, + 0, Cell { pos: ( header_row_idx, diff --git a/src/xlsx/mod.rs b/src/xlsx/mod.rs index 6fc81e4..78d74dd 100644 --- a/src/xlsx/mod.rs +++ b/src/xlsx/mod.rs @@ -1060,7 +1060,7 @@ impl ReaderRef for Xlsx { // an empty cell at the beginning with row `header_row` and same column as the first non-empty cell. if cells.first().map_or(false, |c| c.pos.0 != header_row_idx) { cells.insert( - header_row_idx as usize, + 0, Cell { pos: ( header_row_idx, diff --git a/tests/no-header.xlsx b/tests/no-header.xlsx new file mode 100644 index 0000000..1d938f8 Binary files /dev/null and b/tests/no-header.xlsx differ diff --git a/tests/test.rs b/tests/test.rs index 97d0da7..b74d89e 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2099,3 +2099,29 @@ fn ods_with_annotations() { let range = ods.worksheet_range("table1").unwrap(); range_eq!(range, [[String("cell a.1".to_string())],]); } + +#[rstest] +#[case(HeaderRow::Row(0), &[ + [Empty, Empty], + [Empty, Empty], + [String("a".to_string()), Float(0.0)], + [String("b".to_string()), Float(1.0)] +])] +#[case(HeaderRow::Row(1), &[ + [Empty, Empty], + [String("a".to_string()), Float(0.0)], + [String("b".to_string()), Float(1.0)] +])] +#[case(HeaderRow::Row(2), &[ + [String("a".to_string()), Float(0.0)], + [String("b".to_string()), Float(1.0)] +])] +fn test_no_header(#[case] header_row: HeaderRow, #[case] expected: &[[Data; 2]]) { + let mut excel: Xlsx<_> = wb("no-header.xlsx"); + let range = excel + .with_header_row(header_row) + .worksheet_range_at(0) + .unwrap() + .unwrap(); + range_eq!(range, expected); +}