summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-06-26 11:45:28 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-06-27 15:49:06 -0400
commit604b9e646e365c246aa3a28d497c15248da23d7d (patch)
tree9bf510a0673c595f0ecb911a25c86cba634fc866
parent9241d3b4a7156fa2e236d761aced07dcce8b3bbe (diff)
Implement a way to set an array of formula results to formula cell group.
Change-Id: Ifdea531e963339607a5066f81af32ffedfd408aa
-rw-r--r--sc/inc/column.hxx1
-rw-r--r--sc/inc/document.hxx10
-rw-r--r--sc/inc/table.hxx2
-rw-r--r--sc/source/core/data/column2.cxx26
-rw-r--r--sc/source/core/data/documen8.cxx9
-rw-r--r--sc/source/core/data/table1.cxx8
6 files changed, 56 insertions, 0 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 28c732165e54..8a938e955636 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -454,6 +454,7 @@ public:
bool ResolveStaticReference( ScMatrix& rMat, SCCOL nMatCol, SCROW nRow1, SCROW nRow2 );
void FillMatrix( ScMatrix& rMat, size_t nMatCol, SCROW nRow1, SCROW nRow2 ) const;
const double* FetchDoubleArray( sc::FormulaGroupContext& rCxt, SCROW nRow1, SCROW nRow2 ) const;
+ void SetFormulaResults( SCROW nRow, const double* pResults, size_t nLen );
void SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat );
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 25483df15bbe..fd8f61ffb52a 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1710,6 +1710,16 @@ public:
void FillMatrix( ScMatrix& rMat, SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const;
+ /**
+ * Set an array of numerical formula results to a group of contiguous
+ * formula cells.
+ *
+ * @param rTopPos position of the top formula cell of a group.
+ * @param pResults array of numeric results.
+ * @param nLen length of numeric results.
+ */
+ void SetFormulaResults( const ScAddress& rTopPos, const double* pResults, size_t nLen );
+
private:
ScDocument(const ScDocument& r); // disabled with no definition
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 496b858f6fda..bae3818a7462 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -855,6 +855,8 @@ public:
void InterpretDirtyCells( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
+ void SetFormulaResults( SCCOL nCol, SCROW nRow, const double* pResults, size_t nLen );
+
/** Replace behaves differently to the Search; adjust the rCol and rRow accordingly.
'Replace' replaces at the 'current' position, but in order to achieve
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 80491b5092c4..72056721d304 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2092,6 +2092,32 @@ const double* ScColumn::FetchDoubleArray( sc::FormulaGroupContext& /*rCxt*/, SCR
return &sc::numeric_block::at(*aPos.first->data, aPos.second);
}
+void ScColumn::SetFormulaResults( SCROW nRow, const double* pResults, size_t nLen )
+{
+ sc::CellStoreType::position_type aPos = maCells.position(nRow);
+ sc::CellStoreType::iterator it = aPos.first;
+ if (it->type != sc::element_type_formula)
+ // This is not a formula block.
+ return;
+
+ size_t nBlockLen = it->size - aPos.second;
+ if (nBlockLen < nLen)
+ // Result array is longer than the length of formula cells. Not good.
+ return;
+
+ sc::formula_block::iterator itCell = sc::formula_block::begin(*it->data);
+ std::advance(itCell, aPos.second);
+
+ const double* pResEnd = pResults + nLen;
+ for (; pResults != pResEnd; ++pResults, ++itCell)
+ {
+ ScFormulaCell& rCell = **itCell;
+ rCell.SetResultDouble(*pResults);
+ rCell.ResetDirty();
+ rCell.SetChanged(true);
+ }
+}
+
void ScColumn::SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat )
{
short eOldType = pDocument->GetFormatTable()->GetType(
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 694b3985405a..71e18785332b 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -449,6 +449,15 @@ void ScDocument::FillMatrix(
pTab->FillMatrix(rMat, nCol1, nRow1, nCol2, nRow2);
}
+void ScDocument::SetFormulaResults( const ScAddress& rTopPos, const double* pResults, size_t nLen )
+{
+ ScTable* pTab = FetchTable(rTopPos.Tab());
+ if (!pTab)
+ return;
+
+ pTab->SetFormulaResults(rTopPos.Col(), rTopPos.Row(), pResults, nLen);
+}
+
//------------------------------------------------------------------------
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 2de23b1b9225..be6f4ae6330b 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -2215,6 +2215,14 @@ void ScTable::InterpretDirtyCells( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW
aCol[nCol].InterpretDirtyCells(nRow1, nRow2);
}
+void ScTable::SetFormulaResults( SCCOL nCol, SCROW nRow, const double* pResults, size_t nLen )
+{
+ if (!ValidCol(nCol))
+ return;
+
+ aCol[nCol].SetFormulaResults(nRow, pResults, nLen);
+}
+
const SvtBroadcaster* ScTable::GetBroadcaster( SCCOL nCol, SCROW nRow ) const
{
if (!ValidColRow(nCol, nRow))