diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-04 01:01:02 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-04 01:03:15 -0400 |
commit | d9e86913fc03a5b7aa8b1c8cae63ee0cd61a781b (patch) | |
tree | b6360868788c8f560d9b989105024d3b1ca1d095 | |
parent | 8f3e3ce107bf644772ad6d30a4d2f1d325d17f76 (diff) |
Expand shared formula tokens from Excel (which are basically range names).
Also, use a better way to fetch a double array.
Change-Id: I65a5bb9c972620f63e79a84b461245cc7fea1a51
-rw-r--r-- | sc/source/core/data/column2.cxx | 50 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 26 |
2 files changed, 44 insertions, 32 deletions
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index b987a31ad557..fc53dab92f52 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -1833,43 +1833,29 @@ const double* ScColumn::FetchDoubleArray( sc::FormulaGroupContext& /*rCxt*/, SCR if (nRow1 > nRow2) return NULL; - ColDoubleEntry aBound; - aBound.mnStart = nRow1; - std::vector<ColDoubleEntry*>::const_iterator it = - std::lower_bound(maDoubles.begin(), maDoubles.end(), &aBound, ColDoubleEntry::LessByPtr()); - - if (it == maDoubles.end()) - return NULL; - - // There should never be an entry with empty double array. So we don't - // even bother checking for emptiness here. - - const ColDoubleEntry& rEntry = **it; - - if (rEntry.mnStart == nRow1) + std::vector<ColDoubleEntry*>::const_iterator it = maDoubles.begin(), itEnd = maDoubles.end(); + size_t nOffset = 0; + for (; it != itEnd; ++it) { - SCROW nLastRow = rEntry.mnStart + rEntry.maData.size() - 1; - if (nLastRow < nRow2) - // Array is shorter than requested length. - return NULL; - - return &rEntry.maData[0]; + const ColDoubleEntry& rEntry = **it; + SCROW nRowStart = rEntry.mnStart; + SCROW nRowEnd = nRowStart + rEntry.maData.size() - 1; + if (nRowStart <= nRow1 && nRow2 <= nRowEnd) + { + // Found it. + nOffset = nRow1 - nRowStart; + break; + } } - OSL_ASSERT(nRow1 < rEntry.mnStart); - - if (it == maDoubles.begin()) - // This is the very first array entry. - return NULL; - - --it; // Go to previous array so that rEntry.mnStart < nRow1. - OSL_ASSERT((**it).mnStart < nRow1); - SCROW nLastRow = rEntry.mnStart + rEntry.maData.size() - 1; - if (nLastRow < nRow2) - // Array is shorter than requested length. + if (it == itEnd) + { + // Array not found. return NULL; + } - return &rEntry.maData[nRow1 - rEntry.mnStart]; + const ColDoubleEntry& rEntry = **it; + return &rEntry.maData[0] + nOffset; } ScRefCellValue ScColumn::GetRefCellValue( SCROW nRow ) diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 11b6353db06d..da36a3435a0c 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -3044,6 +3044,32 @@ public: } } break; + case svIndex: + { + // Named range. + ScRangeName* pNames = mrDoc.GetRangeName(); + if (!pNames) + // This should never fail. + return false; + + ScRangeData* pRange = pNames->findByIndex(p->GetIndex()); + if (!pRange) + // No named range exists by that index. + return false; + + ScTokenArray* pNamedTokens = pRange->GetCode(); + if (!pNamedTokens) + // This named range is empty. + return false; + + mrGroupTokens.AddOpCode(ocOpen); + + if (!convert(*pNamedTokens)) + return false; + + mrGroupTokens.AddOpCode(ocClose); + } + break; default: mrGroupTokens.AddToken(*pToken); } |