21 #include <rtl/math.hxx>
23 #include <osl/diagnose.h>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
29 #include <document.hxx>
40 for (
bool bHas = aIter.
first(); bHas; bHas = aIter.
next())
54 double fInt = (fVal >= 0.0) ? ::rtl::math::approxFloor( fVal ) :
55 ::rtl::math::approxCeil( fVal );
70 uno::Sequence< uno::Sequence<sal_Int32> > aRowSeq( nRowCount );
71 uno::Sequence<sal_Int32>* pRowAry = aRowSeq.getArray();
72 for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
74 uno::Sequence<sal_Int32> aColSeq( nColCount );
75 sal_Int32* pColAry = aColSeq.getArray();
76 for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
78 ScAddress( static_cast<SCCOL>(nStartCol+nCol), static_cast<SCROW>(nStartRow+nRow), nTab ) ) );
80 pRowAry[nRow] = aColSeq;
96 uno::Sequence< uno::Sequence<sal_Int32> > aRowSeq( static_cast<sal_Int32>(nRowCount) );
97 uno::Sequence<sal_Int32>* pRowAry = aRowSeq.getArray();
98 for (
SCSIZE nRow = 0; nRow < nRowCount; nRow++)
100 uno::Sequence<sal_Int32> aColSeq( static_cast<sal_Int32>(nColCount) );
101 sal_Int32* pColAry = aColSeq.getArray();
102 for (
SCSIZE nCol = 0; nCol < nColCount; nCol++)
108 pRowAry[nRow] = aColSeq;
123 uno::Sequence< uno::Sequence<double> > aRowSeq( nRowCount );
124 uno::Sequence<double>* pRowAry = aRowSeq.getArray();
125 for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
127 uno::Sequence<double> aColSeq( nColCount );
128 double* pColAry = aColSeq.getArray();
129 for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
131 ScAddress( static_cast<SCCOL>(nStartCol+nCol), static_cast<SCROW>(nStartRow+nRow), nTab ) );
133 pRowAry[nRow] = aColSeq;
149 uno::Sequence< uno::Sequence<double> > aRowSeq( static_cast<sal_Int32>(nRowCount) );
150 uno::Sequence<double>* pRowAry = aRowSeq.getArray();
151 for (
SCSIZE nRow = 0; nRow < nRowCount; nRow++)
153 uno::Sequence<double> aColSeq( static_cast<sal_Int32>(nColCount) );
154 double* pColAry = aColSeq.getArray();
155 for (
SCSIZE nCol = 0; nCol < nColCount; nCol++)
159 pColAry[nCol] = pMatrix->
GetDouble( nCol, nRow );
161 pRowAry[nRow] = aColSeq;
176 bool bHasErrors =
false;
178 uno::Sequence< uno::Sequence<OUString> > aRowSeq( nRowCount );
179 uno::Sequence<OUString>* pRowAry = aRowSeq.getArray();
180 for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
182 uno::Sequence<OUString> aColSeq( nColCount );
183 OUString* pColAry = aColSeq.getArray();
184 for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
187 ScAddress(static_cast<SCCOL>(nStartCol+nCol), static_cast<SCROW>(nStartRow+nRow), nTab),
189 if ( nErrCode != FormulaError::NONE )
192 pRowAry[nRow] = aColSeq;
209 uno::Sequence< uno::Sequence<OUString> > aRowSeq( static_cast<sal_Int32>(nRowCount) );
210 uno::Sequence<OUString>* pRowAry = aRowSeq.getArray();
211 for (
SCSIZE nRow = 0; nRow < nRowCount; nRow++)
213 uno::Sequence<OUString> aColSeq( static_cast<sal_Int32>(nColCount) );
214 OUString* pColAry = aColSeq.getArray();
215 for (
SCSIZE nCol = 0; nCol < nColCount; nCol++)
220 if ( !pMatrix->
IsEmpty( nCol, nRow ) )
223 else if ( pFormatter )
225 double fVal = pMatrix->
GetDouble( nCol, nRow );
229 pColAry[nCol] = aStr;
232 pRowAry[nRow] = aColSeq;
248 bool bHasErrors =
false;
250 uno::Sequence< uno::Sequence<uno::Any> > aRowSeq( nRowCount );
251 uno::Sequence<uno::Any>* pRowAry = aRowSeq.getArray();
252 for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
254 uno::Sequence<uno::Any> aColSeq( nColCount );
255 uno::Any* pColAry = aColSeq.getArray();
256 for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
260 ScAddress aPos( static_cast<SCCOL>(nStartCol+nCol), static_cast<SCROW>(nStartRow+nRow), nTab );
265 rElement <<= OUString();
269 if (aCell.meType ==
CELLTYPE_FORMULA && aCell.mpFormula->GetErrCode() != FormulaError::NONE)
274 else if (aCell.hasNumeric())
275 rElement <<= aCell.getValue();
277 rElement <<= aCell.getString(&rDoc);
279 pRowAry[nRow] = aColSeq;
283 return bAllowNV || !bHasErrors;
295 uno::Sequence< uno::Sequence<uno::Any> > aRowSeq( static_cast<sal_Int32>(nRowCount) );
296 uno::Sequence<uno::Any>* pRowAry = aRowSeq.getArray();
297 for (
SCSIZE nRow = 0; nRow < nRowCount; nRow++)
299 uno::Sequence<uno::Any> aColSeq( static_cast<sal_Int32>(nColCount) );
300 uno::Any* pColAry = aColSeq.getArray();
301 for (
SCSIZE nCol = 0; nCol < nColCount; nCol++)
306 if ( !pMatrix->
IsEmpty( nCol, nRow ) )
308 pColAry[nCol] <<= aStr;
312 double fVal = pMatrix->
GetDouble( nCol, nRow );
313 if (bDataTypes && pMatrix->
IsBoolean( nCol, nRow ))
314 pColAry[nCol] <<= fVal != 0.0;
316 pColAry[nCol] <<= fVal;
320 pRowAry[nRow] = aColSeq;
328 css::uno::TypeClass & o_eClass,
329 const css::uno::Any & rAny )
332 o_eClass = rAny.getValueTypeClass();
336 case uno::TypeClass_ENUM:
337 case uno::TypeClass_BOOLEAN:
338 case uno::TypeClass_CHAR:
339 case uno::TypeClass_BYTE:
340 case uno::TypeClass_SHORT:
341 case uno::TypeClass_UNSIGNED_SHORT:
342 case uno::TypeClass_LONG:
343 case uno::TypeClass_UNSIGNED_LONG:
344 case uno::TypeClass_FLOAT:
345 case uno::TypeClass_DOUBLE:
360 uno::Sequence< uno::Sequence< uno::Any > > aSequence;
361 if ( rAny >>= aSequence )
363 sal_Int32 nRowCount = aSequence.getLength();
364 sal_Int32 nMaxColCount = 0;
367 auto pRow = std::max_element(std::cbegin(aSequence), std::cend(aSequence),
368 [](
const uno::Sequence<uno::Any>&
a,
const uno::Sequence<uno::Any>& b) {
369 return a.getLength() < b.getLength(); });
370 nMaxColCount = pRow->getLength();
372 if ( nMaxColCount && nRowCount )
374 const uno::Sequence<uno::Any>* pRowArr = aSequence.getConstArray();
377 static_cast<SCSIZE>(nMaxColCount),
378 static_cast<SCSIZE>(nRowCount), 0.0);
380 xMatrix->GetDimensions( nCols, nRows);
381 if (nCols != static_cast<SCSIZE>(nMaxColCount) || nRows != static_cast<SCSIZE>(nRowCount))
383 OSL_FAIL(
"ScSequenceToMatrix::CreateMixedMatrix: matrix exceeded max size, returning NULL matrix");
386 for (sal_Int32 nRow=0; nRow<nRowCount; nRow++)
388 sal_Int32 nColCount = pRowArr[nRow].getLength();
389 const uno::Any* pColArr = pRowArr[nRow].getConstArray();
390 for (sal_Int32 nCol=0; nCol<nColCount; nCol++)
393 uno::TypeClass eClass;
396 if (eClass == uno::TypeClass_BOOLEAN)
397 xMatrix->PutBoolean( fVal != 0.0,
398 static_cast<SCSIZE>(nCol),
399 static_cast<SCSIZE>(nRow) );
401 xMatrix->PutDouble( fVal,
402 static_cast<SCSIZE>(nCol),
403 static_cast<SCSIZE>(nRow) );
409 if ( pColArr[nCol] >>= aUStr )
416 static_cast<SCSIZE>(nCol),
417 static_cast<SCSIZE>(nRow) );
420 for (sal_Int32 nCol=nColCount; nCol<nMaxColCount; nCol++)
423 static_cast<SCSIZE>(nCol),
424 static_cast<SCSIZE>(nRow) );
433 sal_uInt16 nEncoding )
435 uno::Sequence<sal_Int8>
aSeq;
438 rString = OUString( reinterpret_cast<const char*>(aSeq.getConstArray()),
439 aSeq.getLength(), nEncoding );
OString stripEnd(const OString &rIn, char c)
Matrix data type that can store values of mixed types.
constexpr std::enable_if_t< std::is_floating_point_v< F > &&std::is_integral_v< I >, bool > convertsToAtLeast(F value, I min)
static bool FillLongArray(css::uno::Any &rAny, ScDocument &rDoc, const ScRange &rRange)
OUString getString() const
static bool lcl_HasErrors(ScDocument &rDoc, const ScRange &rRange)
static bool ConvertAnyToDouble(double &o_fVal, css::uno::TypeClass &o_eClass, const css::uno::Any &rAny)
Convert a uno::Any to double if possible, including integer types.
This is very similar to ScCellValue, except that it references the original value instead of copying ...
ScFormulaCell * getFormulaCell()
double GetDouble(SCSIZE nC, SCSIZE nR) const
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Walk through all cells in an area.
bool IsStringOrEmpty(SCSIZE nIndex) const
static bool FillMixedArray(css::uno::Any &rAny, ScDocument &rDoc, const ScRange &rRange, bool bAllowNV=false)
static bool FillDoubleArray(css::uno::Any &rAny, ScDocument &rDoc, const ScRange &rRange)
SC_DLLPUBLIC double GetValue(const ScAddress &rPos) const
constexpr std::enable_if_t< std::is_floating_point_v< F > &&std::is_integral_v< I >, bool > convertsToAtMost(F value, I max)
static bool FillStringArray(css::uno::Any &rAny, ScDocument &rDoc, const ScRange &rRange)
svl::SharedString GetString(SCSIZE nC, SCSIZE nR) const
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
bool IsBoolean(SCSIZE nC, SCSIZE nR) const
static tools::Long lcl_DoubleToLong(double fVal)
static bool GetString(OUString &rString, const css::uno::Any &rAny, sal_uInt16 nEncoding)
bool IsEmpty(SCSIZE nC, SCSIZE nR) const
static ScMatrixRef CreateMixedMatrix(const css::uno::Any &rAny)
Convert a sequence of mixed elements to ScMatrix.
Sequence< sal_Int8 > aSeq
FormulaError GetStringForFormula(const ScAddress &rPos, OUString &rString)