summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2018-05-05 22:03:34 +0300
committerEike Rathke <erack@redhat.com>2018-06-26 17:33:20 +0200
commitc8a040faa218959c23adaac1e0dbe9d679a0bd9e (patch)
tree38db8c0ef5cf7315fb1373e81d31b5effbb10fbd
parent2fe360492ecee70b1ea2bc6aa6aa97b7d8652cfe (diff)
sc excel export: use name, not index for named ranges map
prep work for tdf#113991. The index that was being used for the map was a LO implementation value, not data that is used in the excel filter. That hindered doing creative things to overcome excel limitations. The name/tab combination is unique, and both parts are obviously critical to proper exporting, so use that combination instead. This will help to emulate global named ranges that are relative. That can be emulated by adding an absolute range to each tab. There IS no index in this case, and an existing, conflicting name will nicely prevent the lower-priority emulation item from being inserted. Change-Id: I0bb75b0aa8a5d784754988f9428c5f2b3eee0da3 Reviewed-on: https://gerrit.libreoffice.org/54741 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/source/filter/excel/xename.cxx31
1 files changed, 16 insertions, 15 deletions
diff --git a/sc/source/filter/excel/xename.cxx b/sc/source/filter/excel/xename.cxx
index c55840e2532e..d44246600241 100644
--- a/sc/source/filter/excel/xename.cxx
+++ b/sc/source/filter/excel/xename.cxx
@@ -144,7 +144,7 @@ private:
typedef XclExpRecordList< XclExpName > XclExpNameList;
typedef XclExpNameList::RecordRefType XclExpNameRef;
- typedef ::std::map< ::std::pair<SCTAB, sal_uInt16>, sal_uInt16> NamedExpIndexMap;
+ typedef ::std::map< ::std::pair<SCTAB, OUString>, sal_uInt16> NamedExpMap;
private:
/**
@@ -153,7 +153,7 @@ private:
*
* @return excel's name index.
*/
- sal_uInt16 FindNamedExpIndex( SCTAB nTab, sal_uInt16 nScIdx );
+ sal_uInt16 FindNamedExp( SCTAB nTab, OUString sName );
/** Returns the index of an existing built-in NAME record with the passed definition, otherwise 0. */
sal_uInt16 FindBuiltInNameIdx( const OUString& rName,
@@ -179,7 +179,7 @@ private:
* -1 as their table index, whereas sheet-local names have 0-based table
* index.
*/
- NamedExpIndexMap maNamedExpMap;
+ NamedExpMap maNamedExpMap;
XclExpNameList maNameList; /// List of NAME records.
size_t mnFirstUserIdx; /// List index of first user-defined NAME record.
};
@@ -385,17 +385,18 @@ void XclExpNameManagerImpl::Initialize()
sal_uInt16 XclExpNameManagerImpl::InsertName( SCTAB nTab, sal_uInt16 nScNameIdx )
{
- sal_uInt16 nNameIdx = FindNamedExpIndex( nTab, nScNameIdx );
- if (nNameIdx)
- return nNameIdx;
-
+ sal_uInt16 nNameIdx = 0;
const ScRangeData* pData = nullptr;
ScRangeName* pRN = (nTab == SCTAB_GLOBAL) ? GetDoc().GetRangeName() : GetDoc().GetRangeName(nTab);
if (pRN)
pData = pRN->findByIndex(nScNameIdx);
if (pData)
- nNameIdx = CreateName(nTab, *pData);
+ {
+ nNameIdx = FindNamedExp( nTab, pData->GetName() );
+ if (!nNameIdx)
+ nNameIdx = CreateName(nTab, *pData);
+ }
return nNameIdx;
}
@@ -499,10 +500,10 @@ void XclExpNameManagerImpl::SaveXml( XclExpXmlStream& rStrm )
// private --------------------------------------------------------------------
-sal_uInt16 XclExpNameManagerImpl::FindNamedExpIndex( SCTAB nTab, sal_uInt16 nScIdx )
+sal_uInt16 XclExpNameManagerImpl::FindNamedExp( SCTAB nTab, OUString sName )
{
- NamedExpIndexMap::key_type key = NamedExpIndexMap::key_type(nTab, nScIdx);
- NamedExpIndexMap::const_iterator itr = maNamedExpMap.find(key);
+ NamedExpMap::key_type key = NamedExpMap::key_type(nTab, sName);
+ NamedExpMap::const_iterator itr = maNamedExpMap.find(key);
return (itr == maNamedExpMap.end()) ? 0 : itr->second;
}
@@ -572,7 +573,7 @@ sal_uInt16 XclExpNameManagerImpl::CreateName( SCTAB nTab, const ScRangeData& rRa
xName->SetLocalTab(nTab);
sal_uInt16 nNameIdx = Append( xName );
// store the index of the NAME record in the lookup map
- NamedExpIndexMap::key_type key = NamedExpIndexMap::key_type(nTab, rRangeData.GetIndex());
+ NamedExpMap::key_type key = NamedExpMap::key_type(nTab, rRangeData.GetName());
maNamedExpMap[key] = nNameIdx;
/* Create the definition formula.
@@ -616,7 +617,7 @@ sal_uInt16 XclExpNameManagerImpl::CreateName( SCTAB nTab, const ScRangeData& rRa
while( maNameList.GetSize() > nOldListSize )
maNameList.RemoveRecord( maNameList.GetSize() - 1 );
// use index of the found built-in NAME record
- key = NamedExpIndexMap::key_type(nTab, rRangeData.GetIndex());
+ key = NamedExpMap::key_type(nTab, rRangeData.GetName());
maNamedExpMap[key] = nNameIdx = nBuiltInIdx;
}
}
@@ -695,7 +696,7 @@ void XclExpNameManagerImpl::CreateUserNames()
for (; itr != itrEnd; ++itr)
{
// skip definitions of shared formulas
- if (!FindNamedExpIndex(SCTAB_GLOBAL, itr->second->GetIndex()))
+ if (!FindNamedExp(SCTAB_GLOBAL, itr->second->GetName()))
CreateName(SCTAB_GLOBAL, *itr->second);
}
//look at sheets containing local range names
@@ -709,7 +710,7 @@ void XclExpNameManagerImpl::CreateUserNames()
for (; itr != itrEnd; ++itr)
{
// skip definitions of shared formulas
- if (!FindNamedExpIndex(tabIt->first, itr->second->GetIndex()))
+ if (!FindNamedExp(tabIt->first, itr->second->GetName()))
CreateName(tabIt->first, *itr->second);
}
}