summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/ucalc_formula.cxx37
-rw-r--r--sc/source/core/data/column2.cxx21
2 files changed, 51 insertions, 7 deletions
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index b572c54024c9..cb4b3f4128e1 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -736,6 +736,43 @@ void Test::testFetchVectorRefArray()
CPPUNIT_ASSERT(rtl::math::isNan(aArray.mpNumericArray[1]));
CPPUNIT_ASSERT(rtl::math::isNan(aArray.mpNumericArray[2]));
+ // The column begins with a string header at row 1 (Column C).
+ m_pDoc->SetString(ScAddress(2,0,0), "MyHeader");
+ for (SCROW i = 1; i <= 9; ++i) // rows 2-10 are numeric.
+ m_pDoc->SetValue(ScAddress(2,i,0), i);
+
+ aArray = m_pDoc->FetchVectorRefArray(ScAddress(2,1,0), 9); // C2:C10
+ CPPUNIT_ASSERT_MESSAGE("Array should have a numeric array.", aArray.mpNumericArray);
+ CPPUNIT_ASSERT_MESSAGE("Array should NOT have a string array.", !aArray.mpStringArray);
+ for (size_t i = 0; i < 9; ++i)
+ CPPUNIT_ASSERT_EQUAL(double(i+1), aArray.mpNumericArray[i]);
+
+ // The column begins with a number, followed by a string then followed by
+ // a block of numbers (Column D).
+ m_pDoc->SetValue(ScAddress(3,0,0), 0.0);
+ m_pDoc->SetString(ScAddress(3,1,0), "Some string");
+ for (SCROW i = 2; i <= 9; ++i) // rows 3-10 are numeric.
+ m_pDoc->SetValue(ScAddress(3,i,0), i);
+
+ aArray = m_pDoc->FetchVectorRefArray(ScAddress(3,2,0), 8); // D3:D10
+ CPPUNIT_ASSERT_MESSAGE("Array should have a numeric array.", aArray.mpNumericArray);
+ CPPUNIT_ASSERT_MESSAGE("Array should NOT have a string array.", !aArray.mpStringArray);
+ for (size_t i = 0; i < 8; ++i)
+ CPPUNIT_ASSERT_EQUAL(double(i+2), aArray.mpNumericArray[i]);
+
+ // The column begins with a formula, followed by a string then followed by
+ // a block of numbers (Column E).
+ m_pDoc->SetString(ScAddress(4,0,0), "=1*2");
+ m_pDoc->SetString(ScAddress(4,1,0), "Some string");
+ for (SCROW i = 2; i <= 9; ++i) // rows 3-10 are numeric.
+ m_pDoc->SetValue(ScAddress(4,i,0), i*2);
+
+ aArray = m_pDoc->FetchVectorRefArray(ScAddress(4,2,0), 8); // E3:E10
+ CPPUNIT_ASSERT_MESSAGE("Array should have a numeric array.", aArray.mpNumericArray);
+ CPPUNIT_ASSERT_MESSAGE("Array should NOT have a string array.", !aArray.mpStringArray);
+ for (size_t i = 0; i < 8; ++i)
+ CPPUNIT_ASSERT_EQUAL(double((i+2)*2), aArray.mpNumericArray[i]);
+
m_pDoc->DeleteTab(0);
}
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index c5e136b0f7f2..581607e9475d 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2628,10 +2628,11 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
if (!appendToBlock(pDocument, rCxt, *pColArray, nPos, nRow2+1, itBlk, maCells.end()))
return formula::VectorRefArray(formula::VectorRefArray::Invalid);
- if (pColArray->mpStrArray)
- return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1], &(*pColArray->mpStrArray)[nRow1]);
- else
- return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1]);
+ rtl_uString** pStr = nullptr;
+ if (pColArray->mpStrArray && hasNonEmpty(*pColArray->mpStrArray, nRow1, nRow2))
+ pStr = &(*pColArray->mpStrArray)[nRow1];
+
+ return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1], pStr);
}
break;
case sc::element_type_string:
@@ -2660,10 +2661,16 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
if (!appendToBlock(pDocument, rCxt, *pColArray, nPos, nRow2+1, itBlk, maCells.end()))
return formula::VectorRefArray(formula::VectorRefArray::Invalid);
+ assert(pColArray->mpStrArray);
+
+ rtl_uString** pStr = nullptr;
+ if (hasNonEmpty(*pColArray->mpStrArray, nRow1, nRow2))
+ pStr = &(*pColArray->mpStrArray)[nRow1];
+
if (pColArray->mpNumArray)
- return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1], &(*pColArray->mpStrArray)[nRow1]);
+ return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1], pStr);
else
- return formula::VectorRefArray(&(*pColArray->mpStrArray)[nRow1]);
+ return formula::VectorRefArray(pStr);
}
break;
case sc::element_type_formula:
@@ -2701,7 +2708,7 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
rtl_uString** pStr = nullptr;
if (pColArray->mpNumArray)
pNum = &(*pColArray->mpNumArray)[nRow1];
- if (pColArray->mpStrArray)
+ if (pColArray->mpStrArray && hasNonEmpty(*pColArray->mpStrArray, nRow1, nRow2))
pStr = &(*pColArray->mpStrArray)[nRow1];
return formula::VectorRefArray(pNum, pStr);