summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2016-04-29 22:05:05 +0200
committerEike Rathke <erack@redhat.com>2016-04-30 00:30:35 +0200
commit02a8589553b5ce0e57a7ee9e66327376125b4378 (patch)
tree3c3424c1947613df77f7b682445577c2013e77d4
parent8162cf2a005be68262525c2a11947fa0e10d15ed (diff)
Resolves: tdf#76523 copy used names or pointing to sheet to other document
Change-Id: I767ed1f212c257741fd982e8bbd0882a29d439c1
-rw-r--r--sc/inc/document.hxx12
-rw-r--r--sc/source/core/data/documen2.cxx8
-rw-r--r--sc/source/core/data/document10.cxx7
-rw-r--r--sc/source/core/data/formulacell.cxx2
-rw-r--r--sc/source/core/tool/rangenam.cxx2
5 files changed, 26 insertions, 5 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index a38279f66037..05b93f38e4a8 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -628,11 +628,21 @@ public:
position of the existing name adjusted for Tab.
rOldPos.nTab MUST point to the old sheet copied from.
+ @param bGlobalNamesToLocal
+ If TRUE, affected global names are copied to sheet-local names.
+ If FALSE, global names are copied to global names in another document.
+
+ @param bUsedByFormula
+ If TRUE, forces a global name to be affected/used.
+ If FALSE, a global name is only affected if it evaluates to be
+ referencing the sheet.
+
@return TRUE if copied and caller may need to evaluate rpRangeData and rSheet and rIndex.
FALSE if nothing to be done.
*/
bool CopyAdjustRangeName( SCTAB& rSheet, sal_uInt16& rIndex, ScRangeData*& rpRangeData, ScDocument& rNewDoc,
- const ScAddress& rNewPos, const ScAddress& rOldPos, const bool bGlobalNamesToLocal) const;
+ const ScAddress& rNewPos, const ScAddress& rOldPos, const bool bGlobalNamesToLocal,
+ const bool bUsedByFormula ) const;
/**
* Call this immediately before updating all named ranges.
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index a393463cc78f..e92b6a8df847 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -987,6 +987,14 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
nDestPos = std::min(nDestPos, (SCTAB)(GetTableCount() - 1));
{ // scope for bulk broadcast
ScBulkBroadcast aBulkBroadcast( pBASM);
+ if (!bResultsOnly)
+ {
+ const bool bGlobalNamesToLocal = false;
+ const ScRangeName* pNames = pSrcDoc->GetRangeName( nSrcPos);
+ if (pNames)
+ pNames->CopyUsedNames( nSrcPos, nSrcPos, nDestPos, *pSrcDoc, *this, bGlobalNamesToLocal);
+ pSrcDoc->GetRangeName()->CopyUsedNames( -1, nSrcPos, nDestPos, *pSrcDoc, *this, bGlobalNamesToLocal);
+ }
pSrcDoc->maTabs[nSrcPos]->CopyToTable(aCxt, 0, 0, MAXCOL, MAXROW,
( bResultsOnly ? InsertDeleteFlags::ALL & ~InsertDeleteFlags::FORMULA : InsertDeleteFlags::ALL),
false, maTabs[nDestPos] );
diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx
index f7ed6e89b80c..4690f9ba855b 100644
--- a/sc/source/core/data/document10.cxx
+++ b/sc/source/core/data/document10.cxx
@@ -656,7 +656,8 @@ ScRangeData* copyRangeNames( SheetIndexMap& rSheetIndexMap, std::vector<ScRangeD
} // namespace
bool ScDocument::CopyAdjustRangeName( SCTAB& rSheet, sal_uInt16& rIndex, ScRangeData*& rpRangeData,
- ScDocument& rNewDoc, const ScAddress& rNewPos, const ScAddress& rOldPos, const bool bGlobalNamesToLocal) const
+ ScDocument& rNewDoc, const ScAddress& rNewPos, const ScAddress& rOldPos, const bool bGlobalNamesToLocal,
+ const bool bUsedByFormula ) const
{
const bool bSameDoc = (rNewDoc.GetPool() == const_cast<ScDocument*>(this)->GetPool());
if (bSameDoc && ((rSheet < 0 && !bGlobalNamesToLocal) || (rSheet >= 0 && rSheet != rOldPos.Tab())))
@@ -725,7 +726,9 @@ bool ScDocument::CopyAdjustRangeName( SCTAB& rSheet, sal_uInt16& rIndex, ScRange
// If no range name was found copy it.
if (!rpRangeData)
{
- bool bEarlyBailOut = (nOldSheet < 0 && bSameDoc);
+ // Do not copy global name if it doesn't reference sheet or is not used
+ // by a formula copied to another document.
+ bool bEarlyBailOut = (nOldSheet < 0 && (bSameDoc || !bUsedByFormula));
MightReferenceSheet eMightReference = mightRangeNameReferenceSheet( pOldRangeData, nOldTab);
if (bEarlyBailOut && eMightReference == MightReferenceSheet::NONE)
return false;
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index b61d89c3dcf5..6e3bbca0b449 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -430,7 +430,7 @@ void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const S
ScRangeData* pRangeData = nullptr;
SCTAB nSheet = pToken->GetSheet();
sal_uInt16 nIndex = pToken->GetIndex();
- if (!pOldDoc->CopyAdjustRangeName( nSheet, nIndex, pRangeData, rNewDoc, rNewPos, rOldPos, bGlobalNamesToLocal))
+ if (!pOldDoc->CopyAdjustRangeName( nSheet, nIndex, pRangeData, rNewDoc, rNewPos, rOldPos, bGlobalNamesToLocal, true))
return; // nothing to do
if (!pRangeData)
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index 89500acb0d62..62b90c7da8a3 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -797,7 +797,7 @@ void ScRangeName::CopyUsedNames( const SCTAB nLocalTab, const SCTAB nOldTab, con
ScAddress aNewPos( aOldPos);
aNewPos.SetTab( nNewTab);
ScRangeData* pRangeData = nullptr;
- rOldDoc.CopyAdjustRangeName( nSheet, nIndex, pRangeData, rNewDoc, aNewPos, aOldPos, bGlobalNamesToLocal);
+ rOldDoc.CopyAdjustRangeName( nSheet, nIndex, pRangeData, rNewDoc, aNewPos, aOldPos, bGlobalNamesToLocal, false);
}
}