Skip to content

Commit

Permalink
Merge pull request #470 from PrettyWood/fix/header-row-middle
Browse files Browse the repository at this point in the history
fix: header row in the middle can break
  • Loading branch information
tafia authored Oct 10, 2024
2 parents 1b12664 + f5cfdca commit f39b58a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/xlsb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ impl<RS: Read + Seek> ReaderRef<RS> for Xlsb<RS> {
// 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,
Expand Down
2 changes: 1 addition & 1 deletion src/xlsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ impl<RS: Read + Seek> ReaderRef<RS> for Xlsx<RS> {
// 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,
Expand Down
Binary file added tests/no-header.xlsx
Binary file not shown.
26 changes: 26 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit f39b58a

Please sign in to comment.