From e7e1d75d6ca522bd0139c6ef8b26662ce9631567 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 12 Oct 2024 22:57:11 +0200 Subject: [PATCH] XLSX: do not emit error on without 'r' attribute Fixes https://github.com/duckdb/duckdb_spatial/issues/425 --- .../data/xlsx/row_without_r_attribute.xlsx | Bin 0 -> 2325 bytes autotest/ogr/ogr_xlsx.py | 13 ++++++++++++ ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp | 20 ++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 autotest/ogr/data/xlsx/row_without_r_attribute.xlsx diff --git a/autotest/ogr/data/xlsx/row_without_r_attribute.xlsx b/autotest/ogr/data/xlsx/row_without_r_attribute.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..53fbf6b644cf4ad0d5d654796f392e4867a7dff1 GIT binary patch literal 2325 zcmWIWW@Zs#;Nak3$gFgaWIzHEKz2oretCXTc5y~(YDuv^m@?F>$jyoEcjRkU5O7`Z zlorn(YvRkiBeSaM8w1PAS*IKtGWz2m9g3R%`Ct7{$%}P&j-*Lne&Oj9TbMAd=e^r2 zRU7&5msz7!#pLg2ZZO*%v|J_egk_B2WXUy`SAIGeB{|k8LRTe<#k=nt;hdvvvxkdW!axgflFpY^=BpOr0!E# zC9i6cdr4>Gr1VnWS~h1)@4NDls!I zgy(Yn-}S@#U_8i6`k(D2dVxOL2E@3%#0`{t)0Y+mN(@3W#o;*^qQT)`#9up0XaeWm6-O?E8R6E4k`OMe@@&EsO`&9hc6FRe1S zN|v@4%}%v`X(t(=;lXU)>WT}%EDOOVJu#dksqj}{S!GJfLzn%XR{40#^oAM!7ma4^7yG5PL-lh( z^s>LZIyb}f|?1egaF9SX9%!Dr$h(Lm-I3uwrH6^&DC^Ij;7@TQ)PlFP*>-Rd> z6G0nR^1G<`eiU^4z?l1|;gXxQf#+MFqvy?)N-mx~VEMhMeYyN^mHfL+AN3Yq)>!7U z`%?HZTcN7p_LE)9nwS+dYo8k|kkDGh%tBjhA$`-erYdwyU+0hP9q~AIfeP63< zknlUbC!&jl2GTfBc~&bgu&Q_fs1F_V84Gw+F? zV9&896JpP+?9NMFwkUpfLcClnx5hq@x4%~`NZtzc)DIxWo%s17-bPLfy?tl%n!y>M zb?f&d4y#wV&WKs%wR3CWt=-Jt8=7*rWKa6`Hru1#;@cLfv)he>^Xzl<^*nO+1W#BS zEbt=hzC?M@hq8(|+XLIYPOV=4`Qq=*9Xpa)V>z4^RjXBweqvPnShDD(cVX12 z`;TW%V-@w-u;NN+Qta=0!rn9W%kPCopGis1I1+Mg(V+#4HzwZgxPJBUlc2 zIpv`9hMTh6HWV)1b(g!jTvp|1_Pwsid{L%QyCysf& zSI@1?=lwKAp~j2f?2pSwx#Is~$@L5tj{hbY+^g@FcMW=MXe-=zQ@mYj|A9x~jMr_Z zen1=;rjE>@6v)UV!honVk!u@Jorwx?)u8C6AQ$kcraS-|h{Y6eJ%w%xa@h&03=m*5 z(Dg`F1G>f*q>=?xv?9PfU|EB^phY(aIje%oAq3b73_74W7^M=r3CKwpl%)}10}DJL kV1+%pX5@GRrE&zg#fmk}2Y9oxffTU=;aOl18L@+S0O6``4*&oF literal 0 HcmV?d00001 diff --git a/autotest/ogr/ogr_xlsx.py b/autotest/ogr/ogr_xlsx.py index f0c7a3a877c9..a4b8cc287935 100755 --- a/autotest/ogr/ogr_xlsx.py +++ b/autotest/ogr/ogr_xlsx.py @@ -649,3 +649,16 @@ def test_ogr_xlsx_read_xml_prefix(): f = lyr.GetNextFeature() assert f["Col1"] == "foo" assert f["Col2"] == "bar" + + +############################################################################### +# Test reading a XLSX file with without "r" attribute + + +def test_ogr_xlsx_read_row_without_r_attribute(): + + ds = ogr.Open("data/xlsx/row_without_r_attribute.xlsx") + lyr = ds.GetLayer(0) + f = lyr.GetNextFeature() + assert f["ID"] == 1 + assert f["NAME"] == "TEST123" diff --git a/ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp b/ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp index 5f4fdf4544eb..f7d32b508e4a 100644 --- a/ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp +++ b/ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp @@ -816,14 +816,22 @@ void OGRXLSXDataSource::startElementTable(const char *pszNameIn, apoCurLineValues.clear(); apoCurLineTypes.clear(); - int nNewCurLine = atoi(GetAttributeValue(ppszAttr, "r", "0")); - if (nNewCurLine <= 0) + int nNewCurLine; + if (const char *pszR = GetAttributeValue(ppszAttr, "r", nullptr)) { - CPLError(CE_Failure, CPLE_AppDefined, "Invalid row: %d", - nNewCurLine); - return; + nNewCurLine = atoi(pszR); + if (nNewCurLine <= 0) + { + CPLError(CE_Failure, CPLE_AppDefined, "Invalid row: %d", + nNewCurLine); + return; + } + nNewCurLine--; + } + else + { + nNewCurLine = nCurLine; } - nNewCurLine--; const int nFields = std::max( static_cast(apoFirstLineValues.size()), poCurLayer != nullptr ? poCurLayer->GetLayerDefn()->GetFieldCount()