summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorNoel Power <noel.power@novell.com>2012-01-26 14:28:36 +0000
committerNoel Power <noel.power@novell.com>2012-02-03 12:43:43 +0000
commit16af091a3339f6d00fe273f9dc5f155126e58881 (patch)
treedffd48ec40d78c6bf0caae5fe07f66e27d3870ba /oox
parentc07e9299bb2c8d5477669568b12708bd2ff12684 (diff)
fix corrupted group field entries in xlsx imported pivot table fdo#45268
Diffstat (limited to 'oox')
-rw-r--r--oox/inc/oox/xls/pivotcachebuffer.hxx6
-rw-r--r--oox/inc/oox/xls/pivottablebuffer.hxx1
-rw-r--r--oox/source/xls/pivotcachebuffer.cxx27
-rw-r--r--oox/source/xls/pivottablebuffer.cxx6
4 files changed, 32 insertions, 8 deletions
diff --git a/oox/inc/oox/xls/pivotcachebuffer.hxx b/oox/inc/oox/xls/pivotcachebuffer.hxx
index 208fbd432a20..5f73527648bc 100644
--- a/oox/inc/oox/xls/pivotcachebuffer.hxx
+++ b/oox/inc/oox/xls/pivotcachebuffer.hxx
@@ -99,10 +99,13 @@ public:
inline const ::com::sun::star::uno::Any& getValue() const { return maValue; }
/** Returns the string representation of the item. */
::rtl::OUString getName() const;
+ /** Returns true if the item is unused. */
+ inline bool isUnused() const { return mbUnused; }
private:
::com::sun::star::uno::Any maValue; /// Value of the item.
sal_Int32 mnType; /// Value type (OOXML token identifier).
+ bool mbUnused;
};
// ----------------------------------------------------------------------------
@@ -285,6 +288,8 @@ public:
const PivotCacheItem* getCacheItem( sal_Int32 nItemIdx ) const;
/** Returns the names of all shared or group items. */
void getCacheItemNames( ::std::vector< ::rtl::OUString >& orItemNames ) const;
+ /** Returns shared or group items. */
+ PivotCacheItemList getCacheItems() const;
/** Creates inplace numeric grouping settings. */
void convertNumericGrouping(
@@ -295,6 +300,7 @@ public:
/** Creates a new grouped DataPilot field and returns its name. */
::rtl::OUString createParentGroupField(
const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField,
+ const PivotCacheField& rBaseCacheField,
PivotCacheGroupItemVector& orItemNames ) const;
/** Writes the title of the field into the passed sheet at the passed address. */
diff --git a/oox/inc/oox/xls/pivottablebuffer.hxx b/oox/inc/oox/xls/pivottablebuffer.hxx
index 25c7bb104998..f118476ccbb9 100644
--- a/oox/inc/oox/xls/pivottablebuffer.hxx
+++ b/oox/inc/oox/xls/pivottablebuffer.hxx
@@ -170,6 +170,7 @@ public:
/** Finalizes the grouped field after import. */
void finalizeParentGroupingImport(
const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField,
+ const PivotCacheField& rBaseCacheField,
PivotCacheGroupItemVector& orItemNames );
/** Returns the name of the DataPilot field in the fields collection. */
diff --git a/oox/source/xls/pivotcachebuffer.cxx b/oox/source/xls/pivotcachebuffer.cxx
index e4ed2a381dd7..5132b7d43a16 100644
--- a/oox/source/xls/pivotcachebuffer.cxx
+++ b/oox/source/xls/pivotcachebuffer.cxx
@@ -173,7 +173,7 @@ void lclAdjustBinDateTime( DateTime& orDateTime )
// ============================================================================
PivotCacheItem::PivotCacheItem() :
- mnType( XML_m )
+ mnType( XML_m ), mbUnused( false )
{
}
@@ -187,6 +187,7 @@ void PivotCacheItem::readNumeric( const AttributeList& rAttribs )
{
maValue <<= rAttribs.getDouble( XML_v, 0.0 );
mnType = XML_n;
+ mbUnused = rAttribs.getBool( XML_u, false );
}
void PivotCacheItem::readDate( const AttributeList& rAttribs )
@@ -760,6 +761,13 @@ void PivotCacheField::getCacheItemNames( ::std::vector< OUString >& orItemNames
maSharedItems.getCacheItemNames( orItemNames );
}
+PivotCacheItemList PivotCacheField::getCacheItems() const
+{
+ if( hasGroupItems() )
+ return maGroupItems;
+ return maSharedItems;
+}
+
void PivotCacheField::convertNumericGrouping( const Reference< XDataPilotField >& rxDPField ) const
{
OSL_ENSURE( hasGroupItems() && hasNumericGrouping(), "PivotCacheField::convertNumericGrouping - not a numeric group field" );
@@ -822,7 +830,7 @@ OUString PivotCacheField::createDateGroupField( const Reference< XDataPilotField
return xFieldName.is() ? xFieldName->getName() : OUString();
}
-OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotField >& rxBaseDPField, PivotCacheGroupItemVector& orItemNames ) const
+OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotField >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ) const
{
OSL_ENSURE( hasGroupItems() && !maDiscreteItems.empty(), "PivotCacheField::createParentGroupField - not a group field" );
OSL_ENSURE( maDiscreteItems.size() == orItemNames.size(), "PivotCacheField::createParentGroupField - number of item names does not match grouping info" );
@@ -834,16 +842,25 @@ OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotFie
typedef ::std::vector< GroupItemList > GroupItemMap;
GroupItemMap aItemMap( maGroupItems.size() );
for( IndexVector::const_iterator aBeg = maDiscreteItems.begin(), aIt = aBeg, aEnd = maDiscreteItems.end(); aIt != aEnd; ++aIt )
+ {
if( GroupItemList* pItems = ContainerHelper::getVectorElementAccess( aItemMap, *aIt ) )
+ {
+ if ( const PivotCacheItem* pItem = rBaseCacheField.getCacheItems().getCacheItem( aIt - aBeg ) )
+ {
+ // Skip unspecified or ununsed entries or errors
+ if ( pItem->isUnused() || ( pItem->getType() == XML_m ) || ( pItem->getType() == XML_e ) )
+ continue;
+ }
pItems->push_back( static_cast< sal_Int32 >( aIt - aBeg ) );
+ }
+ }
// process all groups
Reference< XDataPilotField > xDPGroupField;
for( GroupItemMap::iterator aBeg = aItemMap.begin(), aIt = aBeg, aEnd = aItemMap.end(); aIt != aEnd; ++aIt )
{
OSL_ENSURE( !aIt->empty(), "PivotCacheField::createParentGroupField - item/group should not be empty" );
- // if the item count is greater than 1, the item is a group of items
- if( aIt->size() > 1 )
+ if( !aIt->empty() )
{
/* Insert the names of the items that are part of this group. Calc
expects the names of the members of the field whose members are
@@ -860,7 +877,7 @@ OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotFie
/* Check again, that this is not just a group that is not grouped
further with other items. */
- if( aMembers.size() > 1 ) try
+ if( !aMembers.empty() ) try
{
// only the first call of createNameGroup() returns the new field
Reference< XDataPilotField > xDPNewField = xDPGrouping->createNameGroup( ContainerHelper::vectorToSequence( aMembers ) );
diff --git a/oox/source/xls/pivottablebuffer.cxx b/oox/source/xls/pivottablebuffer.cxx
index fefced861456..850dda8eb6bc 100644
--- a/oox/source/xls/pivottablebuffer.cxx
+++ b/oox/source/xls/pivottablebuffer.cxx
@@ -579,13 +579,13 @@ void PivotTableField::finalizeDateGroupingImport( const Reference< XDataPilotFie
}
}
-void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, PivotCacheGroupItemVector& orItemNames )
+void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames )
{
if( maDPFieldName.isEmpty() ) // prevent endless loops if file format is broken
{
if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
{
- maDPFieldName = pCacheField->createParentGroupField( rxBaseDPField, orItemNames );
+ maDPFieldName = pCacheField->createParentGroupField( rxBaseDPField, rBaseCacheField, orItemNames );
// on success, try to create nested group fields
Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName );
if( xDPField.is() )
@@ -1455,7 +1455,7 @@ void PivotTable::finalizeParentGroupingImport( const Reference< XDataPilotField
{
// try to create parent group fields that group the items of the passed base field
if( PivotTableField* pParentTableField = maFields.get( rBaseCacheField.getParentGroupField() ).get() )
- pParentTableField->finalizeParentGroupingImport( rxBaseDPField, orItemNames );
+ pParentTableField->finalizeParentGroupingImport( rxBaseDPField, rBaseCacheField, orItemNames );
}
Reference< XDataPilotField > PivotTable::getDataPilotField( const OUString& rFieldName ) const