1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <xihelper.hxx>
22 #include <svl/itemset.hxx>
23 #include <svl/sharedstringpool.hxx>
24 #include <editeng/editobj.hxx>
25 #include <tools/urlobj.hxx>
26 #include <editeng/eeitem.hxx>
27 #include <editeng/flditem.hxx>
28 #include <document.hxx>
29 #include <rangelst.hxx>
30 #include <editutil.hxx>
32 #include <xltracer.hxx>
33 #include <xistream.hxx>
34 #include <xistring.hxx>
35 #include <xistyle.hxx>
36 #include <excform.hxx>
37 #include <scmatrix.hxx>
38 #include <documentimport.hxx>
39 #include <sal/log.hxx>
41 // Excel->Calc cell address/range conversion ==================================
45 /** Fills the passed Calc address with the passed Excel cell coordinates without checking any limits. */
46 void lclFillAddress( ScAddress
& rScPos
, sal_uInt16 nXclCol
, sal_uInt32 nXclRow
, SCTAB nScTab
)
48 rScPos
.SetCol( static_cast< SCCOL
>( nXclCol
) );
49 rScPos
.SetRow( static_cast< SCROW
>( nXclRow
) );
50 rScPos
.SetTab( nScTab
);
55 XclImpAddressConverter::XclImpAddressConverter( const XclImpRoot
& rRoot
) :
56 XclAddressConverterBase( rRoot
.GetTracer(), rRoot
.GetScMaxPos() )
60 // cell address ---------------------------------------------------------------
62 bool XclImpAddressConverter::CheckAddress( const XclAddress
& rXclPos
, bool bWarn
)
64 bool bValidCol
= rXclPos
.mnCol
<= mnMaxCol
;
65 bool bValidRow
= rXclPos
.mnRow
<= mnMaxRow
;
66 bool bValid
= bValidCol
&& bValidRow
;
67 if( !bValid
&& bWarn
)
69 mbColTrunc
|= !bValidCol
;
70 mbRowTrunc
|= !bValidRow
;
71 mrTracer
.TraceInvalidAddress( ScAddress(
72 static_cast< SCCOL
>( rXclPos
.mnCol
), static_cast< SCROW
>( rXclPos
.mnRow
), 0 ), maMaxPos
);
77 bool XclImpAddressConverter::ConvertAddress( ScAddress
& rScPos
,
78 const XclAddress
& rXclPos
, SCTAB nScTab
, bool bWarn
)
80 bool bValid
= CheckAddress( rXclPos
, bWarn
);
82 lclFillAddress( rScPos
, rXclPos
.mnCol
, rXclPos
.mnRow
, nScTab
);
86 ScAddress
XclImpAddressConverter::CreateValidAddress(
87 const XclAddress
& rXclPos
, SCTAB nScTab
, bool bWarn
)
89 ScAddress
aScPos( ScAddress::UNINITIALIZED
);
90 if( !ConvertAddress( aScPos
, rXclPos
, nScTab
, bWarn
) )
92 aScPos
.SetCol( static_cast< SCCOL
>( ::std::min( rXclPos
.mnCol
, mnMaxCol
) ) );
93 aScPos
.SetRow( static_cast< SCROW
>( ::std::min( rXclPos
.mnRow
, mnMaxRow
) ) );
94 aScPos
.SetTab( limit_cast
< SCTAB
>( nScTab
, 0, maMaxPos
.Tab() ) );
99 // cell range -----------------------------------------------------------------
101 bool XclImpAddressConverter::ConvertRange( ScRange
& rScRange
,
102 const XclRange
& rXclRange
, SCTAB nScTab1
, SCTAB nScTab2
, bool bWarn
)
104 // check start position
105 bool bValidStart
= CheckAddress( rXclRange
.maFirst
, bWarn
);
108 lclFillAddress( rScRange
.aStart
, rXclRange
.maFirst
.mnCol
, rXclRange
.maFirst
.mnRow
, nScTab1
);
110 // check & correct end position
111 sal_uInt16 nXclCol2
= rXclRange
.maLast
.mnCol
;
112 sal_uInt32 nXclRow2
= rXclRange
.maLast
.mnRow
;
113 if( !CheckAddress( rXclRange
.maLast
, bWarn
) )
115 nXclCol2
= ::std::min( nXclCol2
, mnMaxCol
);
116 nXclRow2
= ::std::min( nXclRow2
, mnMaxRow
);
118 lclFillAddress( rScRange
.aEnd
, nXclCol2
, nXclRow2
, nScTab2
);
123 // cell range list ------------------------------------------------------------
125 void XclImpAddressConverter::ConvertRangeList( ScRangeList
& rScRanges
,
126 const XclRangeList
& rXclRanges
, SCTAB nScTab
, bool bWarn
)
128 rScRanges
.RemoveAll();
129 for( const auto& rXclRange
: rXclRanges
)
131 ScRange
aScRange( ScAddress::UNINITIALIZED
);
132 if( ConvertRange( aScRange
, rXclRange
, nScTab
, nScTab
, bWarn
) )
133 rScRanges
.push_back( aScRange
);
137 // String->EditEngine conversion ==============================================
141 std::unique_ptr
<EditTextObject
> lclCreateTextObject( const XclImpRoot
& rRoot
,
142 const XclImpString
& rString
, XclFontItemType eType
, sal_uInt16 nXFIndex
)
144 std::unique_ptr
<EditTextObject
> pTextObj
;
146 const XclImpXFBuffer
& rXFBuffer
= rRoot
.GetXFBuffer();
147 const XclImpFont
* pFirstFont
= rXFBuffer
.GetFont( nXFIndex
);
148 bool bFirstEscaped
= pFirstFont
&& pFirstFont
->HasEscapement();
150 if( rString
.IsRich() || bFirstEscaped
)
152 const XclImpFontBuffer
& rFontBuffer
= rRoot
.GetFontBuffer();
153 const XclFormatRunVec
& rFormats
= rString
.GetFormats();
155 ScEditEngineDefaulter
& rEE
= rRoot
.GetEditEngine();
156 rEE
.SetText( rString
.GetText() );
158 SfxItemSet
aItemSet( rEE
.GetEmptyItemSet() );
160 rFontBuffer
.FillToItemSet( aItemSet
, eType
, rXFBuffer
.GetFontIndex( nXFIndex
) );
161 ESelection aSelection
;
163 XclFormatRun aNextRun
;
164 XclFormatRunVec::const_iterator aIt
= rFormats
.begin();
165 XclFormatRunVec::const_iterator aEnd
= rFormats
.end();
170 aNextRun
.mnChar
= 0xFFFF;
172 sal_Int32 nLen
= rString
.GetText().getLength();
173 for( sal_Int32 nChar
= 0; nChar
< nLen
; ++nChar
)
175 // reached new different formatted text portion
176 if( nChar
>= aNextRun
.mnChar
)
178 // send items to edit engine
179 rEE
.QuickSetAttribs( aItemSet
, aSelection
);
181 // start new item set
182 aItemSet
.ClearItem();
183 rFontBuffer
.FillToItemSet( aItemSet
, eType
, aNextRun
.mnFontIdx
);
185 // read new formatting information
189 aNextRun
.mnChar
= 0xFFFF;
191 // reset selection start to current position
192 aSelection
.nStartPara
= aSelection
.nEndPara
;
193 aSelection
.nStartPos
= aSelection
.nEndPos
;
196 // set end of selection to current position
197 if( rString
.GetText()[ nChar
] == '\n' )
199 ++aSelection
.nEndPara
;
200 aSelection
.nEndPos
= 0;
203 ++aSelection
.nEndPos
;
206 // send items of last text portion to edit engine
207 rEE
.QuickSetAttribs( aItemSet
, aSelection
);
209 pTextObj
= rEE
.CreateTextObject();
217 std::unique_ptr
<EditTextObject
> XclImpStringHelper::CreateTextObject(
218 const XclImpRoot
& rRoot
, const XclImpString
& rString
)
220 return lclCreateTextObject( rRoot
, rString
, XclFontItemType::Editeng
, 0 );
223 void XclImpStringHelper::SetToDocument(
224 ScDocumentImport
& rDoc
, const ScAddress
& rPos
, const XclImpRoot
& rRoot
,
225 const XclImpString
& rString
, sal_uInt16 nXFIndex
)
227 if (rString
.GetText().isEmpty())
230 ::std::unique_ptr
< EditTextObject
> pTextObj( lclCreateTextObject( rRoot
, rString
, XclFontItemType::Editeng
, nXFIndex
) );
234 rDoc
.setEditCell(rPos
, std::move(pTextObj
));
238 const OUString
& aStr
= rString
.GetText();
239 if (aStr
.indexOf('\n') != -1 || aStr
.indexOf('\r') != -1)
241 // Multiline content.
242 ScFieldEditEngine
& rEngine
= rDoc
.getDoc().GetEditEngine();
243 rEngine
.SetText(aStr
);
244 rDoc
.setEditCell(rPos
, rEngine
.CreateTextObject());
249 rDoc
.setStringCell(rPos
, aStr
);
254 // Header/footer conversion ===================================================
256 XclImpHFConverter::XclImpHFPortionInfo::XclImpHFPortionInfo() :
260 maSel
.nStartPara
= maSel
.nEndPara
= 0;
261 maSel
.nStartPos
= maSel
.nEndPos
= 0;
264 XclImpHFConverter::XclImpHFConverter( const XclImpRoot
& rRoot
) :
266 mrEE( rRoot
.GetHFEditEngine() ),
267 mxFontData( new XclFontData
),
268 meCurrObj( EXC_HF_CENTER
)
272 XclImpHFConverter::~XclImpHFConverter()
276 void XclImpHFConverter::ParseString( const OUString
& rHFString
)
278 // edit engine objects
279 mrEE
.SetText( EMPTY_OUSTRING
);
281 maInfos
.resize( EXC_HF_PORTION_COUNT
);
282 meCurrObj
= EXC_HF_CENTER
;
284 // parser temporaries
285 maCurrText
.truncate();
286 OUStringBuffer aReadFont
; // current font name
287 OUStringBuffer aReadStyle
; // current font style
288 sal_uInt16 nReadHeight
= 0; // current font height
291 /** State of the parser. */
292 enum XclHFParserState
294 xlPSText
, /// Read text, search for functions.
295 xlPSFunc
, /// Read function (token following a '&').
296 xlPSFont
, /// Read font name ('&' is followed by '"', reads until next '"' or ',').
297 xlPSFontStyle
, /// Read font style name (font part after ',', reads until next '"').
298 xlPSHeight
/// Read font height ('&' is followed by num. digits, reads until non-digit).
301 const sal_Unicode
* pChar
= rHFString
.getStr();
302 const sal_Unicode
* pNull
= pChar
+ rHFString
.getLength(); // pointer to terminating null char
308 // --- read text character ---
314 case '&': // new command
318 case '\n': // line break
323 maCurrText
.append(OUStringChar(*pChar
));
328 // --- read control sequence ---
335 case '&': maCurrText
.append("&"); break; // the '&' character
337 case 'L': SetNewPortion( EXC_HF_LEFT
); break; // Left portion
338 case 'C': SetNewPortion( EXC_HF_CENTER
); break; // Center portion
339 case 'R': SetNewPortion( EXC_HF_RIGHT
); break; // Right portion
341 case 'P': InsertField( SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD
) ); break; // page
342 case 'N': InsertField( SvxFieldItem( SvxPagesField(), EE_FEATURE_FIELD
) ); break; // page count
343 case 'D': InsertField( SvxFieldItem( SvxDateField(), EE_FEATURE_FIELD
) ); break; // date
344 case 'T': InsertField( SvxFieldItem( SvxTimeField(), EE_FEATURE_FIELD
) ); break; // time
345 case 'A': InsertField( SvxFieldItem( SvxTableField(), EE_FEATURE_FIELD
) ); break; // table name
347 case 'Z': // file path
348 InsertField( SvxFieldItem( SvxExtFileField(), EE_FEATURE_FIELD
) ); // convert to full name
349 if( (pNull
- pChar
>= 2) && (*(pChar
+ 1) == '&') && (*(pChar
+ 2) == 'F') )
351 // &Z&F found - ignore the &F part
355 case 'F': // file name
356 InsertField( SvxFieldItem( SvxExtFileField( EMPTY_OUSTRING
, SvxFileType::Var
, SvxFileFormat::NameAndExt
), EE_FEATURE_FIELD
) );
359 case 'U': // underline
361 mxFontData
->mnUnderline
= (mxFontData
->mnUnderline
== EXC_FONTUNDERL_SINGLE
) ?
362 EXC_FONTUNDERL_NONE
: EXC_FONTUNDERL_SINGLE
;
364 case 'E': // double underline
366 mxFontData
->mnUnderline
= (mxFontData
->mnUnderline
== EXC_FONTUNDERL_DOUBLE
) ?
367 EXC_FONTUNDERL_NONE
: EXC_FONTUNDERL_DOUBLE
;
369 case 'S': // strikeout
371 mxFontData
->mbStrikeout
= !mxFontData
->mbStrikeout
;
373 case 'X': // superscript
375 mxFontData
->mnEscapem
= (mxFontData
->mnEscapem
== EXC_FONTESC_SUPER
) ?
376 EXC_FONTESC_NONE
: EXC_FONTESC_SUPER
;
378 case 'Y': // subsrcipt
380 mxFontData
->mnEscapem
= (mxFontData
->mnEscapem
== EXC_FONTESC_SUB
) ?
381 EXC_FONTESC_NONE
: EXC_FONTESC_SUB
;
384 case '\"': // font name
385 aReadFont
.setLength(0);
386 aReadStyle
.setLength(0);
390 if( ('0' <= *pChar
) && (*pChar
<= '9') ) // font size
392 nReadHeight
= *pChar
- '0';
399 // --- read font name ---
409 eState
= xlPSFontStyle
;
412 aReadFont
.append(*pChar
);
417 // --- read font style ---
425 if( !aReadFont
.isEmpty() )
426 mxFontData
->maName
= aReadFont
.toString();
427 mxFontData
->maStyle
= aReadStyle
.toString();
431 aReadStyle
.append(*pChar
);
436 // --- read font height ---
440 if( ('0' <= *pChar
) && (*pChar
<= '9') )
442 if( nReadHeight
!= 0xFFFF )
445 nReadHeight
+= (*pChar
- '0');
446 if( nReadHeight
> 1600 ) // max 1600pt = 32000twips
447 nReadHeight
= 0xFFFF;
452 if( (nReadHeight
!= 0) && (nReadHeight
!= 0xFFFF) )
455 mxFontData
->mnHeight
= nReadHeight
* 20;
468 maInfos
[ EXC_HF_LEFT
].mnHeight
+= GetMaxLineHeight( EXC_HF_LEFT
);
469 maInfos
[ EXC_HF_CENTER
].mnHeight
+= GetMaxLineHeight( EXC_HF_CENTER
);
470 maInfos
[ EXC_HF_RIGHT
].mnHeight
+= GetMaxLineHeight( EXC_HF_RIGHT
);
473 void XclImpHFConverter::FillToItemSet( SfxItemSet
& rItemSet
, sal_uInt16 nWhichId
) const
475 ScPageHFItem
aHFItem( nWhichId
);
476 if( maInfos
[ EXC_HF_LEFT
].mxObj
.get() )
477 aHFItem
.SetLeftArea( *maInfos
[ EXC_HF_LEFT
].mxObj
);
478 if( maInfos
[ EXC_HF_CENTER
].mxObj
.get() )
479 aHFItem
.SetCenterArea( *maInfos
[ EXC_HF_CENTER
].mxObj
);
480 if( maInfos
[ EXC_HF_RIGHT
].mxObj
.get() )
481 aHFItem
.SetRightArea( *maInfos
[ EXC_HF_RIGHT
].mxObj
);
482 rItemSet
.Put( aHFItem
);
485 sal_Int32
XclImpHFConverter::GetTotalHeight() const
487 return ::std::max( maInfos
[ EXC_HF_LEFT
].mnHeight
,
488 ::std::max( maInfos
[ EXC_HF_CENTER
].mnHeight
, maInfos
[ EXC_HF_RIGHT
].mnHeight
) );
491 // private --------------------------------------------------------------------
493 sal_uInt16
XclImpHFConverter::GetMaxLineHeight( XclImpHFPortion ePortion
) const
495 sal_uInt16 nMaxHt
= maInfos
[ ePortion
].mnMaxLineHt
;
496 return (nMaxHt
== 0) ? mxFontData
->mnHeight
: nMaxHt
;
499 void XclImpHFConverter::UpdateMaxLineHeight( XclImpHFPortion ePortion
)
501 sal_uInt16
& rnMaxHt
= maInfos
[ ePortion
].mnMaxLineHt
;
502 rnMaxHt
= ::std::max( rnMaxHt
, mxFontData
->mnHeight
);
505 void XclImpHFConverter::UpdateCurrMaxLineHeight()
507 UpdateMaxLineHeight( meCurrObj
);
510 void XclImpHFConverter::SetAttribs()
512 ESelection
& rSel
= GetCurrSel();
513 if( (rSel
.nStartPara
!= rSel
.nEndPara
) || (rSel
.nStartPos
!= rSel
.nEndPos
) )
515 SfxItemSet
aItemSet( mrEE
.GetEmptyItemSet() );
516 XclImpFont
aFont( GetRoot(), *mxFontData
);
517 aFont
.FillToItemSet( aItemSet
, XclFontItemType::HeaderFooter
);
518 mrEE
.QuickSetAttribs( aItemSet
, rSel
);
519 rSel
.nStartPara
= rSel
.nEndPara
;
520 rSel
.nStartPos
= rSel
.nEndPos
;
524 void XclImpHFConverter::ResetFontData()
526 if( const XclImpFont
* pFirstFont
= GetFontBuffer().GetFont( EXC_FONT_APP
) )
527 *mxFontData
= pFirstFont
->GetFontData();
531 mxFontData
->mnHeight
= 200;
535 void XclImpHFConverter::InsertText()
537 if( !maCurrText
.isEmpty() )
539 ESelection
& rSel
= GetCurrSel();
540 OUString
sString(maCurrText
.makeStringAndClear());
541 mrEE
.QuickInsertText( sString
, ESelection( rSel
.nEndPara
, rSel
.nEndPos
, rSel
.nEndPara
, rSel
.nEndPos
) );
542 rSel
.nEndPos
= rSel
.nEndPos
+ sString
.getLength();
543 UpdateCurrMaxLineHeight();
547 void XclImpHFConverter::InsertField( const SvxFieldItem
& rFieldItem
)
549 ESelection
& rSel
= GetCurrSel();
550 mrEE
.QuickInsertField( rFieldItem
, ESelection( rSel
.nEndPara
, rSel
.nEndPos
, rSel
.nEndPara
, rSel
.nEndPos
) );
552 UpdateCurrMaxLineHeight();
555 void XclImpHFConverter::InsertLineBreak()
557 ESelection
& rSel
= GetCurrSel();
558 mrEE
.QuickInsertText( OUString('\n'), ESelection( rSel
.nEndPara
, rSel
.nEndPos
, rSel
.nEndPara
, rSel
.nEndPos
) );
561 GetCurrInfo().mnHeight
+= GetMaxLineHeight( meCurrObj
);
562 GetCurrInfo().mnMaxLineHt
= 0;
565 void XclImpHFConverter::CreateCurrObject()
569 GetCurrObj() = mrEE
.CreateTextObject();
572 void XclImpHFConverter::SetNewPortion( XclImpHFPortion eNew
)
574 if( eNew
!= meCurrObj
)
578 if( GetCurrObj().get() )
579 mrEE
.SetText( *GetCurrObj() );
581 mrEE
.SetText( EMPTY_OUSTRING
);
586 // URL conversion =============================================================
590 void lclAppendUrlChar( OUString
& rUrl
, sal_Unicode cChar
)
592 // encode special characters
595 case '#': rUrl
+= "%23"; break;
596 case '%': rUrl
+= "%25"; break;
597 default: rUrl
+= OUStringChar( cChar
);
603 void XclImpUrlHelper::DecodeUrl(
604 OUString
& rUrl
, OUString
& rTabName
, bool& rbSameWb
,
605 const XclImpRoot
& rRoot
, const OUString
& rEncodedUrl
)
609 xlUrlInit
, /// Initial state, read string mode character.
610 xlUrlPath
, /// Read URL path.
611 xlUrlFileName
, /// Read file name.
612 xlUrlSheetName
, /// Read sheet name.
613 xlUrlRaw
/// Raw mode. No control characters will occur.
614 } eState
= xlUrlInit
;
616 bool bEncoded
= true;
619 sal_Unicode cCurrDrive
= 0;
620 OUString
aDosBase( INetURLObject( rRoot
.GetBasePath() ).getFSysPath( FSysStyle::Dos
) );
621 if (!aDosBase
.isEmpty() && aDosBase
.match(":\\", 1))
622 cCurrDrive
= aDosBase
[0];
624 const sal_Unicode
* pChar
= rEncodedUrl
.getStr();
630 // --- first character ---
636 case EXC_URLSTART_ENCODED
:
639 case EXC_URLSTART_SELF
:
640 case EXC_URLSTART_SELFENCODED
:
642 eState
= xlUrlSheetName
;
646 eState
= xlUrlFileName
;
650 lclAppendUrlChar( rUrl
, *pChar
);
662 case EXC_URL_DOSDRIVE
:
671 lclAppendUrlChar( rUrl
, *pChar
);
676 rUrl
+= "<NULL-DRIVE!>";
679 case EXC_URL_DRIVEROOT
:
682 lclAppendUrlChar( rUrl
, cCurrDrive
);
689 else // control character in raw name -> DDE link
691 rUrl
+= OUStringChar(EXC_DDE_DELIM
);
695 case EXC_URL_PARENTDIR
:
702 sal_Int32 nLen
= *++pChar
;
703 for( sal_Int32 nChar
= 0; (nChar
< nLen
) && *(pChar
+ 1); ++nChar
)
704 lclAppendUrlChar( rUrl
, *++pChar
);
705 // rUrl.Append( ':' );
710 eState
= xlUrlFileName
;
713 lclAppendUrlChar( rUrl
, *pChar
);
724 case ']': eState
= xlUrlSheetName
; break;
725 default: lclAppendUrlChar( rUrl
, *pChar
);
730 // --- sheet name ---
733 rTabName
+= OUStringChar( *pChar
);
736 // --- raw read mode ---
739 lclAppendUrlChar( rUrl
, *pChar
);
747 void XclImpUrlHelper::DecodeUrl(
748 OUString
& rUrl
, bool& rbSameWb
, const XclImpRoot
& rRoot
, const OUString
& rEncodedUrl
)
752 DecodeUrl( aUrl
, aTabName
, rbSameWb
, rRoot
, rEncodedUrl
);
754 OSL_ENSURE( aTabName
.isEmpty(), "XclImpUrlHelper::DecodeUrl - sheet name ignored" );
757 bool XclImpUrlHelper::DecodeLink( OUString
& rApplic
, OUString
& rTopic
, const OUString
& rEncUrl
)
759 sal_Int32 nPos
= rEncUrl
.indexOf( EXC_DDE_DELIM
);
760 if( (nPos
> 0) && (nPos
+ 1 < rEncUrl
.getLength()) )
762 rApplic
= rEncUrl
.copy( 0, nPos
);
763 rTopic
= rEncUrl
.copy( nPos
+ 1 );
769 // Cached Values ==============================================================
771 XclImpCachedValue::XclImpCachedValue( XclImpStream
& rStrm
) :
775 mnType
= rStrm
.ReaduInt8();
778 case EXC_CACHEDVAL_EMPTY
:
781 case EXC_CACHEDVAL_DOUBLE
:
782 mfValue
= rStrm
.ReadDouble();
784 case EXC_CACHEDVAL_STRING
:
785 maStr
= rStrm
.ReadUniString();
787 case EXC_CACHEDVAL_BOOL
:
788 case EXC_CACHEDVAL_ERROR
:
791 mnBoolErr
= rStrm
.ReaduInt8();
794 std::unique_ptr
<ScTokenArray
> pScTokArr
= rStrm
.GetRoot().GetOldFmlaConverter().GetBoolErr(
795 XclTools::ErrorToEnum( fVal
, mnType
== EXC_CACHEDVAL_ERROR
, mnBoolErr
) );
797 mxTokArr
= std::move( pScTokArr
);
801 OSL_FAIL( "XclImpCachedValue::XclImpCachedValue - unknown data type" );
805 XclImpCachedValue::~XclImpCachedValue()
809 FormulaError
XclImpCachedValue::GetScError() const
811 return (mnType
== EXC_CACHEDVAL_ERROR
) ? XclTools::GetScErrorCode( mnBoolErr
) : FormulaError::NONE
;
814 // Matrix Cached Values ==============================================================
816 XclImpCachedMatrix::XclImpCachedMatrix( XclImpStream
& rStrm
) :
820 mnScCols
= rStrm
.ReaduInt8();
821 mnScRows
= rStrm
.ReaduInt16();
823 if( rStrm
.GetRoot().GetBiff() <= EXC_BIFF5
)
825 // in BIFF2-BIFF7: 256 columns represented by 0 columns
831 // in BIFF8: columns and rows decreaed by 1
836 //assuming worst case scenario of unknown types
837 const size_t nMinRecordSize
= 1;
838 const size_t nMaxRows
= rStrm
.GetRecLeft() / (nMinRecordSize
* mnScCols
);
839 if (mnScRows
> nMaxRows
)
841 SAL_WARN("sc", "Parsing error: " << nMaxRows
<<
842 " max possible rows, but " << mnScRows
<< " claimed, truncating");
846 for( SCSIZE nScRow
= 0; nScRow
< mnScRows
; ++nScRow
)
847 for( SCSIZE nScCol
= 0; nScCol
< mnScCols
; ++nScCol
)
848 maValueList
.push_back( std::make_unique
<XclImpCachedValue
>( rStrm
) );
851 XclImpCachedMatrix::~XclImpCachedMatrix()
855 ScMatrixRef
XclImpCachedMatrix::CreateScMatrix( svl::SharedStringPool
& rPool
) const
857 ScMatrixRef xScMatrix
;
858 OSL_ENSURE( mnScCols
* mnScRows
== maValueList
.size(), "XclImpCachedMatrix::CreateScMatrix - element count mismatch" );
859 if( mnScCols
&& mnScRows
&& static_cast< sal_uLong
>( mnScCols
* mnScRows
) <= maValueList
.size() )
861 xScMatrix
= new ScMatrix(mnScCols
, mnScRows
, 0.0);
862 XclImpValueList::const_iterator itValue
= maValueList
.begin();
863 for( SCSIZE nScRow
= 0; nScRow
< mnScRows
; ++nScRow
)
865 for( SCSIZE nScCol
= 0; nScCol
< mnScCols
; ++nScCol
)
867 switch( (*itValue
)->GetType() )
869 case EXC_CACHEDVAL_EMPTY
:
870 // Excel shows 0.0 here, not an empty cell
871 xScMatrix
->PutEmpty( nScCol
, nScRow
);
873 case EXC_CACHEDVAL_DOUBLE
:
874 xScMatrix
->PutDouble( (*itValue
)->GetValue(), nScCol
, nScRow
);
876 case EXC_CACHEDVAL_STRING
:
877 xScMatrix
->PutString(rPool
.intern((*itValue
)->GetString()), nScCol
, nScRow
);
879 case EXC_CACHEDVAL_BOOL
:
880 xScMatrix
->PutBoolean( (*itValue
)->GetBool(), nScCol
, nScRow
);
882 case EXC_CACHEDVAL_ERROR
:
883 xScMatrix
->PutError( (*itValue
)->GetScError(), nScCol
, nScRow
);
886 OSL_FAIL( "XclImpCachedMatrix::CreateScMatrix - unknown value type" );
887 xScMatrix
->PutEmpty( nScCol
, nScRow
);
896 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */