LibreOffice Module sc (master) 1
xehelper.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 <sal/config.h>
21
22#include <string_view>
23
24#include <com/sun/star/i18n/XBreakIterator.hpp>
25#include <com/sun/star/i18n/ScriptType.hpp>
26#include <com/sun/star/uri/XUriReference.hpp>
27#include <com/sun/star/uri/XUriReferenceFactory.hpp>
28#include <com/sun/star/uri/UriReferenceFactory.hpp>
30#include <o3tl/string_view.hxx>
31#include <sfx2/objsh.hxx>
32#include <vcl/font.hxx>
33#include <tools/urlobj.hxx>
34#include <svl/itemset.hxx>
35#include <svtools/ctrltool.hxx>
36#include <svx/svdotext.hxx>
37#include <editeng/outlobj.hxx>
38#include <scitems.hxx>
39#include <editeng/fhgtitem.hxx>
40#include <editeng/flstitem.hxx>
41#include <editeng/colritem.hxx>
42#include <editeng/eeitem.hxx>
43#include <editeng/flditem.hxx>
45#include <editeng/svxfont.hxx>
46#include <editeng/editids.hrc>
47#include <osl/file.hxx>
48
49#include <document.hxx>
50#include <docpool.hxx>
51#include <editutil.hxx>
52#include <patattr.hxx>
53#include <scmatrix.hxx>
54#include <xestyle.hxx>
55#include <fprogressbar.hxx>
56#include <globstr.hrc>
57#include <xltracer.hxx>
58#include <xltools.hxx>
59#include <xecontent.hxx>
60#include <xelink.hxx>
61#include <xehelper.hxx>
62
63using ::com::sun::star::uno::Reference;
64using ::com::sun::star::i18n::XBreakIterator;
65
66// Export progress bar ========================================================
67
69 XclExpRoot( rRoot ),
70 mxProgress( new ScfProgressBar( rRoot.GetDocShell(), STR_SAVE_DOC ) ),
71 mpSubProgress( nullptr ),
72 mpSubRowCreate( nullptr ),
73 mpSubRowFinal( nullptr ),
74 mnSegRowFinal( SCF_INV_SEGMENT ),
75 mnRowCount( 0 )
76{
77}
78
80{
81}
82
84{
85 const ScDocument& rDoc = GetDoc();
86 const XclExpTabInfo& rTabInfo = GetTabInfo();
87 SCTAB nScTabCount = rTabInfo.GetScTabCount();
88
89 // *** segment: creation of ROW records *** -------------------------------
90
91 sal_Int32 nSegRowCreate = mxProgress->AddSegment( 2000 );
92 mpSubRowCreate = &mxProgress->GetSegmentProgressBar( nSegRowCreate );
93 maSubSegRowCreate.resize( nScTabCount, SCF_INV_SEGMENT );
94
95 for( SCTAB nScTab = 0; nScTab < nScTabCount; ++nScTab )
96 {
97 if( rTabInfo.IsExportTab( nScTab ) )
98 {
99 SCCOL nLastUsedScCol;
100 SCROW nLastUsedScRow;
101 rDoc.GetTableArea( nScTab, nLastUsedScCol, nLastUsedScRow );
102 std::size_t nSegSize = static_cast< std::size_t >( nLastUsedScRow + 1 );
103 maSubSegRowCreate[ nScTab ] = mpSubRowCreate->AddSegment( nSegSize );
104 }
105 }
106
107 // *** segment: writing all ROW records *** -------------------------------
108
109 mnSegRowFinal = mxProgress->AddSegment( 1000 );
110 // sub progress bar and segment are created later in ActivateFinalRowsSegment()
111}
112
114{
115 ++mnRowCount;
116}
117
119{
120 OSL_ENSURE( (0 <= GetCurrScTab()) && (GetCurrScTab() < GetTabInfo().GetScTabCount()),
121 "XclExpProgressBar::ActivateCreateRowsSegment - invalid sheet" );
122 sal_Int32 nSeg = maSubSegRowCreate[ GetCurrScTab() ];
123 OSL_ENSURE( nSeg != SCF_INV_SEGMENT, "XclExpProgressBar::ActivateCreateRowsSegment - invalid segment" );
124 if( nSeg != SCF_INV_SEGMENT )
125 {
128 }
129 else
130 mpSubProgress = nullptr;
131}
132
134{
135 if( !mpSubRowFinal && (mnRowCount > 0) )
136 {
137 mpSubRowFinal = &mxProgress->GetSegmentProgressBar( mnSegRowFinal );
139 }
141 if( mpSubProgress )
143}
144
146{
149}
150
151// Calc->Excel cell address/range conversion ==================================
152
153namespace {
154
156void lclFillAddress( XclAddress& rXclPos, SCCOL nScCol, SCROW nScRow )
157{
158 rXclPos.mnCol = static_cast< sal_uInt16 >( nScCol );
159 rXclPos.mnRow = static_cast< sal_uInt32 >( nScRow );
160}
161
162} // namespace
163
165 XclAddressConverterBase( rRoot.GetTracer(), rRoot.GetXclMaxPos() )
166{
167}
168
169// cell address ---------------------------------------------------------------
170
171bool XclExpAddressConverter::CheckAddress( const ScAddress& rScPos, bool bWarn )
172{
173 // ScAddress::operator<=() doesn't do what we want here
174 bool bValidCol = (0 <= rScPos.Col()) && (rScPos.Col() <= maMaxPos.Col());
175 bool bValidRow = (0 <= rScPos.Row()) && (rScPos.Row() <= maMaxPos.Row());
176 bool bValidTab = (0 <= rScPos.Tab()) && (rScPos.Tab() <= maMaxPos.Tab());
177
178 bool bValid = bValidCol && bValidRow && bValidTab;
179 if( !bValid )
180 {
181 mbColTrunc |= !bValidCol;
182 mbRowTrunc |= !bValidRow;
183 }
184 if( !bValid && bWarn )
185 {
186 mbTabTrunc |= (rScPos.Tab() > maMaxPos.Tab()); // do not warn for deleted refs
188 }
189 return bValid;
190}
191
193 const ScAddress& rScPos, bool bWarn )
194{
195 bool bValid = CheckAddress( rScPos, bWarn );
196 if( bValid )
197 lclFillAddress( rXclPos, rScPos.Col(), rScPos.Row() );
198 return bValid;
199}
200
202{
204 if( !ConvertAddress( aXclPos, rScPos, bWarn ) )
205 lclFillAddress( aXclPos, ::std::min( rScPos.Col(), maMaxPos.Col() ), ::std::min( rScPos.Row(), maMaxPos.Row() ) );
206 return aXclPos;
207}
208
209// cell range -----------------------------------------------------------------
210
211bool XclExpAddressConverter::CheckRange( const ScRange& rScRange, bool bWarn )
212{
213 return CheckAddress( rScRange.aStart, bWarn ) && CheckAddress( rScRange.aEnd, bWarn );
214}
215
217{
218 rScRange.PutInOrder();
219
220 // check start position
221 bool bValidStart = CheckAddress( rScRange.aStart, bWarn );
222 if( bValidStart )
223 {
224 // check & correct end position
225 ScAddress& rScEnd = rScRange.aEnd;
226 if( !CheckAddress( rScEnd, bWarn ) )
227 {
228 rScEnd.SetCol( ::std::min( rScEnd.Col(), maMaxPos.Col() ) );
229 rScEnd.SetRow( ::std::min( rScEnd.Row(), maMaxPos.Row() ) );
230 rScEnd.SetTab( ::std::min( rScEnd.Tab(), maMaxPos.Tab() ) );
231 }
232 }
233
234 return bValidStart;
235}
236
238 const ScRange& rScRange, bool bWarn )
239{
240 // check start position
241 bool bValidStart = CheckAddress( rScRange.aStart, bWarn );
242 if( bValidStart )
243 {
244 lclFillAddress( rXclRange.maFirst, rScRange.aStart.Col(), rScRange.aStart.Row() );
245
246 // check & correct end position
247 SCCOL nScCol2 = rScRange.aEnd.Col();
248 SCROW nScRow2 = rScRange.aEnd.Row();
249 if( !CheckAddress( rScRange.aEnd, bWarn ) )
250 {
251 nScCol2 = ::std::min( nScCol2, maMaxPos.Col() );
252 nScRow2 = ::std::min( nScRow2, maMaxPos.Row() );
253 }
254 lclFillAddress( rXclRange.maLast, nScCol2, nScRow2 );
255 }
256 return bValidStart;
257}
258
259// cell range list ------------------------------------------------------------
260
262{
263 for ( size_t nRange = rScRanges.size(); nRange > 0; )
264 {
265 ScRange & rScRange = rScRanges[ --nRange ];
266 if( !CheckRange( rScRange, bWarn ) )
267 rScRanges.Remove(nRange);
268 }
269}
270
272 const ScRangeList& rScRanges, bool bWarn )
273{
274 rXclRanges.clear();
275 for( size_t nPos = 0, nCount = rScRanges.size(); nPos < nCount; ++nPos )
276 {
277 const ScRange & rScRange = rScRanges[ nPos ];
279 if( ConvertRange( aXclRange, rScRange, bWarn ) )
280 rXclRanges.push_back( aXclRange );
281 }
282}
283
284// EditEngine->String conversion ==============================================
285
286namespace {
287
288OUString lclGetUrlRepresentation( const SvxURLField& rUrlField )
289{
290 const OUString& aRepr = rUrlField.GetRepresentation();
291 // no representation -> use URL
292 return aRepr.isEmpty() ? rUrlField.GetURL() : aRepr;
293}
294
295} // namespace
296
298 XclExpRoot( rRoot ),
299 maScPos( rScPos ),
300 mbMultipleUrls( false )
301{
302}
303
305{
306}
307
309{
310 OUString aUrlRepr;
311
312 if( GetBiff() == EXC_BIFF8 ) // no HLINK records in BIFF2-BIFF7
313 {
314 // there was/is already a HLINK record
315 mbMultipleUrls = static_cast< bool >(mxLinkRec);
316
317 mxLinkRec = new XclExpHyperlink( GetRoot(), rUrlField, maScPos );
318
319 if( const OUString* pRepr = mxLinkRec->GetRepr() )
320 aUrlRepr = *pRepr;
321
322 // add URL to note text
323 maUrlList = ScGlobal::addToken( maUrlList, rUrlField.GetURL(), '\n' );
324 }
325
326 // no hyperlink representation from Excel HLINK record -> use it from text field
327 return aUrlRepr.isEmpty() ? lclGetUrlRepresentation(rUrlField) : aUrlRepr;
328}
329
331{
332 return !mbMultipleUrls && mxLinkRec;
333}
334
336{
337 if( HasLinkRecord() )
338 return mxLinkRec;
339 return XclExpHyperlinkRef();
340}
341
342namespace {
343
359XclExpStringRef lclCreateFormattedString(
360 const XclExpRoot& rRoot, const OUString& rText, const ScPatternAttr* pCellAttr,
361 XclStrFlags nFlags, sal_uInt16 nMaxLen )
362{
363 /* Create an empty Excel string object with correctly initialized BIFF mode,
364 because this function only uses Append() functions that require this. */
365 XclExpStringRef xString = XclExpStringHelper::CreateString( rRoot, OUString(), nFlags, nMaxLen );
366
367 // script type handling
368 Reference< XBreakIterator > xBreakIt = rRoot.GetDoc().GetBreakIterator();
369 namespace ApiScriptType = ::com::sun::star::i18n::ScriptType;
370 // #i63255# get script type for leading weak characters
371 sal_Int16 nLastScript = XclExpStringHelper::GetLeadingScriptType( rRoot, rText );
372
373 // font buffer and cell item set
374 XclExpFontBuffer& rFontBuffer = rRoot.GetFontBuffer();
375 const SfxItemSet& rItemSet = pCellAttr ? pCellAttr->GetItemSet() : rRoot.GetDoc().GetDefPattern()->GetItemSet();
376
377 // process all script portions
378 sal_Int32 nPortionPos = 0;
379 sal_Int32 nTextLen = rText.getLength();
380 while( nPortionPos < nTextLen )
381 {
382 // get script type and end position of next script portion
383 sal_Int16 nScript = xBreakIt->getScriptType( rText, nPortionPos );
384 sal_Int32 nPortionEnd = xBreakIt->endOfScript( rText, nPortionPos, nScript );
385
386 // reuse previous script for following weak portions
387 if( nScript == ApiScriptType::WEAK )
388 nScript = nLastScript;
389
390 // construct font from current text portion
391 SvxFont aFont(XclExpFontHelper::GetFontFromItemSet(rRoot, rItemSet, nScript));
392 model::ComplexColor aComplexColor;
393 ScPatternAttr::fillColor(aComplexColor, rItemSet, ScAutoFontColorMode::Raw);
394
395 // Excel start position of this portion
396 sal_Int32 nXclPortionStart = xString->Len();
397 // add portion text to Excel string
398 XclExpStringHelper::AppendString( *xString, rRoot, rText.subView( nPortionPos, nPortionEnd - nPortionPos ) );
399 if( nXclPortionStart < xString->Len() )
400 {
401 // insert font into buffer
402 sal_uInt16 nFontIdx = rFontBuffer.Insert(aFont, aComplexColor, EXC_COLOR_CELLTEXT);
403 // insert font index into format run vector
404 xString->AppendFormat( nXclPortionStart, nFontIdx );
405 }
406
407 // go to next script portion
408 nLastScript = nScript;
409 nPortionPos = nPortionEnd;
410 }
411
412 return xString;
413}
414
429XclExpStringRef lclCreateFormattedString(
430 const XclExpRoot& rRoot, EditEngine& rEE, XclExpHyperlinkHelper* pLinkHelper,
431 XclStrFlags nFlags, sal_uInt16 nMaxLen )
432{
433 /* Create an empty Excel string object with correctly initialized BIFF mode,
434 because this function only uses Append() functions that require this. */
435 XclExpStringRef xString = XclExpStringHelper::CreateString( rRoot, OUString(), nFlags, nMaxLen );
436
437 // font buffer and helper item set for edit engine -> Calc item conversion
438 XclExpFontBuffer& rFontBuffer = rRoot.GetFontBuffer();
440
441 // script type handling
442 Reference< XBreakIterator > xBreakIt = rRoot.GetDoc().GetBreakIterator();
443 namespace ApiScriptType = ::com::sun::star::i18n::ScriptType;
444 // #i63255# get script type for leading weak characters
445 sal_Int16 nLastScript = XclExpStringHelper::GetLeadingScriptType( rRoot, rEE.GetText() );
446
447 // process all paragraphs
448 sal_Int32 nParaCount = rEE.GetParagraphCount();
449 for( sal_Int32 nPara = 0; nPara < nParaCount; ++nPara )
450 {
451 ESelection aSel( nPara, 0 );
452 OUString aParaText( rEE.GetText( nPara ) );
453
454 std::vector<sal_Int32> aPosList;
455 rEE.GetPortions( nPara, aPosList );
456
457 // process all portions in the paragraph
458 for( const auto& rPos : aPosList )
459 {
460 aSel.nEndPos = rPos;
461 OUString aXclPortionText = aParaText.copy( aSel.nStartPos, aSel.nEndPos - aSel.nStartPos );
462
463 aItemSet.ClearItem();
464 SfxItemSet aEditSet( rEE.GetAttribs( aSel ) );
465 ScPatternAttr::GetFromEditItemSet( aItemSet, aEditSet );
466
467 // get escapement value
468 short nEsc = aEditSet.Get( EE_CHAR_ESCAPEMENT ).GetEsc();
469
470 // process text fields
471 bool bIsHyperlink = false;
472 if( aSel.nStartPos + 1 == aSel.nEndPos )
473 {
474 // test if the character is a text field
475 if( const SvxFieldItem* pItem = aEditSet.GetItemIfSet( EE_FEATURE_FIELD, false ) )
476 {
477 const SvxFieldData* pField = pItem->GetField();
478 if( const SvxURLField* pUrlField = dynamic_cast<const SvxURLField*>( pField ) )
479 {
480 // convert URL field to string representation
481 aXclPortionText = pLinkHelper ?
482 pLinkHelper->ProcessUrlField( *pUrlField ) :
483 lclGetUrlRepresentation( *pUrlField );
484 bIsHyperlink = true;
485 }
486 else
487 {
488 OSL_FAIL( "lclCreateFormattedString - unknown text field" );
489 aXclPortionText.clear();
490 }
491 }
492 }
493
494 // Excel start position of this portion
495 sal_Int32 nXclPortionStart = xString->Len();
496 // add portion text to Excel string
497 XclExpStringHelper::AppendString( *xString, rRoot, aXclPortionText );
498 if( (nXclPortionStart < xString->Len()) || (aParaText.isEmpty()) )
499 {
500 /* Construct font from current edit engine text portion. Edit engine
501 creates different portions for different script types, no need to loop. */
502 sal_Int16 nScript = xBreakIt->getScriptType( aXclPortionText, 0 );
503 if( nScript == ApiScriptType::WEAK )
504 nScript = nLastScript;
505 SvxFont aFont( XclExpFontHelper::GetFontFromItemSet(rRoot, aItemSet, nScript));
506 model::ComplexColor aComplexColor;
507 ScPatternAttr::fillColor(aComplexColor, aItemSet, ScAutoFontColorMode::Raw);
508
509 nLastScript = nScript;
510
511 // add escapement
512 aFont.SetEscapement( nEsc );
513 // modify automatic font color for hyperlinks
514 if (bIsHyperlink && aItemSet.Get(ATTR_FONT_COLOR).GetValue() == COL_AUTO)
515 aComplexColor.setFinalColor(COL_LIGHTBLUE);
516
517 // insert font into buffer
518 sal_uInt16 nFontIdx = rFontBuffer.Insert(aFont, aComplexColor, EXC_COLOR_CELLTEXT);
519 // insert font index into format run vector
520 xString->AppendFormat( nXclPortionStart, nFontIdx );
521 }
522
523 aSel.nStartPos = aSel.nEndPos;
524 }
525
526 // add trailing newline (important for correct character index calculation)
527 if( nPara + 1 < nParaCount )
528 XclExpStringHelper::AppendChar( *xString, rRoot, '\n' );
529 }
530
531 return xString;
532}
533
534} // namespace
535
537 const XclExpRoot& rRoot, const OUString& rString, XclStrFlags nFlags, sal_uInt16 nMaxLen )
538{
539 XclExpStringRef xString = std::make_shared<XclExpString>();
540 if( rRoot.GetBiff() == EXC_BIFF8 )
541 xString->Assign( rString, nFlags, nMaxLen );
542 else
543 xString->AssignByte( rString, rRoot.GetTextEncoding(), nFlags, nMaxLen );
544 return xString;
545}
546
548 const XclExpRoot& rRoot, sal_Unicode cChar, XclStrFlags nFlags, sal_uInt16 nMaxLen )
549{
550 XclExpStringRef xString = CreateString( rRoot, OUString(), nFlags, nMaxLen );
551 AppendChar( *xString, rRoot, cChar );
552 return xString;
553}
554
555void XclExpStringHelper::AppendString( XclExpString& rXclString, const XclExpRoot& rRoot, std::u16string_view rString )
556{
557 if( rRoot.GetBiff() == EXC_BIFF8 )
558 rXclString.Append( rString );
559 else
560 rXclString.AppendByte( rString, rRoot.GetTextEncoding() );
561}
562
564{
565 if( rRoot.GetBiff() == EXC_BIFF8 )
566 rXclString.Append( rtl::OUStringChar(cChar) );
567 else
568 rXclString.AppendByte( cChar, rRoot.GetTextEncoding() );
569}
570
572 const XclExpRoot& rRoot, const OUString& rString, const ScPatternAttr* pCellAttr,
573 XclStrFlags nFlags, sal_uInt16 nMaxLen )
574{
575 return lclCreateFormattedString(rRoot, rString, pCellAttr, nFlags, nMaxLen);
576}
577
579 const XclExpRoot& rRoot, const EditTextObject& rEditText, const ScPatternAttr* pCellAttr,
580 XclExpHyperlinkHelper& rLinkHelper, XclStrFlags nFlags, sal_uInt16 nMaxLen )
581{
582 XclExpStringRef xString;
583
584 // formatted cell
586 bool bOldUpdateMode = rEE.SetUpdateLayout( true );
587
588 // default items
589 const SfxItemSet& rItemSet = pCellAttr ? pCellAttr->GetItemSet() : rRoot.GetDoc().GetDefPattern()->GetItemSet();
590 auto pEEItemSet = std::make_unique<SfxItemSet>( rEE.GetEmptyItemSet() );
591 ScPatternAttr::FillToEditItemSet( *pEEItemSet, rItemSet );
592 rEE.SetDefaults( std::move(pEEItemSet) ); // edit engine takes ownership
593
594 // create the string
595 rEE.SetTextCurrentDefaults(rEditText);
596 xString = lclCreateFormattedString( rRoot, rEE, &rLinkHelper, nFlags, nMaxLen );
597 rEE.SetUpdateLayout( bOldUpdateMode );
598
599 return xString;
600}
601
603 const XclExpRoot& rRoot, const SdrTextObj& rTextObj,
604 XclStrFlags nFlags )
605{
606 XclExpStringRef xString;
607 if( const OutlinerParaObject* pParaObj = rTextObj.GetOutlinerParaObject() )
608 {
609 EditEngine& rEE = rRoot.GetDrawEditEngine();
610 bool bOldUpdateMode = rEE.SetUpdateLayout( true );
611 // create the string
612 rEE.SetText( pParaObj->GetTextObject() );
613 xString = lclCreateFormattedString( rRoot, rEE, nullptr, nFlags, EXC_STR_MAXLEN );
614 rEE.SetUpdateLayout( bOldUpdateMode );
615 // limit formats - TODO: BIFF dependent
616 if( !xString->IsEmpty() )
617 {
618 xString->LimitFormatCount( EXC_MAXRECSIZE_BIFF8 / 8 - 1 );
619 xString->AppendTrailingFormat( EXC_FONT_APP );
620 }
621 }
622 else
623 {
624 OSL_FAIL( "XclExpStringHelper::CreateString - textbox without para object" );
625 // create BIFF dependent empty Excel string
626 xString = CreateString( rRoot, OUString(), nFlags );
627 }
628 return xString;
629}
630
632 const XclExpRoot& rRoot, const EditTextObject& rEditObj,
633 XclStrFlags nFlags )
634{
635 XclExpStringRef xString;
636 EditEngine& rEE = rRoot.GetDrawEditEngine();
637 bool bOldUpdateMode = rEE.SetUpdateLayout( true );
638 rEE.SetText( rEditObj );
639 xString = lclCreateFormattedString( rRoot, rEE, nullptr, nFlags, EXC_STR_MAXLEN );
640 rEE.SetUpdateLayout( bOldUpdateMode );
641 // limit formats - TODO: BIFF dependent
642 if( !xString->IsEmpty() )
643 {
644 xString->LimitFormatCount( EXC_MAXRECSIZE_BIFF8 / 8 - 1 );
645 xString->AppendTrailingFormat( EXC_FONT_APP );
646 }
647 return xString;
648}
649
650sal_Int16 XclExpStringHelper::GetLeadingScriptType( const XclExpRoot& rRoot, const OUString& rString )
651{
652 namespace ApiScriptType = ::com::sun::star::i18n::ScriptType;
653 Reference< XBreakIterator > xBreakIt = rRoot.GetDoc().GetBreakIterator();
654 sal_Int32 nStrPos = 0;
655 sal_Int32 nStrLen = rString.getLength();
656 sal_Int16 nScript = ApiScriptType::WEAK;
657 while( (nStrPos < nStrLen) && (nScript == ApiScriptType::WEAK) )
658 {
659 nScript = xBreakIt->getScriptType( rString, nStrPos );
660 nStrPos = xBreakIt->endOfScript( rString, nStrPos, nScript );
661 }
662 return (nScript == ApiScriptType::WEAK) ? rRoot.GetDefApiScript() : nScript;
663}
664
665// Header/footer conversion ===================================================
666
668 XclExpRoot( rRoot ),
669 mrEE( rRoot.GetHFEditEngine() ),
670 mnTotalHeight( 0 )
671{
672}
673
675 const EditTextObject* pLeftObj,
676 const EditTextObject* pCenterObj,
677 const EditTextObject* pRightObj )
678{
679 maHFString.clear();
680 mnTotalHeight = 0;
681 AppendPortion( pLeftObj, 'L' );
682 AppendPortion( pCenterObj, 'C' );
683 AppendPortion( pRightObj, 'R' );
684}
685
687{
688 if( !pTextObj ) return;
689
690 OUString aText;
691 sal_Int32 nHeight = 0;
693
694 // edit engine
695 bool bOldUpdateMode = mrEE.SetUpdateLayout( true );
696 mrEE.SetText( *pTextObj );
697
698 // font information
699 XclFontData aFontData, aNewData;
700 if( const XclExpFont* pFirstFont = GetFontBuffer().GetFont( EXC_FONT_APP ) )
701 {
702 aFontData = pFirstFont->GetFontData();
703 aFontData.mnHeight = (aFontData.mnHeight + 10) / 20; // using pt here, not twips
704 }
705 else
706 aFontData.mnHeight = 10;
707
708 const FontList* pFontList = nullptr;
709 if( SfxObjectShell* pDocShell = GetDocShell() )
710 {
711 if( const SvxFontListItem* pInfoItem = static_cast< const SvxFontListItem* >(
712 pDocShell->GetItem( SID_ATTR_CHAR_FONTLIST ) ) )
713 pFontList = pInfoItem->GetFontList();
714 }
715
716 sal_Int32 nParaCount = mrEE.GetParagraphCount();
717 for( sal_Int32 nPara = 0; nPara < nParaCount; ++nPara )
718 {
719 ESelection aSel( nPara, 0 );
720 OUStringBuffer aParaText;
721 sal_Int32 nParaHeight = 0;
722 std::vector<sal_Int32> aPosList;
723 mrEE.GetPortions( nPara, aPosList );
724
725 for( const auto& rPos : aPosList )
726 {
727 aSel.nEndPos = rPos;
728 if( aSel.nStartPos < aSel.nEndPos )
729 {
730
731// --- font attributes ---
732
733 vcl::Font aFont;
734 model::ComplexColor aComplexColor;
735 aItemSet.ClearItem();
736 SfxItemSet aEditSet( mrEE.GetAttribs( aSel ) );
737 ScPatternAttr::GetFromEditItemSet( aItemSet, aEditSet );
738 ScPatternAttr::fillFontOnly(aFont, aItemSet);
739 ScPatternAttr::fillColor(aComplexColor, aItemSet, ScAutoFontColorMode::Raw);
740
741 // font name and style
742 aNewData.maName = XclTools::GetXclFontName( aFont.GetFamilyName() );
744 aNewData.mbItalic = (aFont.GetItalic() != ITALIC_NONE);
745 bool bNewFont = (aFontData.maName != aNewData.maName);
746 bool bNewStyle = (aFontData.mnWeight != aNewData.mnWeight) ||
747 (aFontData.mbItalic != aNewData.mbItalic);
748 if( bNewFont || (bNewStyle && pFontList) )
749 {
750 aParaText.append("&\"" + aNewData.maName);
751 if( pFontList )
752 {
753 FontMetric aFontMetric( pFontList->Get(
754 aNewData.maName,
756 aNewData.mbItalic ? ITALIC_NORMAL : ITALIC_NONE ) );
757 aNewData.maStyle = pFontList->GetStyleName( aFontMetric );
758 if( !aNewData.maStyle.isEmpty() )
759 aParaText.append("," + aNewData.maStyle);
760 }
761 aParaText.append("\"");
762 }
763
764 // height
765 // is calculated wrong in ScPatternAttr::GetFromEditItemSet, because already in twips and not 100thmm
766 // -> get it directly from edit engine item set
767 aNewData.mnHeight = ulimit_cast< sal_uInt16 >( aEditSet.Get( EE_CHAR_FONTHEIGHT ).GetHeight() );
768 aNewData.mnHeight = (aNewData.mnHeight + 10) / 20;
769 bool bFontHtChanged = (aFontData.mnHeight != aNewData.mnHeight);
770 if( bFontHtChanged )
771 aParaText.append("&" + OUString::number(aNewData.mnHeight));
772 // update maximum paragraph height, convert to twips
773 nParaHeight = ::std::max< sal_Int32 >( nParaHeight, aNewData.mnHeight * 20 );
774
775 // underline
777 switch( aFont.GetUnderline() )
778 {
779 case LINESTYLE_NONE: aNewData.mnUnderline = EXC_FONTUNDERL_NONE; break;
780 case LINESTYLE_SINGLE: aNewData.mnUnderline = EXC_FONTUNDERL_SINGLE; break;
781 case LINESTYLE_DOUBLE: aNewData.mnUnderline = EXC_FONTUNDERL_DOUBLE; break;
782 default: aNewData.mnUnderline = EXC_FONTUNDERL_SINGLE;
783 }
784 if( aFontData.mnUnderline != aNewData.mnUnderline )
785 {
786 sal_uInt8 nTmpUnderl = (aNewData.mnUnderline == EXC_FONTUNDERL_NONE) ?
787 aFontData.mnUnderline : aNewData.mnUnderline;
788 (nTmpUnderl == EXC_FONTUNDERL_SINGLE)? aParaText.append("&U") : aParaText.append("&E");
789 }
790
791 // font color
792 aNewData.maComplexColor = aComplexColor;
793 Color aNewColor = aNewData.maComplexColor.getFinalColor();
794
795 if (!aFontData.maComplexColor.getFinalColor().IsRGBEqual(aNewColor))
796 {
797 aParaText.append("&K" + aNewColor.AsRGBHexString());
798 }
799
800 // strikeout
801 aNewData.mbStrikeout = (aFont.GetStrikeout() != STRIKEOUT_NONE);
802 if( aFontData.mbStrikeout != aNewData.mbStrikeout )
803 aParaText.append("&S");
804
805 // super/sub script
806 const SvxEscapementItem& rEscapeItem = aEditSet.Get( EE_CHAR_ESCAPEMENT );
807 aNewData.SetScEscapement( rEscapeItem.GetEsc() );
808 if( aFontData.mnEscapem != aNewData.mnEscapem )
809 {
810 switch(aNewData.mnEscapem)
811 {
812 // close the previous super/sub script.
813 case EXC_FONTESC_NONE: (aFontData.mnEscapem == EXC_FONTESC_SUPER) ? aParaText.append("&X") : aParaText.append("&Y"); break;
814 case EXC_FONTESC_SUPER: aParaText.append("&X"); break;
815 case EXC_FONTESC_SUB: aParaText.append("&Y"); break;
816 default: break;
817 }
818 }
819
820 aFontData = aNewData;
821
822// --- text content or text fields ---
823
824 const SvxFieldItem* pItem;
825 if( (aSel.nStartPos + 1 == aSel.nEndPos) && // fields are single characters
826 (pItem = aEditSet.GetItemIfSet( EE_FEATURE_FIELD, false )) )
827 {
828 if( const SvxFieldData* pFieldData = pItem->GetField() )
829 {
830 if( dynamic_cast<const SvxPageField*>( pFieldData) != nullptr )
831 aParaText.append("&P");
832 else if( dynamic_cast<const SvxPagesField*>( pFieldData) != nullptr )
833 aParaText.append("&N");
834 else if( dynamic_cast<const SvxDateField*>( pFieldData) != nullptr )
835 aParaText.append("&D");
836 else if( dynamic_cast<const SvxTimeField*>( pFieldData) != nullptr || dynamic_cast<const SvxExtTimeField*>( pFieldData) != nullptr )
837 aParaText.append("&T");
838 else if( dynamic_cast<const SvxTableField*>( pFieldData) != nullptr )
839 aParaText.append("&A");
840 else if( dynamic_cast<const SvxFileField*>( pFieldData) != nullptr ) // title -> file name
841 aParaText.append("&F");
842 else if( const SvxExtFileField* pFileField = dynamic_cast<const SvxExtFileField*>( pFieldData ) )
843 {
844 switch( pFileField->GetFormat() )
845 {
846 case SvxFileFormat::NameAndExt:
847 case SvxFileFormat::NameOnly:
848 aParaText.append("&F");
849 break;
850 case SvxFileFormat::PathOnly:
851 aParaText.append("&Z");
852 break;
853 case SvxFileFormat::PathFull:
854 aParaText.append("&Z&F");
855 break;
856 default:
857 OSL_FAIL( "XclExpHFConverter::AppendPortion - unknown file field" );
858 }
859 }
860 }
861 }
862 else
863 {
864 OUString aPortionText( mrEE.GetText( aSel ) );
865 aPortionText = aPortionText.replaceAll( "&", "&&" );
866 // #i17440# space between font height and numbers in text
867 if( bFontHtChanged && aParaText.getLength() && !aPortionText.isEmpty() )
868 {
869 sal_Unicode cLast = aParaText[ aParaText.getLength() - 1 ];
870 sal_Unicode cFirst = aPortionText[0];
871 if( ('0' <= cLast) && (cLast <= '9') && ('0' <= cFirst) && (cFirst <= '9') )
872 aParaText.append(" ");
873 }
874 aParaText.append(aPortionText);
875 }
876 }
877
878 aSel.nStartPos = aSel.nEndPos;
879 }
880
881 aText = ScGlobal::addToken( aText, aParaText, '\n' );
882 aParaText.setLength(0);
883 if( nParaHeight == 0 )
884 nParaHeight = aFontData.mnHeight * 20; // points -> twips
885 nHeight += nParaHeight;
886 }
887
888 mrEE.SetUpdateLayout( bOldUpdateMode );
889
890 if( !aText.isEmpty() )
891 {
892 maHFString += "&" + OUStringChar(cPortionCode) + aText;
893 mnTotalHeight = ::std::max( mnTotalHeight, nHeight );
894 }
895}
896
897// URL conversion =============================================================
898
899namespace {
900
903OUString lclEncodeDosPath(
904 XclBiff eBiff, std::u16string_view path, bool bIsRel, const OUString* pTableName)
905{
906 OUStringBuffer aBuf;
907
908 if (!path.empty())
909 {
911
912 if ( path.length() > 2 && o3tl::starts_with(path, u"\\\\") )
913 {
914 // UNC
915 aBuf.append(OUStringChar(EXC_URL_DOSDRIVE) + "@");
916 path = path.substr(2);
917 }
918 else if ( path.length() > 2 && o3tl::starts_with(path.substr(1), u":\\") )
919 {
920 aBuf.append(OUStringChar(EXC_URL_DOSDRIVE) + OUStringChar(path[0]));
921 path = path.substr(3);
922 }
923 else if ( !bIsRel )
924 {
925 // URL probably points to a document on a Unix-like file system
926 aBuf.append(EXC_URL_DRIVEROOT);
927 }
928
929 // directories
930 auto nPos = std::u16string_view::npos;
931 while((nPos = path.find('\\')) != std::u16string_view::npos)
932 {
933 if ( o3tl::starts_with(path, u"..") )
934 // parent dir (NOTE: the MS-XLS spec doesn't mention this, and
935 // Excel seems confused by this token).
936 aBuf.append(EXC_URL_PARENTDIR);
937 else
938 aBuf.append(path.substr(0,nPos) + OUStringChar(EXC_URL_SUBDIR));
939
940 path = path.substr(nPos + 1);
941 }
942
943 // file name
944 if (pTableName) // enclose file name in brackets if table name follows
945 aBuf.append(OUString::Concat("[") + path + "]");
946 else
947 aBuf.append(path);
948 }
949 else // empty URL -> self reference
950 {
951 switch( eBiff )
952 {
953 case EXC_BIFF5:
954 aBuf.append(pTableName ? EXC_URLSTART_SELFENCODED : EXC_URLSTART_SELF);
955 break;
956 case EXC_BIFF8:
957 DBG_ASSERT( pTableName, "lclEncodeDosUrl - sheet name required for BIFF8" );
958 aBuf.append(EXC_URLSTART_SELF);
959 break;
960 default:
962 }
963 }
964
965 // table name
966 if (pTableName)
967 aBuf.append(*pTableName);
968
969 // VirtualPath must be shorter than 255 chars ([MS-XLS].pdf 2.5.277)
970 // It's better to truncate, than generate invalid file that Excel cannot open.
971 if (aBuf.getLength() > 255)
972 aBuf.setLength(255);
973
974 return aBuf.makeStringAndClear();
975}
976
977bool isUrlRelative(const OUString& aUrl)
978{
979 css::uno::Reference<css::uri::XUriReferenceFactory> xUriFactory(
980 css::uri::UriReferenceFactory::create(
982 css::uno::Reference<css::uri::XUriReference> xUri(xUriFactory->parse(aUrl));
983
984 return !xUri->isAbsolute();
985}
986
987} // namespace
988
989OUString XclExpUrlHelper::EncodeUrl( const XclExpRoot& rRoot, std::u16string_view rAbsUrl, const OUString* pTableName )
990{
991 OUString aDosPath;
992 bool bIsRel = false;
993
994 if (rRoot.IsRelUrl())
995 {
996 OUString aUrlPath = INetURLObject::GetRelURL(
997 rRoot.GetBasePath(), OUString(rAbsUrl),
1000 RTL_TEXTENCODING_UTF8, FSysStyle::Detect
1001 );
1002
1003 if (isUrlRelative(aUrlPath))
1004 {
1005 bIsRel = true;
1006 osl::FileBase::getSystemPathFromFileURL(aUrlPath, aDosPath);
1007 aDosPath = aDosPath.replaceAll(u"/", u"\\");
1008 }
1009 }
1010
1011 if (!bIsRel)
1012 aDosPath = INetURLObject(rAbsUrl).getFSysPath(FSysStyle::Dos);
1013
1014 return lclEncodeDosPath(rRoot.GetBiff(), aDosPath, bIsRel, pTableName);
1015}
1016
1017OUString XclExpUrlHelper::EncodeDde( std::u16string_view rApplic, std::u16string_view rTopic )
1018{
1019 return rApplic + OUStringChar(EXC_DDE_DELIM) + rTopic;
1020}
1021
1022// Cached Value Lists =========================================================
1023
1025 : mrMatrix( rMatrix )
1026{
1027 mrMatrix.IncRef();
1028}
1030{
1031 mrMatrix.DecRef();
1032}
1033
1035{
1036 mrMatrix.GetDimensions( nCols, nRows );
1037
1038 OSL_ENSURE( nCols && nRows, "XclExpCachedMatrix::GetDimensions - empty matrix" );
1039 OSL_ENSURE( nCols <= 256, "XclExpCachedMatrix::GetDimensions - too many columns" );
1040}
1041
1043{
1044 SCSIZE nCols, nRows;
1045
1046 GetDimensions( nCols, nRows );
1047
1048 /* The returned size may be wrong if the matrix contains strings. The only
1049 effect is that the export stream has to update a wrong record size which is
1050 faster than to iterate through all cached values and calculate their sizes. */
1051 return 3 + 9 * (nCols * nRows);
1052}
1053
1055{
1056 SCSIZE nCols, nRows;
1057
1058 GetDimensions( nCols, nRows );
1059
1060 if( rStrm.GetRoot().GetBiff() <= EXC_BIFF5 )
1061 // in BIFF2-BIFF7: 256 columns represented by 0 columns
1062 rStrm << static_cast< sal_uInt8 >( nCols ) << static_cast< sal_uInt16 >( nRows );
1063 else
1064 // in BIFF8: columns and rows decreased by 1
1065 rStrm << static_cast< sal_uInt8 >( nCols - 1 ) << static_cast< sal_uInt16 >( nRows - 1 );
1066
1067 for( SCSIZE nRow = 0; nRow < nRows; ++nRow )
1068 {
1069 for( SCSIZE nCol = 0; nCol < nCols; ++nCol )
1070 {
1071 ScMatrixValue nMatVal = mrMatrix.Get( nCol, nRow );
1072
1073 FormulaError nScError;
1074 if( ScMatValType::Empty == nMatVal.nType )
1075 {
1076 rStrm.SetSliceSize( 9 );
1078 rStrm.WriteZeroBytes( 8 );
1079 }
1080 else if( ScMatrix::IsNonValueType( nMatVal.nType ) )
1081 {
1083 rStrm.SetSliceSize( 6 );
1085 }
1086 else if( ScMatValType::Boolean == nMatVal.nType )
1087 {
1088 sal_Int8 nBool = sal_Int8(nMatVal.GetBoolean());
1089 rStrm.SetSliceSize( 9 );
1090 rStrm << EXC_CACHEDVAL_BOOL << nBool;
1091 rStrm.WriteZeroBytes( 7 );
1092 }
1093 else if( (nScError = nMatVal.GetError()) != FormulaError::NONE )
1094 {
1095 sal_Int8 nError ( XclTools::GetXclErrorCode( nScError ) );
1096 rStrm.SetSliceSize( 9 );
1097 rStrm << EXC_CACHEDVAL_ERROR << nError;
1098 rStrm.WriteZeroBytes( 7 );
1099 }
1100 else
1101 {
1102 rStrm.SetSliceSize( 9 );
1103 rStrm << EXC_CACHEDVAL_DOUBLE << nMatVal.fVal;
1104 }
1105 }
1106 }
1107}
1108
1109/* 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
OUString AsRGBHexString() const
bool IsRGBEqual(const Color &rColor) const
void GetPortions(sal_Int32 nPara, std::vector< sal_Int32 > &rList)
OUString GetText(LineEnd eEnd=LINEEND_LF) const
void SetText(const OUString &rStr)
bool SetUpdateLayout(bool bUpdate, bool bRestoring=false)
sal_Int32 GetParagraphCount() const
SfxItemSet GetAttribs(sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, GetAttribsFlags nFlags=GetAttribsFlags::ALL) const
const SfxItemSet & GetEmptyItemSet() const
FontMetric Get(const OUString &rName, const OUString &rStyleName) const
const OUString & GetStyleName(FontWeight eWeight, FontItalic eItalic) const
static OUString GetRelURL(std::u16string_view rTheBaseURIRef, OUString const &rTheAbsURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
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
SCROW Row() const
Definition: address.hxx:274
void SetRow(SCROW nRowP)
Definition: address.hxx:287
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
SCCOL Col() const
Definition: address.hxx:279
SC_DLLPUBLIC ScPatternAttr * GetDefPattern() const
Definition: document.cxx:6045
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6050
SC_DLLPUBLIC bool GetTableArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow, bool bCalcHiddens=false) const
Definition: document.cxx:1008
SC_DLLPUBLIC const css::uno::Reference< css::i18n::XBreakIterator > & GetBreakIterator()
Definition: documen6.cxx:40
void SetDefaults(const SfxItemSet &rDefaults, bool bRememberCopy=true)
Creates a copy of SfxItemSet if bRememberCopy set.
Definition: editutil.cxx:564
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:619
static SC_DLLPUBLIC OUString addToken(std::u16string_view rTokenList, std::u16string_view rToken, sal_Unicode cSep, sal_Int32 nSepCount=1, bool bForceSep=false)
Adds the string rToken to rTokenList, using a list separator character.
Definition: global.cxx:705
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:101
ScMatrixValue Get(SCSIZE nC, SCSIZE nR) const
@ATTENTION: If bString the ScMatrixValue->pS may still be NULL to indicate an empty string!
Definition: scmatrix.cxx:3253
void IncRef() const
Definition: scmatrix.cxx:3003
void DecRef() const
Definition: scmatrix.cxx:3008
static bool IsNonValueType(ScMatValType nType)
String, empty or empty path, but not value nor boolean.
Definition: scmatrix.hxx:179
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
Definition: scmatrix.cxx:3143
static void fillColor(model::ComplexColor &rComplexColor, const SfxItemSet &rItemSet, ScAutoFontColorMode eAutoMode, const SfxItemSet *pCondSet=nullptr, const Color *pBackConfigColor=nullptr, const Color *pTextConfigColor=nullptr)
Definition: patattr.cxx:435
static void FillToEditItemSet(SfxItemSet &rEditSet, const SfxItemSet &rSrcSet, const SfxItemSet *pCondSet=nullptr)
Converts all Calc items contained in rSrcSet to edit engine items and puts them into rEditSet.
Definition: patattr.cxx:642
SfxItemSet & GetItemSet()
Definition: patattr.hxx:192
static void fillFontOnly(vcl::Font &rFont, const SfxItemSet &rItemSet, const OutputDevice *pOutDev=nullptr, const Fraction *pScale=nullptr, const SfxItemSet *pCondSet=nullptr, SvtScriptType nScript=SvtScriptType::NONE)
Static helper function to fill a font object from the passed item set.
Definition: patattr.cxx:266
static void GetFromEditItemSet(SfxItemSet &rDestSet, const SfxItemSet &rEditSet)
Converts all edit engine items contained in rEditSet to Calc items and puts them into rDestSet.
Definition: patattr.cxx:874
size_t size() const
Definition: rangelst.hxx:89
void Remove(size_t nPos)
Definition: rangelst.cxx:1093
void PutInOrder()
Definition: address.hxx:622
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
Progress bar for complex progress representation.
sal_Int32 AddSegment(std::size_t nSize)
Adds a new segment to the progress bar.
void ActivateSegment(sal_Int32 nSegment)
Starts the progress bar or activates another segment.
bool IsFull() const
Returns true, if the current progress segment is already full.
void Progress(std::size_t nDelta=1)
Increase current segment by the passed value.
void Activate()
Starts the progress bar (with first segment).
virtual OutlinerParaObject * GetOutlinerParaObject() const override
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SvxFieldData * GetField() const
const OUString & GetRepresentation() const
const OUString & GetURL() const
Base class for import/export address converters.
Definition: xladdress.hxx:140
bool mbTabTrunc
Flag for "rows truncated" warning box.
Definition: xladdress.hxx:166
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
void ValidateRangeList(ScRangeList &rScRanges, bool bWarn)
Checks and eventually crops the cell ranges to valid dimensions.
Definition: xehelper.cxx:261
XclExpAddressConverter(const XclExpRoot &rRoot)
Definition: xehelper.cxx:164
bool ConvertAddress(XclAddress &rXclPos, const ScAddress &rScPos, bool bWarn)
Converts the passed Calc cell address to an Excel cell address.
Definition: xehelper.cxx:192
XclAddress CreateValidAddress(const ScAddress &rScPos, bool bWarn)
Returns a valid cell address by moving it into allowed dimensions.
Definition: xehelper.cxx:201
bool CheckRange(const ScRange &rScRange, bool bWarn)
Checks if the passed cell range is valid (checks start and end position).
Definition: xehelper.cxx:211
bool ConvertRange(XclRange &rXclRange, const ScRange &rScRange, bool bWarn)
Converts the passed Calc cell range to an Excel cell range.
Definition: xehelper.cxx:237
void ConvertRangeList(XclRangeList &rXclRanges, const ScRangeList &rScRanges, bool bWarn)
Converts the passed Calc cell range list to an Excel cell range list.
Definition: xehelper.cxx:271
bool CheckAddress(const ScAddress &rScPos, bool bWarn)
Checks if the passed Calc cell address is valid.
Definition: xehelper.cxx:171
bool ValidateRange(ScRange &rScRange, bool bWarn)
Checks and eventually crops the cell range to valid dimensions.
Definition: xehelper.cxx:216
XclExpCachedMatrix(const ScMatrix &rMatrix)
Constructs and fills a new matrix.
Definition: xehelper.cxx:1024
void GetDimensions(SCSIZE &nCols, SCSIZE &nRows) const
Definition: xehelper.cxx:1034
const ScMatrix & mrMatrix
Definition: xehelper.hxx:435
std::size_t GetSize() const
Returns the byte count of all contained data.
Definition: xehelper.cxx:1042
void Save(XclExpStream &rStrm) const
Writes the complete matrix to stream.
Definition: xehelper.cxx:1054
Stores the data of all fonts used in the document.
Definition: xestyle.hxx:209
sal_uInt16 Insert(const XclFontData &rFontData, XclExpColorType eColorType, bool bAppFont=false)
Inserts a new font with the passed font data into the buffer if not present.
Definition: xestyle.cxx:1195
Stores all data of an Excel font and provides export of FONT records.
Definition: xestyle.hxx:156
XclExpHFConverter(const XclExpHFConverter &)=delete
delete copy constructor
EditEngine & mrEE
Definition: xehelper.hxx:389
void AppendPortion(const EditTextObject *pTextObj, sal_Unicode cPortionCode)
Converts the text object contents and stores it in the passed string.
Definition: xehelper.cxx:686
sal_Int32 mnTotalHeight
The last generated header/footer string.
Definition: xehelper.hxx:391
OUString maHFString
The header/footer edit engine.
Definition: xehelper.hxx:390
void GenerateString(const EditTextObject *pLeftObj, const EditTextObject *pCenterObj, const EditTextObject *pRightObj)
Generates the header/footer string from the passed edit engine text objects.
Definition: xehelper.cxx:674
Helper to create HLINK records during creation of formatted cell strings.
Definition: xehelper.hxx:178
rtl::Reference< XclExpHyperlink > XclExpHyperlinkRef
Definition: xehelper.hxx:180
bool HasLinkRecord() const
Returns true, if a single HLINK record has been created.
Definition: xehelper.cxx:330
XclExpHyperlinkRef GetLinkRecord() const
Returns the created single HLINk record, or an empty reference.
Definition: xehelper.cxx:335
XclExpHyperlinkRef mxLinkRec
Definition: xehelper.hxx:200
XclExpHyperlinkHelper(const XclExpRoot &rRoot, const ScAddress &rScPos)
Definition: xehelper.cxx:297
bool mbMultipleUrls
List with all processed URLs.
Definition: xehelper.hxx:203
OUString maUrlList
Cell position to set at the HLINK record.
Definition: xehelper.hxx:202
virtual ~XclExpHyperlinkHelper() override
Definition: xehelper.cxx:304
OUString ProcessUrlField(const SvxURLField &rUrlField)
Processes the passed URL field (tries to create a HLINK record).
Definition: xehelper.cxx:308
ScAddress maScPos
Created HLINK record.
Definition: xehelper.hxx:201
void ActivateFinalRowsSegment()
Activates the progress segment to finalize ROW records.
Definition: xehelper.cxx:133
ScfInt32Vec maSubSegRowCreate
Sub progress bar for creating table rows.
Definition: xehelper.hxx:70
sal_Int32 mnSegRowFinal
Sub progress bar for finalizing ROW records.
Definition: xehelper.hxx:73
void Progress()
Increases the currently activated (sub) progress bar by 1 step.
Definition: xehelper.cxx:145
ScfProgressBar * mpSubRowFinal
Segment ID's for all sheets in sub progress bar.
Definition: xehelper.hxx:72
virtual ~XclExpProgressBar() override
Definition: xehelper.cxx:79
void ActivateCreateRowsSegment()
Activates the progress segment to create ROW records.
Definition: xehelper.cxx:118
void Initialize()
Initializes all segments and sub progress bars.
Definition: xehelper.cxx:83
std::size_t mnRowCount
Progress segment for finalizing ROW records.
Definition: xehelper.hxx:75
XclExpProgressBar(const XclExpRoot &rRoot)
Definition: xehelper.cxx:68
ScfProgressBar * mpSubProgress
Progress bar implementation.
Definition: xehelper.hxx:67
ScfProgressBarPtr mxProgress
Definition: xehelper.hxx:66
ScfProgressBar * mpSubRowCreate
Current sub progress bar.
Definition: xehelper.hxx:69
void IncRowRecordCount()
Increases the number of existing ROW records by 1.
Definition: xehelper.cxx:113
Access to global data from other classes.
Definition: xeroot.hxx:113
XclExpFontBuffer & GetFontBuffer() const
Returns the font buffer.
Definition: xeroot.cxx:112
bool IsRelUrl() const
Returns true, if URLs should be stored relative to the document location.
Definition: xeroot.hxx:120
XclExpTabInfo & GetTabInfo() const
Returns the buffer for Calc->Excel sheet index conversion.
Definition: xeroot.cxx:76
const XclExpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
Definition: xeroot.hxx:118
This class is used to export Excel record streams.
Definition: xestream.hxx:73
static void AppendChar(XclExpString &rXclString, const XclExpRoot &rRoot, sal_Unicode cChar)
Appends a character to an Excel string object.
Definition: xehelper.cxx:563
static sal_Int16 GetLeadingScriptType(const XclExpRoot &rRoot, const OUString &rString)
Returns the script type first text portion different to WEAK, or the system default script type,...
Definition: xehelper.cxx:650
static XclExpStringRef CreateString(const XclExpRoot &rRoot, const OUString &rString, XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Creates a new unformatted string from the passed string.
Definition: xehelper.cxx:536
static void AppendString(XclExpString &rXclString, const XclExpRoot &rRoot, std::u16string_view rString)
Appends an unformatted string to an Excel string object.
Definition: xehelper.cxx:555
static XclExpStringRef CreateCellString(const XclExpRoot &rRoot, const OUString &rString, const ScPatternAttr *pCellAttr, XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Creates a new formatted string from a Calc string cell.
Definition: xehelper.cxx:571
This class stores an unformatted or formatted string for Excel export.
Definition: xestring.hxx:48
void AppendByte(std::u16string_view rString, rtl_TextEncoding eTextEnc)
Appends a string.
Definition: xestring.cxx:137
void Append(std::u16string_view rString)
Appends a string.
Definition: xestring.cxx:132
Stores the correct Excel sheet index for each Calc sheet.
Definition: xelink.hxx:62
SCTAB GetScTabCount() const
Returns the number of Calc sheets.
Definition: xelink.hxx:89
bool IsExportTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet will be exported.
Definition: xelink.cxx:774
static OUString EncodeDde(std::u16string_view rApplic, std::u16string_view rTopic)
Encodes and returns the passed DDE link to an Excel like DDE link.
Definition: xehelper.cxx:1017
static OUString EncodeUrl(const XclExpRoot &rRoot, std::u16string_view rAbsUrl, const OUString *pTableName=nullptr)
Encodes and returns the URL passed in rAbsUrl to an Excel like URL.
Definition: xehelper.cxx:989
A 2D cell range address list with Excel column and row indexes.
Definition: xladdress.hxx:102
void push_back(const XclRange &rRange)
Definition: xladdress.hxx:114
void clear()
Definition: xladdress.hxx:113
SfxObjectShell * GetDocShell() const
Returns the object shell of the Calc document.
Definition: xlroot.cxx:290
const OUString & GetBasePath() const
Returns the base path of the imported/exported file.
Definition: xlroot.hxx:174
rtl_TextEncoding GetTextEncoding() const
Returns the text encoding to import/export byte strings.
Definition: xlroot.hxx:147
ScEditEngineDefaulter & GetEditEngine() const
Returns the edit engine for import/export of rich strings etc.
Definition: xlroot.cxx:365
sal_Int16 GetDefApiScript() const
Returns the default script type, e.g.
Definition: xlroot.hxx:155
SCTAB GetCurrScTab() const
Returns the current Calc sheet index.
Definition: xlroot.hxx:162
EditEngine & GetDrawEditEngine() const
Returns the edit engine for import/export of drawing text boxes.
Definition: xlroot.cxx:404
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
Definition: xlroot.hxx:141
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
Definition: xlroot.cxx:285
static sal_uInt8 GetXclErrorCode(FormulaError nScError)
Converts a Calc error code to an Excel error code.
Definition: xltools.cxx:201
static OUString GetXclFontName(const OUString &rFontName)
Returns the matching Excel font name for a passed Calc font name.
Definition: xltools.cxx:455
void TraceInvalidAddress(const ScAddress &rPos, const ScAddress &rMaxPos)
Definition: xltracer.cxx:41
void setFinalColor(Color const &rColor)
Color const & getFinalColor() const
const OUString & getString() const
FontStrikeout GetStrikeout() const
FontItalic GetItalic()
const OUString & GetFamilyName() const
FontWeight GetWeight()
FontLineStyle GetUnderline() const
int nCount
#define DBG_ASSERT(sCon, aError)
float u
constexpr TypedWhichId< SvxFieldItem > EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
constexpr TypedWhichId< SvxEscapementItem > EE_CHAR_ESCAPEMENT(EE_CHAR_START+10)
FormulaError
LINESTYLE_SINGLE
LINESTYLE_DOUBLE
LINESTYLE_NONE
STRIKEOUT_NONE
ITALIC_NORMAL
ITALIC_NONE
WEIGHT_BOLD
WEIGHT_NORMAL
const sal_Int32 SCF_INV_SEGMENT
sal_uInt16 nPos
aStr
aBuf
vcl::Font GetFontFromItemSet(const XclExpRoot &rRoot, const SfxItemSet &rItemSet, sal_Int16 nScript)
Returns a VCL font object filled from the passed item set.
Definition: xestyle.cxx:885
Reference< XComponentContext > getProcessComponentContext()
void SvStream & rStrm
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
@ Raw
COL_AUTO is returned.
constexpr TypedWhichId< SvxColorItem > ATTR_FONT_COLOR(109)
sal_Int32 nEndPos
sal_Int32 nStartPos
Try NOT to use this struct.
Definition: scmatrix.hxx:53
ScMatValType nType
Definition: scmatrix.hxx:56
FormulaError GetError() const
Only valid if ScMatrix methods indicate that this is no string!
Definition: scmatrix.hxx:62
double fVal
Definition: scmatrix.hxx:54
const svl::SharedString & GetString() const
Only valid if ScMatrix methods indicate so!
Definition: scmatrix.hxx:59
bool GetBoolean() const
Only valid if ScMatrix methods indicate that this is a boolean.
Definition: scmatrix.hxx:65
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
OUString maStyle
Font name.
Definition: xlstyle.hxx:287
sal_uInt16 mnHeight
String with styles (bold, italic).
Definition: xlstyle.hxx:288
sal_uInt16 mnWeight
Font height in twips (1/20 of a point).
Definition: xlstyle.hxx:289
bool mbItalic
Underline style.
Definition: xlstyle.hxx:294
sal_uInt8 mnUnderline
Windows character set.
Definition: xlstyle.hxx:293
void SetScEscapement(short nScEscapem)
Sets the Calc escapement style.
Definition: xlstyle.cxx:371
bool mbStrikeout
true = Italic.
Definition: xlstyle.hxx:295
sal_uInt16 mnEscapem
Boldness: 400=normal, 700=bold.
Definition: xlstyle.hxx:290
model::ComplexColor maComplexColor
true = Shadowed.
Definition: xlstyle.hxx:299
OUString maName
Definition: xlstyle.hxx:286
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
unsigned char sal_uInt8
sal_uInt16 sal_Unicode
signed char sal_Int8
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
std::shared_ptr< XclExpString > XclExpStringRef
Definition: xeroot.hxx:35
@ EXC_COLOR_CELLTEXT
Definition: xestyle.hxx:49
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_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
XclBiff
An enumeration for all Excel file format types (BIFF types).
Definition: xlconst.hxx:30
@ EXC_BIFF5
MS Excel 4.0.
Definition: xlconst.hxx:34
@ EXC_BIFF8
MS Excel 5.0, MS Excel 7.0 (95)
Definition: xlconst.hxx:35
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
const sal_uInt16 EXC_MAXRECSIZE_BIFF8
Definition: xlstream.hxx:30
const sal_uInt16 EXC_STR_MAXLEN
Definition: xlstring.hxx:43
XclStrFlags
Flags used to specify import/export mode of strings.
Definition: xlstring.hxx:29
const sal_uInt16 EXC_FONTWGHT_NORMAL
Definition: xlstyle.hxx:111
const sal_uInt16 EXC_FONT_APP
Definition: xlstyle.hxx:77
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_FONTWGHT_BOLD
Definition: xlstyle.hxx:114
const sal_uInt16 EXC_FONTESC_SUB
Definition: xlstyle.hxx:128
#define DBG_ERROR_BIFF()
Definition: xltools.hxx:33