LibreOffice Module sc (master)  1
worksheethelper.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 <worksheethelper.hxx>
22 
23 #include <algorithm>
24 #include <utility>
25 #include <com/sun/star/awt/Point.hpp>
26 #include <com/sun/star/awt/Size.hpp>
27 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
28 #include <com/sun/star/sheet/ConditionOperator2.hpp>
29 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
30 #include <com/sun/star/sheet/ValidationType.hpp>
31 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
32 #include <com/sun/star/sheet/XCellAddressable.hpp>
33 #include <com/sun/star/sheet/XMultiFormulaTokens.hpp>
34 #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
35 #include <com/sun/star/sheet/XSheetCondition2.hpp>
36 #include <com/sun/star/sheet/XSheetOutline.hpp>
37 #include <com/sun/star/sheet/XSpreadsheet.hpp>
38 #include <com/sun/star/table/XColumnRowRange.hpp>
39 #include <com/sun/star/text/WritingMode2.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <osl/diagnose.h>
42 #include <rtl/ustrbuf.hxx>
43 #include <oox/core/filterbase.hxx>
45 #include <oox/token/properties.hxx>
46 #include <oox/token/tokens.hxx>
47 #include <addressconverter.hxx>
48 #include <autofilterbuffer.hxx>
49 #include <commentsbuffer.hxx>
50 #include <condformatbuffer.hxx>
51 #include <document.hxx>
52 #include <drawingfragment.hxx>
53 #include <pagesettings.hxx>
54 #include <querytablebuffer.hxx>
55 #include <sheetdatabuffer.hxx>
56 #include <stylesbuffer.hxx>
57 #include <tokenuno.hxx>
58 #include <unitconverter.hxx>
59 #include <viewsettings.hxx>
60 #include <worksheetbuffer.hxx>
61 #include <worksheetsettings.hxx>
62 #include <formulabuffer.hxx>
63 #include <scitems.hxx>
64 #include <editutil.hxx>
65 #include <tokenarray.hxx>
66 #include <tablebuffer.hxx>
67 #include <documentimport.hxx>
68 #include <stlsheet.hxx>
69 #include <stlpool.hxx>
70 #include <cellvalue.hxx>
71 #include <columnspanset.hxx>
72 #include <dbdata.hxx>
73 
74 #include <svl/stritem.hxx>
75 #include <editeng/eeitem.hxx>
76 #include <editeng/editobj.hxx>
77 #include <editeng/flditem.hxx>
78 #include <tools/gen.hxx>
79 
80 namespace oox::xls {
81 
82 using namespace ::com::sun::star;
83 using namespace ::com::sun::star::beans;
84 using namespace ::com::sun::star::drawing;
85 using namespace ::com::sun::star::lang;
86 using namespace ::com::sun::star::sheet;
87 using namespace ::com::sun::star::table;
88 using namespace ::com::sun::star::text;
89 using namespace ::com::sun::star::uno;
90 
91 namespace {
92 
93 void lclUpdateProgressBar( const ISegmentProgressBarRef& rxProgressBar, double fPosition )
94 {
95  if( rxProgressBar )
96  rxProgressBar->setPosition( fPosition );
97 }
98 
99 // TODO Needed because input might be >32-bit (in 64-bit builds),
100 // or a negative, already overflown value (in 32-bit builds)
101 sal_Int32 lclClampToNonNegativeInt32( tools::Long aVal )
102 {
103  if ( aVal > SAL_MAX_INT32 || aVal < 0 )
104  {
105  SAL_WARN( "sc.filter", "Overflow detected, " << aVal << " does not fit into sal_Int32, or is negative." );
106  return SAL_MAX_INT32;
107  }
108  return static_cast<sal_Int32>( aVal );
109 }
110 
111 } // namespace
112 
114  maRange( -1 ),
115  mfWidth( 0.0 ),
116  mnXfId( -1 ),
117  mnLevel( 0 ),
118  mbShowPhonetic( false ),
119  mbHidden( false ),
120  mbCollapsed( false )
121 {
122 }
123 
124 bool ColumnModel::isMergeable( const ColumnModel& rModel ) const
125 {
126  return
127  (maRange.mnFirst <= rModel.maRange.mnFirst) &&
128  (rModel.maRange.mnFirst <= maRange.mnLast + 1) &&
129  (mfWidth == rModel.mfWidth) &&
130  // ignore mnXfId, cell formatting is always set directly
131  (mnLevel == rModel.mnLevel) &&
132  (mbHidden == rModel.mbHidden) &&
133  (mbCollapsed == rModel.mbCollapsed);
134 }
135 
137  mnRow( -1 ),
138  mfHeight( 0.0 ),
139  mnXfId( -1 ),
140  mnLevel( 0 ),
141  mbCustomHeight( false ),
142  mbCustomFormat( false ),
143  mbShowPhonetic( false ),
144  mbHidden( false ),
145  mbCollapsed( false ),
146  mbThickTop( false ),
147  mbThickBottom( false )
148 {
149 }
150 
151 void RowModel::insertColSpan( const ValueRange& rColSpan )
152 {
153  if( (0 <= rColSpan.mnFirst) && (rColSpan.mnFirst <= rColSpan.mnLast) )
154  maColSpans.insert( rColSpan );
155 }
156 
157 bool RowModel::isMergeable( const RowModel& rModel ) const
158 {
159  return
160  // ignore maColSpans - is handled separately in SheetDataBuffer class
161  (mfHeight == rModel.mfHeight) &&
162  // ignore mnXfId, mbCustomFormat, mbShowPhonetic - cell formatting is always set directly
163  (mnLevel == rModel.mnLevel) &&
164  (mbCustomHeight == rModel.mbCustomHeight) &&
165  (mbHidden == rModel.mbHidden) &&
166  (mbCollapsed == rModel.mbCollapsed);
167 }
168 
170  : mnColRow(0)
171  , mnMin(0)
172  , mnMax(0)
173  , mbManual(false)
174 {
175 }
176 
178 {
179 }
180 
182  mnType( XML_none ),
183  mnOperator( XML_between ),
184  mnErrorStyle( XML_stop ),
185  mbShowInputMsg( false ),
186  mbShowErrorMsg( false ),
187  mbNoDropDown( false ),
188  mbAllowBlank( false )
189 {
190 }
191 
193 {
194  static const sal_Int32 spnTypeIds[] = {
195  XML_none, XML_whole, XML_decimal, XML_list, XML_date, XML_time, XML_textLength, XML_custom };
196  mnType = STATIC_ARRAY_SELECT( spnTypeIds, nType, XML_none );
197 }
198 
200 {
201  static const sal_Int32 spnOperators[] = {
202  XML_between, XML_notBetween, XML_equal, XML_notEqual,
203  XML_greaterThan, XML_lessThan, XML_greaterThanOrEqual, XML_lessThanOrEqual };
204  mnOperator = STATIC_ARRAY_SELECT( spnOperators, nOperator, XML_TOKEN_INVALID );
205 }
206 
208 {
209  static const sal_Int32 spnErrorStyles[] = { XML_stop, XML_warning, XML_information };
210  mnErrorStyle = STATIC_ARRAY_SELECT( spnErrorStyles, nErrorStyle, XML_stop );
211 }
212 
214 {
215 public:
216  explicit WorksheetGlobals(
217  const WorkbookHelper& rHelper,
218  const ISegmentProgressBarRef& rxProgressBar,
219  WorksheetType eSheetType,
220  SCTAB nSheet );
221 
223  bool isValidSheet() const { return mxSheet.is(); }
224 
228  SCTAB getSheetIndex() const { return maUsedArea.aStart.Tab(); }
230  const Reference< XSpreadsheet >& getSheet() const { return mxSheet; }
231 
233  Reference< XCell > getCell( const ScAddress& rAddress ) const;
235  Reference< XCellRange > getCellRange( const ScRange& rRange ) const;
237  Reference< XSheetCellRanges > getCellRangeList( const ScRangeList& rRanges ) const;
238 
240  Reference< XCellRange > getColumn( sal_Int32 nCol ) const;
242  Reference< XCellRange > getRow( sal_Int32 nRow ) const;
243 
245  Reference< XDrawPage > getDrawPage() const;
247  const awt::Size& getDrawPageSize() const;
248 
250  awt::Point getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const;
251 
253  ScAddress getCellAddressFromPosition( const awt::Point& rPosition ) const;
255  ScRange getCellRangeFromRectangle( const awt::Rectangle& rRect ) const;
256 
276  ExtLst& getExtLst() { return maExtLst; }
277 
279  void setPageBreak( const PageBreakModel& rModel, bool bRowBreak );
281  void setHyperlink( const HyperlinkModel& rModel );
283  void setValidation( const ValidationModel& rModel );
285  void setDrawingPath( const OUString& rDrawingPath );
287  void setVmlDrawingPath( const OUString& rVmlDrawingPath );
288 
290  void extendUsedArea( const ScAddress& rAddress );
291 
293  void extendUsedArea( const ScRange& rRange );
295  void extendShapeBoundingBox( const awt::Rectangle& rShapeRect );
296 
299  void setBaseColumnWidth( sal_Int32 nWidth );
302  void setDefaultColumnWidth( double fWidth );
306  void setColumnModel( const ColumnModel& rModel );
308  void convertColumnFormat( sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId );
309 
311  void setDefaultRowSettings( double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom );
315  void setRowModel( const RowModel& rModel );
316 
321 
322  void finalizeDrawingImport();
323 
326  {
327  return mxRowProgress;
328  }
329  virtual void setCustomRowProgress( const ISegmentProgressBarRef &rxRowProgress ) override
330  {
331  mxRowProgress = rxRowProgress;
332  mbFastRowProgress = true;
333  }
334 
335 private:
336  typedef ::std::vector< sal_Int32 > OutlineLevelVec;
337  typedef ::std::pair< ColumnModel, sal_Int32 > ColumnModelRange;
338  typedef ::std::map< sal_Int32, ColumnModelRange > ColumnModelRangeMap;
339  typedef ::std::pair< RowModel, sal_Int32 > RowModelRange;
340  typedef ::std::map< sal_Int32, RowModelRange > RowModelRangeMap;
341 
345  OUString getHyperlinkUrl( const HyperlinkModel& rHyperlink ) const;
347  void insertHyperlink( const ScAddress& rAddress, const OUString& rUrl );
348 
350  void finalizeValidationRanges() const;
351 
353  void convertColumns();
355  void convertColumns( OutlineLevelVec& orColLevels, const ValueRange& rColRange, const ColumnModel& rModel );
356 
358  void convertRows(const std::vector<sc::ColRowSpan>& rSpans);
360  void convertRows(OutlineLevelVec& orRowLevels, const ValueRange& rRowRange,
361  const RowModel& rModel,
362  const std::vector<sc::ColRowSpan>& rSpans,
363  double fDefHeight = -1.0);
364 
366  void convertOutlines( OutlineLevelVec& orLevels, sal_Int32 nColRow, sal_Int32 nLevel, bool bCollapsed, bool bRows );
368  void groupColumnsOrRows( sal_Int32 nFirstColRow, sal_Int32 nLastColRow, bool bCollapsed, bool bRows );
369 
371  void finalizeDrawings();
372 
374  void UpdateRowProgress( const ScRange& rUsedArea, SCROW nRow );
375 
376 private:
377  typedef ::std::unique_ptr< VmlDrawing > VmlDrawingPtr;
378 
382  ColumnModelRangeMap maColModels;
384  RowModelRangeMap maRowModels;
385  std::vector< HyperlinkModel > maHyperlinks;
386  std::vector< ValidationModel > maValidations;
395  VmlDrawingPtr mxVmlDrawing;
397  OUString maDrawingPath;
398  OUString maVmlDrawingPath;
399  awt::Size maDrawPageSize;
400  awt::Rectangle maShapeBoundingBox;
406  Reference< XSpreadsheet > mxSheet;
408 };
409 
410 constexpr OUStringLiteral gaSheetCellRanges( u"com.sun.star.sheet.SheetCellRanges" );
411 
412 WorksheetGlobals::WorksheetGlobals( const WorkbookHelper& rHelper, const ISegmentProgressBarRef& rxProgressBar, WorksheetType eSheetType, SCTAB nSheet ) :
413  WorkbookHelper( rHelper ),
414  mrMaxApiPos( rHelper.getAddressConverter().getMaxApiAddress() ),
415  maUsedArea( SCCOL_MAX, SCROW_MAX, nSheet, -1, -1, nSheet ), // Set start address to largest possible value, and end address to smallest
416  maSheetData( *this ),
417  maCondFormats( *this ),
418  maComments( *this ),
419  maAutoFilters( *this ),
420  maQueryTables( *this ),
421  maSheetSett( *this ),
422  maPageSett( *this ),
423  maSheetViewSett( *this ),
424  mxProgressBar( rxProgressBar ),
425  mbFastRowProgress( false ),
426  meSheetType( eSheetType ),
427  mxSheet(getSheetFromDoc( nSheet )),
428  mbHasDefWidth( false )
429 {
430  if( !mxSheet.is() )
431  maUsedArea.aStart.SetTab( -1 );
432 
433  // default column settings (width and hidden state may be updated later)
434  maDefColModel.mfWidth = 8.5;
435  maDefColModel.mnXfId = -1;
437  maDefColModel.mbHidden = false;
438  maDefColModel.mbCollapsed = false;
439 
440  // default row settings (height and hidden state may be updated later)
441  maDefRowModel.mfHeight = 0.0;
442  maDefRowModel.mnXfId = -1;
447  maDefRowModel.mbHidden = false;
448  maDefRowModel.mbCollapsed = false;
449 
450  // buffers
451  mxVmlDrawing.reset( new VmlDrawing( *this ) );
452 
453  // prepare progress bars
454  if( mxProgressBar )
455  {
456  mxRowProgress = mxProgressBar->createSegment( 0.5 );
457  mxFinalProgress = mxProgressBar->createSegment( 0.5 );
458  }
459 }
460 
461 Reference< XCell > WorksheetGlobals::getCell( const ScAddress& rAddress ) const
462 {
463  Reference< XCell > xCell;
464  if( mxSheet.is() ) try
465  {
466  xCell = mxSheet->getCellByPosition( rAddress.Col(), rAddress.Row() );
467  }
468  catch( Exception& )
469  {
470  }
471  return xCell;
472 }
473 
474 Reference< XCellRange > WorksheetGlobals::getCellRange( const ScRange& rRange ) const
475 {
476  Reference< XCellRange > xRange;
477  if( mxSheet.is() ) try
478  {
479  xRange = mxSheet->getCellRangeByPosition( rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row() );
480  }
481  catch( Exception& )
482  {
483  }
484  return xRange;
485 }
486 
487 Reference< XSheetCellRanges > WorksheetGlobals::getCellRangeList( const ScRangeList& rRanges ) const
488 {
489  Reference< XSheetCellRanges > xRanges;
490  if( mxSheet.is() && !rRanges.empty() ) try
491  {
492  xRanges.set( getBaseFilter().getModelFactory()->createInstance( gaSheetCellRanges ), UNO_QUERY_THROW );
493  Reference< XSheetCellRangeContainer > xRangeCont( xRanges, UNO_QUERY_THROW );
494  xRangeCont->addRangeAddresses( AddressConverter::toApiSequence(rRanges), false );
495  }
496  catch( Exception& )
497  {
498  }
499  return xRanges;
500 }
501 
502 Reference< XCellRange > WorksheetGlobals::getColumn( sal_Int32 nCol ) const
503 {
504  Reference< XCellRange > xColumn;
505  try
506  {
507  Reference< XColumnRowRange > xColRowRange( mxSheet, UNO_QUERY_THROW );
508  Reference< XTableColumns > xColumns( xColRowRange->getColumns(), UNO_SET_THROW );
509  xColumn.set( xColumns->getByIndex( nCol ), UNO_QUERY );
510  }
511  catch( Exception& )
512  {
513  }
514  return xColumn;
515 }
516 
517 Reference< XCellRange > WorksheetGlobals::getRow( sal_Int32 nRow ) const
518 {
519  Reference< XCellRange > xRow;
520  try
521  {
522  Reference< XColumnRowRange > xColRowRange( mxSheet, UNO_QUERY_THROW );
523  Reference< XTableRows > xRows( xColRowRange->getRows(), UNO_SET_THROW );
524  xRow.set( xRows->getByIndex( nRow ), UNO_QUERY );
525  }
526  catch( Exception& )
527  {
528  }
529  return xRow;
530 }
531 
532 Reference< XDrawPage > WorksheetGlobals::getDrawPage() const
533 {
534  Reference< XDrawPage > xDrawPage;
535  try
536  {
537  xDrawPage = Reference< XDrawPageSupplier >( mxSheet, UNO_QUERY_THROW )->getDrawPage();
538  }
539  catch( Exception& )
540  {
541  }
542  return xDrawPage;
543 }
544 
545 const awt::Size& WorksheetGlobals::getDrawPageSize() const
546 {
547  OSL_ENSURE( (maDrawPageSize.Width > 0) && (maDrawPageSize.Height > 0), "WorksheetGlobals::getDrawPageSize - called too early, size invalid" );
548  return maDrawPageSize;
549 }
550 
551 awt::Point WorksheetGlobals::getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const
552 {
553  const tools::Rectangle aMMRect( getScDocument().GetMMRect( nCol, nRow, nCol, nRow, getSheetIndex() ) );
554  awt::Point aPoint( lclClampToNonNegativeInt32( aMMRect.Left() ),
555  lclClampToNonNegativeInt32( aMMRect.Top() ) );
556  return aPoint;
557 }
558 
559 namespace {
560 
561 sal_Int32 lclGetMidAddr( sal_Int32 nBegAddr, sal_Int32 nEndAddr, sal_Int32 nBegPos, sal_Int32 nEndPos, sal_Int32 nSearchPos )
562 {
563  // use sal_Int64 to prevent integer overflow
564  return nBegAddr + 1 + static_cast< sal_Int32 >( static_cast< sal_Int64 >( nEndAddr - nBegAddr - 2 ) * (nSearchPos - nBegPos) / (nEndPos - nBegPos) );
565 }
566 
567 bool lclPrepareInterval( sal_Int32 nBegAddr, sal_Int32& rnMidAddr, sal_Int32 nEndAddr,
568  sal_Int32 nBegPos, sal_Int32 nEndPos, sal_Int32 nSearchPos )
569 {
570  // searched position before nBegPos -> use nBegAddr
571  if( nSearchPos <= nBegPos )
572  {
573  rnMidAddr = nBegAddr;
574  return false;
575  }
576 
577  // searched position after nEndPos, or begin next to end -> use nEndAddr
578  if( (nSearchPos >= nEndPos) || (nBegAddr + 1 >= nEndAddr) )
579  {
580  rnMidAddr = nEndAddr;
581  return false;
582  }
583 
584  /* Otherwise find mid address according to position. lclGetMidAddr() will
585  return an address between nBegAddr and nEndAddr. */
586  rnMidAddr = lclGetMidAddr( nBegAddr, nEndAddr, nBegPos, nEndPos, nSearchPos );
587  return true;
588 }
589 
590 bool lclUpdateInterval( sal_Int32& rnBegAddr, sal_Int32& rnMidAddr, sal_Int32& rnEndAddr,
591  sal_Int32& rnBegPos, sal_Int32 nMidPos, sal_Int32& rnEndPos, sal_Int32 nSearchPos )
592 {
593  // nSearchPos < nMidPos: use the interval [begin,mid] in the next iteration
594  if( nSearchPos < nMidPos )
595  {
596  // if rnBegAddr is next to rnMidAddr, the latter is the column/row in question
597  if( rnBegAddr + 1 >= rnMidAddr )
598  return false;
599  // otherwise, set interval end to mid
600  rnEndPos = nMidPos;
601  rnEndAddr = rnMidAddr;
602  rnMidAddr = lclGetMidAddr( rnBegAddr, rnEndAddr, rnBegPos, rnEndPos, nSearchPos );
603  return true;
604  }
605 
606  // nSearchPos > nMidPos: use the interval [mid,end] in the next iteration
607  if( nSearchPos > nMidPos )
608  {
609  // if rnMidAddr is next to rnEndAddr, the latter is the column/row in question
610  if( rnMidAddr + 1 >= rnEndAddr )
611  {
612  rnMidAddr = rnEndAddr;
613  return false;
614  }
615  // otherwise, set interval start to mid
616  rnBegPos = nMidPos;
617  rnBegAddr = rnMidAddr;
618  rnMidAddr = lclGetMidAddr( rnBegAddr, rnEndAddr, rnBegPos, rnEndPos, nSearchPos );
619  return true;
620  }
621 
622  // nSearchPos == nMidPos: rnMidAddr is the column/row in question, do not loop anymore
623  return false;
624 }
625 
626 } // namespace
627 
628 ScAddress WorksheetGlobals::getCellAddressFromPosition( const awt::Point& rPosition ) const
629 {
630  // starting cell address and its position in drawing layer (top-left edge)
631  sal_Int32 nBegCol = 0;
632  sal_Int32 nBegRow = 0;
633  awt::Point aBegPos( 0, 0 );
634 
635  // end cell address and its position in drawing layer (bottom-right edge)
636  sal_Int32 nEndCol = mrMaxApiPos.Col() + 1;
637  sal_Int32 nEndRow = mrMaxApiPos.Row() + 1;
638  awt::Point aEndPos( maDrawPageSize.Width, maDrawPageSize.Height );
639 
640  // starting point for interval search
641  sal_Int32 nMidCol, nMidRow;
642  bool bLoopCols = lclPrepareInterval( nBegCol, nMidCol, nEndCol, aBegPos.X, aEndPos.X, rPosition.X );
643  bool bLoopRows = lclPrepareInterval( nBegRow, nMidRow, nEndRow, aBegPos.Y, aEndPos.Y, rPosition.Y );
644  awt::Point aMidPos = getCellPosition( nMidCol, nMidRow );
645 
646  /* The loop will find the column/row index of the cell right of/below
647  the cell containing the passed point, unless the point is located at
648  the top or left border of the containing cell. */
649  while( bLoopCols || bLoopRows )
650  {
651  bLoopCols = bLoopCols && lclUpdateInterval( nBegCol, nMidCol, nEndCol, aBegPos.X, aMidPos.X, aEndPos.X, rPosition.X );
652  bLoopRows = bLoopRows && lclUpdateInterval( nBegRow, nMidRow, nEndRow, aBegPos.Y, aMidPos.Y, aEndPos.Y, rPosition.Y );
653  aMidPos = getCellPosition( nMidCol, nMidRow );
654  }
655 
656  /* The cell left of/above the current search position contains the passed
657  point, unless the point is located on the top/left border of the cell,
658  or the last column/row of the sheet has been reached. */
659  if( aMidPos.X > rPosition.X ) --nMidCol;
660  if( aMidPos.Y > rPosition.Y ) --nMidRow;
661  return ScAddress( nMidCol, nMidRow, getSheetIndex() );
662 }
663 
664 ScRange WorksheetGlobals::getCellRangeFromRectangle( const awt::Rectangle& rRect ) const
665 {
666  ScAddress aStartAddr = getCellAddressFromPosition( awt::Point( rRect.X, rRect.Y ) );
667  awt::Point aBotRight( rRect.X + rRect.Width, rRect.Y + rRect.Height );
668  ScAddress aEndAddr = getCellAddressFromPosition( aBotRight );
669  bool bMultiCols = aStartAddr.Col() < aEndAddr.Col();
670  bool bMultiRows = aStartAddr.Row() < aEndAddr.Row();
671  if( bMultiCols || bMultiRows )
672  {
673  /* Reduce end position of the cell range to previous column or row, if
674  the rectangle ends exactly between two columns or rows. */
675  awt::Point aEndPos = getCellPosition( aEndAddr.Col(), aEndAddr.Row() );
676  if( bMultiCols && (aBotRight.X <= aEndPos.X) )
677  aEndAddr.IncCol(-1);
678  if( bMultiRows && (aBotRight.Y <= aEndPos.Y) )
679  aEndAddr.IncRow(-1);
680  }
681  return ScRange( aStartAddr.Col(), aStartAddr.Row(), getSheetIndex(),
682  aEndAddr.Col(), aEndAddr.Row(), getSheetIndex() );
683 }
684 
685 void WorksheetGlobals::setPageBreak( const PageBreakModel& rModel, bool bRowBreak )
686 {
687  if( rModel.mbManual && (rModel.mnColRow > 0) )
688  {
689  PropertySet aPropSet( bRowBreak ? getRow( rModel.mnColRow ) : getColumn( rModel.mnColRow ) );
690  aPropSet.setProperty( PROP_IsStartOfNewPage, true );
691  }
692 }
693 
695 {
696  maHyperlinks.push_back( rModel );
697 }
698 
700 {
701  maValidations.push_back( rModel );
702 }
703 
704 void WorksheetGlobals::setDrawingPath( const OUString& rDrawingPath )
705 {
706  maDrawingPath = rDrawingPath;
707 }
708 
709 void WorksheetGlobals::setVmlDrawingPath( const OUString& rVmlDrawingPath )
710 {
711  maVmlDrawingPath = rVmlDrawingPath;
712 }
713 
715 {
716  maUsedArea.aStart.SetCol( ::std::min( maUsedArea.aStart.Col(), rAddress.Col() ) );
717  maUsedArea.aStart.SetRow( ::std::min( maUsedArea.aStart.Row(), rAddress.Row() ) );
718  maUsedArea.aEnd.SetCol( ::std::max( maUsedArea.aEnd.Col(), rAddress.Col() ) );
719  maUsedArea.aEnd.SetRow( ::std::max( maUsedArea.aEnd.Row(), rAddress.Row() ) );
720 }
721 
723 {
724  extendUsedArea( rRange.aStart );
725  extendUsedArea( rRange.aEnd );
726 }
727 
729 {
730  extendUsedArea( rRange.aStart );
731  extendUsedArea( rRange.aEnd );
732 }
733 
734 void WorksheetGlobals::extendShapeBoundingBox( const awt::Rectangle& rShapeRect )
735 {
736  if( (maShapeBoundingBox.Width == 0) && (maShapeBoundingBox.Height == 0) )
737  {
738  // width and height of maShapeBoundingBox are assumed to be zero on first cell
739  maShapeBoundingBox = rShapeRect;
740  }
741  else
742  {
743  sal_Int32 nEndX = ::std::max( maShapeBoundingBox.X + maShapeBoundingBox.Width, rShapeRect.X + rShapeRect.Width );
744  sal_Int32 nEndY = ::std::max( maShapeBoundingBox.Y + maShapeBoundingBox.Height, rShapeRect.Y + rShapeRect.Height );
745  maShapeBoundingBox.X = ::std::min( maShapeBoundingBox.X, rShapeRect.X );
746  maShapeBoundingBox.Y = ::std::min( maShapeBoundingBox.Y, rShapeRect.Y );
747  maShapeBoundingBox.Width = nEndX - maShapeBoundingBox.X;
748  maShapeBoundingBox.Height = nEndY - maShapeBoundingBox.Y;
749  }
750 }
751 
752 void WorksheetGlobals::setBaseColumnWidth( sal_Int32 nWidth )
753 {
754  // do not modify width, if setDefaultColumnWidth() has been used
755  if( !mbHasDefWidth && (nWidth > 0) )
756  {
757  // #i3006# add 5 pixels padding to the width
759  }
760 }
761 
763 {
764  // overrides a width set with setBaseColumnWidth()
765  if( fWidth > 0.0 )
766  {
767  maDefColModel.mfWidth = fWidth;
768  mbHasDefWidth = true;
769  }
770 }
771 
773 {
774  // convert 1-based OOXML column indexes to 0-based API column indexes
775  sal_Int32 nFirstCol = rModel.maRange.mnFirst - 1;
776  sal_Int32 nLastCol = rModel.maRange.mnLast - 1;
777  if( !(getAddressConverter().checkCol( nFirstCol, true ) && (nFirstCol <= nLastCol)) )
778  return;
779 
780  // Validate last column index.
781  // If last column is equal to last possible column, Excel adds one
782  // more. We do that also in XclExpColinfo::SaveXml() and for 1024 end
783  // up with 1025 instead, which would lead to excess columns in
784  // checkCol(). Cater for this oddity.
785  if (nLastCol == mrMaxApiPos.Col() + 1)
786  --nLastCol;
787  // This is totally fouled up. If we saved 1025 and the file is saved
788  // with Excel again, it increments the value to 1026.
789  else if (nLastCol == mrMaxApiPos.Col() + 2)
790  nLastCol -= 2;
791  // Excel may add a column range for the remaining columns (with
792  // <cols><col .../></cols>), even if not used or only used to grey out
793  // columns in page break view. Don't let that trigger overflow warning,
794  // so check for the last possible column. If there really is content in
795  // the range that should be caught anyway.
796  else if (nLastCol == getAddressConverter().getMaxXlsAddress().Col())
797  nLastCol = mrMaxApiPos.Col();
798  // User may have applied custom column widths to arbitrary excess
799  // columns. Ignore those and don't track as overflow columns (false).
800  // Effectively this does the same as the above cases, just keep them
801  // for explanation.
802  // Actual data present should trigger the overflow detection later.
803  else if( !getAddressConverter().checkCol( nLastCol, false ) )
804  nLastCol = mrMaxApiPos.Col();
805  // try to find entry in column model map that is able to merge with the passed model
806  bool bInsertModel = true;
807  if( !maColModels.empty() )
808  {
809  // find first column model range following nFirstCol (nFirstCol < aIt->first), or end of map
810  ColumnModelRangeMap::iterator aIt = maColModels.upper_bound( nFirstCol );
811  OSL_ENSURE( aIt == maColModels.end(), "WorksheetGlobals::setColModel - columns are unsorted" );
812  // if inserting before another column model, get last free column
813  OSL_ENSURE( (aIt == maColModels.end()) || (nLastCol < aIt->first), "WorksheetGlobals::setColModel - multiple models of the same column" );
814  if( aIt != maColModels.end() )
815  nLastCol = ::std::min( nLastCol, aIt->first - 1 );
816  if( aIt != maColModels.begin() )
817  {
818  // go to previous map element (which may be able to merge with the passed model)
819  --aIt;
820  // the usage of upper_bound() above ensures that aIt->first is less than or equal to nFirstCol now
821  sal_Int32& rnLastMapCol = aIt->second.second;
822  OSL_ENSURE( rnLastMapCol < nFirstCol, "WorksheetGlobals::setColModel - multiple models of the same column" );
823  nFirstCol = ::std::max( rnLastMapCol + 1, nFirstCol );
824  if( (rnLastMapCol + 1 == nFirstCol) && (nFirstCol <= nLastCol) && aIt->second.first.isMergeable( rModel ) )
825  {
826  // can merge with existing model, update last column index
827  rnLastMapCol = nLastCol;
828  bInsertModel = false;
829  }
830  }
831  }
832  if( nFirstCol <= nLastCol )
833  {
834  // insert the column model, if it has not been merged with another
835  if( bInsertModel )
836  maColModels[ nFirstCol ] = ColumnModelRange( rModel, nLastCol );
837  // set column formatting directly
838  convertColumnFormat( nFirstCol, nLastCol, rModel.mnXfId );
839  }
840 }
841 
842 void WorksheetGlobals::convertColumnFormat( sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId )
843 {
844  ScRange aRange( nFirstCol, 0, getSheetIndex(), nLastCol, mrMaxApiPos.Row(), getSheetIndex() );
845  if( getAddressConverter().validateCellRange( aRange, true, false ) )
846  {
847  const StylesBuffer& rStyles = getStyles();
848 
849  // Set cell styles via direct API - the preferred approach.
850  ScDocumentImport& rDoc = getDocImport();
851  rStyles.writeCellXfToDoc(rDoc, aRange, nXfId);
852  }
853 }
854 
855 void WorksheetGlobals::setDefaultRowSettings( double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom )
856 {
857  maDefRowModel.mfHeight = fHeight;
858  maDefRowModel.mbCustomHeight = bCustomHeight;
859  maDefRowModel.mbHidden = bHidden;
860  maDefRowModel.mbThickTop = bThickTop;
861  maDefRowModel.mbThickBottom = bThickBottom;
862 }
863 
865 {
866  // convert 1-based OOXML row index to 0-based API row index
867  sal_Int32 nRow = rModel.mnRow - 1;
868  if( getAddressConverter().checkRow( nRow, true ) )
869  {
870  // try to find entry in row model map that is able to merge with the passed model
871  bool bInsertModel = true;
872  bool bUnusedRow = true;
873  if( !maRowModels.empty() )
874  {
875  // find first row model range following nRow (nRow < aIt->first), or end of map
876  RowModelRangeMap::iterator aIt = maRowModels.upper_bound( nRow );
877  OSL_ENSURE( aIt == maRowModels.end(), "WorksheetGlobals::setRowModel - rows are unsorted" );
878  if( aIt != maRowModels.begin() )
879  {
880  // go to previous map element (which may be able to merge with the passed model)
881  --aIt;
882  // the usage of upper_bound() above ensures that aIt->first is less than or equal to nRow now
883  sal_Int32& rnLastMapRow = aIt->second.second;
884  bUnusedRow = rnLastMapRow < nRow;
885  OSL_ENSURE( bUnusedRow, "WorksheetGlobals::setRowModel - multiple models of the same row" );
886  if( (rnLastMapRow + 1 == nRow) && aIt->second.first.isMergeable( rModel ) )
887  {
888  // can merge with existing model, update last row index
889  ++rnLastMapRow;
890  bInsertModel = false;
891  }
892  }
893  }
894  if( bUnusedRow )
895  {
896  // insert the row model, if it has not been merged with another
897  if( bInsertModel )
898  maRowModels[ nRow ] = RowModelRange( rModel, nRow );
899  // set row formatting
900  maSheetData.setRowFormat( nRow, rModel.mnXfId, rModel.mbCustomFormat );
901  // set column spans
902  maSheetData.setColSpans( nRow, rModel.maColSpans );
903  }
904  }
905 
906  UpdateRowProgress( maUsedArea, nRow );
907 }
908 
909 // This is called at a higher frequency inside the (threaded) inner loop.
910 void WorksheetGlobals::UpdateRowProgress( const ScRange& rUsedArea, SCROW nRow )
911 {
912  if (!mxRowProgress || nRow < rUsedArea.aStart.Row() || rUsedArea.aEnd.Row() < nRow)
913  return;
914 
915  double fNewPos = static_cast<double>(nRow - rUsedArea.aStart.Row() + 1.0) / (rUsedArea.aEnd.Row() - rUsedArea.aStart.Row() + 1.0);
916 
917  if (mbFastRowProgress)
918  mxRowProgress->setPosition(fNewPos);
919  else
920  {
921  double fCurPos = mxRowProgress->getPosition();
922  if (fCurPos < fNewPos && (fNewPos - fCurPos) > 0.3)
923  // Try not to re-draw progress bar too frequently.
924  mxRowProgress->setPosition(fNewPos);
925  }
926 }
927 
929 {
930  // set default cell style for unused cells
931  ScDocumentImport& rDoc = getDocImport();
932 
933  ScStyleSheet* pStyleSheet =
934  static_cast<ScStyleSheet*>(rDoc.getDoc().GetStyleSheetPool()->Find(
935  getStyles().getDefaultStyleName(), SfxStyleFamily::Para));
936 
937  if (pStyleSheet)
938  rDoc.setCellStyleToSheet(getSheetIndex(), *pStyleSheet);
939 
940  /* Remember the current sheet index in global data, needed by global
941  objects, e.g. the chart converter. */
943 }
944 
946 {
947  lclUpdateProgressBar( mxRowProgress, 1.0 );
949  // assumes getTables().finalizeImport ( which creates the DatabaseRanges )
950  // has been called already
952 
954  lclUpdateProgressBar( mxFinalProgress, 0.25 );
962 
963  lclUpdateProgressBar( mxFinalProgress, 0.5 );
964  convertColumns();
965 
966  // tdf#99913 rows hidden by filter need extra flag
967  ScDocument& rDoc = getScDocument();
968  std::vector<sc::ColRowSpan> aSpans;
969  SCTAB nTab = getSheetIndex();
970  ScDBData* pDBData = rDoc.GetAnonymousDBData(nTab);
971  if (pDBData && pDBData->HasAutoFilter())
972  {
973  ScRange aRange;
974  pDBData->GetArea(aRange);
975  SCCOLROW nStartRow = static_cast<SCCOLROW>(aRange.aStart.Row());
976  SCCOLROW nEndRow = static_cast<SCCOLROW>(aRange.aEnd.Row());
977  aSpans.push_back(sc::ColRowSpan(nStartRow, nEndRow));
978  }
979  ScDBCollection* pDocColl = rDoc.GetDBCollection();
980  if (!pDocColl->empty())
981  {
982  ScDBCollection::NamedDBs& rDBs = pDocColl->getNamedDBs();
983  for (const auto& rxDB : rDBs)
984  {
985  if (rxDB->GetTab() == nTab && rxDB->HasAutoFilter())
986  {
987  ScRange aRange;
988  rxDB->GetArea(aRange);
989  SCCOLROW nStartRow = static_cast<SCCOLROW>(aRange.aStart.Row());
990  SCCOLROW nEndRow = static_cast<SCCOLROW>(aRange.aEnd.Row());
991  aSpans.push_back(sc::ColRowSpan(nStartRow, nEndRow));
992  }
993  }
994  }
995  convertRows(aSpans);
996  lclUpdateProgressBar( mxFinalProgress, 1.0 );
997 }
998 
1000 {
1001  finalizeDrawings();
1002 
1003  // forget current sheet index in global data
1004  setCurrentSheetIndex( -1 );
1005 }
1006 
1007 // private --------------------------------------------------------------------
1008 
1010 {
1011  for (auto const& link : maHyperlinks)
1012  {
1013  OUString aUrl = getHyperlinkUrl(link);
1014  // try to insert URL into each cell of the range
1015  if( !aUrl.isEmpty() )
1016  for( ScAddress aAddress(link.maRange.aStart.Col(), link.maRange.aStart.Row(), getSheetIndex() ); aAddress.Row() <= link.maRange.aEnd.Row(); aAddress.IncRow() )
1017  for( aAddress.SetCol(link.maRange.aStart.Col()); aAddress.Col() <= link.maRange.aEnd.Col(); aAddress.IncCol() )
1018  insertHyperlink( aAddress, aUrl );
1019  }
1020 }
1021 
1022 OUString WorksheetGlobals::getHyperlinkUrl( const HyperlinkModel& rHyperlink ) const
1023 {
1024  OUStringBuffer aUrlBuffer;
1025  if( !rHyperlink.maTarget.isEmpty() )
1026  aUrlBuffer.append( getBaseFilter().getAbsoluteUrl( rHyperlink.maTarget ) );
1027  if( !rHyperlink.maLocation.isEmpty() )
1028  aUrlBuffer.append( '#' ).append( rHyperlink.maLocation );
1029  OUString aUrl = aUrlBuffer.makeStringAndClear();
1030 
1031  if( aUrl.startsWith("#") )
1032  {
1033  sal_Int32 nSepPos = aUrl.lastIndexOf( '!' );
1034  if( nSepPos > 0 )
1035  {
1036  // Do not attempt to blindly convert '#SheetName!A1' to
1037  // '#SheetName.A1', it can be #SheetName!R1C1 as well. Hyperlink
1038  // handler has to handle all, but prefer '#SheetName.A1' if
1039  // possible.
1040  if (nSepPos < aUrl.getLength() - 1)
1041  {
1042  ScRange aRange;
1043  const ScDocumentImport& rDoc = getDocImport();
1044  if ((aRange.ParseAny( aUrl.copy( nSepPos + 1 ), rDoc.getDoc(),
1047  aUrl = aUrl.replaceAt( nSepPos, 1, rtl::OUStringChar( '.' ) );
1048  }
1049  // #i66592# convert sheet names that have been renamed on import
1050  OUString aSheetName = aUrl.copy( 1, nSepPos - 1 );
1051  OUString aCalcName = getWorksheets().getCalcSheetName( aSheetName );
1052  if( !aCalcName.isEmpty() )
1053  aUrl = aUrl.replaceAt( 1, nSepPos - 1, aCalcName );
1054  }
1055  }
1056 
1057  return aUrl;
1058 }
1059 
1060 void WorksheetGlobals::insertHyperlink( const ScAddress& rAddress, const OUString& rUrl )
1061 {
1062  ScDocumentImport& rDoc = getDocImport();
1063  ScRefCellValue aCell(rDoc.getDoc(), rAddress);
1064 
1065  if (aCell.meType == CELLTYPE_STRING || aCell.meType == CELLTYPE_EDIT)
1066  {
1067  OUString aStr = aCell.getString(&rDoc.getDoc());
1068  ScFieldEditEngine& rEE = rDoc.getDoc().GetEditEngine();
1069  rEE.Clear();
1070 
1071  SvxURLField aURLField(rUrl, aStr, SvxURLFormat::Repr);
1072  SvxFieldItem aURLItem(aURLField, EE_FEATURE_FIELD);
1073  rEE.QuickInsertField(aURLItem, ESelection());
1074 
1075  rDoc.setEditCell(rAddress, rEE.CreateTextObject());
1076  }
1077  else
1078  {
1079  // Handle other cell types e.g. formulas ( and ? ) that have associated
1080  // hyperlinks.
1081  // Ideally all hyperlinks should be treated as below. For the moment,
1082  // given the current absence of ods support lets just handle what we
1083  // previously didn't handle the new way.
1084  // Unfortunately we won't be able to preserve such hyperlinks when
1085  // saving to ods. Note: when we are able to save such hyperlinks to ods
1086  // we should handle *all* imported hyperlinks as below ( e.g. as cell
1087  // attribute ) for better interoperability.
1088 
1089  SfxStringItem aItem(ATTR_HYPERLINK, rUrl);
1090  rDoc.getDoc().ApplyAttr(rAddress.Col(), rAddress.Row(), rAddress.Tab(), aItem);
1091  }
1092 }
1093 
1095 {
1096  for (auto const& validation : maValidations)
1097  {
1098  PropertySet aPropSet( getCellRangeList(validation.maRanges) );
1099 
1100  Reference< XPropertySet > xValidation( aPropSet.getAnyProperty( PROP_Validation ), UNO_QUERY );
1101  if( xValidation.is() )
1102  {
1103  PropertySet aValProps( xValidation );
1104 
1105  try
1106  {
1107  const OUString aToken = validation.msRef.getToken( 0, ' ' );
1108 
1109  Reference<XSpreadsheet> xSheet = getSheetFromDoc( getCurrentSheetIndex() );
1110  Reference<XCellRange> xDBCellRange;
1111  Reference<XCell> xCell;
1112  xDBCellRange = xSheet->getCellRangeByName( aToken );
1113 
1114  xCell = xDBCellRange->getCellByPosition( 0, 0 );
1115  Reference<XCellAddressable> xCellAddressable( xCell, UNO_QUERY_THROW );
1116  CellAddress aFirstCell = xCellAddressable->getCellAddress();
1117  Reference<XSheetCondition> xCondition( xValidation, UNO_QUERY_THROW );
1118  xCondition->setSourcePosition( aFirstCell );
1119  }
1120  catch(const Exception&)
1121  {
1122  }
1123 
1124  // convert validation type to API enum
1125  ValidationType eType = ValidationType_ANY;
1126  switch( validation.mnType )
1127  {
1128  case XML_custom: eType = ValidationType_CUSTOM; break;
1129  case XML_date: eType = ValidationType_DATE; break;
1130  case XML_decimal: eType = ValidationType_DECIMAL; break;
1131  case XML_list: eType = ValidationType_LIST; break;
1132  case XML_none: eType = ValidationType_ANY; break;
1133  case XML_textLength: eType = ValidationType_TEXT_LEN; break;
1134  case XML_time: eType = ValidationType_TIME; break;
1135  case XML_whole: eType = ValidationType_WHOLE; break;
1136  default: OSL_FAIL( "WorksheetData::finalizeValidationRanges - unknown validation type" );
1137  }
1138  aValProps.setProperty( PROP_Type, eType );
1139 
1140  // convert error alert style to API enum
1141  ValidationAlertStyle eAlertStyle = ValidationAlertStyle_STOP;
1142  switch( validation.mnErrorStyle )
1143  {
1144  case XML_information: eAlertStyle = ValidationAlertStyle_INFO; break;
1145  case XML_stop: eAlertStyle = ValidationAlertStyle_STOP; break;
1146  case XML_warning: eAlertStyle = ValidationAlertStyle_WARNING; break;
1147  default: OSL_FAIL( "WorksheetData::finalizeValidationRanges - unknown error style" );
1148  }
1149  aValProps.setProperty( PROP_ErrorAlertStyle, eAlertStyle );
1150 
1151  // convert dropdown style to API visibility constants
1152  sal_Int16 nVisibility = validation.mbNoDropDown ? TableValidationVisibility::INVISIBLE : TableValidationVisibility::UNSORTED;
1153  aValProps.setProperty( PROP_ShowList, nVisibility );
1154 
1155  // messages
1156  aValProps.setProperty( PROP_ShowInputMessage, validation.mbShowInputMsg );
1157  aValProps.setProperty( PROP_InputTitle, validation.maInputTitle );
1158  aValProps.setProperty( PROP_InputMessage, validation.maInputMessage );
1159  aValProps.setProperty( PROP_ShowErrorMessage, validation.mbShowErrorMsg );
1160  aValProps.setProperty( PROP_ErrorTitle, validation.maErrorTitle );
1161  aValProps.setProperty( PROP_ErrorMessage, validation.maErrorMessage );
1162 
1163  // allow blank cells
1164  aValProps.setProperty( PROP_IgnoreBlankCells, validation.mbAllowBlank );
1165 
1166  try
1167  {
1168  // condition operator
1169  Reference< XSheetCondition2 > xSheetCond( xValidation, UNO_QUERY_THROW );
1170  if( eType == ValidationType_CUSTOM )
1171  xSheetCond->setConditionOperator( ConditionOperator2::FORMULA );
1172  else
1173  xSheetCond->setConditionOperator( CondFormatBuffer::convertToApiOperator( validation.mnOperator ) );
1174 
1175  // condition formulas
1176  Reference< XMultiFormulaTokens > xTokens( xValidation, UNO_QUERY_THROW );
1177  xTokens->setTokens( 0, validation.maTokens1 );
1178  xTokens->setTokens( 1, validation.maTokens2 );
1179  }
1180  catch( Exception& )
1181  {
1182  }
1183 
1184  // write back validation settings to cell range(s)
1185  aPropSet.setProperty( PROP_Validation, xValidation );
1186  }
1187  }
1188 }
1189 
1191 {
1192  sal_Int32 nNextCol = 0;
1193  sal_Int32 nMaxCol = mrMaxApiPos.Col();
1194  // stores first grouped column index for each level
1195  OutlineLevelVec aColLevels;
1196 
1197  for (auto const& colModel : maColModels)
1198  {
1199  // column indexes are stored 0-based in maColModels
1200  ValueRange aColRange( ::std::max( colModel.first, nNextCol ), ::std::min( colModel.second.second, nMaxCol ) );
1201  // process gap between two column models, use default column model
1202  if( nNextCol < aColRange.mnFirst )
1203  convertColumns( aColLevels, ValueRange( nNextCol, aColRange.mnFirst - 1 ), maDefColModel );
1204  // process the column model
1205  convertColumns( aColLevels, aColRange, colModel.second.first );
1206  // cache next column to be processed
1207  nNextCol = aColRange.mnLast + 1;
1208  }
1209 
1210  // remaining default columns to end of sheet
1211  convertColumns( aColLevels, ValueRange( nNextCol, nMaxCol ), maDefColModel );
1212  // close remaining column outlines spanning to end of sheet
1213  convertOutlines( aColLevels, nMaxCol + 1, 0, false, false );
1214 }
1215 
1217  const ValueRange& rColRange, const ColumnModel& rModel )
1218 {
1219  // column width: convert 'number of characters' to column width in twips
1220  sal_Int32 nWidth = std::round(getUnitConverter().scaleValue( rModel.mfWidth, Unit::Digit, Unit::Twip ));
1221 
1222  SCTAB nTab = getSheetIndex();
1223  ScDocument& rDoc = getScDocument();
1224  SCCOL nStartCol = rColRange.mnFirst;
1225  SCCOL nEndCol = rColRange.mnLast;
1226 
1227  if( nWidth > 0 )
1228  {
1229  // macro sheets have double width
1231  nWidth *= 2;
1232 
1233  for( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
1234  {
1235  rDoc.SetColWidthOnly(nCol, nTab, nWidth);
1236  }
1237  }
1238 
1239  // hidden columns: TODO: #108683# hide columns later?
1240  if( rModel.mbHidden )
1241  {
1242  rDoc.SetColHidden( nStartCol, nEndCol, nTab, true );
1243  }
1244 
1245  // outline settings for this column range
1246  convertOutlines( orColLevels, rColRange.mnFirst, rModel.mnLevel, rModel.mbCollapsed, false );
1247 }
1248 
1249 void WorksheetGlobals::convertRows(const std::vector<sc::ColRowSpan>& rSpans)
1250 {
1251  sal_Int32 nNextRow = 0;
1252  sal_Int32 nMaxRow = mrMaxApiPos.Row();
1253  // stores first grouped row index for each level
1254  OutlineLevelVec aRowLevels;
1255 
1256  for (auto const& rowModel : maRowModels)
1257  {
1258  // row indexes are stored 0-based in maRowModels
1259  ValueRange aRowRange( ::std::max( rowModel.first, nNextRow ), ::std::min( rowModel.second.second, nMaxRow ) );
1260  // process gap between two row models, use default row model
1261  if( nNextRow < aRowRange.mnFirst )
1262  convertRows(aRowLevels, ValueRange(nNextRow, aRowRange.mnFirst - 1), maDefRowModel,
1263  rSpans);
1264  // process the row model
1265  convertRows(aRowLevels, aRowRange, rowModel.second.first, rSpans, maDefRowModel.mfHeight);
1266  // cache next row to be processed
1267  nNextRow = aRowRange.mnLast + 1;
1268  }
1269 
1270  // remaining default rows to end of sheet
1271  convertRows(aRowLevels, ValueRange(nNextRow, nMaxRow), maDefRowModel, rSpans);
1272  // close remaining row outlines spanning to end of sheet
1273  convertOutlines( aRowLevels, nMaxRow + 1, 0, false, true );
1274 }
1275 
1276 void WorksheetGlobals::convertRows(OutlineLevelVec& orRowLevels, const ValueRange& rRowRange,
1277  const RowModel& rModel,
1278  const std::vector<sc::ColRowSpan>& rSpans, double fDefHeight)
1279 {
1280  // row height: convert points to row height in twips
1281  double fHeight = (rModel.mfHeight >= 0.0) ? rModel.mfHeight : fDefHeight;
1282  sal_Int32 nHeight = std::round(o3tl::toTwips( fHeight, o3tl::Length::pt ));
1283  SCROW nStartRow = rRowRange.mnFirst;
1284  SCROW nEndRow = rRowRange.mnLast;
1285  SCTAB nTab = getSheetIndex();
1286  if( nHeight > 0 )
1287  {
1288  /* always import the row height, ensures better layout */
1289  ScDocument& rDoc = getScDocument();
1290  rDoc.SetRowHeightOnly(nStartRow, nEndRow, nTab, nHeight);
1291  if(rModel.mbCustomHeight)
1292  rDoc.SetManualHeight( nStartRow, nEndRow, nTab, true );
1293  }
1294 
1295  // hidden rows: TODO: #108683# hide rows later?
1296  if( rModel.mbHidden )
1297  {
1298  ScDocument& rDoc = getScDocument();
1299  rDoc.SetRowHidden( nStartRow, nEndRow, nTab, true );
1300  for (const auto& rSpan : rSpans)
1301  {
1302  // tdf#99913 rows hidden by filter need extra flag
1303  if (rSpan.mnStart <= nStartRow && nStartRow <= rSpan.mnEnd)
1304  {
1305  SCROW nLast = ::std::min(nEndRow, rSpan.mnEnd);
1306  rDoc.SetRowFiltered(nStartRow, nLast, nTab, true);
1307  break;
1308  }
1309  }
1310  }
1311 
1312  // outline settings for this row range
1313  convertOutlines( orRowLevels, rRowRange.mnFirst, rModel.mnLevel, rModel.mbCollapsed, true );
1314 }
1315 
1317  sal_Int32 nColRow, sal_Int32 nLevel, bool bCollapsed, bool bRows )
1318 {
1319  /* It is ensured from caller functions, that this function is called
1320  without any gaps between the processed column or row ranges. */
1321 
1322  OSL_ENSURE( nLevel >= 0, "WorksheetGlobals::convertOutlines - negative outline level" );
1323  nLevel = ::std::max< sal_Int32 >( nLevel, 0 );
1324 
1325  sal_Int32 nSize = orLevels.size();
1326  if( nSize < nLevel )
1327  {
1328  // Outline level increased. Push the begin column position.
1329  orLevels.insert(orLevels.end(), nLevel - nSize, nColRow);
1330  }
1331  else if( nLevel < nSize )
1332  {
1333  // Outline level decreased. Pop them all out.
1334  for( sal_Int32 nIndex = nLevel; nIndex < nSize; ++nIndex )
1335  {
1336  sal_Int32 nFirstInLevel = orLevels.back();
1337  orLevels.pop_back();
1338  groupColumnsOrRows( nFirstInLevel, nColRow - 1, bCollapsed, bRows );
1339  bCollapsed = false; // collapse only once
1340  }
1341  }
1342 }
1343 
1344 void WorksheetGlobals::groupColumnsOrRows( sal_Int32 nFirstColRow, sal_Int32 nLastColRow, bool bCollapse, bool bRows )
1345 {
1346  try
1347  {
1348  Reference< XSheetOutline > xOutline( mxSheet, UNO_QUERY_THROW );
1349  if( bRows )
1350  {
1351  CellRangeAddress aRange( getSheetIndex(), 0, nFirstColRow, 0, nLastColRow );
1352  xOutline->group( aRange, TableOrientation_ROWS );
1353  if( bCollapse )
1354  xOutline->hideDetail( aRange );
1355  }
1356  else
1357  {
1358  CellRangeAddress aRange( getSheetIndex(), nFirstColRow, 0, nLastColRow, 0 );
1359  xOutline->group( aRange, TableOrientation_COLUMNS );
1360  if( bCollapse )
1361  xOutline->hideDetail( aRange );
1362  }
1363  }
1364  catch( Exception& )
1365  {
1366  }
1367 }
1368 
1370 {
1371  // calculate the current drawing page size (after rows/columns are imported)
1372  const Size aPageSize( getScDocument().GetMMRect( 0, 0, mrMaxApiPos.Col(), mrMaxApiPos.Row(), getSheetIndex() ).GetSize() );
1373  maDrawPageSize.Width = lclClampToNonNegativeInt32( aPageSize.Width() );
1374  maDrawPageSize.Height = lclClampToNonNegativeInt32( aPageSize.Height() );
1375 
1376  // import DML and VML
1377  if( !maDrawingPath.isEmpty() )
1379  if( !maVmlDrawingPath.isEmpty() )
1381 
1382  // comments (after callout shapes have been imported from VML/DFF)
1384 
1385  /* Extend used area of the sheet by cells covered with drawing objects.
1386  Needed if the imported document is inserted as "OLE object from file"
1387  and thus does not provide an OLE size property by itself. */
1388  if( (maShapeBoundingBox.Width > 0) || (maShapeBoundingBox.Height > 0) )
1390 
1391  // if no used area is set, default to A1
1392  if( maUsedArea.aStart.Col() > maUsedArea.aEnd.Col() )
1393  {
1394  maUsedArea.aStart.SetCol( 0 );
1395  maUsedArea.aEnd.SetCol( 0 );
1396  }
1397 
1398  if( maUsedArea.aStart.Row() > maUsedArea.aEnd.Row() )
1399  {
1400  maUsedArea.aStart.SetRow( 0 );
1401  maUsedArea.aEnd.SetRow( 0 );
1402  }
1403 
1404  /* Register the used area of this sheet in global view settings. The
1405  global view settings will set the visible area if this document is an
1406  embedded OLE object. */
1408 
1409  /* #i103686# Set right-to-left sheet layout. Must be done after all
1410  drawing shapes to simplify calculation of shape coordinates. */
1412  {
1413  PropertySet aPropSet( mxSheet );
1414  aPropSet.setProperty( PROP_TableLayout, WritingMode2::RL_TB );
1415  }
1416 }
1417 
1419  WorkbookHelper( rSheetGlob ),
1420  mrSheetGlob( rSheetGlob )
1421 {
1422 }
1423 
1425 {
1426  return getDocImport().getDoc();
1427 }
1428 
1430  const ISegmentProgressBarRef& rxProgressBar, WorksheetType eSheetType, SCTAB nSheet )
1431 {
1432  WorksheetGlobalsRef xSheetGlob = std::make_shared<WorksheetGlobals>( rHelper, rxProgressBar, eSheetType, nSheet );
1433  if( !xSheetGlob->isValidSheet() )
1434  xSheetGlob.reset();
1435  return xSheetGlob;
1436 }
1437 
1439 {
1440  return static_cast< IWorksheetProgress *>( xRef.get() );
1441 }
1442 
1444 {
1445  return mrSheetGlob.getSheetType();
1446 }
1447 
1449 {
1450  return mrSheetGlob.getSheetIndex();
1451 }
1452 
1453 const Reference< XSpreadsheet >& WorksheetHelper::getSheet() const
1454 {
1455  return mrSheetGlob.getSheet();
1456 }
1457 
1458 Reference< XCell > WorksheetHelper::getCell( const ScAddress& rAddress ) const
1459 {
1460  return mrSheetGlob.getCell( rAddress );
1461 }
1462 
1463 Reference< XCellRange > WorksheetHelper::getCellRange( const ScRange& rRange ) const
1464 {
1465  return mrSheetGlob.getCellRange( rRange );
1466 }
1467 
1468 Reference< XDrawPage > WorksheetHelper::getDrawPage() const
1469 {
1470  return mrSheetGlob.getDrawPage();
1471 }
1472 
1473 awt::Point WorksheetHelper::getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const
1474 {
1475  return mrSheetGlob.getCellPosition( nCol, nRow );
1476 }
1477 
1478 const awt::Size& WorksheetHelper::getDrawPageSize() const
1479 {
1480  return mrSheetGlob.getDrawPageSize();
1481 }
1482 
1484 {
1485  return mrSheetGlob.getSheetData();
1486 }
1487 
1489 {
1490  return mrSheetGlob.getCondFormats();
1491 }
1492 
1494 {
1495  return mrSheetGlob.getComments();
1496 }
1497 
1499 {
1500  return mrSheetGlob.getAutoFilters();
1501 }
1502 
1504 {
1505  return mrSheetGlob.getQueryTables();
1506 }
1507 
1509 {
1511 }
1512 
1514 {
1515  return mrSheetGlob.getPageSettings();
1516 }
1517 
1519 {
1521 }
1522 
1524 {
1525  return mrSheetGlob.getVmlDrawing();
1526 }
1527 
1529 {
1530  return mrSheetGlob.getExtLst();
1531 }
1532 
1533 void WorksheetHelper::setPageBreak( const PageBreakModel& rModel, bool bRowBreak )
1534 {
1535  mrSheetGlob.setPageBreak( rModel, bRowBreak );
1536 }
1537 
1539 {
1540  mrSheetGlob.setHyperlink( rModel );
1541 }
1542 
1544 {
1545  mrSheetGlob.setValidation( rModel );
1546 }
1547 
1548 void WorksheetHelper::setDrawingPath( const OUString& rDrawingPath )
1549 {
1550  mrSheetGlob.setDrawingPath( rDrawingPath );
1551 }
1552 
1553 void WorksheetHelper::setVmlDrawingPath( const OUString& rVmlDrawingPath )
1554 {
1555  mrSheetGlob.setVmlDrawingPath( rVmlDrawingPath );
1556 }
1557 
1559 {
1560  mrSheetGlob.extendUsedArea( rAddress );
1561 }
1562 
1563 void WorksheetHelper::extendShapeBoundingBox( const awt::Rectangle& rShapeRect )
1564 {
1565  mrSheetGlob.extendShapeBoundingBox( rShapeRect );
1566 }
1567 
1568 void WorksheetHelper::setBaseColumnWidth( sal_Int32 nWidth )
1569 {
1570  mrSheetGlob.setBaseColumnWidth( nWidth );
1571 }
1572 
1574 {
1576 }
1577 
1579 {
1580  mrSheetGlob.setColumnModel( rModel );
1581 }
1582 
1583 void WorksheetHelper::setDefaultRowSettings( double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom )
1584 {
1585  mrSheetGlob.setDefaultRowSettings( fHeight, bCustomHeight, bHidden, bThickTop, bThickBottom );
1586 }
1587 
1589 {
1590  mrSheetGlob.setRowModel( rModel );
1591 }
1592 
1594  const ScAddress& rAddress, const OUString& rValueStr, sal_Int32 nCellType )
1595 {
1596  getFormulaBuffer().setCellFormulaValue(rAddress, rValueStr, nCellType);
1597 }
1598 
1599 void WorksheetHelper::putRichString( const ScAddress& rAddress, const RichString& rString, const oox::xls::Font* pFirstPortionFont )
1600 {
1602 
1603  // The cell will own the text object instance returned from convert().
1604  getDocImport().setEditCell(rAddress, rString.convert(rEE, pFirstPortionFont));
1605 }
1606 
1607 void WorksheetHelper::putFormulaTokens( const ScAddress& rAddress, const ApiTokenSequence& rTokens )
1608 {
1609  ScDocumentImport& rDoc = getDocImport();
1610  std::unique_ptr<ScTokenArray> pTokenArray(new ScTokenArray(rDoc.getDoc()));
1611  ScTokenConversion::ConvertToTokenArray(rDoc.getDoc(), *pTokenArray, rTokens);
1612  rDoc.setFormulaCell(rAddress, std::move(pTokenArray));
1613 }
1614 
1616 {
1618 }
1619 
1621 {
1623 }
1624 
1626 {
1628 }
1629 
1630 void WorksheetHelper::setCellFormula( const ScAddress& rTokenAddress, const OUString& rTokenStr )
1631 {
1632  getFormulaBuffer().setCellFormula( rTokenAddress, rTokenStr );
1633 }
1634 
1636  const ScAddress& rAddr, sal_Int32 nSharedId,
1637  const OUString& rCellValue, sal_Int32 nValueType )
1638 {
1639  getFormulaBuffer().setCellFormula(rAddr, nSharedId, rCellValue, nValueType);
1640 }
1641 
1642 void WorksheetHelper::setCellArrayFormula( const ScRange& rRangeAddress, const ScAddress& rTokenAddress, const OUString& rTokenStr )
1643 {
1644  getFormulaBuffer().setCellArrayFormula( rRangeAddress, rTokenAddress, rTokenStr );
1645 }
1646 
1648  const ScAddress& rAddress, sal_Int32 nSharedId, const OUString& rTokens )
1649 {
1650  getFormulaBuffer().createSharedFormulaMapEntry(rAddress, nSharedId, rTokens);
1651 }
1652 
1653 } // namespace oox
1654 
1655 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void convertColumns()
Converts column properties for all columns in the sheet.
static css::uno::Sequence< css::table::CellRangeAddress > toApiSequence(const ScRangeList &orRanges)
Converts the passed range list to a sequence of cell range addresses.
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Definition: address.cxx:1733
Helper class to provide access to global workbook data.
bool isSheetRightToLeft() const
Returns true, if the sheet layout is set to right-to-left.
HyperlinkModel()
Additional tooltip text.
SCTAB getSheetIndex() const
Returns the index of the current sheet.
static WorksheetGlobalsRef constructGlobals(const WorkbookHelper &rHelper, const ISegmentProgressBarRef &rxProgressBar, WorksheetType eSheetType, SCTAB nSheet)
bool mbFastRowProgress
Sheet progress bar.
void setBaseColumnWidth(sal_Int32 nWidth)
Sets base width for all columns (without padding pixels).
void setCurrentSheetIndex(SCTAB nSheet)
Sets the index of the current Calc sheet, if filter currently processes a sheet.
awt::Size maDrawPageSize
Path to legacy VML drawing fragment.
bool HasAutoFilter() const
Definition: dbdata.hxx:204
double scaleValue(double fValue, Unit eFromUnit, Unit eToUnit) const
Converts the passed value between the passed units.
sal_Int32 nIndex
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:825
ScAddress getCellAddressFromPosition(const awt::Point &rPosition) const
Returns the address of the cell that contains the passed point in 1/100 mm.
ScAddress aStart
Definition: address.hxx:497
ScDocumentImport & getDocImport()
SheetDataBuffer & getSheetData() const
Returns the buffer for cell contents and cell formatting.
static sal_Int32 convertToApiOperator(sal_Int32 nToken)
Converts an OOXML condition operator token to the API constant.
Reference< XRow > xRow
Reference< XDrawPage > getDrawPage() const
Returns the XDrawPage interface of the draw page of the current sheet.
constexpr auto toTwips(N number, Length from)
PageSettings & getPageSettings()
Returns the page/print settings for this sheet.
SC_DLLPUBLIC ScDBData * GetAnonymousDBData(SCTAB nTab)
Definition: document.cxx:308
SCROW Row() const
Definition: address.hxx:274
bool mbThickTop
True = row outline is collapsed.
UnitConverter & getUnitConverter() const
Returns the measurement unit converter.
sal_Int16 mnLevel
constexpr tools::Long Left() const
void createSharedFormulaMapEntry(const ScAddress &rAddress, sal_Int32 nSharedId, const OUString &rTokens)
WorksheetSettings & getWorksheetSettings()
Returns the worksheet settings object.
void setColumnModel(const ColumnModel &rModel)
Sets column settings for a specific column range.
const awt::Size & getDrawPageSize() const
Returns the size of the entire drawing page in 1/100 mm.
void QuickInsertField(const SvxFieldItem &rFld, const ESelection &rSel)
bool validateCellRange(ScRange &orRange, bool bAllowOverflow, bool bTrackOverflow)
Checks the passed cell range, may try to fit it to current sheet limits.
Contains string data and a list of formatting runs for a rich formatted string.
Definition: richstring.hxx:208
long Long
OUString getCalcSheetName(sal_Int32 nWorksheet) const
Returns the finalized name of the specified worksheet.
const SCCOL SCCOL_MAX
Definition: address.hxx:56
SheetDataBuffer maSheetData
Cell ranges containing data validation settings.
::std::map< sal_Int32, RowModelRange > RowModelRangeMap
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
bool mbHasDefWidth
Reference to the current sheet.
SC_DLLPUBLIC void SetColHidden(SCCOL nStartCol, SCCOL nEndCol, SCTAB nTab, bool bHidden)
Definition: document.cxx:4517
WorksheetGlobals & mrSheetGlob
void finalizeImport()
Converts all imported sheet view settings.
void convertOutlines(OutlineLevelVec &orLevels, sal_Int32 nColRow, sal_Int32 nLevel, bool bCollapsed, bool bRows)
Converts outline grouping for the passed column or row.
ColumnModel()
True = column outline is collapsed.
bool mbCustomFormat
True = row has custom height.
void extendShapeBoundingBox(const awt::Rectangle &rShapeRect)
Extends the shape bounding box by the position and size of the passed rectangle.
ExtLst & getExtLst()
returns the ExtLst entries that need to be filled
RowModel maDefRowModel
Ranges of columns sorted by first column index.
css::uno::Reference< css::table::XCellRange > getCellRange(const ScRange &rRange) const
Returns the XCellRange interface for the passed cell range address.
ScAddress aEnd
Definition: address.hxx:498
void finalizeImport()
Inserts all web queries into the sheet.
SheetViewSettings & getSheetViewSettings()
Returns the view settings for this sheet.
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:103
#define STATIC_ARRAY_SELECT(array, index, def)
WorksheetSettings & getWorksheetSettings() const
Returns the worksheet settings object.
SC_DLLPUBLIC void ApplyAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, const SfxPoolItem &rAttr)
Definition: document.cxx:4821
Accessor class to ScDocument.
ScRange maUsedArea
Reference to maximum Calc cell address from address converter.
SheetViewSettings & getSheetViewSettings() const
Returns the view settings for this sheet.
const SCROW SCROW_MAX
Definition: address.hxx:55
StylesBuffer & getStyles() const
Returns all cell formatting objects read from the styles substream.
void putFormulaTokens(const ScAddress &rAddress, const ApiTokenSequence &rTokens)
Inserts a formula cell directly into the Calc sheet.
void finalizeDrawings()
Imports the drawings of the sheet (DML, VML, DFF) and updates the used area.
ISegmentProgressBarRef mxFinalProgress
Progress bar for row/cell processing.
bool importOoxFragment(const rtl::Reference< oox::core::FragmentHandler > &rxHandler)
Imports a fragment using the passed fragment handler, which contains the full path to the fragment st...
void setEditCell(const ScAddress &rPos, std::unique_ptr< EditTextObject > pEditText)
QueryTableBuffer maQueryTables
Sheet auto filters (not associated to a table).
const css::awt::Size & getDrawPageSize() const
Returns the size of the entire drawing page in 1/100 mm.
Fragment handler for a complete sheet drawing.
Reference< XSheetCellRanges > getCellRangeList(const ScRangeList &rRanges) const
Returns the XSheetCellRanges interface for the passed cell range addresses.
void setDrawingPath(const OUString &rDrawingPath)
Sets the path to the DrawingML fragment of this sheet.
void setHyperlink(const HyperlinkModel &rModel)
Inserts the hyperlink URL into the spreadsheet.
CondFormatBuffer & getCondFormats() const
Returns the conditional formatting in this sheet.
void extendShapeBoundingBox(const css::awt::Rectangle &rShapeRect)
Extends the shape bounding box by the position and size of the passed rectangle (in 1/100 mm)...
void finalizeImport()
Finalizes the formatted string of all comments.
bool mbShowPhonetic
True = cells in row have explicit formatting.
ViewSettings & getViewSettings() const
Returns the workbook and sheet view settings object.
void initializeWorksheetImport()
Initial conversion before importing the worksheet.
void setBiffType(sal_uInt8 nType)
Sets the passed BIFF validation type.
void finalizeValidationRanges() const
Inserts all imported data validations into their cell ranges.
constexpr TypedWhichId< SvxFieldItem > EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
bool mbCustomHeight
Row outline level.
Reference< XSpreadsheet > mxSheet
Type of this sheet.
std::shared_ptr< WorksheetGlobals > WorksheetGlobalsRef
std::vector< ValidationModel > maValidations
Cell ranges containing hyperlinks.
void convertColumnFormat(sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId)
Converts column default cell formatting.
Stores formatting data about a page break.
bool mbCollapsed
True = row is hidden.
void setRowFormat(sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat)
Sets default cell formatting for the specified range of rows.
WorksheetType getSheetType() const
Returns the type of this sheet.
void setVmlDrawingPath(const OUString &rVmlDrawingPath)
Sets the path to the legacy VML drawing fragment of this sheet.
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
void setCellArrayFormula(const ScRange &rRangeAddress, const ScAddress &rTokenAddress, const OUString &rTokenStr)
void putRichString(const ScAddress &rAddress, const RichString &rString, const oox::xls::Font *pFirstPortionFont)
Inserts a rich-string cell directly into the Calc sheet.
sal_Int16 getCurrentSheetIndex() const
Returns the index of the current Calc sheet, if filter currently processes a sheet.
SCTAB Tab() const
Definition: address.hxx:283
void SetRow(SCROW nRowP)
Definition: address.hxx:287
WorksheetType meSheetType
Progress bar for finalization.
void applyAutoFilters()
Applies autofilters from created database range ( requires finalizeImport to have run before being ca...
CommentsBuffer & getComments() const
Returns the buffer for all cell comments in this sheet.
CommentsBuffer maComments
Buffer for conditional formatting.
double mfHeight
0-based (!) column ranges of used cells.
void extendUsedArea(const ScAddress &rAddress)
Extends the used area of this sheet by the passed cell position.
SC_DLLPUBLIC void SetColWidthOnly(SCCOL nCol, SCTAB nTab, sal_uInt16 nNewWidth)
Definition: document.cxx:4139
bool isValidSheet() const
Returns true, if this helper refers to an existing Calc sheet.
XML_TOKEN_INVALID
std::vector< HyperlinkModel > maHyperlinks
Ranges of rows sorted by first row index.
static IWorksheetProgress * getWorksheetInterface(const WorksheetGlobalsRef &xRef)
SC_DLLPUBLIC void SetRowHeightOnly(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, sal_uInt16 nNewHeight)
Definition: document.cxx:4158
sal_Int32 mnLevel
Column default formatting.
bool isMergeable(const ColumnModel &rModel) const
Returns true, if this entry can be merged with the passed column range (column settings are equal)...
void setCellStyleToSheet(SCTAB nTab, const ScStyleSheet &rStyle)
Apply specified cell style to an entire sheet.
void SetCol(SCCOL nColP)
Definition: address.hxx:291
CommentsBuffer & getComments()
Returns the buffer for all cell comments in this sheet.
void setCellFormulaValue(const ScAddress &rAddress, const OUString &rValueStr, sal_Int32 nCellType)
Stores settings and formatting data about a sheet row.
void setBiffOperator(sal_uInt8 nOperator)
Sets the passed BIFF operator.
OUString getHyperlinkUrl(const HyperlinkModel &rHyperlink) const
Generates the final URL for the passed hyperlink.
bool empty() const
Definition: rangelst.hxx:88
DocumentType eType
awt::Rectangle maShapeBoundingBox
Current size of the drawing page in 1/100 mm.
AutoFilterBuffer maAutoFilters
Buffer for all cell comments in this sheet.
sal_Int32 mnFirst
double mfWidth
1-based (!) range of the described columns.
sal_Int32 mnXfId
Column width in number of characters.
bool mbHidden
True = cells in row show phonetic settings.
void setCellFormula(const ScAddress &rTokenAddress, const OUString &)
VmlDrawingPtr mxVmlDrawing
View settings for this sheet.
::std::map< sal_Int32, ColumnModelRange > ColumnModelRangeMap
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
void createSharedFormulaMapEntry(const ScAddress &rAddress, sal_Int32 nSharedId, const OUString &rTokens)
css::uno::Reference< css::drawing::XDrawPage > getDrawPage() const
Returns the XDrawPage interface of the draw page of the current sheet.
#define SAL_MAX_INT32
void setDrawingPath(const OUString &rDrawingPath)
Sets the path to the DrawingML fragment of this sheet.
ISegmentProgressBarRef mxProgressBar
Bounding box for all shapes from all drawings.
void setCellFormula(const ScAddress &rAddress, const OUString &)
bool mbHidden
True = cells in column show phonetic settings.
bool mbCollapsed
True = column is hidden.
ISegmentProgressBarRef mxRowProgress
Do we have a progress bar thread ?
void setDefaultRowSettings(double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom)
Sets default height and hidden state for all unused rows in the sheet.
bool empty() const
Definition: dbdata.cxx:1603
void setDefaultColumnWidth(double fWidth)
Sets default width for all columns.
PageBreakModel()
True = manual page break.
void IncCol(SCCOL nDelta=1)
Definition: address.hxx:316
void convertRows(const std::vector< sc::ColRowSpan > &rSpans)
Converts row properties for all rows in the sheet.
sal_Int32 mnType
virtual void setCustomRowProgress(const ISegmentProgressBarRef &rxRowProgress) override
Reference< XCellRange > getCellRange(const ScRange &rRange) const
Returns the XCellRange interface for the passed cell range address.
sal_Int16 SCCOL
Definition: types.hxx:21
Stores settings and formatting data about a range of sheet columns.
void UpdateRowProgress(const ScRange &rUsedArea, SCROW nRow)
Update the row import progress bar.
WorksheetType getSheetType() const
Returns the type of this sheet.
std::shared_ptr< ISegmentProgressBar > ISegmentProgressBarRef
::std::pair< ColumnModel, sal_Int32 > ColumnModelRange
void insertHyperlink(const ScAddress &rAddress, const OUString &rUrl)
Inserts a hyperlinks into the specified cell.
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
void setPageBreak(const PageBreakModel &rModel, bool bRowBreak)
Sets a column or row page break described in the passed struct.
std::unique_ptr< EditTextObject > CreateTextObject()
AutoFilterBuffer & getAutoFilters()
Returns the auto filters for the sheet.
void IncRow(SCROW nDelta=1)
Definition: address.hxx:312
void convert(const css::uno::Reference< css::text::XText > &rxText) const
Converts the string and writes it into the passed XText, replace old contents of the text object...
const Reference< XSpreadsheet > & getSheet() const
Returns the XSpreadsheet interface of the current sheet.
void insertColSpan(const ValueRange &rColSpan)
Inserts the passed column span into the row model.
SheetViewSettings maSheetViewSett
Page/print settings for this sheet.
constexpr tools::Long Top() const
static SC_DLLPUBLIC bool ConvertToTokenArray(ScDocument &rDoc, ScTokenArray &rTokenArray, const css::uno::Sequence< css::sheet::FormulaToken > &rSequence)
Definition: tokenuno.cxx:375
void setBaseColumnWidth(sal_Int32 nWidth)
Sets base width for all columns (without padding pixels).
void finalizeImport(sal_Int16 nSheet)
Applies filter settings to a new database range object (used for sheet autofilter or advanced filter ...
ScEditEngineDefaulter & getEditEngine() const
void setVmlDrawingPath(const OUString &rVmlDrawingPath)
Sets the path to the legacy VML drawing fragment of this sheet.
css::uno::Reference< css::table::XCell > getCell(const ScAddress &rAddress) const
Returns the XCell interface for the passed cell address.
VmlDrawing & getVmlDrawing()
Returns the VML drawing page for this sheet (OOXML/BIFF12 only).
void setDefaultRowSettings(double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom)
Sets default height and hidden state for all unused rows in the sheet.
::std::map< OUString, ScDataBarFormatData * > ExtLst
CondFormatBuffer maCondFormats
Buffer for cell contents and cell formatting.
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
Definition: dbdata.cxx:300
void initializeWorksheetImport()
Initial conversion before importing the worksheet.
ExtLst maExtLst
Collection of all VML shapes.
QueryTableBuffer & getQueryTables() const
Returns the buffer for all web query tables in this sheet.
ColumnModelRangeMap maColModels
Default column formatting.
void setColumnModel(const ColumnModel &rModel)
Sets column settings for a specific range of columns.
OUString maVmlDrawingPath
Path to DrawingML fragment.
SCCOL Col() const
Definition: address.hxx:279
void setValidation(const ValidationModel &rModel)
Inserts the data validation settings into the spreadsheet.
RowModel()
True = row has extra space below text.
::std::vector< sal_Int32 > OutlineLevelVec
sal_Int32 mnXfId
Row height in points.
CondFormatBuffer & getCondFormats()
Returns the conditional formatting in this sheet.
css::uno::Sequence< ApiToken > ApiTokenSequence
Stores data about ranges with data validation settings.
void finalizeDrawingImport()
Final import of drawing objects.
Stores global named database ranges.
Definition: dbdata.hxx:234
ScRange getCellRangeFromRectangle(const awt::Rectangle &rRect) const
Returns the cell range address that contains the passed rectangle in 1/100 mm.
PageSettings maPageSett
Global settings for this sheet.
void extendUsedArea(const ScAddress &rAddress)
Extends the used area of this sheet by the passed cell position.
void setFormulaCell(const ScAddress &rPos, const OUString &rFormula, formula::FormulaGrammar::Grammar eGrammar, const double *pResult=nullptr)
sal_Int32 SCROW
Definition: types.hxx:17
ColumnModel maDefColModel
Used area of the sheet, and sheet index of the sheet.
bool isMergeable(const RowModel &rModel) const
Returns true, if this entry can be merged with the passed row range (row settings are equal)...
void setColSpans(sal_Int32 nRow, const ValueRangeSet &rColSpans)
Sets column span information for a row.
void setCellArrayFormula(const ScRange &rRangeAddress, const ScAddress &rTokenAddress, const OUString &)
css::awt::Point getCellPosition(sal_Int32 nCol, sal_Int32 nRow) const
Returns the absolute cell position in 1/100 mm.
void setSheetUsedArea(const ScRange &rUsedArea)
Stores the used area for a specific worksheet.
void finalizeImport()
Creates a page style for the spreadsheet and sets all page properties.
const css::uno::Reference< css::sheet::XSpreadsheet > & getSheet() const
Returns the XSpreadsheet interface of the current sheet.
WorksheetGlobals(const WorkbookHelper &rHelper, const ISegmentProgressBarRef &rxProgressBar, WorksheetType eSheetType, SCTAB nSheet)
Service name for a SheetCellRanges object.
unsigned char sal_uInt8
void finalizeWorksheetImport()
Final conversion after importing the worksheet.
SheetDataBuffer & getSheetData()
Returns the buffer for cell contents and cell formatting.
ValueRangeSet maColSpans
1-based (!) index of the described row.
RowModelRangeMap maRowModels
Default row formatting.
Reference< XCell > getCell(const ScAddress &rAddress) const
Returns the XCell interface for the passed cell address.
English Metric Unit (1/360,000 cm).
SCTAB getSheetIndex() const
Returns the index of the current sheet.
void insert(const ValueRange &rRange)
awt::Point getCellPosition(sal_Int32 nCol, sal_Int32 nRow) const
Returns the absolute position of the top-left corner of the cell in 1/100 mm.
XML_none
void setCellFormulaValue(const ScAddress &rAddress, const OUString &rValueStr, sal_Int32 nCellType)
SC_DLLPUBLIC void SetManualHeight(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bManual)
Definition: document.cxx:4164
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
::std::unique_ptr< VmlDrawing > VmlDrawingPtr
QueryTableBuffer & getQueryTables()
Returns the buffer for all web query tables in this sheet.
SC_DLLPUBLIC void SetRowHidden(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bHidden)
Definition: document.cxx:4509
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6161
SC_DLLPUBLIC void SetRowFiltered(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bFiltered)
Definition: document.cxx:4573
void finalizeImport()
Converts the imported worksheet settings.
constexpr TypedWhichId< SfxStringItem > ATTR_HYPERLINK(155)
Reference< XColumn > xColumn
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:316
TableBuffer & getTables() const
Returns the tables collection (equivalent to Calc's database ranges).
Reference< XCellRange > getColumn(sal_Int32 nCol) const
Returns the XCellRange interface for a column.
css::uno::Reference< css::sheet::XSpreadsheet > getSheetFromDoc(sal_Int32 nSheet) const
Returns a reference to the specified spreadsheet in the document model.
virtual ISegmentProgressBarRef getRowProgress() override
Allow the threaded importer to override our progress bar impl.
#define SAL_WARN(area, stream)
WorksheetHelper(WorksheetGlobals &rSheetGlob)
void writeCellXfToDoc(ScDocumentImport &rDoc, const ScRange &rRange, sal_Int32 nXfId) const
Writes the cell formatting attributes of the specified XF to the passed property set.
VmlDrawing & getVmlDrawing() const
Returns the VML drawing page for this sheet (OOXML/BIFF12 only).
sal_Int32 mnRow
WorksheetSettings maSheetSett
Buffer for all web query tables in this sheet.
void finalizeImport()
Final processing after the sheet has been imported.
void setHyperlink(const HyperlinkModel &rModel)
Inserts the hyperlink URL into the spreadsheet.
Stores data about a hyperlink range.
Reference< XCellRange > getRow(sal_Int32 nRow) const
Returns the XCellRange interface for a row.
sal_Int32 mnLevel
Row default formatting (see mbIsFormatted).
WorksheetType
An enumeration for all types of sheets in a workbook.
void setValidation(const ValidationModel &rModel)
Inserts the data validation settings into the spreadsheet.
constexpr OUStringLiteral first
constexpr OUStringLiteral gaSheetCellRanges(u"com.sun.star.sheet.SheetCellRanges")
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
::std::pair< RowModel, sal_Int32 > RowModelRange
AutoFilterBuffer & getAutoFilters() const
Returns the auto filters for the sheet.
void setPageBreak(const PageBreakModel &rModel, bool bRowBreak)
Sets a column or row page break described in the passed struct.
const ScAddress & getMaxXlsAddress() const
Returns the biggest valid cell address in the imported/exported Excel document.
aStr
void setRowModel(const RowModel &rModel)
Sets row settings for a specific row.
void finalizeWorksheetImport()
Final conversion after importing the worksheet.
OUString maDrawingPath
List of extended elements.
SC_DLLPUBLIC ScFieldEditEngine & GetEditEngine()
Definition: documen2.cxx:475
void finalizeHyperlinkRanges()
Inserts all imported hyperlinks into their cell ranges.
bool mbThickBottom
True = row has extra space above text.
bool setProperty(sal_Int32 nPropId, const Type &rValue)
B2DRange maRange
void setRowModel(const RowModel &rModel)
Sets row settings for a specific range of rows.
sal_Int16 SCTAB
Definition: types.hxx:22
PageSettings & getPageSettings() const
Returns the page/print settings for this sheet.
Manages the cell contents and cell formatting of a sheet.
Vertical screen pixels.
void Clear()
bool mbManual
End of limited break.
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
FormulaBuffer & getFormulaBuffer() const
sal_Int32 mnLast
void groupColumnsOrRows(sal_Int32 nFirstColRow, sal_Int32 nLastColRow, bool bCollapsed, bool bRows)
Groups columns or rows for the given range.
bool m_bDetectedRangeSegmentation false
void setDefaultColumnWidth(double fWidth)
Sets default width for all columns.
void setBiffErrorStyle(sal_uInt8 nErrorStyle)
Sets the passed BIFF error style.
WorksheetBuffer & getWorksheets() const
Returns the worksheet buffer containing sheet names and properties.
ScDocument & getDoc()