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/UnitConversion.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 } // namespace
100 
102  maRange( -1 ),
103  mfWidth( 0.0 ),
104  mnXfId( -1 ),
105  mnLevel( 0 ),
106  mbShowPhonetic( false ),
107  mbHidden( false ),
108  mbCollapsed( false )
109 {
110 }
111 
112 bool ColumnModel::isMergeable( const ColumnModel& rModel ) const
113 {
114  return
115  (maRange.mnFirst <= rModel.maRange.mnFirst) &&
116  (rModel.maRange.mnFirst <= maRange.mnLast + 1) &&
117  (mfWidth == rModel.mfWidth) &&
118  // ignore mnXfId, cell formatting is always set directly
119  (mnLevel == rModel.mnLevel) &&
120  (mbHidden == rModel.mbHidden) &&
121  (mbCollapsed == rModel.mbCollapsed);
122 }
123 
125  mnRow( -1 ),
126  mfHeight( 0.0 ),
127  mnXfId( -1 ),
128  mnLevel( 0 ),
129  mbCustomHeight( false ),
130  mbCustomFormat( false ),
131  mbShowPhonetic( false ),
132  mbHidden( false ),
133  mbCollapsed( false ),
134  mbThickTop( false ),
135  mbThickBottom( false )
136 {
137 }
138 
139 void RowModel::insertColSpan( const ValueRange& rColSpan )
140 {
141  if( (0 <= rColSpan.mnFirst) && (rColSpan.mnFirst <= rColSpan.mnLast) )
142  maColSpans.insert( rColSpan );
143 }
144 
145 bool RowModel::isMergeable( const RowModel& rModel ) const
146 {
147  return
148  // ignore maColSpans - is handled separately in SheetDataBuffer class
149  (mfHeight == rModel.mfHeight) &&
150  // ignore mnXfId, mbCustomFormat, mbShowPhonetic - cell formatting is always set directly
151  (mnLevel == rModel.mnLevel) &&
152  (mbCustomHeight == rModel.mbCustomHeight) &&
153  (mbHidden == rModel.mbHidden) &&
154  (mbCollapsed == rModel.mbCollapsed);
155 }
156 
158  : mnColRow(0)
159  , mnMin(0)
160  , mnMax(0)
161  , mbManual(false)
162 {
163 }
164 
166 {
167 }
168 
170  mnType( XML_none ),
171  mnOperator( XML_between ),
172  mnErrorStyle( XML_stop ),
173  mbShowInputMsg( false ),
174  mbShowErrorMsg( false ),
175  mbNoDropDown( false ),
176  mbAllowBlank( false )
177 {
178 }
179 
181 {
182  static const sal_Int32 spnTypeIds[] = {
183  XML_none, XML_whole, XML_decimal, XML_list, XML_date, XML_time, XML_textLength, XML_custom };
184  mnType = STATIC_ARRAY_SELECT( spnTypeIds, nType, XML_none );
185 }
186 
188 {
189  static const sal_Int32 spnOperators[] = {
190  XML_between, XML_notBetween, XML_equal, XML_notEqual,
191  XML_greaterThan, XML_lessThan, XML_greaterThanOrEqual, XML_lessThanOrEqual };
192  mnOperator = STATIC_ARRAY_SELECT( spnOperators, nOperator, XML_TOKEN_INVALID );
193 }
194 
196 {
197  static const sal_Int32 spnErrorStyles[] = { XML_stop, XML_warning, XML_information };
198  mnErrorStyle = STATIC_ARRAY_SELECT( spnErrorStyles, nErrorStyle, XML_stop );
199 }
200 
202 {
203 public:
204  explicit WorksheetGlobals(
205  const WorkbookHelper& rHelper,
206  const ISegmentProgressBarRef& rxProgressBar,
207  WorksheetType eSheetType,
208  SCTAB nSheet );
209 
211  bool isValidSheet() const { return mxSheet.is(); }
212 
216  SCTAB getSheetIndex() const { return maUsedArea.aStart.Tab(); }
218  const Reference< XSpreadsheet >& getSheet() const { return mxSheet; }
219 
221  Reference< XCell > getCell( const ScAddress& rAddress ) const;
223  Reference< XCellRange > getCellRange( const ScRange& rRange ) const;
225  Reference< XSheetCellRanges > getCellRangeList( const ScRangeList& rRanges ) const;
226 
228  Reference< XCellRange > getColumn( sal_Int32 nCol ) const;
230  Reference< XCellRange > getRow( sal_Int32 nRow ) const;
231 
233  Reference< XDrawPage > getDrawPage() const;
235  const awt::Size& getDrawPageSize() const;
236 
238  awt::Point getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const;
239 
241  ScAddress getCellAddressFromPosition( const awt::Point& rPosition ) const;
243  ScRange getCellRangeFromRectangle( const awt::Rectangle& rRect ) const;
244 
264  ExtLst& getExtLst() { return maExtLst; }
265 
267  void setPageBreak( const PageBreakModel& rModel, bool bRowBreak );
269  void setHyperlink( const HyperlinkModel& rModel );
271  void setValidation( const ValidationModel& rModel );
273  void setDrawingPath( const OUString& rDrawingPath );
275  void setVmlDrawingPath( const OUString& rVmlDrawingPath );
276 
278  void extendUsedArea( const ScAddress& rAddress );
279 
281  void extendUsedArea( const ScRange& rRange );
283  void extendShapeBoundingBox( const awt::Rectangle& rShapeRect );
284 
287  void setBaseColumnWidth( sal_Int32 nWidth );
290  void setDefaultColumnWidth( double fWidth );
294  void setColumnModel( const ColumnModel& rModel );
296  void convertColumnFormat( sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId );
297 
299  void setDefaultRowSettings( double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom );
303  void setRowModel( const RowModel& rModel );
304 
309 
310  void finalizeDrawingImport();
311 
314  {
315  return mxRowProgress;
316  }
317  virtual void setCustomRowProgress( const ISegmentProgressBarRef &rxRowProgress ) override
318  {
319  mxRowProgress = rxRowProgress;
320  mbFastRowProgress = true;
321  }
322 
323 private:
324  typedef ::std::vector< sal_Int32 > OutlineLevelVec;
325  typedef ::std::pair< ColumnModel, sal_Int32 > ColumnModelRange;
326  typedef ::std::map< sal_Int32, ColumnModelRange > ColumnModelRangeMap;
327  typedef ::std::pair< RowModel, sal_Int32 > RowModelRange;
328  typedef ::std::map< sal_Int32, RowModelRange > RowModelRangeMap;
329 
333  OUString getHyperlinkUrl( const HyperlinkModel& rHyperlink ) const;
335  void insertHyperlink( const ScAddress& rAddress, const OUString& rUrl );
336 
338  void finalizeValidationRanges() const;
339 
341  void convertColumns();
343  void convertColumns( OutlineLevelVec& orColLevels, const ValueRange& rColRange, const ColumnModel& rModel );
344 
346  void convertRows(const std::vector<sc::ColRowSpan>& rSpans);
348  void convertRows(OutlineLevelVec& orRowLevels, const ValueRange& rRowRange,
349  const RowModel& rModel,
350  const std::vector<sc::ColRowSpan>& rSpans,
351  double fDefHeight = -1.0);
352 
354  void convertOutlines( OutlineLevelVec& orLevels, sal_Int32 nColRow, sal_Int32 nLevel, bool bCollapsed, bool bRows );
356  void groupColumnsOrRows( sal_Int32 nFirstColRow, sal_Int32 nLastColRow, bool bCollapsed, bool bRows );
357 
359  void finalizeDrawings();
360 
362  void UpdateRowProgress( const ScRange& rUsedArea, SCROW nRow );
363 
364 private:
365  typedef ::std::unique_ptr< VmlDrawing > VmlDrawingPtr;
366 
370  ColumnModelRangeMap maColModels;
372  RowModelRangeMap maRowModels;
373  std::vector< HyperlinkModel > maHyperlinks;
374  std::vector< ValidationModel > maValidations;
383  VmlDrawingPtr mxVmlDrawing;
385  OUString maDrawingPath;
386  OUString maVmlDrawingPath;
387  awt::Size maDrawPageSize;
388  awt::Rectangle maShapeBoundingBox;
394  Reference< XSpreadsheet > mxSheet;
396 };
397 
398 constexpr OUStringLiteral gaSheetCellRanges( u"com.sun.star.sheet.SheetCellRanges" );
399 
400 WorksheetGlobals::WorksheetGlobals( const WorkbookHelper& rHelper, const ISegmentProgressBarRef& rxProgressBar, WorksheetType eSheetType, SCTAB nSheet ) :
401  WorkbookHelper( rHelper ),
402  mrMaxApiPos( rHelper.getAddressConverter().getMaxApiAddress() ),
403  maUsedArea( SCCOL_MAX, SCROW_MAX, nSheet, -1, -1, nSheet ), // Set start address to largest possible value, and end address to smallest
404  maSheetData( *this ),
405  maCondFormats( *this ),
406  maComments( *this ),
407  maAutoFilters( *this ),
408  maQueryTables( *this ),
409  maSheetSett( *this ),
410  maPageSett( *this ),
411  maSheetViewSett( *this ),
412  mxProgressBar( rxProgressBar ),
413  mbFastRowProgress( false ),
414  meSheetType( eSheetType ),
415  mxSheet(getSheetFromDoc( nSheet )),
416  mbHasDefWidth( false )
417 {
418  if( !mxSheet.is() )
419  maUsedArea.aStart.SetTab( -1 );
420 
421  // default column settings (width and hidden state may be updated later)
422  maDefColModel.mfWidth = 8.5;
423  maDefColModel.mnXfId = -1;
425  maDefColModel.mbHidden = false;
426  maDefColModel.mbCollapsed = false;
427 
428  // default row settings (height and hidden state may be updated later)
429  maDefRowModel.mfHeight = 0.0;
430  maDefRowModel.mnXfId = -1;
435  maDefRowModel.mbHidden = false;
436  maDefRowModel.mbCollapsed = false;
437 
438  // buffers
439  mxVmlDrawing.reset( new VmlDrawing( *this ) );
440 
441  // prepare progress bars
442  if( mxProgressBar )
443  {
444  mxRowProgress = mxProgressBar->createSegment( 0.5 );
445  mxFinalProgress = mxProgressBar->createSegment( 0.5 );
446  }
447 }
448 
449 Reference< XCell > WorksheetGlobals::getCell( const ScAddress& rAddress ) const
450 {
451  Reference< XCell > xCell;
452  if( mxSheet.is() ) try
453  {
454  xCell = mxSheet->getCellByPosition( rAddress.Col(), rAddress.Row() );
455  }
456  catch( Exception& )
457  {
458  }
459  return xCell;
460 }
461 
462 Reference< XCellRange > WorksheetGlobals::getCellRange( const ScRange& rRange ) const
463 {
464  Reference< XCellRange > xRange;
465  if( mxSheet.is() ) try
466  {
467  xRange = mxSheet->getCellRangeByPosition( rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row() );
468  }
469  catch( Exception& )
470  {
471  }
472  return xRange;
473 }
474 
475 Reference< XSheetCellRanges > WorksheetGlobals::getCellRangeList( const ScRangeList& rRanges ) const
476 {
477  Reference< XSheetCellRanges > xRanges;
478  if( mxSheet.is() && !rRanges.empty() ) try
479  {
480  xRanges.set( getBaseFilter().getModelFactory()->createInstance( gaSheetCellRanges ), UNO_QUERY_THROW );
481  Reference< XSheetCellRangeContainer > xRangeCont( xRanges, UNO_QUERY_THROW );
482  xRangeCont->addRangeAddresses( AddressConverter::toApiSequence(rRanges), false );
483  }
484  catch( Exception& )
485  {
486  }
487  return xRanges;
488 }
489 
490 Reference< XCellRange > WorksheetGlobals::getColumn( sal_Int32 nCol ) const
491 {
492  Reference< XCellRange > xColumn;
493  try
494  {
495  Reference< XColumnRowRange > xColRowRange( mxSheet, UNO_QUERY_THROW );
496  Reference< XTableColumns > xColumns( xColRowRange->getColumns(), UNO_SET_THROW );
497  xColumn.set( xColumns->getByIndex( nCol ), UNO_QUERY );
498  }
499  catch( Exception& )
500  {
501  }
502  return xColumn;
503 }
504 
505 Reference< XCellRange > WorksheetGlobals::getRow( sal_Int32 nRow ) const
506 {
507  Reference< XCellRange > xRow;
508  try
509  {
510  Reference< XColumnRowRange > xColRowRange( mxSheet, UNO_QUERY_THROW );
511  Reference< XTableRows > xRows( xColRowRange->getRows(), UNO_SET_THROW );
512  xRow.set( xRows->getByIndex( nRow ), UNO_QUERY );
513  }
514  catch( Exception& )
515  {
516  }
517  return xRow;
518 }
519 
520 Reference< XDrawPage > WorksheetGlobals::getDrawPage() const
521 {
522  Reference< XDrawPage > xDrawPage;
523  try
524  {
525  xDrawPage = Reference< XDrawPageSupplier >( mxSheet, UNO_QUERY_THROW )->getDrawPage();
526  }
527  catch( Exception& )
528  {
529  }
530  return xDrawPage;
531 }
532 
533 const awt::Size& WorksheetGlobals::getDrawPageSize() const
534 {
535  OSL_ENSURE( (maDrawPageSize.Width > 0) && (maDrawPageSize.Height > 0), "WorksheetGlobals::getDrawPageSize - called too early, size invalid" );
536  return maDrawPageSize;
537 }
538 
539 awt::Point WorksheetGlobals::getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const
540 {
541  awt::Point aPoint;
542  PropertySet aCellProp( getCell( ScAddress( nCol, nRow, getSheetIndex() ) ) );
543  aCellProp.getProperty( aPoint, PROP_Position );
544  return aPoint;
545 }
546 
547 namespace {
548 
549 sal_Int32 lclGetMidAddr( sal_Int32 nBegAddr, sal_Int32 nEndAddr, sal_Int32 nBegPos, sal_Int32 nEndPos, sal_Int32 nSearchPos )
550 {
551  // use sal_Int64 to prevent integer overflow
552  return nBegAddr + 1 + static_cast< sal_Int32 >( static_cast< sal_Int64 >( nEndAddr - nBegAddr - 2 ) * (nSearchPos - nBegPos) / (nEndPos - nBegPos) );
553 }
554 
555 bool lclPrepareInterval( sal_Int32 nBegAddr, sal_Int32& rnMidAddr, sal_Int32 nEndAddr,
556  sal_Int32 nBegPos, sal_Int32 nEndPos, sal_Int32 nSearchPos )
557 {
558  // searched position before nBegPos -> use nBegAddr
559  if( nSearchPos <= nBegPos )
560  {
561  rnMidAddr = nBegAddr;
562  return false;
563  }
564 
565  // searched position after nEndPos, or begin next to end -> use nEndAddr
566  if( (nSearchPos >= nEndPos) || (nBegAddr + 1 >= nEndAddr) )
567  {
568  rnMidAddr = nEndAddr;
569  return false;
570  }
571 
572  /* Otherwise find mid address according to position. lclGetMidAddr() will
573  return an address between nBegAddr and nEndAddr. */
574  rnMidAddr = lclGetMidAddr( nBegAddr, nEndAddr, nBegPos, nEndPos, nSearchPos );
575  return true;
576 }
577 
578 bool lclUpdateInterval( sal_Int32& rnBegAddr, sal_Int32& rnMidAddr, sal_Int32& rnEndAddr,
579  sal_Int32& rnBegPos, sal_Int32 nMidPos, sal_Int32& rnEndPos, sal_Int32 nSearchPos )
580 {
581  // nSearchPos < nMidPos: use the interval [begin,mid] in the next iteration
582  if( nSearchPos < nMidPos )
583  {
584  // if rnBegAddr is next to rnMidAddr, the latter is the column/row in question
585  if( rnBegAddr + 1 >= rnMidAddr )
586  return false;
587  // otherwise, set interval end to mid
588  rnEndPos = nMidPos;
589  rnEndAddr = rnMidAddr;
590  rnMidAddr = lclGetMidAddr( rnBegAddr, rnEndAddr, rnBegPos, rnEndPos, nSearchPos );
591  return true;
592  }
593 
594  // nSearchPos > nMidPos: use the interval [mid,end] in the next iteration
595  if( nSearchPos > nMidPos )
596  {
597  // if rnMidAddr is next to rnEndAddr, the latter is the column/row in question
598  if( rnMidAddr + 1 >= rnEndAddr )
599  {
600  rnMidAddr = rnEndAddr;
601  return false;
602  }
603  // otherwise, set interval start to mid
604  rnBegPos = nMidPos;
605  rnBegAddr = rnMidAddr;
606  rnMidAddr = lclGetMidAddr( rnBegAddr, rnEndAddr, rnBegPos, rnEndPos, nSearchPos );
607  return true;
608  }
609 
610  // nSearchPos == nMidPos: rnMidAddr is the column/row in question, do not loop anymore
611  return false;
612 }
613 
614 } // namespace
615 
617 {
618  // starting cell address and its position in drawing layer (top-left edge)
619  sal_Int32 nBegCol = 0;
620  sal_Int32 nBegRow = 0;
621  awt::Point aBegPos( 0, 0 );
622 
623  // end cell address and its position in drawing layer (bottom-right edge)
624  sal_Int32 nEndCol = mrMaxApiPos.Col() + 1;
625  sal_Int32 nEndRow = mrMaxApiPos.Row() + 1;
626  awt::Point aEndPos( maDrawPageSize.Width, maDrawPageSize.Height );
627 
628  // starting point for interval search
629  sal_Int32 nMidCol, nMidRow;
630  bool bLoopCols = lclPrepareInterval( nBegCol, nMidCol, nEndCol, aBegPos.X, aEndPos.X, rPosition.X );
631  bool bLoopRows = lclPrepareInterval( nBegRow, nMidRow, nEndRow, aBegPos.Y, aEndPos.Y, rPosition.Y );
632  awt::Point aMidPos = getCellPosition( nMidCol, nMidRow );
633 
634  /* The loop will find the column/row index of the cell right of/below
635  the cell containing the passed point, unless the point is located at
636  the top or left border of the containing cell. */
637  while( bLoopCols || bLoopRows )
638  {
639  bLoopCols = bLoopCols && lclUpdateInterval( nBegCol, nMidCol, nEndCol, aBegPos.X, aMidPos.X, aEndPos.X, rPosition.X );
640  bLoopRows = bLoopRows && lclUpdateInterval( nBegRow, nMidRow, nEndRow, aBegPos.Y, aMidPos.Y, aEndPos.Y, rPosition.Y );
641  aMidPos = getCellPosition( nMidCol, nMidRow );
642  }
643 
644  /* The cell left of/above the current search position contains the passed
645  point, unless the point is located on the top/left border of the cell,
646  or the last column/row of the sheet has been reached. */
647  if( aMidPos.X > rPosition.X ) --nMidCol;
648  if( aMidPos.Y > rPosition.Y ) --nMidRow;
649  return ScAddress( nMidCol, nMidRow, getSheetIndex() );
650 }
651 
652 ScRange WorksheetGlobals::getCellRangeFromRectangle( const awt::Rectangle& rRect ) const
653 {
654  ScAddress aStartAddr = getCellAddressFromPosition( awt::Point( rRect.X, rRect.Y ) );
655  awt::Point aBotRight( rRect.X + rRect.Width, rRect.Y + rRect.Height );
656  ScAddress aEndAddr = getCellAddressFromPosition( aBotRight );
657  bool bMultiCols = aStartAddr.Col() < aEndAddr.Col();
658  bool bMultiRows = aStartAddr.Row() < aEndAddr.Row();
659  if( bMultiCols || bMultiRows )
660  {
661  /* Reduce end position of the cell range to previous column or row, if
662  the rectangle ends exactly between two columns or rows. */
663  awt::Point aEndPos = getCellPosition( aEndAddr.Col(), aEndAddr.Row() );
664  if( bMultiCols && (aBotRight.X <= aEndPos.X) )
665  aEndAddr.IncCol(-1);
666  if( bMultiRows && (aBotRight.Y <= aEndPos.Y) )
667  aEndAddr.IncRow(-1);
668  }
669  return ScRange( aStartAddr.Col(), aStartAddr.Row(), getSheetIndex(),
670  aEndAddr.Col(), aEndAddr.Row(), getSheetIndex() );
671 }
672 
673 void WorksheetGlobals::setPageBreak( const PageBreakModel& rModel, bool bRowBreak )
674 {
675  if( rModel.mbManual && (rModel.mnColRow > 0) )
676  {
677  PropertySet aPropSet( bRowBreak ? getRow( rModel.mnColRow ) : getColumn( rModel.mnColRow ) );
678  aPropSet.setProperty( PROP_IsStartOfNewPage, true );
679  }
680 }
681 
683 {
684  maHyperlinks.push_back( rModel );
685 }
686 
688 {
689  maValidations.push_back( rModel );
690 }
691 
692 void WorksheetGlobals::setDrawingPath( const OUString& rDrawingPath )
693 {
694  maDrawingPath = rDrawingPath;
695 }
696 
697 void WorksheetGlobals::setVmlDrawingPath( const OUString& rVmlDrawingPath )
698 {
699  maVmlDrawingPath = rVmlDrawingPath;
700 }
701 
703 {
704  maUsedArea.aStart.SetCol( ::std::min( maUsedArea.aStart.Col(), rAddress.Col() ) );
705  maUsedArea.aStart.SetRow( ::std::min( maUsedArea.aStart.Row(), rAddress.Row() ) );
706  maUsedArea.aEnd.SetCol( ::std::max( maUsedArea.aEnd.Col(), rAddress.Col() ) );
707  maUsedArea.aEnd.SetRow( ::std::max( maUsedArea.aEnd.Row(), rAddress.Row() ) );
708 }
709 
711 {
712  extendUsedArea( rRange.aStart );
713  extendUsedArea( rRange.aEnd );
714 }
715 
717 {
718  extendUsedArea( rRange.aStart );
719  extendUsedArea( rRange.aEnd );
720 }
721 
722 void WorksheetGlobals::extendShapeBoundingBox( const awt::Rectangle& rShapeRect )
723 {
724  if( (maShapeBoundingBox.Width == 0) && (maShapeBoundingBox.Height == 0) )
725  {
726  // width and height of maShapeBoundingBox are assumed to be zero on first cell
727  maShapeBoundingBox = rShapeRect;
728  }
729  else
730  {
731  sal_Int32 nEndX = ::std::max( maShapeBoundingBox.X + maShapeBoundingBox.Width, rShapeRect.X + rShapeRect.Width );
732  sal_Int32 nEndY = ::std::max( maShapeBoundingBox.Y + maShapeBoundingBox.Height, rShapeRect.Y + rShapeRect.Height );
733  maShapeBoundingBox.X = ::std::min( maShapeBoundingBox.X, rShapeRect.X );
734  maShapeBoundingBox.Y = ::std::min( maShapeBoundingBox.Y, rShapeRect.Y );
735  maShapeBoundingBox.Width = nEndX - maShapeBoundingBox.X;
736  maShapeBoundingBox.Height = nEndY - maShapeBoundingBox.Y;
737  }
738 }
739 
740 void WorksheetGlobals::setBaseColumnWidth( sal_Int32 nWidth )
741 {
742  // do not modify width, if setDefaultColumnWidth() has been used
743  if( !mbHasDefWidth && (nWidth > 0) )
744  {
745  // #i3006# add 5 pixels padding to the width
746  const UnitConverter& rUnitConv = getUnitConverter();
748  rUnitConv.scaleToMm100( nWidth, Unit::Digit ) + rUnitConv.scaleToMm100( 5, Unit::ScreenX ), Unit::Digit );
749  }
750 }
751 
753 {
754  // overrides a width set with setBaseColumnWidth()
755  if( fWidth > 0.0 )
756  {
757  maDefColModel.mfWidth = fWidth;
758  mbHasDefWidth = true;
759  }
760 }
761 
763 {
764  // convert 1-based OOXML column indexes to 0-based API column indexes
765  sal_Int32 nFirstCol = rModel.maRange.mnFirst - 1;
766  sal_Int32 nLastCol = rModel.maRange.mnLast - 1;
767  if( !(getAddressConverter().checkCol( nFirstCol, true ) && (nFirstCol <= nLastCol)) )
768  return;
769 
770  // Validate last column index.
771  // If last column is equal to last possible column, Excel adds one
772  // more. We do that also in XclExpColinfo::SaveXml() and for 1024 end
773  // up with 1025 instead, which would lead to excess columns in
774  // checkCol(). Cater for this oddity.
775  if (nLastCol == mrMaxApiPos.Col() + 1)
776  --nLastCol;
777  // This is totally fouled up. If we saved 1025 and the file is saved
778  // with Excel again, it increments the value to 1026.
779  else if (nLastCol == mrMaxApiPos.Col() + 2)
780  nLastCol -= 2;
781  // Excel may add a column range for the remaining columns (with
782  // <cols><col .../></cols>), even if not used or only used to grey out
783  // columns in page break view. Don't let that trigger overflow warning,
784  // so check for the last possible column. If there really is content in
785  // the range that should be caught anyway.
786  else if (nLastCol == getAddressConverter().getMaxXlsAddress().Col())
787  nLastCol = mrMaxApiPos.Col();
788  // User may have applied custom column widths to arbitrary excess
789  // columns. Ignore those and don't track as overflow columns (false).
790  // Effectively this does the same as the above cases, just keep them
791  // for explanation.
792  // Actual data present should trigger the overflow detection later.
793  else if( !getAddressConverter().checkCol( nLastCol, false ) )
794  nLastCol = mrMaxApiPos.Col();
795  // try to find entry in column model map that is able to merge with the passed model
796  bool bInsertModel = true;
797  if( !maColModels.empty() )
798  {
799  // find first column model range following nFirstCol (nFirstCol < aIt->first), or end of map
800  ColumnModelRangeMap::iterator aIt = maColModels.upper_bound( nFirstCol );
801  OSL_ENSURE( aIt == maColModels.end(), "WorksheetGlobals::setColModel - columns are unsorted" );
802  // if inserting before another column model, get last free column
803  OSL_ENSURE( (aIt == maColModels.end()) || (nLastCol < aIt->first), "WorksheetGlobals::setColModel - multiple models of the same column" );
804  if( aIt != maColModels.end() )
805  nLastCol = ::std::min( nLastCol, aIt->first - 1 );
806  if( aIt != maColModels.begin() )
807  {
808  // go to previous map element (which may be able to merge with the passed model)
809  --aIt;
810  // the usage of upper_bound() above ensures that aIt->first is less than or equal to nFirstCol now
811  sal_Int32& rnLastMapCol = aIt->second.second;
812  OSL_ENSURE( rnLastMapCol < nFirstCol, "WorksheetGlobals::setColModel - multiple models of the same column" );
813  nFirstCol = ::std::max( rnLastMapCol + 1, nFirstCol );
814  if( (rnLastMapCol + 1 == nFirstCol) && (nFirstCol <= nLastCol) && aIt->second.first.isMergeable( rModel ) )
815  {
816  // can merge with existing model, update last column index
817  rnLastMapCol = nLastCol;
818  bInsertModel = false;
819  }
820  }
821  }
822  if( nFirstCol <= nLastCol )
823  {
824  // insert the column model, if it has not been merged with another
825  if( bInsertModel )
826  maColModels[ nFirstCol ] = ColumnModelRange( rModel, nLastCol );
827  // set column formatting directly
828  convertColumnFormat( nFirstCol, nLastCol, rModel.mnXfId );
829  }
830 }
831 
832 void WorksheetGlobals::convertColumnFormat( sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId )
833 {
834  ScRange aRange( nFirstCol, 0, getSheetIndex(), nLastCol, mrMaxApiPos.Row(), getSheetIndex() );
835  if( getAddressConverter().validateCellRange( aRange, true, false ) )
836  {
837  const StylesBuffer& rStyles = getStyles();
838 
839  // Set cell styles via direct API - the preferred approach.
840  ScDocumentImport& rDoc = getDocImport();
841  rStyles.writeCellXfToDoc(rDoc, aRange, nXfId);
842  }
843 }
844 
845 void WorksheetGlobals::setDefaultRowSettings( double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom )
846 {
847  maDefRowModel.mfHeight = fHeight;
848  maDefRowModel.mbCustomHeight = bCustomHeight;
849  maDefRowModel.mbHidden = bHidden;
850  maDefRowModel.mbThickTop = bThickTop;
851  maDefRowModel.mbThickBottom = bThickBottom;
852 }
853 
855 {
856  // convert 1-based OOXML row index to 0-based API row index
857  sal_Int32 nRow = rModel.mnRow - 1;
858  if( getAddressConverter().checkRow( nRow, true ) )
859  {
860  // try to find entry in row model map that is able to merge with the passed model
861  bool bInsertModel = true;
862  bool bUnusedRow = true;
863  if( !maRowModels.empty() )
864  {
865  // find first row model range following nRow (nRow < aIt->first), or end of map
866  RowModelRangeMap::iterator aIt = maRowModels.upper_bound( nRow );
867  OSL_ENSURE( aIt == maRowModels.end(), "WorksheetGlobals::setRowModel - rows are unsorted" );
868  if( aIt != maRowModels.begin() )
869  {
870  // go to previous map element (which may be able to merge with the passed model)
871  --aIt;
872  // the usage of upper_bound() above ensures that aIt->first is less than or equal to nRow now
873  sal_Int32& rnLastMapRow = aIt->second.second;
874  bUnusedRow = rnLastMapRow < nRow;
875  OSL_ENSURE( bUnusedRow, "WorksheetGlobals::setRowModel - multiple models of the same row" );
876  if( (rnLastMapRow + 1 == nRow) && aIt->second.first.isMergeable( rModel ) )
877  {
878  // can merge with existing model, update last row index
879  ++rnLastMapRow;
880  bInsertModel = false;
881  }
882  }
883  }
884  if( bUnusedRow )
885  {
886  // insert the row model, if it has not been merged with another
887  if( bInsertModel )
888  maRowModels[ nRow ] = RowModelRange( rModel, nRow );
889  // set row formatting
890  maSheetData.setRowFormat( nRow, rModel.mnXfId, rModel.mbCustomFormat );
891  // set column spans
892  maSheetData.setColSpans( nRow, rModel.maColSpans );
893  }
894  }
895 
896  UpdateRowProgress( maUsedArea, nRow );
897 }
898 
899 // This is called at a higher frequency inside the (threaded) inner loop.
900 void WorksheetGlobals::UpdateRowProgress( const ScRange& rUsedArea, SCROW nRow )
901 {
902  if (!mxRowProgress || nRow < rUsedArea.aStart.Row() || rUsedArea.aEnd.Row() < nRow)
903  return;
904 
905  double fNewPos = static_cast<double>(nRow - rUsedArea.aStart.Row() + 1.0) / (rUsedArea.aEnd.Row() - rUsedArea.aStart.Row() + 1.0);
906 
907  if (mbFastRowProgress)
908  mxRowProgress->setPosition(fNewPos);
909  else
910  {
911  double fCurPos = mxRowProgress->getPosition();
912  if (fCurPos < fNewPos && (fNewPos - fCurPos) > 0.3)
913  // Try not to re-draw progress bar too frequently.
914  mxRowProgress->setPosition(fNewPos);
915  }
916 }
917 
919 {
920  // set default cell style for unused cells
921  ScDocumentImport& rDoc = getDocImport();
922 
923  ScStyleSheet* pStyleSheet =
924  static_cast<ScStyleSheet*>(rDoc.getDoc().GetStyleSheetPool()->Find(
925  getStyles().getDefaultStyleName(), SfxStyleFamily::Para));
926 
927  if (pStyleSheet)
928  rDoc.setCellStyleToSheet(getSheetIndex(), *pStyleSheet);
929 
930  /* Remember the current sheet index in global data, needed by global
931  objects, e.g. the chart converter. */
933 }
934 
936 {
937  lclUpdateProgressBar( mxRowProgress, 1.0 );
939  // assumes getTables().finalizeImport ( which creates the DatabaseRanges )
940  // has been called already
942 
944  lclUpdateProgressBar( mxFinalProgress, 0.25 );
952 
953  lclUpdateProgressBar( mxFinalProgress, 0.5 );
954  convertColumns();
955 
956  // tdf#99913 rows hidden by filter need extra flag
957  ScDocument& rDoc = getScDocument();
958  std::vector<sc::ColRowSpan> aSpans;
959  SCTAB nTab = getSheetIndex();
960  ScDBData* pDBData = rDoc.GetAnonymousDBData(nTab);
961  if (pDBData && pDBData->HasAutoFilter())
962  {
963  ScRange aRange;
964  pDBData->GetArea(aRange);
965  SCCOLROW nStartRow = static_cast<SCCOLROW>(aRange.aStart.Row());
966  SCCOLROW nEndRow = static_cast<SCCOLROW>(aRange.aEnd.Row());
967  aSpans.push_back(sc::ColRowSpan(nStartRow, nEndRow));
968  }
969  ScDBCollection* pDocColl = rDoc.GetDBCollection();
970  if (!pDocColl->empty())
971  {
972  ScDBCollection::NamedDBs& rDBs = pDocColl->getNamedDBs();
973  for (const auto& rxDB : rDBs)
974  {
975  if (rxDB->GetTab() == nTab && rxDB->HasAutoFilter())
976  {
977  ScRange aRange;
978  rxDB->GetArea(aRange);
979  SCCOLROW nStartRow = static_cast<SCCOLROW>(aRange.aStart.Row());
980  SCCOLROW nEndRow = static_cast<SCCOLROW>(aRange.aEnd.Row());
981  aSpans.push_back(sc::ColRowSpan(nStartRow, nEndRow));
982  }
983  }
984  }
985  convertRows(aSpans);
986  lclUpdateProgressBar( mxFinalProgress, 1.0 );
987 }
988 
990 {
992 
993  // forget current sheet index in global data
994  setCurrentSheetIndex( -1 );
995 }
996 
997 // private --------------------------------------------------------------------
998 
1000 {
1001  for (auto const& link : maHyperlinks)
1002  {
1003  OUString aUrl = getHyperlinkUrl(link);
1004  // try to insert URL into each cell of the range
1005  if( !aUrl.isEmpty() )
1006  for( ScAddress aAddress(link.maRange.aStart.Col(), link.maRange.aStart.Row(), getSheetIndex() ); aAddress.Row() <= link.maRange.aEnd.Row(); aAddress.IncRow() )
1007  for( aAddress.SetCol(link.maRange.aStart.Col()); aAddress.Col() <= link.maRange.aEnd.Col(); aAddress.IncCol() )
1008  insertHyperlink( aAddress, aUrl );
1009  }
1010 }
1011 
1012 OUString WorksheetGlobals::getHyperlinkUrl( const HyperlinkModel& rHyperlink ) const
1013 {
1014  OUStringBuffer aUrlBuffer;
1015  if( !rHyperlink.maTarget.isEmpty() )
1016  aUrlBuffer.append( getBaseFilter().getAbsoluteUrl( rHyperlink.maTarget ) );
1017  if( !rHyperlink.maLocation.isEmpty() )
1018  aUrlBuffer.append( '#' ).append( rHyperlink.maLocation );
1019  OUString aUrl = aUrlBuffer.makeStringAndClear();
1020 
1021  if( aUrl.startsWith("#") )
1022  {
1023  sal_Int32 nSepPos = aUrl.lastIndexOf( '!' );
1024  if( nSepPos > 0 )
1025  {
1026  // Do not attempt to blindly convert '#SheetName!A1' to
1027  // '#SheetName.A1', it can be #SheetName!R1C1 as well. Hyperlink
1028  // handler has to handle all, but prefer '#SheetName.A1' if
1029  // possible.
1030  if (nSepPos < aUrl.getLength() - 1)
1031  {
1032  ScRange aRange;
1033  const ScDocumentImport& rDoc = getDocImport();
1034  if ((aRange.ParseAny( aUrl.copy( nSepPos + 1 ), rDoc.getDoc(),
1037  aUrl = aUrl.replaceAt( nSepPos, 1, OUString( '.' ) );
1038  }
1039  // #i66592# convert sheet names that have been renamed on import
1040  OUString aSheetName = aUrl.copy( 1, nSepPos - 1 );
1041  OUString aCalcName = getWorksheets().getCalcSheetName( aSheetName );
1042  if( !aCalcName.isEmpty() )
1043  aUrl = aUrl.replaceAt( 1, nSepPos - 1, aCalcName );
1044  }
1045  }
1046 
1047  return aUrl;
1048 }
1049 
1050 void WorksheetGlobals::insertHyperlink( const ScAddress& rAddress, const OUString& rUrl )
1051 {
1052  ScDocumentImport& rDoc = getDocImport();
1053  ScRefCellValue aCell(rDoc.getDoc(), rAddress);
1054 
1055  if (aCell.meType == CELLTYPE_STRING || aCell.meType == CELLTYPE_EDIT)
1056  {
1057  OUString aStr = aCell.getString(&rDoc.getDoc());
1058  ScFieldEditEngine& rEE = rDoc.getDoc().GetEditEngine();
1059  rEE.Clear();
1060 
1061  SvxURLField aURLField(rUrl, aStr, SvxURLFormat::Repr);
1062  SvxFieldItem aURLItem(aURLField, EE_FEATURE_FIELD);
1063  rEE.QuickInsertField(aURLItem, ESelection());
1064 
1065  rDoc.setEditCell(rAddress, rEE.CreateTextObject());
1066  }
1067  else
1068  {
1069  // Handle other cell types e.g. formulas ( and ? ) that have associated
1070  // hyperlinks.
1071  // Ideally all hyperlinks should be treated as below. For the moment,
1072  // given the current absence of ods support lets just handle what we
1073  // previously didn't handle the new way.
1074  // Unfortunately we won't be able to preserve such hyperlinks when
1075  // saving to ods. Note: when we are able to save such hyperlinks to ods
1076  // we should handle *all* imported hyperlinks as below ( e.g. as cell
1077  // attribute ) for better interoperability.
1078 
1079  SfxStringItem aItem(ATTR_HYPERLINK, rUrl);
1080  rDoc.getDoc().ApplyAttr(rAddress.Col(), rAddress.Row(), rAddress.Tab(), aItem);
1081  }
1082 }
1083 
1085 {
1086  for (auto const& validation : maValidations)
1087  {
1088  PropertySet aPropSet( getCellRangeList(validation.maRanges) );
1089 
1090  Reference< XPropertySet > xValidation( aPropSet.getAnyProperty( PROP_Validation ), UNO_QUERY );
1091  if( xValidation.is() )
1092  {
1093  PropertySet aValProps( xValidation );
1094 
1095  try
1096  {
1097  const OUString aToken = validation.msRef.getToken( 0, ' ' );
1098 
1099  Reference<XSpreadsheet> xSheet = getSheetFromDoc( getCurrentSheetIndex() );
1100  Reference<XCellRange> xDBCellRange;
1101  Reference<XCell> xCell;
1102  xDBCellRange = xSheet->getCellRangeByName( aToken );
1103 
1104  xCell = xDBCellRange->getCellByPosition( 0, 0 );
1105  Reference<XCellAddressable> xCellAddressable( xCell, UNO_QUERY_THROW );
1106  CellAddress aFirstCell = xCellAddressable->getCellAddress();
1107  Reference<XSheetCondition> xCondition( xValidation, UNO_QUERY_THROW );
1108  xCondition->setSourcePosition( aFirstCell );
1109  }
1110  catch(const Exception&)
1111  {
1112  }
1113 
1114  // convert validation type to API enum
1115  ValidationType eType = ValidationType_ANY;
1116  switch( validation.mnType )
1117  {
1118  case XML_custom: eType = ValidationType_CUSTOM; break;
1119  case XML_date: eType = ValidationType_DATE; break;
1120  case XML_decimal: eType = ValidationType_DECIMAL; break;
1121  case XML_list: eType = ValidationType_LIST; break;
1122  case XML_none: eType = ValidationType_ANY; break;
1123  case XML_textLength: eType = ValidationType_TEXT_LEN; break;
1124  case XML_time: eType = ValidationType_TIME; break;
1125  case XML_whole: eType = ValidationType_WHOLE; break;
1126  default: OSL_FAIL( "WorksheetData::finalizeValidationRanges - unknown validation type" );
1127  }
1128  aValProps.setProperty( PROP_Type, eType );
1129 
1130  // convert error alert style to API enum
1131  ValidationAlertStyle eAlertStyle = ValidationAlertStyle_STOP;
1132  switch( validation.mnErrorStyle )
1133  {
1134  case XML_information: eAlertStyle = ValidationAlertStyle_INFO; break;
1135  case XML_stop: eAlertStyle = ValidationAlertStyle_STOP; break;
1136  case XML_warning: eAlertStyle = ValidationAlertStyle_WARNING; break;
1137  default: OSL_FAIL( "WorksheetData::finalizeValidationRanges - unknown error style" );
1138  }
1139  aValProps.setProperty( PROP_ErrorAlertStyle, eAlertStyle );
1140 
1141  // convert dropdown style to API visibility constants
1142  sal_Int16 nVisibility = validation.mbNoDropDown ? TableValidationVisibility::INVISIBLE : TableValidationVisibility::UNSORTED;
1143  aValProps.setProperty( PROP_ShowList, nVisibility );
1144 
1145  // messages
1146  aValProps.setProperty( PROP_ShowInputMessage, validation.mbShowInputMsg );
1147  aValProps.setProperty( PROP_InputTitle, validation.maInputTitle );
1148  aValProps.setProperty( PROP_InputMessage, validation.maInputMessage );
1149  aValProps.setProperty( PROP_ShowErrorMessage, validation.mbShowErrorMsg );
1150  aValProps.setProperty( PROP_ErrorTitle, validation.maErrorTitle );
1151  aValProps.setProperty( PROP_ErrorMessage, validation.maErrorMessage );
1152 
1153  // allow blank cells
1154  aValProps.setProperty( PROP_IgnoreBlankCells, validation.mbAllowBlank );
1155 
1156  try
1157  {
1158  // condition operator
1159  Reference< XSheetCondition2 > xSheetCond( xValidation, UNO_QUERY_THROW );
1160  if( eType == ValidationType_CUSTOM )
1161  xSheetCond->setConditionOperator( ConditionOperator2::FORMULA );
1162  else
1163  xSheetCond->setConditionOperator( CondFormatBuffer::convertToApiOperator( validation.mnOperator ) );
1164 
1165  // condition formulas
1166  Reference< XMultiFormulaTokens > xTokens( xValidation, UNO_QUERY_THROW );
1167  xTokens->setTokens( 0, validation.maTokens1 );
1168  xTokens->setTokens( 1, validation.maTokens2 );
1169  }
1170  catch( Exception& )
1171  {
1172  }
1173 
1174  // write back validation settings to cell range(s)
1175  aPropSet.setProperty( PROP_Validation, xValidation );
1176  }
1177  }
1178 }
1179 
1181 {
1182  sal_Int32 nNextCol = 0;
1183  sal_Int32 nMaxCol = mrMaxApiPos.Col();
1184  // stores first grouped column index for each level
1185  OutlineLevelVec aColLevels;
1186 
1187  for (auto const& colModel : maColModels)
1188  {
1189  // column indexes are stored 0-based in maColModels
1190  ValueRange aColRange( ::std::max( colModel.first, nNextCol ), ::std::min( colModel.second.second, nMaxCol ) );
1191  // process gap between two column models, use default column model
1192  if( nNextCol < aColRange.mnFirst )
1193  convertColumns( aColLevels, ValueRange( nNextCol, aColRange.mnFirst - 1 ), maDefColModel );
1194  // process the column model
1195  convertColumns( aColLevels, aColRange, colModel.second.first );
1196  // cache next column to be processed
1197  nNextCol = aColRange.mnLast + 1;
1198  }
1199 
1200  // remaining default columns to end of sheet
1201  convertColumns( aColLevels, ValueRange( nNextCol, nMaxCol ), maDefColModel );
1202  // close remaining column outlines spanning to end of sheet
1203  convertOutlines( aColLevels, nMaxCol + 1, 0, false, false );
1204 }
1205 
1207  const ValueRange& rColRange, const ColumnModel& rModel )
1208 {
1209  // column width: convert 'number of characters' to column width in 1/100 mm
1210  sal_Int32 nWidth = getUnitConverter().scaleToMm100( rModel.mfWidth, Unit::Digit );
1211 
1212  // macro sheets have double width
1214  nWidth *= 2;
1215 
1216  SCTAB nTab = getSheetIndex();
1217  ScDocument& rDoc = getScDocument();
1218  SCCOL nStartCol = rColRange.mnFirst;
1219  SCCOL nEndCol = rColRange.mnLast;
1220 
1221  if( nWidth > 0 )
1222  {
1223  for( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
1224  {
1225  rDoc.SetColWidthOnly(nCol, nTab, static_cast<sal_uInt16>(convertMm100ToTwip(nWidth)));
1226  }
1227  }
1228 
1229  // hidden columns: TODO: #108683# hide columns later?
1230  if( rModel.mbHidden )
1231  {
1232  rDoc.SetColHidden( nStartCol, nEndCol, nTab, true );
1233  }
1234 
1235  // outline settings for this column range
1236  convertOutlines( orColLevels, rColRange.mnFirst, rModel.mnLevel, rModel.mbCollapsed, false );
1237 }
1238 
1239 void WorksheetGlobals::convertRows(const std::vector<sc::ColRowSpan>& rSpans)
1240 {
1241  sal_Int32 nNextRow = 0;
1242  sal_Int32 nMaxRow = mrMaxApiPos.Row();
1243  // stores first grouped row index for each level
1244  OutlineLevelVec aRowLevels;
1245 
1246  for (auto const& rowModel : maRowModels)
1247  {
1248  // row indexes are stored 0-based in maRowModels
1249  ValueRange aRowRange( ::std::max( rowModel.first, nNextRow ), ::std::min( rowModel.second.second, nMaxRow ) );
1250  // process gap between two row models, use default row model
1251  if( nNextRow < aRowRange.mnFirst )
1252  convertRows(aRowLevels, ValueRange(nNextRow, aRowRange.mnFirst - 1), maDefRowModel,
1253  rSpans);
1254  // process the row model
1255  convertRows(aRowLevels, aRowRange, rowModel.second.first, rSpans, maDefRowModel.mfHeight);
1256  // cache next row to be processed
1257  nNextRow = aRowRange.mnLast + 1;
1258  }
1259 
1260  // remaining default rows to end of sheet
1261  convertRows(aRowLevels, ValueRange(nNextRow, nMaxRow), maDefRowModel, rSpans);
1262  // close remaining row outlines spanning to end of sheet
1263  convertOutlines( aRowLevels, nMaxRow + 1, 0, false, true );
1264 }
1265 
1266 void WorksheetGlobals::convertRows(OutlineLevelVec& orRowLevels, const ValueRange& rRowRange,
1267  const RowModel& rModel,
1268  const std::vector<sc::ColRowSpan>& rSpans, double fDefHeight)
1269 {
1270  // row height: convert points to row height in 1/100 mm
1271  double fHeight = (rModel.mfHeight >= 0.0) ? rModel.mfHeight : fDefHeight;
1272  sal_Int32 nHeight = getUnitConverter().scaleToMm100( fHeight, Unit::Point );
1273  SCROW nStartRow = rRowRange.mnFirst;
1274  SCROW nEndRow = rRowRange.mnLast;
1275  SCTAB nTab = getSheetIndex();
1276  if( nHeight > 0 )
1277  {
1278  /* always import the row height, ensures better layout */
1279  ScDocument& rDoc = getScDocument();
1280  rDoc.SetRowHeightOnly(nStartRow, nEndRow, nTab,
1281  static_cast<sal_uInt16>(convertMm100ToTwip(nHeight)));
1282  if(rModel.mbCustomHeight)
1283  rDoc.SetManualHeight( nStartRow, nEndRow, nTab, true );
1284  }
1285 
1286  // hidden rows: TODO: #108683# hide rows later?
1287  if( rModel.mbHidden )
1288  {
1289  ScDocument& rDoc = getScDocument();
1290  rDoc.SetRowHidden( nStartRow, nEndRow, nTab, true );
1291  for (const auto& rSpan : rSpans)
1292  {
1293  // tdf#99913 rows hidden by filter need extra flag
1294  if (rSpan.mnStart <= nStartRow && nStartRow <= rSpan.mnEnd)
1295  {
1296  SCROW nLast = ::std::min(nEndRow, rSpan.mnEnd);
1297  rDoc.SetRowFiltered(nStartRow, nLast, nTab, true);
1298  break;
1299  }
1300  }
1301  }
1302 
1303  // outline settings for this row range
1304  convertOutlines( orRowLevels, rRowRange.mnFirst, rModel.mnLevel, rModel.mbCollapsed, true );
1305 }
1306 
1308  sal_Int32 nColRow, sal_Int32 nLevel, bool bCollapsed, bool bRows )
1309 {
1310  /* It is ensured from caller functions, that this function is called
1311  without any gaps between the processed column or row ranges. */
1312 
1313  OSL_ENSURE( nLevel >= 0, "WorksheetGlobals::convertOutlines - negative outline level" );
1314  nLevel = ::std::max< sal_Int32 >( nLevel, 0 );
1315 
1316  sal_Int32 nSize = orLevels.size();
1317  if( nSize < nLevel )
1318  {
1319  // Outline level increased. Push the begin column position.
1320  orLevels.insert(orLevels.end(), nLevel - nSize, nColRow);
1321  }
1322  else if( nLevel < nSize )
1323  {
1324  // Outline level decreased. Pop them all out.
1325  for( sal_Int32 nIndex = nLevel; nIndex < nSize; ++nIndex )
1326  {
1327  sal_Int32 nFirstInLevel = orLevels.back();
1328  orLevels.pop_back();
1329  groupColumnsOrRows( nFirstInLevel, nColRow - 1, bCollapsed, bRows );
1330  bCollapsed = false; // collapse only once
1331  }
1332  }
1333 }
1334 
1335 void WorksheetGlobals::groupColumnsOrRows( sal_Int32 nFirstColRow, sal_Int32 nLastColRow, bool bCollapse, bool bRows )
1336 {
1337  try
1338  {
1339  Reference< XSheetOutline > xOutline( mxSheet, UNO_QUERY_THROW );
1340  if( bRows )
1341  {
1342  CellRangeAddress aRange( getSheetIndex(), 0, nFirstColRow, 0, nLastColRow );
1343  xOutline->group( aRange, TableOrientation_ROWS );
1344  if( bCollapse )
1345  xOutline->hideDetail( aRange );
1346  }
1347  else
1348  {
1349  CellRangeAddress aRange( getSheetIndex(), nFirstColRow, 0, nLastColRow, 0 );
1350  xOutline->group( aRange, TableOrientation_COLUMNS );
1351  if( bCollapse )
1352  xOutline->hideDetail( aRange );
1353  }
1354  }
1355  catch( Exception& )
1356  {
1357  }
1358 }
1359 
1361 {
1362  // calculate the current drawing page size (after rows/columns are imported)
1364  aRangeProp.getProperty( maDrawPageSize, PROP_Size );
1365 
1366  // import DML and VML
1367  if( !maDrawingPath.isEmpty() )
1369  if( !maVmlDrawingPath.isEmpty() )
1371 
1372  // comments (after callout shapes have been imported from VML/DFF)
1374 
1375  /* Extend used area of the sheet by cells covered with drawing objects.
1376  Needed if the imported document is inserted as "OLE object from file"
1377  and thus does not provide an OLE size property by itself. */
1378  if( (maShapeBoundingBox.Width > 0) || (maShapeBoundingBox.Height > 0) )
1380 
1381  // if no used area is set, default to A1
1382  if( maUsedArea.aStart.Col() > maUsedArea.aEnd.Col() )
1383  {
1384  maUsedArea.aStart.SetCol( 0 );
1385  maUsedArea.aEnd.SetCol( 0 );
1386  }
1387 
1388  if( maUsedArea.aStart.Row() > maUsedArea.aEnd.Row() )
1389  {
1390  maUsedArea.aStart.SetRow( 0 );
1391  maUsedArea.aEnd.SetRow( 0 );
1392  }
1393 
1394  /* Register the used area of this sheet in global view settings. The
1395  global view settings will set the visible area if this document is an
1396  embedded OLE object. */
1398 
1399  /* #i103686# Set right-to-left sheet layout. Must be done after all
1400  drawing shapes to simplify calculation of shape coordinates. */
1402  {
1403  PropertySet aPropSet( mxSheet );
1404  aPropSet.setProperty( PROP_TableLayout, WritingMode2::RL_TB );
1405  }
1406 }
1407 
1409  WorkbookHelper( rSheetGlob ),
1410  mrSheetGlob( rSheetGlob )
1411 {
1412 }
1413 
1415 {
1416  return getDocImport().getDoc();
1417 }
1418 
1420  const ISegmentProgressBarRef& rxProgressBar, WorksheetType eSheetType, SCTAB nSheet )
1421 {
1422  WorksheetGlobalsRef xSheetGlob = std::make_shared<WorksheetGlobals>( rHelper, rxProgressBar, eSheetType, nSheet );
1423  if( !xSheetGlob->isValidSheet() )
1424  xSheetGlob.reset();
1425  return xSheetGlob;
1426 }
1427 
1429 {
1430  return static_cast< IWorksheetProgress *>( xRef.get() );
1431 }
1432 
1434 {
1435  return mrSheetGlob.getSheetType();
1436 }
1437 
1439 {
1440  return mrSheetGlob.getSheetIndex();
1441 }
1442 
1443 const Reference< XSpreadsheet >& WorksheetHelper::getSheet() const
1444 {
1445  return mrSheetGlob.getSheet();
1446 }
1447 
1448 Reference< XCell > WorksheetHelper::getCell( const ScAddress& rAddress ) const
1449 {
1450  return mrSheetGlob.getCell( rAddress );
1451 }
1452 
1453 Reference< XCellRange > WorksheetHelper::getCellRange( const ScRange& rRange ) const
1454 {
1455  return mrSheetGlob.getCellRange( rRange );
1456 }
1457 
1458 Reference< XDrawPage > WorksheetHelper::getDrawPage() const
1459 {
1460  return mrSheetGlob.getDrawPage();
1461 }
1462 
1463 awt::Point WorksheetHelper::getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const
1464 {
1465  return mrSheetGlob.getCellPosition( nCol, nRow );
1466 }
1467 
1468 const awt::Size& WorksheetHelper::getDrawPageSize() const
1469 {
1470  return mrSheetGlob.getDrawPageSize();
1471 }
1472 
1474 {
1475  return mrSheetGlob.getSheetData();
1476 }
1477 
1479 {
1480  return mrSheetGlob.getCondFormats();
1481 }
1482 
1484 {
1485  return mrSheetGlob.getComments();
1486 }
1487 
1489 {
1490  return mrSheetGlob.getAutoFilters();
1491 }
1492 
1494 {
1495  return mrSheetGlob.getQueryTables();
1496 }
1497 
1499 {
1501 }
1502 
1504 {
1505  return mrSheetGlob.getPageSettings();
1506 }
1507 
1509 {
1511 }
1512 
1514 {
1515  return mrSheetGlob.getVmlDrawing();
1516 }
1517 
1519 {
1520  return mrSheetGlob.getExtLst();
1521 }
1522 
1523 void WorksheetHelper::setPageBreak( const PageBreakModel& rModel, bool bRowBreak )
1524 {
1525  mrSheetGlob.setPageBreak( rModel, bRowBreak );
1526 }
1527 
1529 {
1530  mrSheetGlob.setHyperlink( rModel );
1531 }
1532 
1534 {
1535  mrSheetGlob.setValidation( rModel );
1536 }
1537 
1538 void WorksheetHelper::setDrawingPath( const OUString& rDrawingPath )
1539 {
1540  mrSheetGlob.setDrawingPath( rDrawingPath );
1541 }
1542 
1543 void WorksheetHelper::setVmlDrawingPath( const OUString& rVmlDrawingPath )
1544 {
1545  mrSheetGlob.setVmlDrawingPath( rVmlDrawingPath );
1546 }
1547 
1549 {
1550  mrSheetGlob.extendUsedArea( rAddress );
1551 }
1552 
1553 void WorksheetHelper::extendShapeBoundingBox( const awt::Rectangle& rShapeRect )
1554 {
1555  mrSheetGlob.extendShapeBoundingBox( rShapeRect );
1556 }
1557 
1558 void WorksheetHelper::setBaseColumnWidth( sal_Int32 nWidth )
1559 {
1560  mrSheetGlob.setBaseColumnWidth( nWidth );
1561 }
1562 
1564 {
1566 }
1567 
1569 {
1570  mrSheetGlob.setColumnModel( rModel );
1571 }
1572 
1573 void WorksheetHelper::setDefaultRowSettings( double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom )
1574 {
1575  mrSheetGlob.setDefaultRowSettings( fHeight, bCustomHeight, bHidden, bThickTop, bThickBottom );
1576 }
1577 
1579 {
1580  mrSheetGlob.setRowModel( rModel );
1581 }
1582 
1584  const ScAddress& rAddress, const OUString& rValueStr, sal_Int32 nCellType )
1585 {
1586  getFormulaBuffer().setCellFormulaValue(rAddress, rValueStr, nCellType);
1587 }
1588 
1589 void WorksheetHelper::putRichString( const ScAddress& rAddress, const RichString& rString, const oox::xls::Font* pFirstPortionFont )
1590 {
1592 
1593  // The cell will own the text object instance returned from convert().
1594  getDocImport().setEditCell(rAddress, rString.convert(rEE, pFirstPortionFont));
1595 }
1596 
1597 void WorksheetHelper::putFormulaTokens( const ScAddress& rAddress, const ApiTokenSequence& rTokens )
1598 {
1599  ScDocumentImport& rDoc = getDocImport();
1600  std::unique_ptr<ScTokenArray> pTokenArray(new ScTokenArray(rDoc.getDoc()));
1601  ScTokenConversion::ConvertToTokenArray(rDoc.getDoc(), *pTokenArray, rTokens);
1602  rDoc.setFormulaCell(rAddress, std::move(pTokenArray));
1603 }
1604 
1606 {
1608 }
1609 
1611 {
1613 }
1614 
1616 {
1618 }
1619 
1620 void WorksheetHelper::setCellFormula( const ScAddress& rTokenAddress, const OUString& rTokenStr )
1621 {
1622  getFormulaBuffer().setCellFormula( rTokenAddress, rTokenStr );
1623 }
1624 
1626  const ScAddress& rAddr, sal_Int32 nSharedId,
1627  const OUString& rCellValue, sal_Int32 nValueType )
1628 {
1629  getFormulaBuffer().setCellFormula(rAddr, nSharedId, rCellValue, nValueType);
1630 }
1631 
1632 void WorksheetHelper::setCellArrayFormula( const ScRange& rRangeAddress, const ScAddress& rTokenAddress, const OUString& rTokenStr )
1633 {
1634  getFormulaBuffer().setCellArrayFormula( rRangeAddress, rTokenAddress, rTokenStr );
1635 }
1636 
1638  const ScAddress& rAddress, sal_Int32 nSharedId, const OUString& rTokens )
1639 {
1640  getFormulaBuffer().createSharedFormulaMapEntry(rAddress, nSharedId, rTokens);
1641 }
1642 
1643 } // namespace oox
1644 
1645 /* 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:1775
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
sal_Int32 nIndex
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:814
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:499
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< XDrawPage > getDrawPage() const
Returns the XDrawPage interface of the draw page of the current sheet.
PageSettings & getPageSettings()
Returns the page/print settings for this sheet.
SC_DLLPUBLIC ScDBData * GetAnonymousDBData(SCTAB nTab)
Definition: document.cxx:306
SCROW Row() const
Definition: address.hxx:261
bool mbThickTop
True = row outline is collapsed.
bool getProperty(Type &orValue, sal_Int32 nPropId) const
UnitConverter & getUnitConverter() const
Returns the measurement unit converter.
sal_Int16 mnLevel
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
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:4498
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.
Helper class that provides functions to convert values from and to different units.
ScAddress aEnd
Definition: address.hxx:500
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:4788
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.
sal_Int32 scaleToMm100(double fValue, Unit eUnit) const
Converts the passed value to 1/100 millimeters.
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.
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:270
void SetRow(SCROW nRowP)
Definition: address.hxx:274
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.
uno::Reference< sdbc::XRow > xRow
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:4120
bool isValidSheet() const
Returns true, if this helper refers to an existing Calc sheet.
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:4139
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:278
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:282
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.
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:1517
void setDefaultColumnWidth(double fWidth)
Sets default width for all columns.
PageBreakModel()
True = manual page break.
void IncCol(SCCOL nDelta=1)
Definition: address.hxx:303
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:299
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.
XML_TOKEN_INVALID
constexpr auto convertMm100ToTwip(N n)
SheetViewSettings maSheetViewSett
Page/print settings for this sheet.
static SC_DLLPUBLIC bool ConvertToTokenArray(ScDocument &rDoc, ScTokenArray &rTokenArray, const css::uno::Sequence< css::sheet::FormulaToken > &rSequence)
Definition: tokenuno.cxx:365
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:266
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:235
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.
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:4145
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:400
::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:4490
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6092
SC_DLLPUBLIC void SetRowFiltered(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bFiltered)
Definition: document.cxx:4554
void finalizeImport()
Converts the imported worksheet settings.
double scaleFromMm100(sal_Int32 nMm100, Unit eUnit) const
Converts the passed value from 1/100 millimeters to the passed unit.
constexpr TypedWhichId< SfxStringItem > ATTR_HYPERLINK(155)
Reference< XColumn > xColumn
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:315
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.
constexpr sal_uInt16 EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
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:456
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.
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()