From 9af4b5254cbe6a6770ebe78ba14074266b05471e Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sat, 10 Feb 2024 00:38:35 +0900 Subject: sc: pivot table not correct when data and PT cache is not in sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It can happen that the pivot table is not updated and the sheet data is changed so much that it doesn't match the pivot table cached definitions. This is a perfectly valid scenario and nothing should be wrong (the pivot table can just be updated once loaded). At XLSX import we should always check the cached definitions, because the pivot table description is made using the cached data, not the actual data. The issue can occur when looking up the name of a PT field we however didn't check the cached definition but checked the sheet data, so because the indices changed so much (many columns were removed in the sheet data) we can not find the actual field name. The solution is simple - get the field name from the cached pivot table definition. Change-Id: I3b5b33f33f3c484f0b66b97ac97200d9913edcfe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163197 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sc/source/filter/oox/pivottablebuffer.cxx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'sc/source/filter/oox') diff --git a/sc/source/filter/oox/pivottablebuffer.cxx b/sc/source/filter/oox/pivottablebuffer.cxx index 252b4773ccf2..f434780d2756 100644 --- a/sc/source/filter/oox/pivottablebuffer.cxx +++ b/sc/source/filter/oox/pivottablebuffer.cxx @@ -396,13 +396,18 @@ void PivotTableField::finalizeImport( const Reference< XDataPilotDescriptor >& r // try to get the source field and its name from passed DataPilot descriptor Reference< XIndexAccess > xDPFieldsIA( rxDPDesc->getDataPilotFields(), UNO_SET_THROW ); xDPField.set( xDPFieldsIA->getByIndex( nDatabaseIdx ), UNO_QUERY_THROW ); - Reference< XNamed > xDPFieldName( xDPField, UNO_QUERY_THROW ); - maDPFieldName = xDPFieldName->getName(); - OSL_ENSURE( !maDPFieldName.isEmpty(), "PivotTableField::finalizeImport - no field name in source data found" ); + } + catch( Exception& ) + { + } + try + { // try to convert grouping settings if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) ) { + maDPFieldName = pCacheField->getName(); + // numeric grouping is done inplace, no nested group fields will appear if( pCacheField->hasNumericGrouping() ) { @@ -428,6 +433,13 @@ void PivotTableField::finalizeImport( const Reference< XDataPilotDescriptor >& r mrPivotTable.finalizeParentGroupingImport( xDPField, *pCacheField, aItemNames ); } } + else + { + // No choice - check the sheet for field name + Reference< XNamed > xDPFieldName( xDPField, UNO_QUERY_THROW ); + maDPFieldName = xDPFieldName->getName(); + OSL_ENSURE( !maDPFieldName.isEmpty(), "PivotTableField::finalizeImport - no field name in source data found" ); + } } catch( Exception& ) { -- cgit v1.2.3