summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2011-11-27 22:15:35 +0100
committerEike Rathke <erack@redhat.com>2011-11-28 15:25:27 +0100
commitf65345b11259c431e715d7f4f17d2ec035cd23d8 (patch)
treeb68abe73622fc369b0d25734649e97ce139e12e8 /sc
parente14b35d3b4333e534007902d28f433a0edc035be (diff)
dr78: #i115015# proper handling of add-in parameter arrays, merged with database functions QueryParam
# HG changeset patch # User Niklas Nebel <nn@openoffice.org> # Date 1290620646 -3600 # Node ID 96608d83032e60946c80e0a5185a55843b74eb6f # Parent 427eca1ec1adf81ed3016bde2ef2b010c9fd9ed1
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/document.hxx1
-rw-r--r--sc/source/core/data/document.cxx54
-rw-r--r--sc/source/core/inc/doubleref.hxx3
-rw-r--r--sc/source/core/tool/doubleref.cxx58
-rw-r--r--sc/source/core/tool/rangeseq.cxx30
5 files changed, 82 insertions, 64 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 3db0dc6140a7..684b16622071 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -775,6 +775,7 @@ public:
SC_DLLPUBLIC rtl::OUString GetString( SCCOL nCol, SCROW nRow, SCTAB nTab) { rtl::OUString aString; GetString(nCol, nRow, nTab, aString); return aString;}
SC_DLLPUBLIC void GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, String& rString );
SC_DLLPUBLIC void GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, rtl::OUString& rString );
+ sal_uInt16 GetStringForFormula( const ScAddress& rPos, rtl::OUString& rString );
SC_DLLPUBLIC double GetValue( const ScAddress& );
SC_DLLPUBLIC double GetValue( const SCCOL nCol, SCROW nRow, SCTAB nTab) { ScAddress aAdr(nCol, nRow, nTab); return GetValue(aAdr);}
SC_DLLPUBLIC void GetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, double& rValue );
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 9c0a8d777af7..efb003ba8f1b 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3075,6 +3075,60 @@ void ScDocument::GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, String& rSt
rString = aString;
}
+sal_uInt16 ScDocument::GetStringForFormula( const ScAddress& rPos, rtl::OUString& rString )
+{
+ // Used in formulas (add-in parameters etc), so it must use the same semantics as
+ // ScInterpreter::GetCellString: always format values as numbers.
+ // The return value is the error code.
+
+ sal_uInt16 nErr = 0;
+ String aStr;
+ ScBaseCell* pCell = GetCell( rPos );
+ if (pCell)
+ {
+ SvNumberFormatter* pFormatter = GetFormatTable();
+ switch (pCell->GetCellType())
+ {
+ case CELLTYPE_STRING:
+ static_cast<ScStringCell*>(pCell)->GetString(aStr);
+ break;
+ case CELLTYPE_EDIT:
+ static_cast<ScEditCell*>(pCell)->GetString(aStr);
+ break;
+ case CELLTYPE_FORMULA:
+ {
+ ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+ nErr = pFCell->GetErrCode();
+ if (pFCell->IsValue())
+ {
+ double fVal = pFCell->GetValue();
+ sal_uLong nIndex = pFormatter->GetStandardFormat(
+ NUMBERFORMAT_NUMBER,
+ ScGlobal::eLnge);
+ pFormatter->GetInputLineString(fVal, nIndex, aStr);
+ }
+ else
+ pFCell->GetString(aStr);
+ }
+ break;
+ case CELLTYPE_VALUE:
+ {
+ double fVal = static_cast<ScValueCell*>(pCell)->GetValue();
+ sal_uLong nIndex = pFormatter->GetStandardFormat(
+ NUMBERFORMAT_NUMBER,
+ ScGlobal::eLnge);
+ pFormatter->GetInputLineString(fVal, nIndex, aStr);
+ }
+ break;
+ default:
+ ;
+ }
+ }
+ rString = aStr;
+ return nErr;
+}
+
+
void ScDocument::GetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, double& rValue )
{
if ( VALIDTAB(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
diff --git a/sc/source/core/inc/doubleref.hxx b/sc/source/core/inc/doubleref.hxx
index 885d3a780c04..fc7267dc9ff1 100644
--- a/sc/source/core/inc/doubleref.hxx
+++ b/sc/source/core/inc/doubleref.hxx
@@ -138,9 +138,6 @@ public:
virtual bool isRangeEqual(const ScRange& rRange) const;
private:
- sal_uInt16 getCellString(::rtl::OUString& rStr, ScBaseCell* pCell) const;
-
-private:
ScRange maRange;
};
diff --git a/sc/source/core/tool/doubleref.cxx b/sc/source/core/tool/doubleref.cxx
index 61c6176b2158..a5d582a75821 100644
--- a/sc/source/core/tool/doubleref.cxx
+++ b/sc/source/core/tool/doubleref.cxx
@@ -321,11 +321,8 @@ OUString ScDBInternalRange::getString(SCCOL nCol, SCROW nRow) const
{
OUString aStr;
const ScAddress& s = maRange.aStart;
- ScBaseCell* pCell = getDoc()->GetCell(ScAddress(s.Col() + nCol, s.Row() + nRow, maRange.aStart.Tab()));
- if (!pCell)
- return aStr;
-
- getCellString(aStr, pCell);
+ // GetStringForFormula is not used here, to allow querying for date values.
+ getDoc()->GetInputString(s.Col() + nCol, s.Row() + nRow, s.Tab(), aStr);
return aStr;
}
@@ -345,54 +342,6 @@ SCCOL ScDBInternalRange::findFieldColumn(SCCOL nIndex) const
return nIndex + nDBCol1 - 1;
}
-sal_uInt16 ScDBInternalRange::getCellString(OUString& rStr, ScBaseCell* pCell) const
-{
- sal_uInt16 nErr = 0;
- String aStr;
- if (pCell)
- {
- SvNumberFormatter* pFormatter = getDoc()->GetFormatTable();
- switch (pCell->GetCellType())
- {
- case CELLTYPE_STRING:
- ((ScStringCell*) pCell)->GetString(aStr);
- break;
- case CELLTYPE_EDIT:
- ((ScEditCell*) pCell)->GetString(aStr);
- break;
- case CELLTYPE_FORMULA:
- {
- ScFormulaCell* pFCell = (ScFormulaCell*) pCell;
- nErr = pFCell->GetErrCode();
- if (pFCell->IsValue())
- {
- double fVal = pFCell->GetValue();
- sal_uLong nIndex = pFormatter->GetStandardFormat(
- NUMBERFORMAT_NUMBER,
- ScGlobal::eLnge);
- pFormatter->GetInputLineString(fVal, nIndex, aStr);
- }
- else
- pFCell->GetString(aStr);
- }
- break;
- case CELLTYPE_VALUE:
- {
- double fVal = ((ScValueCell*) pCell)->GetValue();
- sal_uLong nIndex = pFormatter->GetStandardFormat(
- NUMBERFORMAT_NUMBER,
- ScGlobal::eLnge);
- pFormatter->GetInputLineString(fVal, nIndex, aStr);
- }
- break;
- default:
- ;
- }
- }
- rStr = aStr;
- return nErr;
-}
-
SCCOL ScDBInternalRange::findFieldColumn(const OUString& rStr, sal_uInt16* pErr) const
{
const ScAddress& s = maRange.aStart;
@@ -413,8 +362,7 @@ SCCOL ScDBInternalRange::findFieldColumn(const OUString& rStr, sal_uInt16* pErr)
ScAddress aLook( nDBCol1, nDBRow1, nDBTab1 );
while (!bFound && (aLook.Col() <= nDBCol2))
{
- ScBaseCell* pCell = getDoc()->GetCell( aLook );
- sal_uInt16 nErr = getCellString( aCellStr, pCell );
+ sal_uInt16 nErr = getDoc()->GetStringForFormula( aLook, aCellStr );
if (pErr)
*pErr = nErr;
lcl_toUpper(aCellStr);
diff --git a/sc/source/core/tool/rangeseq.cxx b/sc/source/core/tool/rangeseq.cxx
index 0e966e9c7f3e..eb5172aa7272 100644
--- a/sc/source/core/tool/rangeseq.cxx
+++ b/sc/source/core/tool/rangeseq.cxx
@@ -37,6 +37,7 @@
#include "rangeseq.hxx"
#include "document.hxx"
+#include "dociter.hxx"
#include "scmatrix.hxx"
#include "cell.hxx"
@@ -44,6 +45,20 @@ using namespace com::sun::star;
//------------------------------------------------------------------------
+bool lcl_HasErrors( ScDocument* pDoc, const ScRange& rRange )
+{
+ // no need to look at empty cells - just use ScCellIterator
+ ScCellIterator aIter( pDoc, rRange );
+ ScBaseCell* pCell = aIter.GetFirst();
+ while (pCell)
+ {
+ if ( pCell->GetCellType() == CELLTYPE_FORMULA && static_cast<ScFormulaCell*>(pCell)->GetErrCode() != 0 )
+ return true;
+ pCell = aIter.GetNext();
+ }
+ return false; // no error found
+}
+
long lcl_DoubleToLong( double fVal )
{
double fInt = (fVal >= 0.0) ? ::rtl::math::approxFloor( fVal ) :
@@ -76,7 +91,7 @@ sal_Bool ScRangeToSequence::FillLongArray( uno::Any& rAny, ScDocument* pDoc, con
}
rAny <<= aRowSeq;
- return sal_True; //! check for errors
+ return !lcl_HasErrors( pDoc, rRange );
}
@@ -132,7 +147,7 @@ sal_Bool ScRangeToSequence::FillDoubleArray( uno::Any& rAny, ScDocument* pDoc, c
}
rAny <<= aRowSeq;
- return sal_True; //! check for errors
+ return !lcl_HasErrors( pDoc, rRange );
}
@@ -174,7 +189,7 @@ sal_Bool ScRangeToSequence::FillStringArray( uno::Any& rAny, ScDocument* pDoc, c
long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();
- String aDocStr;
+ bool bHasErrors = false;
uno::Sequence< uno::Sequence<rtl::OUString> > aRowSeq( nRowCount );
uno::Sequence<rtl::OUString>* pRowAry = aRowSeq.getArray();
@@ -184,14 +199,17 @@ sal_Bool ScRangeToSequence::FillStringArray( uno::Any& rAny, ScDocument* pDoc, c
rtl::OUString* pColAry = aColSeq.getArray();
for (long nCol = 0; nCol < nColCount; nCol++)
{
- pDoc->GetString( (SCCOL)(nStartCol+nCol), (SCROW)(nStartRow+nRow), nTab, aDocStr );
- pColAry[nCol] = rtl::OUString( aDocStr );
+ sal_uInt16 nErrCode = pDoc->GetStringForFormula(
+ ScAddress((SCCOL)(nStartCol+nCol), (SCROW)(nStartRow+nRow), nTab),
+ pColAry[nCol] );
+ if ( nErrCode != 0 )
+ bHasErrors = true;
}
pRowAry[nRow] = aColSeq;
}
rAny <<= aRowSeq;
- return sal_True; //! check for errors
+ return !bHasErrors;
}