1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <svl/zforlist.hxx>
30cdf0e10cSrcweir #include <rtl/math.hxx>
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
34cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include "rangeseq.hxx"
37cdf0e10cSrcweir #include "document.hxx"
38cdf0e10cSrcweir #include "dociter.hxx"
39cdf0e10cSrcweir #include "scmatrix.hxx"
40cdf0e10cSrcweir #include "cell.hxx"
41cdf0e10cSrcweir
42cdf0e10cSrcweir using namespace com::sun::star;
43cdf0e10cSrcweir
44cdf0e10cSrcweir //------------------------------------------------------------------------
45cdf0e10cSrcweir
lcl_HasErrors(ScDocument * pDoc,const ScRange & rRange)46cdf0e10cSrcweir bool lcl_HasErrors( ScDocument* pDoc, const ScRange& rRange )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir // no need to look at empty cells - just use ScCellIterator
49cdf0e10cSrcweir ScCellIterator aIter( pDoc, rRange );
50cdf0e10cSrcweir ScBaseCell* pCell = aIter.GetFirst();
51cdf0e10cSrcweir while (pCell)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir if ( pCell->GetCellType() == CELLTYPE_FORMULA && static_cast<ScFormulaCell*>(pCell)->GetErrCode() != 0 )
54cdf0e10cSrcweir return true;
55cdf0e10cSrcweir pCell = aIter.GetNext();
56cdf0e10cSrcweir }
57cdf0e10cSrcweir return false; // no error found
58cdf0e10cSrcweir }
59cdf0e10cSrcweir
lcl_DoubleToLong(double fVal)60cdf0e10cSrcweir long lcl_DoubleToLong( double fVal )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir double fInt = (fVal >= 0.0) ? ::rtl::math::approxFloor( fVal ) :
63cdf0e10cSrcweir ::rtl::math::approxCeil( fVal );
64cdf0e10cSrcweir if ( fInt >= LONG_MIN && fInt <= LONG_MAX )
65cdf0e10cSrcweir return (long)fInt;
66cdf0e10cSrcweir else
67cdf0e10cSrcweir return 0; // out of range
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
FillLongArray(uno::Any & rAny,ScDocument * pDoc,const ScRange & rRange)70cdf0e10cSrcweir sal_Bool ScRangeToSequence::FillLongArray( uno::Any& rAny, ScDocument* pDoc, const ScRange& rRange )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir SCTAB nTab = rRange.aStart.Tab();
73cdf0e10cSrcweir SCCOL nStartCol = rRange.aStart.Col();
74cdf0e10cSrcweir SCROW nStartRow = rRange.aStart.Row();
75cdf0e10cSrcweir long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
76cdf0e10cSrcweir long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();
77cdf0e10cSrcweir
78cdf0e10cSrcweir uno::Sequence< uno::Sequence<sal_Int32> > aRowSeq( nRowCount );
79cdf0e10cSrcweir uno::Sequence<sal_Int32>* pRowAry = aRowSeq.getArray();
80cdf0e10cSrcweir for (long nRow = 0; nRow < nRowCount; nRow++)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir uno::Sequence<sal_Int32> aColSeq( nColCount );
83cdf0e10cSrcweir sal_Int32* pColAry = aColSeq.getArray();
84cdf0e10cSrcweir for (long nCol = 0; nCol < nColCount; nCol++)
85cdf0e10cSrcweir pColAry[nCol] = lcl_DoubleToLong( pDoc->GetValue(
86cdf0e10cSrcweir ScAddress( (SCCOL)(nStartCol+nCol), (SCROW)(nStartRow+nRow), nTab ) ) );
87cdf0e10cSrcweir
88cdf0e10cSrcweir pRowAry[nRow] = aColSeq;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir rAny <<= aRowSeq;
92cdf0e10cSrcweir return !lcl_HasErrors( pDoc, rRange );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir
FillLongArray(uno::Any & rAny,const ScMatrix * pMatrix)96cdf0e10cSrcweir sal_Bool ScRangeToSequence::FillLongArray( uno::Any& rAny, const ScMatrix* pMatrix )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir if (!pMatrix)
99cdf0e10cSrcweir return sal_False;
100cdf0e10cSrcweir
101cdf0e10cSrcweir SCSIZE nColCount;
102cdf0e10cSrcweir SCSIZE nRowCount;
103cdf0e10cSrcweir pMatrix->GetDimensions( nColCount, nRowCount );
104cdf0e10cSrcweir
105cdf0e10cSrcweir uno::Sequence< uno::Sequence<sal_Int32> > aRowSeq( static_cast<sal_Int32>(nRowCount) );
106cdf0e10cSrcweir uno::Sequence<sal_Int32>* pRowAry = aRowSeq.getArray();
107cdf0e10cSrcweir for (SCSIZE nRow = 0; nRow < nRowCount; nRow++)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir uno::Sequence<sal_Int32> aColSeq( static_cast<sal_Int32>(nColCount) );
110cdf0e10cSrcweir sal_Int32* pColAry = aColSeq.getArray();
111cdf0e10cSrcweir for (SCSIZE nCol = 0; nCol < nColCount; nCol++)
112cdf0e10cSrcweir if ( pMatrix->IsString( nCol, nRow ) )
113cdf0e10cSrcweir pColAry[nCol] = 0;
114cdf0e10cSrcweir else
115cdf0e10cSrcweir pColAry[nCol] = lcl_DoubleToLong( pMatrix->GetDouble( nCol, nRow ) );
116cdf0e10cSrcweir
117cdf0e10cSrcweir pRowAry[nRow] = aColSeq;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir rAny <<= aRowSeq;
121cdf0e10cSrcweir return sal_True;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir //------------------------------------------------------------------------
125cdf0e10cSrcweir
FillDoubleArray(uno::Any & rAny,ScDocument * pDoc,const ScRange & rRange)126cdf0e10cSrcweir sal_Bool ScRangeToSequence::FillDoubleArray( uno::Any& rAny, ScDocument* pDoc, const ScRange& rRange )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir SCTAB nTab = rRange.aStart.Tab();
129cdf0e10cSrcweir SCCOL nStartCol = rRange.aStart.Col();
130cdf0e10cSrcweir SCROW nStartRow = rRange.aStart.Row();
131cdf0e10cSrcweir long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
132cdf0e10cSrcweir long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();
133cdf0e10cSrcweir
134cdf0e10cSrcweir uno::Sequence< uno::Sequence<double> > aRowSeq( nRowCount );
135cdf0e10cSrcweir uno::Sequence<double>* pRowAry = aRowSeq.getArray();
136cdf0e10cSrcweir for (long nRow = 0; nRow < nRowCount; nRow++)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir uno::Sequence<double> aColSeq( nColCount );
139cdf0e10cSrcweir double* pColAry = aColSeq.getArray();
140cdf0e10cSrcweir for (long nCol = 0; nCol < nColCount; nCol++)
141cdf0e10cSrcweir pColAry[nCol] = pDoc->GetValue(
142cdf0e10cSrcweir ScAddress( (SCCOL)(nStartCol+nCol), (SCROW)(nStartRow+nRow), nTab ) );
143cdf0e10cSrcweir
144cdf0e10cSrcweir pRowAry[nRow] = aColSeq;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir rAny <<= aRowSeq;
148cdf0e10cSrcweir return !lcl_HasErrors( pDoc, rRange );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir
FillDoubleArray(uno::Any & rAny,const ScMatrix * pMatrix)152cdf0e10cSrcweir sal_Bool ScRangeToSequence::FillDoubleArray( uno::Any& rAny, const ScMatrix* pMatrix )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir if (!pMatrix)
155cdf0e10cSrcweir return sal_False;
156cdf0e10cSrcweir
157cdf0e10cSrcweir SCSIZE nColCount;
158cdf0e10cSrcweir SCSIZE nRowCount;
159cdf0e10cSrcweir pMatrix->GetDimensions( nColCount, nRowCount );
160cdf0e10cSrcweir
161cdf0e10cSrcweir uno::Sequence< uno::Sequence<double> > aRowSeq( static_cast<sal_Int32>(nRowCount) );
162cdf0e10cSrcweir uno::Sequence<double>* pRowAry = aRowSeq.getArray();
163cdf0e10cSrcweir for (SCSIZE nRow = 0; nRow < nRowCount; nRow++)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir uno::Sequence<double> aColSeq( static_cast<sal_Int32>(nColCount) );
166cdf0e10cSrcweir double* pColAry = aColSeq.getArray();
167cdf0e10cSrcweir for (SCSIZE nCol = 0; nCol < nColCount; nCol++)
168cdf0e10cSrcweir if ( pMatrix->IsString( nCol, nRow ) )
169cdf0e10cSrcweir pColAry[nCol] = 0.0;
170cdf0e10cSrcweir else
171cdf0e10cSrcweir pColAry[nCol] = pMatrix->GetDouble( nCol, nRow );
172cdf0e10cSrcweir
173cdf0e10cSrcweir pRowAry[nRow] = aColSeq;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir rAny <<= aRowSeq;
177cdf0e10cSrcweir return sal_True;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir //------------------------------------------------------------------------
181cdf0e10cSrcweir
FillStringArray(uno::Any & rAny,ScDocument * pDoc,const ScRange & rRange)182cdf0e10cSrcweir sal_Bool ScRangeToSequence::FillStringArray( uno::Any& rAny, ScDocument* pDoc, const ScRange& rRange )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir SCTAB nTab = rRange.aStart.Tab();
185cdf0e10cSrcweir SCCOL nStartCol = rRange.aStart.Col();
186cdf0e10cSrcweir SCROW nStartRow = rRange.aStart.Row();
187cdf0e10cSrcweir long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
188cdf0e10cSrcweir long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();
189cdf0e10cSrcweir
190cdf0e10cSrcweir bool bHasErrors = false;
191cdf0e10cSrcweir
192cdf0e10cSrcweir uno::Sequence< uno::Sequence<rtl::OUString> > aRowSeq( nRowCount );
193cdf0e10cSrcweir uno::Sequence<rtl::OUString>* pRowAry = aRowSeq.getArray();
194cdf0e10cSrcweir for (long nRow = 0; nRow < nRowCount; nRow++)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir uno::Sequence<rtl::OUString> aColSeq( nColCount );
197cdf0e10cSrcweir rtl::OUString* pColAry = aColSeq.getArray();
198cdf0e10cSrcweir for (long nCol = 0; nCol < nColCount; nCol++)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir sal_uInt16 nErrCode = pDoc->GetStringForFormula(
201cdf0e10cSrcweir ScAddress((SCCOL)(nStartCol+nCol), (SCROW)(nStartRow+nRow), nTab),
202cdf0e10cSrcweir pColAry[nCol] );
203cdf0e10cSrcweir if ( nErrCode != 0 )
204cdf0e10cSrcweir bHasErrors = true;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir pRowAry[nRow] = aColSeq;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir rAny <<= aRowSeq;
210cdf0e10cSrcweir return !bHasErrors;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
213cdf0e10cSrcweir
FillStringArray(uno::Any & rAny,const ScMatrix * pMatrix,SvNumberFormatter * pFormatter)214cdf0e10cSrcweir sal_Bool ScRangeToSequence::FillStringArray( uno::Any& rAny, const ScMatrix* pMatrix,
215cdf0e10cSrcweir SvNumberFormatter* pFormatter )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir if (!pMatrix)
218cdf0e10cSrcweir return sal_False;
219cdf0e10cSrcweir
220cdf0e10cSrcweir SCSIZE nColCount;
221cdf0e10cSrcweir SCSIZE nRowCount;
222cdf0e10cSrcweir pMatrix->GetDimensions( nColCount, nRowCount );
223cdf0e10cSrcweir
224cdf0e10cSrcweir uno::Sequence< uno::Sequence<rtl::OUString> > aRowSeq( static_cast<sal_Int32>(nRowCount) );
225cdf0e10cSrcweir uno::Sequence<rtl::OUString>* pRowAry = aRowSeq.getArray();
226cdf0e10cSrcweir for (SCSIZE nRow = 0; nRow < nRowCount; nRow++)
227cdf0e10cSrcweir {
228cdf0e10cSrcweir uno::Sequence<rtl::OUString> aColSeq( static_cast<sal_Int32>(nColCount) );
229cdf0e10cSrcweir rtl::OUString* pColAry = aColSeq.getArray();
230cdf0e10cSrcweir for (SCSIZE nCol = 0; nCol < nColCount; nCol++)
231cdf0e10cSrcweir {
232cdf0e10cSrcweir String aStr;
233cdf0e10cSrcweir if ( pMatrix->IsString( nCol, nRow ) )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir if ( !pMatrix->IsEmpty( nCol, nRow ) )
236cdf0e10cSrcweir aStr = pMatrix->GetString( nCol, nRow );
237cdf0e10cSrcweir }
238cdf0e10cSrcweir else if ( pFormatter )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir double fVal = pMatrix->GetDouble( nCol, nRow );
241cdf0e10cSrcweir Color* pColor;
242cdf0e10cSrcweir pFormatter->GetOutputString( fVal, 0, aStr, &pColor );
243cdf0e10cSrcweir }
244cdf0e10cSrcweir pColAry[nCol] = rtl::OUString( aStr );
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
247cdf0e10cSrcweir pRowAry[nRow] = aColSeq;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir
250cdf0e10cSrcweir rAny <<= aRowSeq;
251cdf0e10cSrcweir return sal_True;
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
254cdf0e10cSrcweir //------------------------------------------------------------------------
255cdf0e10cSrcweir
lcl_GetValueFromCell(ScBaseCell & rCell)256cdf0e10cSrcweir double lcl_GetValueFromCell( ScBaseCell& rCell )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir //! ScBaseCell member function?
259cdf0e10cSrcweir
260cdf0e10cSrcweir CellType eType = rCell.GetCellType();
261cdf0e10cSrcweir if ( eType == CELLTYPE_VALUE )
262cdf0e10cSrcweir return ((ScValueCell&)rCell).GetValue();
263cdf0e10cSrcweir else if ( eType == CELLTYPE_FORMULA )
264cdf0e10cSrcweir return ((ScFormulaCell&)rCell).GetValue(); // called only if result is value
265cdf0e10cSrcweir
266cdf0e10cSrcweir DBG_ERROR( "GetValueFromCell: wrong type" );
267cdf0e10cSrcweir return 0;
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
FillMixedArray(uno::Any & rAny,ScDocument * pDoc,const ScRange & rRange,sal_Bool bAllowNV)270cdf0e10cSrcweir sal_Bool ScRangeToSequence::FillMixedArray( uno::Any& rAny, ScDocument* pDoc, const ScRange& rRange,
271cdf0e10cSrcweir sal_Bool bAllowNV )
272cdf0e10cSrcweir {
273cdf0e10cSrcweir SCTAB nTab = rRange.aStart.Tab();
274cdf0e10cSrcweir SCCOL nStartCol = rRange.aStart.Col();
275cdf0e10cSrcweir SCROW nStartRow = rRange.aStart.Row();
276cdf0e10cSrcweir long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
277cdf0e10cSrcweir long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();
278cdf0e10cSrcweir
279cdf0e10cSrcweir String aDocStr;
280cdf0e10cSrcweir sal_Bool bHasErrors = sal_False;
281cdf0e10cSrcweir
282cdf0e10cSrcweir uno::Sequence< uno::Sequence<uno::Any> > aRowSeq( nRowCount );
283cdf0e10cSrcweir uno::Sequence<uno::Any>* pRowAry = aRowSeq.getArray();
284cdf0e10cSrcweir for (long nRow = 0; nRow < nRowCount; nRow++)
285cdf0e10cSrcweir {
286cdf0e10cSrcweir uno::Sequence<uno::Any> aColSeq( nColCount );
287cdf0e10cSrcweir uno::Any* pColAry = aColSeq.getArray();
288cdf0e10cSrcweir for (long nCol = 0; nCol < nColCount; nCol++)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir uno::Any& rElement = pColAry[nCol];
291cdf0e10cSrcweir
292cdf0e10cSrcweir ScAddress aPos( (SCCOL)(nStartCol+nCol), (SCROW)(nStartRow+nRow), nTab );
293cdf0e10cSrcweir ScBaseCell* pCell = pDoc->GetCell( aPos );
294cdf0e10cSrcweir if ( pCell )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir if ( pCell->GetCellType() == CELLTYPE_FORMULA &&
297cdf0e10cSrcweir ((ScFormulaCell*)pCell)->GetErrCode() != 0 )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir // if NV is allowed, leave empty for errors
300cdf0e10cSrcweir bHasErrors = sal_True;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir else if ( pCell->HasValueData() )
303cdf0e10cSrcweir rElement <<= (double) lcl_GetValueFromCell( *pCell );
304cdf0e10cSrcweir else
305cdf0e10cSrcweir rElement <<= rtl::OUString( pCell->GetStringData() );
306cdf0e10cSrcweir }
307cdf0e10cSrcweir else
308cdf0e10cSrcweir rElement <<= rtl::OUString(); // empty: empty string
309cdf0e10cSrcweir }
310cdf0e10cSrcweir pRowAry[nRow] = aColSeq;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
313cdf0e10cSrcweir rAny <<= aRowSeq;
314cdf0e10cSrcweir return bAllowNV || !bHasErrors;
315cdf0e10cSrcweir }
316cdf0e10cSrcweir
317cdf0e10cSrcweir
FillMixedArray(uno::Any & rAny,const ScMatrix * pMatrix,bool bDataTypes)318cdf0e10cSrcweir sal_Bool ScRangeToSequence::FillMixedArray( uno::Any& rAny, const ScMatrix* pMatrix, bool bDataTypes )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir if (!pMatrix)
321cdf0e10cSrcweir return sal_False;
322cdf0e10cSrcweir
323cdf0e10cSrcweir SCSIZE nColCount;
324cdf0e10cSrcweir SCSIZE nRowCount;
325cdf0e10cSrcweir pMatrix->GetDimensions( nColCount, nRowCount );
326cdf0e10cSrcweir
327cdf0e10cSrcweir uno::Sequence< uno::Sequence<uno::Any> > aRowSeq( static_cast<sal_Int32>(nRowCount) );
328cdf0e10cSrcweir uno::Sequence<uno::Any>* pRowAry = aRowSeq.getArray();
329cdf0e10cSrcweir for (SCSIZE nRow = 0; nRow < nRowCount; nRow++)
330cdf0e10cSrcweir {
331cdf0e10cSrcweir uno::Sequence<uno::Any> aColSeq( static_cast<sal_Int32>(nColCount) );
332cdf0e10cSrcweir uno::Any* pColAry = aColSeq.getArray();
333cdf0e10cSrcweir for (SCSIZE nCol = 0; nCol < nColCount; nCol++)
334cdf0e10cSrcweir {
335cdf0e10cSrcweir if ( pMatrix->IsString( nCol, nRow ) )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir String aStr;
338cdf0e10cSrcweir if ( !pMatrix->IsEmpty( nCol, nRow ) )
339cdf0e10cSrcweir aStr = pMatrix->GetString( nCol, nRow );
340cdf0e10cSrcweir pColAry[nCol] <<= rtl::OUString( aStr );
341cdf0e10cSrcweir }
342cdf0e10cSrcweir else
343cdf0e10cSrcweir {
344cdf0e10cSrcweir double fVal = pMatrix->GetDouble( nCol, nRow );
345cdf0e10cSrcweir if (bDataTypes && pMatrix->IsBoolean( nCol, nRow ))
346cdf0e10cSrcweir pColAry[nCol] <<= (fVal ? true : false);
347cdf0e10cSrcweir else
348cdf0e10cSrcweir pColAry[nCol] <<= fVal;
349cdf0e10cSrcweir }
350cdf0e10cSrcweir }
351cdf0e10cSrcweir
352cdf0e10cSrcweir pRowAry[nRow] = aColSeq;
353cdf0e10cSrcweir }
354cdf0e10cSrcweir
355cdf0e10cSrcweir rAny <<= aRowSeq;
356cdf0e10cSrcweir return sal_True;
357cdf0e10cSrcweir }
358cdf0e10cSrcweir
359cdf0e10cSrcweir //------------------------------------------------------------------------
360cdf0e10cSrcweir
361cdf0e10cSrcweir // static
ConvertAnyToDouble(double & o_fVal,com::sun::star::uno::TypeClass & o_eClass,const com::sun::star::uno::Any & rAny)362cdf0e10cSrcweir bool ScApiTypeConversion::ConvertAnyToDouble( double & o_fVal,
363cdf0e10cSrcweir com::sun::star::uno::TypeClass & o_eClass,
364cdf0e10cSrcweir const com::sun::star::uno::Any & rAny )
365cdf0e10cSrcweir {
366cdf0e10cSrcweir bool bRet = false;
367cdf0e10cSrcweir o_eClass = rAny.getValueTypeClass();
368cdf0e10cSrcweir switch (o_eClass)
369cdf0e10cSrcweir {
370cdf0e10cSrcweir //! extract integer values
371cdf0e10cSrcweir case uno::TypeClass_ENUM:
372cdf0e10cSrcweir case uno::TypeClass_BOOLEAN:
373cdf0e10cSrcweir case uno::TypeClass_CHAR:
374cdf0e10cSrcweir case uno::TypeClass_BYTE:
375cdf0e10cSrcweir case uno::TypeClass_SHORT:
376cdf0e10cSrcweir case uno::TypeClass_UNSIGNED_SHORT:
377cdf0e10cSrcweir case uno::TypeClass_LONG:
378cdf0e10cSrcweir case uno::TypeClass_UNSIGNED_LONG:
379cdf0e10cSrcweir case uno::TypeClass_FLOAT:
380cdf0e10cSrcweir case uno::TypeClass_DOUBLE:
381cdf0e10cSrcweir rAny >>= o_fVal;
382cdf0e10cSrcweir bRet = true;
383cdf0e10cSrcweir break;
384cdf0e10cSrcweir default:
385cdf0e10cSrcweir ; // nothing, avoid warning
386cdf0e10cSrcweir }
387cdf0e10cSrcweir if (!bRet)
388cdf0e10cSrcweir o_fVal = 0.0;
389cdf0e10cSrcweir return bRet;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
392cdf0e10cSrcweir //------------------------------------------------------------------------
393cdf0e10cSrcweir
394cdf0e10cSrcweir // static
CreateMixedMatrix(const com::sun::star::uno::Any & rAny)395cdf0e10cSrcweir ScMatrixRef ScSequenceToMatrix::CreateMixedMatrix( const com::sun::star::uno::Any & rAny )
396cdf0e10cSrcweir {
397cdf0e10cSrcweir ScMatrixRef xMatrix;
398cdf0e10cSrcweir uno::Sequence< uno::Sequence< uno::Any > > aSequence;
399cdf0e10cSrcweir if ( rAny >>= aSequence )
400cdf0e10cSrcweir {
401cdf0e10cSrcweir sal_Int32 nRowCount = aSequence.getLength();
402cdf0e10cSrcweir const uno::Sequence<uno::Any>* pRowArr = aSequence.getConstArray();
403cdf0e10cSrcweir sal_Int32 nMaxColCount = 0;
404cdf0e10cSrcweir sal_Int32 nCol, nRow;
405cdf0e10cSrcweir for (nRow=0; nRow<nRowCount; nRow++)
406cdf0e10cSrcweir {
407cdf0e10cSrcweir sal_Int32 nTmp = pRowArr[nRow].getLength();
408cdf0e10cSrcweir if ( nTmp > nMaxColCount )
409cdf0e10cSrcweir nMaxColCount = nTmp;
410cdf0e10cSrcweir }
411cdf0e10cSrcweir if ( nMaxColCount && nRowCount )
412cdf0e10cSrcweir {
413cdf0e10cSrcweir rtl::OUString aUStr;
414cdf0e10cSrcweir xMatrix = new ScMatrix(
415cdf0e10cSrcweir static_cast<SCSIZE>(nMaxColCount),
416cdf0e10cSrcweir static_cast<SCSIZE>(nRowCount) );
417cdf0e10cSrcweir ScMatrix* pMatrix = xMatrix;
418cdf0e10cSrcweir SCSIZE nCols, nRows;
419cdf0e10cSrcweir pMatrix->GetDimensions( nCols, nRows);
420cdf0e10cSrcweir if (nCols != static_cast<SCSIZE>(nMaxColCount) || nRows != static_cast<SCSIZE>(nRowCount))
421cdf0e10cSrcweir {
422cdf0e10cSrcweir DBG_ERRORFILE( "ScSequenceToMatrix::CreateMixedMatrix: matrix exceeded max size, returning NULL matrix");
423cdf0e10cSrcweir return NULL;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir for (nRow=0; nRow<nRowCount; nRow++)
426cdf0e10cSrcweir {
427cdf0e10cSrcweir sal_Int32 nColCount = pRowArr[nRow].getLength();
428cdf0e10cSrcweir const uno::Any* pColArr = pRowArr[nRow].getConstArray();
429cdf0e10cSrcweir for (nCol=0; nCol<nColCount; nCol++)
430cdf0e10cSrcweir {
431cdf0e10cSrcweir double fVal;
432cdf0e10cSrcweir uno::TypeClass eClass;
433cdf0e10cSrcweir if (ScApiTypeConversion::ConvertAnyToDouble( fVal, eClass, pColArr[nCol]))
434cdf0e10cSrcweir {
435cdf0e10cSrcweir if (eClass == uno::TypeClass_BOOLEAN)
436cdf0e10cSrcweir pMatrix->PutBoolean( (fVal ? true : false),
437cdf0e10cSrcweir static_cast<SCSIZE>(nCol),
438cdf0e10cSrcweir static_cast<SCSIZE>(nRow) );
439cdf0e10cSrcweir else
440cdf0e10cSrcweir pMatrix->PutDouble( fVal,
441cdf0e10cSrcweir static_cast<SCSIZE>(nCol),
442cdf0e10cSrcweir static_cast<SCSIZE>(nRow) );
443cdf0e10cSrcweir }
444cdf0e10cSrcweir else
445cdf0e10cSrcweir {
446cdf0e10cSrcweir // Try string, else use empty as last resort.
447cdf0e10cSrcweir
448cdf0e10cSrcweir //Reflection* pRefl = pColArr[nCol].getReflection();
449cdf0e10cSrcweir //if ( pRefl->equals( *OUString_getReflection() ) )
450cdf0e10cSrcweir if ( pColArr[nCol] >>= aUStr )
451cdf0e10cSrcweir pMatrix->PutString( String( aUStr ),
452cdf0e10cSrcweir static_cast<SCSIZE>(nCol),
453cdf0e10cSrcweir static_cast<SCSIZE>(nRow) );
454cdf0e10cSrcweir else
455cdf0e10cSrcweir pMatrix->PutEmpty(
456cdf0e10cSrcweir static_cast<SCSIZE>(nCol),
457cdf0e10cSrcweir static_cast<SCSIZE>(nRow) );
458cdf0e10cSrcweir }
459cdf0e10cSrcweir }
460cdf0e10cSrcweir for (nCol=nColCount; nCol<nMaxColCount; nCol++)
461cdf0e10cSrcweir {
462cdf0e10cSrcweir pMatrix->PutEmpty(
463cdf0e10cSrcweir static_cast<SCSIZE>(nCol),
464cdf0e10cSrcweir static_cast<SCSIZE>(nRow) );
465cdf0e10cSrcweir }
466cdf0e10cSrcweir }
467cdf0e10cSrcweir }
468cdf0e10cSrcweir }
469cdf0e10cSrcweir return xMatrix;
470cdf0e10cSrcweir }
471cdf0e10cSrcweir
472cdf0e10cSrcweir
473cdf0e10cSrcweir //------------------------------------------------------------------------
474cdf0e10cSrcweir
GetString(String & rString,const uno::Any & rAny,sal_uInt16 nEncoding)475cdf0e10cSrcweir sal_Bool ScByteSequenceToString::GetString( String& rString, const uno::Any& rAny,
476cdf0e10cSrcweir sal_uInt16 nEncoding )
477cdf0e10cSrcweir {
478cdf0e10cSrcweir uno::Sequence<sal_Int8> aSeq;
479cdf0e10cSrcweir if ( rAny >>= aSeq )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir rString = String( (const sal_Char*)aSeq.getConstArray(),
482cdf0e10cSrcweir (xub_StrLen)aSeq.getLength(), nEncoding );
483cdf0e10cSrcweir rString.EraseTrailingChars( (sal_Unicode) 0 );
484cdf0e10cSrcweir return sal_True;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir return sal_False;
487cdf0e10cSrcweir }
488cdf0e10cSrcweir
489cdf0e10cSrcweir //------------------------------------------------------------------------
490