tdf#171133: PivotTable grouping with string numbers
When pivot table data contains numbers formatted as string, discrete grouping of this data is not preserved. Change-Id: I00866c37048aa545d3707b27451e615e248f8ba2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202953 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Michael Stahl <michael.stahl@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203583 Tested-by: Jenkins Reviewed-by: Balazs Varga <balazs.varga@collabora.com>
This commit is contained in:
committed by
Balazs Varga
parent
4e3f695614
commit
343601b11f
Binary file not shown.
@@ -3011,6 +3011,20 @@ CPPUNIT_TEST_FIXTURE(ScPivotTableFiltersTest, testCalcFieldNameErrorXLSX)
|
||||
CPPUNIT_ASSERT_EQUAL(u"IF(#NAME? >0,#NAME?,0)"_ustr, aFormula);
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(ScPivotTableFiltersTest, testNumberGroupingXLS)
|
||||
{
|
||||
createScDoc("xls/pivottable_number_grouping.xls");
|
||||
save(TestFilter::XLSX);
|
||||
|
||||
xmlDocUniquePtr pCacheDef = parseExport(u"xl/pivotCache/pivotCacheDefinition1.xml"_ustr);
|
||||
CPPUNIT_ASSERT(pCacheDef);
|
||||
|
||||
assertXPath(pCacheDef,
|
||||
"/x:pivotCacheDefinition/x:cacheFields/x:cacheField[@databaseField='0']/"
|
||||
"x:fieldGroup/x:groupItems",
|
||||
"count", u"3");
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -404,6 +404,18 @@ void XclImpPCField::ConvertGroupField( ScDPSaveData& rSaveData, const ScfStringV
|
||||
|
||||
// private --------------------------------------------------------------------
|
||||
|
||||
static OUString lcl_ItemToText( const XclImpPCItem& rItem )
|
||||
{
|
||||
const OUString& rText = rItem.ConvertToText();
|
||||
if( !rText.isEmpty() )
|
||||
return rText;
|
||||
if( const double* pVal = rItem.GetDouble() )
|
||||
return OUString::number( *pVal );
|
||||
if( const sal_Int16* pVal = rItem.GetInteger() )
|
||||
return OUString::number( *pVal );
|
||||
return rText;
|
||||
}
|
||||
|
||||
void XclImpPCField::ConvertStdGroupField( ScDPSaveData& rSaveData, const ScfStringVec& rVisNames ) const
|
||||
{
|
||||
const XclImpPCField* pBaseField = GetGroupBaseField();
|
||||
@@ -419,7 +431,7 @@ void XclImpPCField::ConvertStdGroupField( ScDPSaveData& rSaveData, const ScfStri
|
||||
aGroupItems.reserve( maItems.size() );
|
||||
// initialize with own item names
|
||||
for( const auto& rxItem : maItems )
|
||||
aGroupItems.emplace_back( rxItem->ConvertToText() );
|
||||
aGroupItems.emplace_back(lcl_ItemToText(*rxItem));
|
||||
|
||||
// *** iterate over all base items, set their names at corresponding own items ***
|
||||
for( sal_uInt16 nItemIdx = 0, nItemCount = static_cast< sal_uInt16 >( maGroupOrder.size() ); nItemIdx < nItemCount; ++nItemIdx )
|
||||
@@ -427,7 +439,7 @@ void XclImpPCField::ConvertStdGroupField( ScDPSaveData& rSaveData, const ScfStri
|
||||
if( const XclImpPCItem* pBaseItem = pBaseField->GetItem( nItemIdx ) )
|
||||
if( const XclImpPCItem* pGroupItem = GetItem( maGroupOrder[ nItemIdx ] ) )
|
||||
if( *pBaseItem != *pGroupItem )
|
||||
aGroupItems[ maGroupOrder[ nItemIdx ] ].AddElement( pBaseItem->ConvertToText() );
|
||||
aGroupItems[maGroupOrder[nItemIdx]].AddElement(lcl_ItemToText(*pBaseItem));
|
||||
|
||||
// *** create the ScDPSaveGroupDimension object, fill with grouping info ***
|
||||
ScDPSaveGroupDimension aGroupDim( rBaseFieldName, GetFieldName( rVisNames ) );
|
||||
|
||||
Reference in New Issue
Block a user