LibreOffice Module sc (master) 1
xihelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <memory>
21#include <xihelper.hxx>
22#include <svl/itemset.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>
31#include <attrib.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>
40
41// Excel->Calc cell address/range conversion ==================================
42
43namespace {
44
46void lclFillAddress( ScAddress& rScPos, sal_uInt16 nXclCol, sal_uInt32 nXclRow, SCTAB nScTab )
47{
48 rScPos.SetCol( static_cast< SCCOL >( nXclCol ) );
49 rScPos.SetRow( static_cast< SCROW >( nXclRow ) );
50 rScPos.SetTab( nScTab );
51}
52
53} // namespace
54
56 XclAddressConverterBase( rRoot.GetTracer(), rRoot.GetScMaxPos() )
57{
58}
59
60// cell address ---------------------------------------------------------------
61
62bool XclImpAddressConverter::CheckAddress( const XclAddress& rXclPos, bool bWarn )
63{
64 bool bValidCol = rXclPos.mnCol <= mnMaxCol;
65 bool bValidRow = rXclPos.mnRow <= mnMaxRow;
66 bool bValid = bValidCol && bValidRow;
67 if( !bValid && bWarn )
68 {
69 mbColTrunc |= !bValidCol;
70 mbRowTrunc |= !bValidRow;
72 static_cast< SCCOL >( rXclPos.mnCol ), static_cast< SCROW >( rXclPos.mnRow ), 0 ), maMaxPos );
73 }
74 return bValid;
75}
76
78 const XclAddress& rXclPos, SCTAB nScTab, bool bWarn )
79{
80 bool bValid = CheckAddress( rXclPos, bWarn );
81 if( bValid )
82 lclFillAddress( rScPos, rXclPos.mnCol, rXclPos.mnRow, nScTab );
83 return bValid;
84}
85
87 const XclAddress& rXclPos, SCTAB nScTab, bool bWarn )
88{
90 if( !ConvertAddress( aScPos, rXclPos, nScTab, bWarn ) )
91 {
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() ) );
95 }
96 return aScPos;
97}
98
99// cell range -----------------------------------------------------------------
100
102 const XclRange& rXclRange, SCTAB nScTab1, SCTAB nScTab2, bool bWarn )
103{
104 // check start position
105 bool bValidStart = CheckAddress( rXclRange.maFirst, bWarn );
106 if( bValidStart )
107 {
108 lclFillAddress( rScRange.aStart, rXclRange.maFirst.mnCol, rXclRange.maFirst.mnRow, nScTab1 );
109
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 ) )
114 {
115 nXclCol2 = ::std::min( nXclCol2, mnMaxCol );
116 nXclRow2 = ::std::min( nXclRow2, mnMaxRow );
117 }
118 lclFillAddress( rScRange.aEnd, nXclCol2, nXclRow2, nScTab2 );
119 }
120 return bValidStart;
121}
122
123// cell range list ------------------------------------------------------------
124
126 const XclRangeList& rXclRanges, SCTAB nScTab, bool bWarn )
127{
128 rScRanges.RemoveAll();
129 for( const auto& rXclRange : rXclRanges )
130 {
132 if( ConvertRange( aScRange, rXclRange, nScTab, nScTab, bWarn ) )
133 rScRanges.push_back( aScRange );
134 }
135}
136
137// String->EditEngine conversion ==============================================
138
139namespace {
140
141std::unique_ptr<EditTextObject> lclCreateTextObject( const XclImpRoot& rRoot,
142 const XclImpString& rString, XclFontItemType eType, sal_uInt16 nXFIndex )
143{
144 std::unique_ptr<EditTextObject> pTextObj;
145
146 const XclImpXFBuffer& rXFBuffer = rRoot.GetXFBuffer();
147 const XclImpFont* pFirstFont = rXFBuffer.GetFont( nXFIndex );
148 bool bFirstEscaped = pFirstFont && pFirstFont->HasEscapement();
149
150 if( rString.IsRich() || bFirstEscaped )
151 {
152 const XclImpFontBuffer& rFontBuffer = rRoot.GetFontBuffer();
153 const XclFormatRunVec& rFormats = rString.GetFormats();
154
156 rEE.SetTextCurrentDefaults( rString.GetText() );
157
158 SfxItemSet aItemSet( rEE.GetEmptyItemSet() );
159 if( bFirstEscaped )
160 rFontBuffer.FillToItemSet( aItemSet, eType, rXFBuffer.GetFontIndex( nXFIndex ) );
161 ESelection aSelection;
162
163 XclFormatRun aNextRun;
164 XclFormatRunVec::const_iterator aIt = rFormats.begin();
165 XclFormatRunVec::const_iterator aEnd = rFormats.end();
166
167 if( aIt != aEnd )
168 aNextRun = *aIt++;
169 else
170 aNextRun.mnChar = 0xFFFF;
171
172 sal_Int32 nLen = rString.GetText().getLength();
173 for( sal_Int32 nChar = 0; nChar < nLen; ++nChar )
174 {
175 // reached new different formatted text portion
176 if( nChar >= aNextRun.mnChar )
177 {
178 // send items to edit engine
179 rEE.QuickSetAttribs( aItemSet, aSelection );
180
181 // start new item set
182 aItemSet.ClearItem();
183 rFontBuffer.FillToItemSet( aItemSet, eType, aNextRun.mnFontIdx );
184
185 // read new formatting information
186 if( aIt != aEnd )
187 aNextRun = *aIt++;
188 else
189 aNextRun.mnChar = 0xFFFF;
190
191 // reset selection start to current position
192 aSelection.nStartPara = aSelection.nEndPara;
193 aSelection.nStartPos = aSelection.nEndPos;
194 }
195
196 // set end of selection to current position
197 if( rString.GetText()[ nChar ] == '\n' )
198 {
199 ++aSelection.nEndPara;
200 aSelection.nEndPos = 0;
201 }
202 else
203 ++aSelection.nEndPos;
204 }
205
206 // send items of last text portion to edit engine
207 rEE.QuickSetAttribs( aItemSet, aSelection );
208
209 pTextObj = rEE.CreateTextObject();
210 }
211
212 return pTextObj;
213}
214
215} // namespace
216
217std::unique_ptr<EditTextObject> XclImpStringHelper::CreateTextObject(
218 const XclImpRoot& rRoot, const XclImpString& rString )
219{
220 return lclCreateTextObject( rRoot, rString, XclFontItemType::Editeng, 0 );
221}
222
224 ScDocumentImport& rDoc, const ScAddress& rPos, const XclImpRoot& rRoot,
225 const XclImpString& rString, sal_uInt16 nXFIndex )
226{
227 if (rString.GetText().isEmpty())
228 return;
229
230 ::std::unique_ptr< EditTextObject > pTextObj( lclCreateTextObject( rRoot, rString, XclFontItemType::Editeng, nXFIndex ) );
231
232 if (pTextObj)
233 {
234 rDoc.setEditCell(rPos, std::move(pTextObj));
235 }
236 else
237 {
238 const OUString& aStr = rString.GetText();
239 if (aStr.indexOf('\n') != -1 || aStr.indexOf('\r') != -1)
240 {
241 const XclImpXFBuffer& rXFBuffer = rRoot.GetXFBuffer();
242 const XclImpXF* pXF = rXFBuffer.GetXF( nXFIndex );
243 bool bSingleLine = pXF ? !pXF->GetLineBreak() : false;
244
245 // Multiline content.
246 ScFieldEditEngine& rEngine = rDoc.getDoc().GetEditEngine();
247 rEngine.SetSingleLine(bSingleLine);
249 rDoc.setEditCell(rPos, rEngine.CreateTextObject());
250 rEngine.SetSingleLine(false);
251 }
252 else
253 {
254 // Normal text cell.
255 rDoc.setStringCell(rPos, aStr);
256 }
257 }
258}
259
260// Header/footer conversion ===================================================
261
263 mnHeight( 0 ),
264 mnMaxLineHt( 0 )
265{
268}
269
271 XclImpRoot( rRoot ),
272 mrEE( rRoot.GetHFEditEngine() ),
273 mxFontData( new XclFontData ),
275{
276}
277
279{
280}
281
282void XclImpHFConverter::ParseString( const OUString& rHFString )
283{
284 // edit engine objects
285 mrEE.SetText( OUString() );
286 maInfos.clear();
289
290 // parser temporaries
291 maCurrText.truncate();
292 OUStringBuffer aReadFont; // current font name
293 OUStringBuffer aReadStyle; // current font style
294 sal_uInt16 nReadHeight = 0; // current font height
296
298 enum XclHFParserState
299 {
300 xlPSText,
301 xlPSFunc,
302 xlPSFont,
303 xlPSFontStyle,
304 xlPSHeight
305 } eState = xlPSText;
306
307 const sal_Unicode* pChar = rHFString.getStr();
308 const sal_Unicode* pNull = pChar + rHFString.getLength(); // pointer to terminating null char
309 while( *pChar )
310 {
311 switch( eState )
312 {
313
314// --- read text character ---
315
316 case xlPSText:
317 {
318 switch( *pChar )
319 {
320 case '&': // new command
321 InsertText();
322 eState = xlPSFunc;
323 break;
324 case '\n': // line break
325 InsertText();
327 break;
328 default:
329 maCurrText.append(OUStringChar(*pChar));
330 }
331 }
332 break;
333
334// --- read control sequence ---
335
336 case xlPSFunc:
337 {
338 eState = xlPSText;
339 switch( *pChar )
340 {
341 case '&': maCurrText.append("&"); break; // the '&' character
342
343 case 'L': SetNewPortion( EXC_HF_LEFT ); break; // Left portion
344 case 'C': SetNewPortion( EXC_HF_CENTER ); break; // Center portion
345 case 'R': SetNewPortion( EXC_HF_RIGHT ); break; // Right portion
346
347 case 'P': InsertField( SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD ) ); break; // page
348 case 'N': InsertField( SvxFieldItem( SvxPagesField(), EE_FEATURE_FIELD ) ); break; // page count
349 case 'D': InsertField( SvxFieldItem( SvxDateField(), EE_FEATURE_FIELD ) ); break; // date
350 case 'T': InsertField( SvxFieldItem( SvxTimeField(), EE_FEATURE_FIELD ) ); break; // time
351 case 'A': InsertField( SvxFieldItem( SvxTableField(), EE_FEATURE_FIELD ) ); break; // table name
352
353 case 'Z': // file path
354 InsertField( SvxFieldItem( SvxExtFileField(), EE_FEATURE_FIELD ) ); // convert to full name
355 if( (pNull - pChar >= 2) && (*(pChar + 1) == '&') && (*(pChar + 2) == 'F') )
356 {
357 // &Z&F found - ignore the &F part
358 pChar += 2;
359 }
360 break;
361 case 'F': // file name
362 InsertField( SvxFieldItem( SvxExtFileField( OUString(), SvxFileType::Var, SvxFileFormat::NameAndExt ), EE_FEATURE_FIELD ) );
363 break;
364
365 case 'U': // underline
366 SetAttribs();
367 mxFontData->mnUnderline = (mxFontData->mnUnderline == EXC_FONTUNDERL_SINGLE) ?
369 break;
370 case 'E': // double underline
371 SetAttribs();
372 mxFontData->mnUnderline = (mxFontData->mnUnderline == EXC_FONTUNDERL_DOUBLE) ?
374 break;
375 case 'S': // strikeout
376 SetAttribs();
377 mxFontData->mbStrikeout = !mxFontData->mbStrikeout;
378 break;
379 case 'X': // superscript
380 SetAttribs();
381 mxFontData->mnEscapem = (mxFontData->mnEscapem == EXC_FONTESC_SUPER) ?
383 break;
384 case 'Y': // subscript
385 SetAttribs();
386 mxFontData->mnEscapem = (mxFontData->mnEscapem == EXC_FONTESC_SUB) ?
388 break;
389
390 case '\"': // font name
391 aReadFont.setLength(0);
392 aReadStyle.setLength(0);
393 eState = xlPSFont;
394 break;
395 default:
396 if( ('0' <= *pChar) && (*pChar <= '9') ) // font size
397 {
398 nReadHeight = *pChar - '0';
399 eState = xlPSHeight;
400 }
401 }
402 }
403 break;
404
405// --- read font name ---
406
407 case xlPSFont:
408 {
409 switch( *pChar )
410 {
411 case '\"':
412 --pChar;
413 [[fallthrough]];
414 case ',':
415 eState = xlPSFontStyle;
416 break;
417 default:
418 aReadFont.append(*pChar);
419 }
420 }
421 break;
422
423// --- read font style ---
424
425 case xlPSFontStyle:
426 {
427 switch( *pChar )
428 {
429 case '\"':
430 SetAttribs();
431 if( !aReadFont.isEmpty() )
432 mxFontData->maName = aReadFont.toString();
433 mxFontData->maStyle = aReadStyle.toString();
434 eState = xlPSText;
435 break;
436 default:
437 aReadStyle.append(*pChar);
438 }
439 }
440 break;
441
442// --- read font height ---
443
444 case xlPSHeight:
445 {
446 if( ('0' <= *pChar) && (*pChar <= '9') )
447 {
448 if( nReadHeight != 0xFFFF )
449 {
450 nReadHeight *= 10;
451 nReadHeight += (*pChar - '0');
452 if( nReadHeight > 1600 ) // max 1600pt = 32000twips
453 nReadHeight = 0xFFFF;
454 }
455 }
456 else
457 {
458 if( (nReadHeight != 0) && (nReadHeight != 0xFFFF) )
459 {
460 SetAttribs();
461 mxFontData->mnHeight = nReadHeight * 20;
462 }
463 --pChar;
464 eState = xlPSText;
465 }
466 }
467 break;
468 }
469 ++pChar;
470 }
471
472 // finalize
477}
478
479void XclImpHFConverter::FillToItemSet( SfxItemSet& rItemSet, sal_uInt16 nWhichId ) const
480{
481 ScPageHFItem aHFItem( nWhichId );
482 if( maInfos[ EXC_HF_LEFT ].mxObj )
483 aHFItem.SetLeftArea( *maInfos[ EXC_HF_LEFT ].mxObj );
484 if( maInfos[ EXC_HF_CENTER ].mxObj )
485 aHFItem.SetCenterArea( *maInfos[ EXC_HF_CENTER ].mxObj );
486 if( maInfos[ EXC_HF_RIGHT ].mxObj )
487 aHFItem.SetRightArea( *maInfos[ EXC_HF_RIGHT ].mxObj );
488 rItemSet.Put( aHFItem );
489}
490
492{
493 return ::std::max( maInfos[ EXC_HF_LEFT ].mnHeight,
495}
496
497// private --------------------------------------------------------------------
498
500{
501 sal_uInt16 nMaxHt = maInfos[ ePortion ].mnMaxLineHt;
502 return (nMaxHt == 0) ? mxFontData->mnHeight : nMaxHt;
503}
504
506{
507 sal_uInt16& rnMaxHt = maInfos[ ePortion ].mnMaxLineHt;
508 rnMaxHt = ::std::max( rnMaxHt, mxFontData->mnHeight );
509}
510
512{
514}
515
517{
518 ESelection& rSel = GetCurrSel();
519 if( (rSel.nStartPara != rSel.nEndPara) || (rSel.nStartPos != rSel.nEndPos) )
520 {
521 SfxItemSet aItemSet( mrEE.GetEmptyItemSet() );
522 XclImpFont aFont( GetRoot(), *mxFontData );
524 mrEE.QuickSetAttribs( aItemSet, rSel );
525 rSel.nStartPara = rSel.nEndPara;
526 rSel.nStartPos = rSel.nEndPos;
527 }
528}
529
531{
532 if( const XclImpFont* pFirstFont = GetFontBuffer().GetFont( EXC_FONT_APP ) )
533 *mxFontData = pFirstFont->GetFontData();
534 else
535 {
536 mxFontData->Clear();
537 mxFontData->mnHeight = 200;
538 }
539}
540
542{
543 if( !maCurrText.isEmpty() )
544 {
545 ESelection& rSel = GetCurrSel();
546 OUString sString(maCurrText.makeStringAndClear());
547 mrEE.QuickInsertText( sString, ESelection( rSel.nEndPara, rSel.nEndPos, rSel.nEndPara, rSel.nEndPos ) );
548 rSel.nEndPos = rSel.nEndPos + sString.getLength();
550 }
551}
552
554{
555 ESelection& rSel = GetCurrSel();
556 mrEE.QuickInsertField( rFieldItem, ESelection( rSel.nEndPara, rSel.nEndPos, rSel.nEndPara, rSel.nEndPos ) );
557 ++rSel.nEndPos;
559}
560
562{
563 ESelection& rSel = GetCurrSel();
564 mrEE.QuickInsertText( OUString('\n'), ESelection( rSel.nEndPara, rSel.nEndPos, rSel.nEndPara, rSel.nEndPos ) );
565 ++rSel.nEndPara;
566 rSel.nEndPos = 0;
569}
570
572{
573 InsertText();
574 SetAttribs();
576}
577
579{
580 if( eNew != meCurrObj )
581 {
583 meCurrObj = eNew;
584 if( GetCurrObj() )
585 mrEE.SetText( *GetCurrObj() );
586 else
587 mrEE.SetText( OUString() );
589 }
590}
591
592// URL conversion =============================================================
593
594namespace {
595
596void lclAppendUrlChar( OUString& rUrl, sal_Unicode cChar )
597{
598 // encode special characters
599 switch( cChar )
600 {
601 case '#': rUrl += "%23"; break;
602 case '%': rUrl += "%25"; break;
603 default: rUrl += OUStringChar( cChar );
604 }
605}
606
607} // namespace
608
610 OUString& rUrl, OUString& rTabName, bool& rbSameWb,
611 const XclImpRoot& rRoot, const OUString& rEncodedUrl )
612{
613 enum
614 {
615 xlUrlInit,
616 xlUrlPath,
617 xlUrlFileName,
618 xlUrlSheetName,
619 xlUrlRaw
620 } eState = xlUrlInit;
621
622 bool bEncoded = true;
623 rbSameWb = false;
624
625 sal_Unicode cCurrDrive = 0;
626 OUString aDosBase( INetURLObject( rRoot.GetBasePath() ).getFSysPath( FSysStyle::Dos ) );
627 if (!aDosBase.isEmpty() && aDosBase.match(":\\", 1))
628 cCurrDrive = aDosBase[0];
629
630 const sal_Unicode* pChar = rEncodedUrl.getStr();
631 while( *pChar )
632 {
633 switch( eState )
634 {
635
636// --- first character ---
637
638 case xlUrlInit:
639 {
640 switch( *pChar )
641 {
643 eState = xlUrlPath;
644 break;
647 rbSameWb = true;
648 eState = xlUrlSheetName;
649 break;
650 case '[':
651 bEncoded = false;
652 eState = xlUrlFileName;
653 break;
654 default:
655 bEncoded = false;
656 lclAppendUrlChar( rUrl, *pChar );
657 eState = xlUrlPath;
658 }
659 }
660 break;
661
662// --- URL path ---
663
664 case xlUrlPath:
665 {
666 switch( *pChar )
667 {
668 case EXC_URL_DOSDRIVE:
669 {
670 if( *(pChar + 1) )
671 {
672 ++pChar;
673 if( *pChar == '@' )
674 rUrl += "\\\\";
675 else
676 {
677 lclAppendUrlChar( rUrl, *pChar );
678 rUrl += ":\\";
679 }
680 }
681 else
682 rUrl += "<NULL-DRIVE!>";
683 }
684 break;
686 if( cCurrDrive )
687 {
688 lclAppendUrlChar( rUrl, cCurrDrive );
689 rUrl += ":";
690 }
691 [[fallthrough]];
692 case EXC_URL_SUBDIR:
693 if( bEncoded )
694 rUrl += "\\";
695 else // control character in raw name -> DDE link
696 {
697 rUrl += OUStringChar(EXC_DDE_DELIM);
698 eState = xlUrlRaw;
699 }
700 break;
702 rUrl += "..\\";
703 break;
704 case EXC_URL_RAW:
705 {
706 if( *(pChar + 1) )
707 {
708 sal_Int32 nLen = *++pChar;
709 for( sal_Int32 nChar = 0; (nChar < nLen) && *(pChar + 1); ++nChar )
710 lclAppendUrlChar( rUrl, *++pChar );
711// rUrl.Append( ':' );
712 }
713 }
714 break;
715 case '[':
716 eState = xlUrlFileName;
717 break;
718 default:
719 lclAppendUrlChar( rUrl, *pChar );
720 }
721 }
722 break;
723
724// --- file name ---
725
726 case xlUrlFileName:
727 {
728 switch( *pChar )
729 {
730 case ']': eState = xlUrlSheetName; break;
731 default: lclAppendUrlChar( rUrl, *pChar );
732 }
733 }
734 break;
735
736// --- sheet name ---
737
738 case xlUrlSheetName:
739 rTabName += OUStringChar( *pChar );
740 break;
741
742// --- raw read mode ---
743
744 case xlUrlRaw:
745 lclAppendUrlChar( rUrl, *pChar );
746 break;
747 }
748
749 ++pChar;
750 }
751}
752
754 OUString& rUrl, bool& rbSameWb, const XclImpRoot& rRoot, const OUString& rEncodedUrl )
755{
756 OUString aTabName;
757 OUString aUrl;
758 DecodeUrl( aUrl, aTabName, rbSameWb, rRoot, rEncodedUrl );
759 rUrl = aUrl;
760 OSL_ENSURE( aTabName.isEmpty(), "XclImpUrlHelper::DecodeUrl - sheet name ignored" );
761}
762
763bool XclImpUrlHelper::DecodeLink( OUString& rApplic, OUString& rTopic, std::u16string_view aEncUrl )
764{
765 size_t nPos = aEncUrl.find( EXC_DDE_DELIM );
766 if( nPos != std::u16string_view::npos && (nPos > 0) && (nPos + 1 < aEncUrl.size()) )
767 {
768 rApplic = aEncUrl.substr( 0, nPos );
769 rTopic = aEncUrl.substr( nPos + 1 );
770 return true;
771 }
772 return false;
773}
774
775// Cached Values ==============================================================
776
778 mfValue( 0.0 ),
779 mnBoolErr( 0 )
780{
781 mnType = rStrm.ReaduInt8();
782 switch( mnType )
783 {
785 rStrm.Ignore( 8 );
786 break;
789 break;
791 maStr = rStrm.ReadUniString();
792 break;
795 {
796 double fVal;
797 mnBoolErr = rStrm.ReaduInt8();
798 rStrm.Ignore( 7 );
799
800 std::unique_ptr<ScTokenArray> pScTokArr = rStrm.GetRoot().GetOldFmlaConverter().GetBoolErr(
802 if( pScTokArr )
803 mxTokArr = std::move( pScTokArr );
804 }
805 break;
806 default:
807 OSL_FAIL( "XclImpCachedValue::XclImpCachedValue - unknown data type" );
808 }
809}
810
812{
813}
814
816{
817 return (mnType == EXC_CACHEDVAL_ERROR) ? XclTools::GetScErrorCode( mnBoolErr ) : FormulaError::NONE;
818}
819
820// Matrix Cached Values ==============================================================
821
823 mnScCols( 0 ),
824 mnScRows( 0 )
825{
826 mnScCols = rStrm.ReaduInt8();
827 mnScRows = rStrm.ReaduInt16();
828
829 if( rStrm.GetRoot().GetBiff() <= EXC_BIFF5 )
830 {
831 // in BIFF2-BIFF7: 256 columns represented by 0 columns
832 if( mnScCols == 0 )
833 mnScCols = 256;
834 }
835 else
836 {
837 // in BIFF8: columns and rows decreased by 1
838 ++mnScCols;
839 ++mnScRows;
840 }
841
842 //assuming worst case scenario of unknown types
843 const size_t nMinRecordSize = 1;
844 const size_t nMaxRows = rStrm.GetRecLeft() / (nMinRecordSize * mnScCols);
845 if (mnScRows > nMaxRows)
846 {
847 SAL_WARN("sc", "Parsing error: " << nMaxRows <<
848 " max possible rows, but " << mnScRows << " claimed, truncating");
849 mnScRows = nMaxRows;
850 }
851
852 for( SCSIZE nScRow = 0; nScRow < mnScRows; ++nScRow )
853 for( SCSIZE nScCol = 0; nScCol < mnScCols; ++nScCol )
854 maValueList.push_back( std::make_unique<XclImpCachedValue>( rStrm ) );
855}
856
858{
859}
860
862{
863 ScMatrixRef xScMatrix;
864 OSL_ENSURE( mnScCols * mnScRows == maValueList.size(), "XclImpCachedMatrix::CreateScMatrix - element count mismatch" );
865 if( mnScCols && mnScRows && static_cast< sal_uLong >( mnScCols * mnScRows ) <= maValueList.size() )
866 {
867 xScMatrix = new ScMatrix(mnScCols, mnScRows, 0.0);
868 XclImpValueList::const_iterator itValue = maValueList.begin();
869 for( SCSIZE nScRow = 0; nScRow < mnScRows; ++nScRow )
870 {
871 for( SCSIZE nScCol = 0; nScCol < mnScCols; ++nScCol )
872 {
873 switch( (*itValue)->GetType() )
874 {
876 // Excel shows 0.0 here, not an empty cell
877 xScMatrix->PutEmpty( nScCol, nScRow );
878 break;
880 xScMatrix->PutDouble( (*itValue)->GetValue(), nScCol, nScRow );
881 break;
883 xScMatrix->PutString(rPool.intern((*itValue)->GetString()), nScCol, nScRow);
884 break;
886 xScMatrix->PutBoolean( (*itValue)->GetBool(), nScCol, nScRow );
887 break;
889 xScMatrix->PutError( (*itValue)->GetScError(), nScCol, nScRow );
890 break;
891 default:
892 OSL_FAIL( "XclImpCachedMatrix::CreateScMatrix - unknown value type" );
893 xScMatrix->PutEmpty( nScCol, nScRow );
894 }
895 ++itValue;
896 }
897 }
898 }
899 return xScMatrix;
900}
901
902/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 ...
Definition: address.hxx:44
std::unique_ptr< EditTextObject > CreateTextObject()
void SetText(const OUString &rStr)
void SetSingleLine(bool bValue)
void QuickInsertField(const SvxFieldItem &rFld, const ESelection &rSel)
const SfxItemSet & GetEmptyItemSet() const
void QuickSetAttribs(const SfxItemSet &rSet, const ESelection &rSel)
void QuickInsertText(const OUString &rText, const ESelection &rSel)
OUString getFSysPath(FSysStyle eStyle, sal_Unicode *pDelimiter=nullptr) const
@ UNINITIALIZED
Definition: address.hxx:220
SCTAB Tab() const
Definition: address.hxx:283
void SetCol(SCCOL nColP)
Definition: address.hxx:291
void SetRow(SCROW nRowP)
Definition: address.hxx:287
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
Accessor class to ScDocument.
void setEditCell(const ScAddress &rPos, std::unique_ptr< EditTextObject > pEditText)
void setStringCell(const ScAddress &rPos, const OUString &rStr)
ScDocument & getDoc()
SC_DLLPUBLIC ScFieldEditEngine & GetEditEngine()
Definition: documen2.cxx:483
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:619
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:101
void SetLeftArea(const EditTextObject &rNew)
Definition: attrib.cxx:494
void SetCenterArea(const EditTextObject &rNew)
Definition: attrib.cxx:499
void SetRightArea(const EditTextObject &rNew)
Definition: attrib.cxx:504
void RemoveAll()
Definition: rangelst.cxx:1101
void push_back(const ScRange &rRange)
Definition: rangelst.cxx:1137
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SvStream & ReadDouble(double &rDouble)
Base class for import/export address converters.
Definition: xladdress.hxx:140
sal_uInt32 mnMaxRow
Maximum column index, as 16-bit value.
Definition: xladdress.hxx:163
sal_uInt16 mnMaxCol
Default maximum position.
Definition: xladdress.hxx:162
ScAddress maMaxPos
Tracer for invalid addresses.
Definition: xladdress.hxx:161
bool mbColTrunc
Maximum row index.
Definition: xladdress.hxx:164
bool mbRowTrunc
Flag for "columns truncated" warning box.
Definition: xladdress.hxx:165
bool ConvertRange(ScRange &rScRange, const XclRange &rXclRange, SCTAB nScTab1, SCTAB nScTab2, bool bWarn)
Converts the passed Excel cell range to a Calc cell range.
Definition: xihelper.cxx:101
void ConvertRangeList(ScRangeList &rScRanges, const XclRangeList &rXclRanges, SCTAB nScTab, bool bWarn)
Converts the passed Excel cell range list to a Calc cell range list.
Definition: xihelper.cxx:125
bool CheckAddress(const XclAddress &rXclPos, bool bWarn)
Checks if the passed Excel cell address is valid.
Definition: xihelper.cxx:62
XclImpAddressConverter(const XclImpRoot &rRoot)
Definition: xihelper.cxx:55
bool ConvertAddress(ScAddress &rScPos, const XclAddress &rXclPos, SCTAB nScTab, bool bWarn)
Converts the passed Excel cell address to a Calc cell address.
Definition: xihelper.cxx:77
ScAddress CreateValidAddress(const XclAddress &rXclPos, SCTAB nScTab, bool bWarn)
Returns a valid cell address by moving it into allowed dimensions.
Definition: xihelper.cxx:86
SCSIZE mnScRows
Number of cached columns.
Definition: xihelper.hxx:347
SCSIZE mnScCols
List of cached cell values.
Definition: xihelper.hxx:346
XclImpCachedMatrix(XclImpStream &rStrm)
Definition: xihelper.cxx:822
XclImpValueList maValueList
Definition: xihelper.hxx:345
ScMatrixRef CreateScMatrix(svl::SharedStringPool &rPool) const
Creates a new ScMatrix object and fills it with the contained values.
Definition: xihelper.cxx:861
XclImpCachedValue(const XclImpCachedValue &)=delete
delete copy constructor
sal_uInt8 mnType
Boolean value or Excel error code.
Definition: xihelper.hxx:329
sal_uInt8 mnBoolErr
Cached value is a formula or error code or Boolean.
Definition: xihelper.hxx:328
ScTokenArrayPtr mxTokArr
Cached value is a double.
Definition: xihelper.hxx:327
double mfValue
Cached value is a string.
Definition: xihelper.hxx:326
FormulaError GetScError() const
Returns the cached Calc error code, if this value has Error type, else 0.
Definition: xihelper.cxx:815
virtual ~XclImpCachedValue()
Definition: xihelper.cxx:811
Stores the data of all fonts occurred in an Excel file.
Definition: xistyle.hxx:153
void FillToItemSet(SfxItemSet &rItemSet, XclFontItemType eType, sal_uInt16 nFontIdx, bool bSkipPoolDefs=false) const
Fills all font properties from a FONT record to the item set.
Definition: xistyle.cxx:596
Stores all data of an Excel font and provides import of FONT records.
Definition: xistyle.hxx:71
const XclFontData & GetFontData() const
Returns read-only access to font data.
Definition: xistyle.hxx:86
bool HasEscapement() const
Returns true, if the font contains superscript or subscript.
Definition: xistyle.hxx:90
void FillToItemSet(SfxItemSet &rItemSet, XclFontItemType eType, bool bSkipPoolDefs=false) const
Fills all font properties to the item set.
Definition: xistyle.cxx:317
void ParseString(const OUString &rHFString)
Parses the passed string and creates three new edit engine text objects.
Definition: xihelper.cxx:282
void InsertLineBreak()
Inserts a line break and adjusts the current selection object.
Definition: xihelper.cxx:561
void FillToItemSet(SfxItemSet &rItemSet, sal_uInt16 nWhichId) const
Creates a ScPageHFItem and inserts it into the passed item set.
Definition: xihelper.cxx:479
XclImpHFConverter(const XclImpHFConverter &)=delete
delete copy constructor
sal_uInt16 GetMaxLineHeight(XclImpHFPortion ePortion) const
Returns the maximum line height of the specified portion.
Definition: xihelper.cxx:499
void InsertField(const SvxFieldItem &rFieldItem)
Inserts the passed text field and adjusts the current selection object.
Definition: xihelper.cxx:553
std::vector< XclImpHFPortionInfo > maInfos
The header/footer edit engine.
Definition: xihelper.hxx:240
XclImpHFPortion meCurrObj
Font data of current text.
Definition: xihelper.hxx:243
void ResetFontData()
Resets font data to application default font.
Definition: xihelper.cxx:530
ESelection & GetCurrSel()
Returns the current selection.
Definition: xihelper.hxx:205
EditEngine & mrEE
Definition: xihelper.hxx:238
void SetAttribs()
Sets the font attributes at the current selection.
Definition: xihelper.cxx:516
XclFontDataPtr mxFontData
Current text to insert into edit engine.
Definition: xihelper.hxx:242
void InsertText()
Inserts maCurrText into edit engine and adjusts the current selection object.
Definition: xihelper.cxx:541
void CreateCurrObject()
Creates the edit engine text object of current portion from edit engine.
Definition: xihelper.cxx:571
XclImpHFPortion
Enumerates the supported header/footer portions.
Definition: xihelper.hxx:186
sal_Int32 GetTotalHeight() const
Returns the total height of the converted header or footer in twips.
Definition: xihelper.cxx:491
XclImpHFPortionInfo::EditTextObjectRef & GetCurrObj()
Returns the current edit engine text object.
Definition: xihelper.hxx:203
void UpdateCurrMaxLineHeight()
Updates the current maximum line height, using the current font size.
Definition: xihelper.cxx:511
void UpdateMaxLineHeight(XclImpHFPortion ePortion)
Updates the maximum line height of the specified portion, using the current font size.
Definition: xihelper.cxx:505
virtual ~XclImpHFConverter() override
Definition: xihelper.cxx:278
void SetNewPortion(XclImpHFPortion eNew)
Changes current header/footer portion to eNew.
Definition: xihelper.cxx:578
OUStringBuffer maCurrText
Edit engine text objects for all portions.
Definition: xihelper.hxx:241
XclImpHFPortionInfo & GetCurrInfo()
Returns the current edit engine text object.
Definition: xihelper.hxx:201
Access to global data from other classes.
Definition: xiroot.hxx:129
XclImpXFBuffer & GetXFBuffer() const
Returns the cell formatting attributes buffer.
Definition: xiroot.cxx:160
XclImpFontBuffer & GetFontBuffer() const
Returns the font buffer.
Definition: xiroot.cxx:150
const XclImpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
Definition: xiroot.hxx:134
This class is used to import record oriented streams.
Definition: xistream.hxx:278
static std::unique_ptr< EditTextObject > CreateTextObject(const XclImpRoot &rRoot, const XclImpString &rString)
Returns a new edit engine text object.
Definition: xihelper.cxx:217
static void SetToDocument(ScDocumentImport &rDoc, const ScAddress &rPos, const XclImpRoot &rRoot, const XclImpString &rString, sal_uInt16 nXFIndex)
Definition: xihelper.cxx:223
This class represents an unformatted or formatted string and provides importing from stream.
Definition: xistring.hxx:31
bool IsRich() const
Returns true, if the string contains formatting information.
Definition: xistring.hxx:56
const XclFormatRunVec & GetFormats() const
Returns the formatting run vector.
Definition: xistring.hxx:58
const OUString & GetText() const
Returns the pure text data of the string.
Definition: xistring.hxx:53
static void DecodeUrl(OUString &rUrl, OUString &rTabName, bool &rbSameWb, const XclImpRoot &rRoot, const OUString &rEncodedUrl)
Decodes an encoded external document URL with optional sheet name.
Definition: xihelper.cxx:609
static bool DecodeLink(OUString &rApplic, OUString &rTopic, std::u16string_view aEncUrl)
Decodes the passed URL to OLE or DDE link components.
Definition: xihelper.cxx:763
Contains all XF records occurred in the file.
Definition: xistyle.hxx:479
sal_uInt16 GetFontIndex(sal_uInt16 nXFIndex) const
Returns the index to the Excel font used in the specified XF record.
Definition: xistyle.cxx:1591
XclImpXF * GetXF(sal_uInt16 nXFIndex)
Returns the object that stores all contents of an XF record.
Definition: xistyle.hxx:496
const XclImpFont * GetFont(sal_uInt16 nXFIndex) const
Returns the Excel font used in the specified XF record.
Definition: xistyle.cxx:1597
Contains all data of a XF record and a Calc item set.
Definition: xistyle.hxx:378
bool GetLineBreak() const
Definition: xistyle.hxx:390
A 2D cell range address list with Excel column and row indexes.
Definition: xladdress.hxx:102
ScHeaderEditEngine & GetHFEditEngine() const
Returns the edit engine for import/export of headers/footers.
Definition: xlroot.cxx:380
const OUString & GetBasePath() const
Returns the base path of the imported/exported file.
Definition: xlroot.hxx:174
ScEditEngineDefaulter & GetEditEngine() const
Returns the edit engine for import/export of rich strings etc.
Definition: xlroot.cxx:365
static XclBoolError ErrorToEnum(double &rfDblValue, bool bErrOrBool, sal_uInt8 nValue)
Gets a translated error code or Boolean value from Excel error codes.
Definition: xltools.cxx:247
static FormulaError GetScErrorCode(sal_uInt8 nXclError)
Converts an Excel error code to a Calc error code.
Definition: xltools.cxx:226
void TraceInvalidAddress(const ScAddress &rPos, const ScAddress &rMaxPos)
Definition: xltracer.cxx:41
SharedString intern(const OUString &rStr)
constexpr TypedWhichId< SvxFieldItem > EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
FormulaError
sal_uInt16 nPos
#define SAL_WARN(area, stream)
aStr
void SvStream & rStrm
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
double mnHeight
sal_uIntPtr sal_uLong
sal_Int32 nStartPara
sal_Int32 nEndPos
sal_Int32 nStartPos
sal_Int32 nEndPara
A 2D cell address struct with Excel column and row indexes.
Definition: xladdress.hxx:30
sal_uInt16 mnCol
Definition: xladdress.hxx:31
sal_uInt32 mnRow
Definition: xladdress.hxx:32
This struct helps reading and writing Excel fonts.
Definition: xlstyle.hxx:285
NUL character (unicode).
Definition: xlstring.hxx:65
sal_uInt16 mnChar
Definition: xlstring.hxx:66
sal_uInt16 mnFontIdx
First character this format applies to.
Definition: xlstring.hxx:67
XclImpHFPortionInfo()
Maximum font height for the current text line.
Definition: xihelper.cxx:262
sal_uInt16 mnMaxLineHt
Height of previous lines in twips.
Definition: xihelper.hxx:195
sal_Int32 mnHeight
Edit engine selection.
Definition: xihelper.hxx:194
ESelection maSel
Edit engine text object.
Definition: xihelper.hxx:193
A 2D cell range address struct with Excel column and row indexes.
Definition: xladdress.hxx:59
XclAddress maFirst
Definition: xladdress.hxx:60
XclAddress maLast
Definition: xladdress.hxx:61
sal_uInt16 sal_Unicode
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:25
sal_Int32 SCROW
Definition: types.hxx:17
const sal_Unicode EXC_URL_DRIVEROOT
DOS drive letter or UNC server name.
Definition: xlconst.hxx:94
const sal_Unicode EXC_URLSTART_SELFENCODED
Reference to own workbook.
Definition: xlconst.hxx:90
const sal_Unicode EXC_URL_RAW
Parent directory.
Definition: xlconst.hxx:97
const sal_uInt8 EXC_CACHEDVAL_ERROR
Definition: xlconst.hxx:118
const sal_Unicode EXC_URLSTART_ENCODED
Definition: xlconst.hxx:88
const sal_uInt8 EXC_CACHEDVAL_STRING
Definition: xlconst.hxx:116
const sal_Unicode EXC_URLSTART_SELF
Encoded URL.
Definition: xlconst.hxx:89
const sal_Unicode EXC_URL_DOSDRIVE
Reference to own workbook (BIFF5/BIFF7).
Definition: xlconst.hxx:93
@ EXC_BIFF5
MS Excel 4.0.
Definition: xlconst.hxx:34
const sal_uInt8 EXC_CACHEDVAL_EMPTY
Definition: xlconst.hxx:114
const sal_uInt8 EXC_CACHEDVAL_BOOL
Definition: xlconst.hxx:117
const sal_Unicode EXC_URL_SUBDIR
Root directory of current drive.
Definition: xlconst.hxx:95
const sal_Unicode EXC_URL_PARENTDIR
Directory name delimiter.
Definition: xlconst.hxx:96
const sal_uInt8 EXC_CACHEDVAL_DOUBLE
Definition: xlconst.hxx:115
const sal_Unicode EXC_DDE_DELIM
Sheet name starts here (BIFF4).
Definition: xlconst.hxx:100
::std::vector< XclFormatRun > XclFormatRunVec
A vector with all formatting runs for a rich-string.
Definition: xlstring.hxx:85
const sal_uInt16 EXC_FONT_APP
Definition: xlstyle.hxx:77
XclFontItemType
Enumerates different types of Which-IDs for font items.
Definition: xlstyle.hxx:388
@ HeaderFooter
Use edit engine Which-IDs (EE_CHAR_*).
@ Editeng
Use Calc Which-IDs (ATTR_*).
const sal_uInt16 EXC_FONTESC_SUPER
Definition: xlstyle.hxx:127
const sal_uInt8 EXC_FONTUNDERL_SINGLE
Definition: xlstyle.hxx:120
const sal_uInt8 EXC_FONTUNDERL_DOUBLE
Definition: xlstyle.hxx:121
const sal_uInt16 EXC_FONTESC_NONE
Definition: xlstyle.hxx:126
const sal_uInt8 EXC_FONTUNDERL_NONE
Definition: xlstyle.hxx:119
const sal_uInt16 EXC_FONTESC_SUB
Definition: xlstyle.hxx:128
const char * pChar