From 21c7f617256f118b559ac04aef6dca90a72bc1a2 Mon Sep 17 00:00:00 2001 From: Eric Jolibois Date: Tue, 8 Oct 2024 20:00:16 +0200 Subject: [PATCH 1/2] test: add test that explains the bug --- tests/no-header.xlsx | Bin 0 -> 4716 bytes tests/test.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/no-header.xlsx diff --git a/tests/no-header.xlsx b/tests/no-header.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..1d938f8e533eefcb152875bd3aeb81c8914a44af GIT binary patch literal 4716 zcmai12|Uw(AIEYOX3RBm{Y^rSxo>ji$erBem~-YVL~glKjO0i{=7`FDO|G1iq$F}I zSGkiAEuKx!^G`j`zvr{pw%=Z_ec#*X{ri00pZCW|4{(f;go=uaL`O-}lH^FR60U;~ zqRxH}f$m6G|NmUTM1s5!xkI+d4lx?aPv8}x*_68#D_EV;Zpc6kh~q=Dr{3xZ7EXk{ z)RlG*A?5VKs_d>mM+Ve=)o=ud@-9^|kY8o0*|6mWu6tMCJ}nzHdMUa`%O<4@`K<;b zRq+B-{MTxTU2zrtwHuvQx)+t?apE)|U)9jgaidZ4rN;+#u3Q{^xTN`6l`1>rSwr5b znWc6>HehyhUw<^FPU^(Y+1!(RvOF=&j(g-gF1Yei%16dZMtIWh@Fjl zF>ST)ipOR5*|sKoO`i6T*!NB{_K8|4|v}?dR$528RduiyprH zpfdeAa+Vtuk#}jjeTLJ?s`#B%-NV(3Bik3vzWJkBdrniFX;TUQ#sQAg&rYh9VRcbf zrsMr^D-BT?$u3kQ2uc7m`gR5Iy?&(H8uk>iX6(#i#^hByLoV-=#EBK%EqOjAeYcs4 zq@TIO_YqdCuKYb}+#=AXU8f@X0kF;`&dXJ{A~Y4Tp^uty(1}$$r{?lTEWnn!J5Oqv z&wPyvhA9Gm@#2*aDd<}~!A~wRzBJx-9vgd%f@U+pS2Q4;2Rg>atMmNnx^%=!+l+cm z2M5NyjfQ+Fxu3cFl-qz5WFn8YN{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c~$}N_!^DWso||slET-5n9t9lg&Xz^`Hzy-I9`wY>gvFF z+&n`r%nJnnzRxc=uJD!4vo( z&vSrAPaog%i;$$w*uY-7+Y;f_Cs9igVHmfEav8uI2dmGoU4J6Kgk5ue@$`^&ulO1x zDFWk=LuDi-Vxy&qjhiQD_H@lU(Fk>0N;M>m>ZQS=DEOF%iY#r#}je@8jG6A-tb zpK+cbCcmQm&t2$uz@y%WxJvvCBLWo!z~2{(-vN$#45CH)8I6>O0RLr}en&Vum55&C zXP~HlApGr2em{CtNr_|YXB3?Hn~whsvEL6L6&0e`{tN+{!^8g|y}#oe?O37&{S0eD mI!6TQ_k%}^?pN-$2u}2Ww6~ESIRz2@1mTfQkV4F1&i?{ZZG++f literal 0 HcmV?d00001 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); +} From f5cfdca6cff04c020a883293a51b6ac31ed00376 Mon Sep 17 00:00:00 2001 From: Eric Jolibois Date: Tue, 8 Oct 2024 20:12:48 +0200 Subject: [PATCH 2/2] fix: insert header cell at the beginning of cells --- src/xlsb/mod.rs | 2 +- src/xlsx/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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,