27 #include <com/sun/star/script/ArrayWrapper.hpp>
28 #include <com/sun/star/script/XTypeConverter.hpp>
29 #include <com/sun/star/script/vba/VBAEventId.hpp>
30 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
31 #include <com/sun/star/sheet/XDatabaseRange.hpp>
32 #include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
33 #include <com/sun/star/sheet/XGoalSeek.hpp>
34 #include <com/sun/star/sheet/XSheetOperation.hpp>
35 #include <com/sun/star/sheet/CellFlags.hpp>
36 #include <com/sun/star/table/XColumnRowRange.hpp>
37 #include <com/sun/star/sheet/XCellAddressable.hpp>
38 #include <com/sun/star/table/CellContentType.hpp>
39 #include <com/sun/star/sheet/XCellSeries.hpp>
40 #include <com/sun/star/text/XTextRange.hpp>
41 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
42 #include <com/sun/star/table/CellAddress.hpp>
43 #include <com/sun/star/table/CellRangeAddress.hpp>
44 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
45 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
46 #include <com/sun/star/sheet/XSheetCellRange.hpp>
47 #include <com/sun/star/sheet/XSpreadsheet.hpp>
48 #include <com/sun/star/sheet/XSheetCellCursor.hpp>
49 #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
50 #include <com/sun/star/sheet/XNamedRange.hpp>
51 #include <com/sun/star/sheet/XNamedRanges.hpp>
52 #include <com/sun/star/sheet/XPrintAreas.hpp>
53 #include <com/sun/star/sheet/XCellRangesQuery.hpp>
54 #include <com/sun/star/beans/XPropertySet.hpp>
55 #include <com/sun/star/frame/XModel.hpp>
56 #include <com/sun/star/view/XSelectionSupplier.hpp>
57 #include <com/sun/star/table/XTableRows.hpp>
58 #include <com/sun/star/table/XTableColumns.hpp>
59 #include <com/sun/star/table/TableSortField.hpp>
60 #include <com/sun/star/util/XMergeable.hpp>
61 #include <com/sun/star/uno/XComponentContext.hpp>
62 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
63 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
64 #include <com/sun/star/util/XNumberFormats.hpp>
65 #include <com/sun/star/util/NumberFormat.hpp>
66 #include <com/sun/star/util/XNumberFormatTypes.hpp>
67 #include <com/sun/star/util/XReplaceable.hpp>
68 #include <com/sun/star/util/XSortable.hpp>
69 #include <com/sun/star/sheet/XCellRangeMovement.hpp>
70 #include <com/sun/star/sheet/FormulaResult.hpp>
71 #include <com/sun/star/sheet/FilterOperator2.hpp>
72 #include <com/sun/star/sheet/TableFilterField2.hpp>
73 #include <com/sun/star/sheet/XSheetFilterDescriptor2.hpp>
74 #include <com/sun/star/sheet/FilterConnection.hpp>
75 #include <com/sun/star/util/TriState.hpp>
77 #include <com/sun/star/sheet/XSubTotalCalculatable.hpp>
78 #include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
79 #include <com/sun/star/sheet/GeneralFunction.hpp>
81 #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
82 #include <com/sun/star/sheet/XSheetAnnotations.hpp>
84 #include <ooo/vba/excel/XlPasteSpecialOperation.hpp>
85 #include <ooo/vba/excel/XlPasteType.hpp>
86 #include <ooo/vba/excel/XlFindLookIn.hpp>
87 #include <ooo/vba/excel/XlLookAt.hpp>
88 #include <ooo/vba/excel/XlSearchOrder.hpp>
89 #include <ooo/vba/excel/XlSortOrder.hpp>
90 #include <ooo/vba/excel/XlYesNoGuess.hpp>
91 #include <ooo/vba/excel/XlSortOrientation.hpp>
92 #include <ooo/vba/excel/XlSortMethod.hpp>
93 #include <ooo/vba/excel/XlDirection.hpp>
94 #include <ooo/vba/excel/XlSortDataOption.hpp>
95 #include <ooo/vba/excel/XlDeleteShiftDirection.hpp>
96 #include <ooo/vba/excel/XlInsertShiftDirection.hpp>
97 #include <ooo/vba/excel/XlReferenceStyle.hpp>
98 #include <ooo/vba/excel/XlBordersIndex.hpp>
99 #include <ooo/vba/excel/XlPageBreak.hpp>
100 #include <ooo/vba/excel/XlAutoFilterOperator.hpp>
101 #include <ooo/vba/excel/XlAutoFillType.hpp>
102 #include <ooo/vba/excel/XlCellType.hpp>
103 #include <ooo/vba/excel/XlSpecialCellsValue.hpp>
104 #include <ooo/vba/excel/XlConsolidationFunction.hpp>
105 #include <ooo/vba/excel/XlSearchDirection.hpp>
111 #include <docfunc.hxx>
121 #include <unonames.hxx>
137 #include <compiler.hxx>
146 #include <global.hxx>
153 #include <com/sun/star/bridge/oleautomation/Date.hpp>
154 #include <tokenarray.hxx>
171 const sal_Int16
supportedIndexTable[] = { excel::XlBordersIndex::xlEdgeLeft, excel::XlBordersIndex::xlEdgeTop, excel::XlBordersIndex::xlEdgeBottom, excel::XlBordersIndex::xlEdgeRight, excel::XlBordersIndex::xlDiagonalDown, excel::XlBordersIndex::xlDiagonalUp, excel::XlBordersIndex::xlInsideVertical, excel::XlBordersIndex::xlInsideHorizontal };
175 nVal = nVal *
static_cast<double>(20);
176 short nTwips =
static_cast<short>(nVal);
181 double nPoints = nVal;
187 nVal = (nVal * double(100));
189 if ( ( nVal - tmp ) >= 0.5 )
191 nVal = double(tmp)/100;
195 static uno::Any lcl_makeRange(
const uno::Reference< XHelperInterface >& rParent,
const uno::Reference< uno::XComponentContext >& rContext,
const uno::Any& rAny,
bool bIsRows,
bool bIsColumns )
197 uno::Reference< table::XCellRange > xCellRange(rAny, uno::UNO_QUERY_THROW);
198 return uno::makeAny( uno::Reference< excel::XRange >(
new ScVbaRange( rParent, rContext, xCellRange, bIsRows, bIsColumns ) ) );
201 static uno::Reference< excel::XRange >
lcl_makeXRangeFromSheetCellRanges(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< sheet::XSheetCellRanges >& xLocSheetCellRanges,
ScDocShell* pDoc )
203 uno::Reference< excel::XRange > xRange;
204 const uno::Sequence< table::CellRangeAddress > sAddresses = xLocSheetCellRanges->getRangeAddresses();
206 if ( sAddresses.hasElements() )
208 for (
const auto& rAddress : sAddresses )
215 if ( aCellRanges.
size() == 1 )
217 uno::Reference< table::XCellRange > xTmpRange(
new ScCellRangeObj( pDoc, aCellRanges.
front() ) );
218 xRange =
new ScVbaRange( xParent, xContext, xTmpRange );
222 uno::Reference< sheet::XSheetCellRangeContainer > xRanges(
new ScCellRangesObj( pDoc, aCellRanges ) );
223 xRange =
new ScVbaRange( xParent, xContext, xRanges );
232 return comphelper::getUnoTunnelImplementation<ScCellRangesBase>(
mxRanges );
234 return comphelper::getUnoTunnelImplementation<ScCellRangesBase>(
mxRange );
235 throw uno::RuntimeException(
"General Error creating range - Unknown" );
247 throw uno::RuntimeException(
"Can't access Itemset for range" );
257 const uno::Reference< script::vba::XVBAEventProcessor >& xVBAEvents = rDoc.
GetVbaEventProcessor();
258 if( xVBAEvents.is() )
try
260 uno::Sequence< uno::Any > aArgs( 1 );
261 aArgs[ 0 ] <<= uno::Reference< excel::XRange >( this );
262 xVBAEvents->processVbaEvent( script::vba::VBAEventId::WORKSHEET_CHANGE, aArgs );
264 catch( uno::Exception& )
273 uno::Reference< table::XCellRange > m_xRange;
277 explicit SingleRangeEnumeration(
const uno::Reference< table::XCellRange >& xRange ) : m_xRange( xRange ), bHasMore( true ) { }
278 virtual sal_Bool SAL_CALL hasMoreElements( )
override {
return bHasMore; }
279 virtual uno::Any SAL_CALL nextElement( )
override
282 throw container::NoSuchElementException();
284 return uno::makeAny( m_xRange );
291 class SingleRangeIndexAccess :
public ::cppu::WeakImplHelper< container::XIndexAccess,
292 container::XEnumerationAccess >
295 uno::Reference< table::XCellRange > m_xRange;
298 explicit SingleRangeIndexAccess(
const uno::Reference< table::XCellRange >& xRange ) : m_xRange( xRange ) {}
300 virtual ::sal_Int32 SAL_CALL getCount()
override {
return 1; }
301 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
304 throw lang::IndexOutOfBoundsException();
305 return uno::makeAny( m_xRange );
309 virtual sal_Bool SAL_CALL hasElements()
override {
return true; }
311 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration()
override {
return new SingleRangeEnumeration( m_xRange ); }
321 RangesEnumerationImpl(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XEnumeration >& xEnumeration,
bool bIsRows,
bool bIsColumns ) :
EnumerationHelperImpl( xParent, xContext, xEnumeration ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {}
322 virtual uno::Any SAL_CALL nextElement( )
override
324 return lcl_makeRange( m_xParent, m_xContext, m_xEnumeration->nextElement(), mbIsRows, mbIsColumns );
333 ScVbaRangeAreas(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XIndexAccess >& xIndexAccess,
bool bIsRows,
bool bIsColumns ) :
ScVbaCollectionBaseImpl( xParent, xContext, xIndexAccess ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {}
336 virtual uno::Reference< container::XEnumeration > SAL_CALL
createEnumeration()
override;
345 virtual uno::Sequence< OUString >
getServiceNames()
override {
return uno::Sequence< OUString >(); }
351 uno::Reference< container::XEnumeration > SAL_CALL
352 ScVbaRangeAreas::createEnumeration()
354 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
355 return new RangesEnumerationImpl( mxParent, mxContext, xEnumAccess->createEnumeration(), mbIsRows, mbIsColumns );
359 ScVbaRangeAreas::createCollectionObject(
const uno::Any& aSource )
361 return lcl_makeRange( mxParent, mxContext, aSource, mbIsRows, mbIsColumns );
369 ScCellRangesBase* pUno = comphelper::getUnoTunnelImplementation<ScCellRangesBase>( xIf );
371 throw uno::RuntimeException(
"Failed to access underlying uno range object" );
380 uno::Reference< uno::XInterface > xIf( xRange );
389 uno::Reference< uno::XInterface > xIf( xRanges );
394 static uno::Reference< frame::XModel >
getModelFromXIf(
const uno::Reference< uno::XInterface >& xIf )
401 static uno::Reference< frame::XModel >
getModelFromRange(
const uno::Reference< table::XCellRange >& xRange )
404 uno::Reference< uno::XInterface > xIf( xRange );
413 throw uno::RuntimeException(
"Failed to access underlying docshell from uno range object" );
423 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
424 uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
435 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
436 uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
445 return dynamic_cast< ScVbaRange*
>( rxRange.get() );
451 return pDocShell->GetModel();
452 throw uno::RuntimeException();
458 return pScVbaRange->getUnoModel();
459 throw uno::RuntimeException();
465 return pScRangesBase->GetRangeList();
466 throw uno::RuntimeException(
"Cannot obtain UNO range implementation object" );
472 return pScVbaRange->getScRangeList();
473 throw uno::RuntimeException(
"Cannot obtain VBA range implementation object" );
478 class NumFormatHelper
480 uno::Reference< util::XNumberFormatsSupplier > mxSupplier;
481 uno::Reference< beans::XPropertySet > mxRangeProps;
482 uno::Reference< util::XNumberFormats > mxFormats;
484 explicit NumFormatHelper(
const uno::Reference< table::XCellRange >& xRange )
487 mxRangeProps.set( xRange, uno::UNO_QUERY_THROW);
488 mxFormats = mxSupplier->getNumberFormats();
490 uno::Reference< beans::XPropertySet > getNumberProps()
493 uno::Any aValue = mxRangeProps->getPropertyValue(
"NumberFormat" );
494 aValue >>= nIndexKey;
496 if ( mxFormats.is() )
497 return mxFormats->getByKey( nIndexKey );
498 return uno::Reference< beans::XPropertySet > ();
504 return (getNumberFormat() & util::NumberFormat::LOGICAL) != 0;
509 sal_Int16
nType = getNumberFormat();
510 return ( nType & util::NumberFormat::DATETIME ) != 0;
513 OUString getNumberFormatString()
515 uno::Reference< uno::XInterface > xIf( mxRangeProps, uno::UNO_QUERY_THROW );
516 ScCellRangesBase* pUnoCellRange = comphelper::getUnoTunnelImplementation<ScCellRangesBase>( xIf );
520 SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( pUnoCellRange );
524 if ( eState == SfxItemState::DONTCARE )
528 uno::Reference< beans::XPropertySet > xNumberProps( getNumberProps(), uno::UNO_SET_THROW );
529 OUString aFormatString;
530 uno::Any aString = xNumberProps->getPropertyValue(
"FormatString" );
531 aString >>= aFormatString;
532 return aFormatString;
535 sal_Int16 getNumberFormat()
537 uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps();
538 sal_Int16 nType = ::comphelper::getINT16(
539 xNumberProps->getPropertyValue(
"Type" ) );
543 void setNumberFormat(
const OUString& rFormat )
546 sal_Int32 nNewIndex = 0;
547 if( !rFormat.equalsIgnoreAsciiCase(
"General" ) )
549 lang::Locale aLocale;
550 uno::Reference< beans::XPropertySet > xNumProps = getNumberProps();
551 xNumProps->getPropertyValue(
"Locale" ) >>= aLocale;
552 nNewIndex = mxFormats->queryKey( rFormat, aLocale,
false );
553 if ( nNewIndex == -1 )
554 nNewIndex = mxFormats->addNew( rFormat, aLocale );
556 mxRangeProps->setPropertyValue(
"NumberFormat", uno::makeAny( nNewIndex ) );
559 void setNumberFormat( sal_Int16 nType )
561 uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps();
562 lang::Locale aLocale;
563 xNumberProps->getPropertyValue(
"Locale" ) >>= aLocale;
564 uno::Reference<util::XNumberFormatTypes> xTypes( mxFormats, uno::UNO_QUERY );
567 sal_Int32 nNewIndex = xTypes->getStandardFormat( nType, aLocale );
568 mxRangeProps->setPropertyValue(
"NumberFormat", uno::makeAny( nNewIndex ) );
576 CellPos( sal_Int32 nRow, sal_Int32 nCol, sal_Int32 nArea ):m_nRow(nRow), m_nCol(nCol), m_nArea( nArea ) {};
594 class ColumnsRowEnumeration:
public CellsEnumeration_BASE
596 uno::Reference< excel::XRange > mxRange;
601 ColumnsRowEnumeration(
const uno::Reference< excel::XRange >& xRange, sal_Int32 nElems ) : mxRange( xRange ), mMaxElems( nElems ), mCurElem( 0 )
605 virtual sal_Bool SAL_CALL hasMoreElements()
override {
return mCurElem < mMaxElems; }
607 virtual uno::Any SAL_CALL nextElement()
override
609 if ( !hasMoreElements() )
610 throw container::NoSuchElementException();
611 sal_Int32 vbaIndex = 1 + mCurElem++;
612 return uno::makeAny( mxRange->Item( uno::makeAny( vbaIndex ),
uno::Any() ) );
616 class CellsEnumeration :
public CellsEnumeration_BASE
618 uno::WeakReference< XHelperInterface >
mxParent;
619 uno::Reference< uno::XComponentContext >
mxContext;
620 uno::Reference< XCollection > m_xAreas;
621 vCellPos m_CellPositions;
622 vCellPos::const_iterator m_it;
625 uno::Reference< table::XCellRange >
getArea( sal_Int32 nVBAIndex )
627 if ( nVBAIndex < 1 || nVBAIndex > m_xAreas->getCount() )
628 throw uno::RuntimeException();
629 uno::Reference< excel::XRange > xRange( m_xAreas->Item( uno::makeAny(nVBAIndex),
uno::Any() ), uno::UNO_QUERY_THROW );
634 void populateArea( sal_Int32 nVBAIndex )
636 uno::Reference< table::XCellRange > xRange =
getArea( nVBAIndex );
637 uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, uno::UNO_QUERY_THROW );
638 sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount();
639 sal_Int32
nColCount = xColumnRowRange->getColumns()->getCount();
640 for ( sal_Int32
i=0;
i<nRowCount; ++
i )
642 for ( sal_Int32 j=0; j<nColCount; ++j )
643 m_CellPositions.emplace_back(
i,j,nVBAIndex );
647 CellsEnumeration(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< XCollection >& xAreas ): mxParent( xParent ), mxContext( xContext ), m_xAreas( xAreas )
649 sal_Int32 nItems = m_xAreas->getCount();
652 populateArea(
index );
654 m_it = m_CellPositions.begin();
656 virtual sal_Bool SAL_CALL hasMoreElements()
override {
return m_it != m_CellPositions.end(); }
658 virtual uno::Any SAL_CALL nextElement()
override
660 if ( !hasMoreElements() )
661 throw container::NoSuchElementException();
662 CellPos aPos = *m_it++;
664 uno::Reference< table::XCellRange > xRangeArea =
getArea( aPos.m_nArea );
665 uno::Reference< table::XCellRange > xCellRange( xRangeArea->getCellByPosition( aPos.m_nCol, aPos.m_nRow ), uno::UNO_QUERY_THROW );
666 return uno::makeAny( uno::Reference< excel::XRange >(
new ScVbaRange( mxParent, mxContext, xCellRange ) ) );
690 explicit CellValueSetter(
const uno::Any& aValue );
691 virtual bool processValue(
const uno::Any& aValue,
const uno::Reference< table::XCell >& xCell )
override;
692 virtual void visitNode( sal_Int32
x, sal_Int32
y,
const uno::Reference< table::XCell >& xCell )
override;
698 CellValueSetter::CellValueSetter(
const uno::Any& aValue ):
maValue( aValue ) {}
701 CellValueSetter::visitNode( sal_Int32 , sal_Int32 ,
const uno::Reference< table::XCell >& xCell )
703 processValue( maValue, xCell );
707 CellValueSetter::processValue(
const uno::Any& aValue,
const uno::Reference< table::XCell >& xCell )
710 bool isExtracted =
false;
711 switch ( aValue.getValueTypeClass() )
713 case uno::TypeClass_BOOLEAN:
716 if ( aValue >>= bState )
718 uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
720 xCell->setValue(
double(1) );
722 xCell->setValue(
double(0) );
723 NumFormatHelper cellNumFormat( xRange );
724 cellNumFormat.setNumberFormat( util::NumberFormat::LOGICAL );
728 case uno::TypeClass_STRING:
731 if ( aValue >>= aString )
740 if ( aString.toChar() ==
'\'' )
742 OUString aRemainder( aString.copy(1) );
743 uno::Reference< text::XTextRange > xTextRange( xCell, uno::UNO_QUERY_THROW );
744 xTextRange->setString( aRemainder );
760 double nDouble = 0.0;
761 if ( aValue >>= nDouble )
763 uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
764 NumFormatHelper cellFormat( xRange );
768 if ( cellFormat.isBooleanType() )
769 cellFormat.setNumberFormat(
"General");
770 xCell->setValue( nDouble );
789 virtual void visitNode( sal_Int32 x, sal_Int32 y,
const uno::Reference< table::XCell >& xCell )
override;
798 CellValueGetter::processValue(
const uno::Any& aValue )
802 void CellValueGetter::visitNode( sal_Int32 , sal_Int32 ,
const uno::Reference< table::XCell >& xCell )
805 table::CellContentType
eType = xCell->getType();
806 if( eType == table::CellContentType_VALUE || eType == table::CellContentType_FORMULA )
808 if ( eType == table::CellContentType_FORMULA )
811 OUString sFormula = xCell->getFormula();
812 if ( sFormula ==
"=TRUE()" )
814 else if ( sFormula ==
"=FALSE()" )
818 uno::Reference< beans::XPropertySet > xProp( xCell, uno::UNO_QUERY_THROW );
820 sal_Int32 nResultType = sheet::FormulaResult::VALUE;
822 xProp->getPropertyValue(
"FormulaResultType2" ) >>= nResultType;
824 if ( nResultType == sheet::FormulaResult::STRING )
826 uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW);
827 aValue <<= xTextRange->getString();
830 aValue <<= xCell->getValue();
835 uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
836 NumFormatHelper cellFormat( xRange );
837 if ( cellFormat.isBooleanType() )
838 aValue <<= ( xCell->getValue() != 0.0 );
839 else if ( cellFormat.isDateType() )
840 aValue <<= bridge::oleautomation::Date( xCell->getValue() );
842 aValue <<= xCell->getValue();
845 if( eType == table::CellContentType_TEXT )
847 uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW);
848 aValue <<= xTextRange->getString();
850 processValue( aValue );
855 class CellFormulaValueSetter :
public CellValueSetter
863 bool processValue(
const uno::Any& aValue,
const uno::Reference< table::XCell >& xCell )
override
866 double aDblValue = 0.0;
867 if ( aValue >>= sFormula )
875 uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW );
877 if ( pUnoRangesBase )
882 std::unique_ptr<ScTokenArray> pArray(aCompiler.CompileString(sFormula));
886 aCompiler.CreateStringFromTokenArray(sConverted);
887 sFormula = EQUALS + sConverted;
891 xCell->setFormula( sFormula );
894 else if ( aValue >>= aDblValue )
896 xCell->setValue( aDblValue );
904 class CellFormulaValueGetter :
public CellValueGetter
911 virtual void visitNode( sal_Int32 , sal_Int32 ,
const uno::Reference< table::XCell >& xCell )
override
914 aValue <<= xCell->getFormula();
917 uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW );
919 if ( ( xCell->getType() == table::CellContentType_FORMULA ) &&
924 std::unique_ptr<ScTokenArray> pArray(aCompiler.CompileString(sVal));
928 aCompiler.CreateStringFromTokenArray(sConverted);
929 sVal = EQUALS + sConverted;
933 processValue( aValue );
943 void processValue( sal_Int32 x, sal_Int32 y,
const uno::Any& aValue )
945 uno::Sequence< uno::Sequence< uno::Any > >& aMatrix =
const_cast<css::uno::Sequence<css::uno::Sequence<css::uno::Any>
> &>(*o3tl::doAccess<uno::Sequence<uno::Sequence<uno::Any>>>(maValue));
946 aMatrix[
x][
y] = aValue;
950 Dim2ArrayValueGetter(sal_Int32 nRowCount, sal_Int32 nColCount,
ValueGetter& rValueGetter ): mValueGetter(rValueGetter)
952 uno::Sequence< uno::Sequence< uno::Any > > aMatrix;
953 aMatrix.realloc( nRowCount );
954 for ( sal_Int32 index = 0;
index < nRowCount; ++
index )
955 aMatrix[index].realloc( nColCount );
958 void visitNode( sal_Int32 x, sal_Int32 y,
const uno::Reference< table::XCell >& xCell )
override
961 mValueGetter.visitNode( x, y, xCell );
962 processValue( x, y, mValueGetter.getValue() );
970 constexpr OUStringLiteral
sNA =
u"#N/A";
976 uno::Sequence< uno::Any > aMatrix;
980 Dim1ArrayValueSetter(
const uno::Any& aValue,
ValueSetter& rCellValueSetter ):mCellValueSetter( rCellValueSetter )
983 nColCount = aMatrix.getLength();
985 virtual void visitNode( sal_Int32 , sal_Int32
y,
const uno::Reference< table::XCell >& xCell )
override
990 mCellValueSetter.
processValue( uno::makeAny( OUString(sNA) ), xCell );
996 uno::Sequence< uno::Sequence< uno::Any > > aMatrix;
1001 Dim2ArrayValueSetter(
const uno::Any& aValue,
ValueSetter& rCellValueSetter ) : mCellValueSetter( rCellValueSetter )
1004 nRowCount = aMatrix.getLength();
1005 nColCount = aMatrix[0].getLength();
1008 virtual void visitNode( sal_Int32
x, sal_Int32
y,
const uno::Reference< table::XCell >& xCell )
override
1010 if ( x < nRowCount && y < nColCount )
1011 mCellValueSetter.
processValue( aMatrix[ x ][ y ], xCell );
1013 mCellValueSetter.
processValue( uno::makeAny( OUString(sNA) ), xCell );
1018 class RangeProcessor
1021 virtual void process(
const uno::Reference< excel::XRange >& xRange ) = 0;
1024 ~RangeProcessor() {}
1027 class RangeValueProcessor :
public RangeProcessor
1031 explicit RangeValueProcessor(
const uno::Any& rVal ):m_aVal( rVal ) {}
1032 virtual ~RangeValueProcessor() {}
1033 virtual void process(
const uno::Reference< excel::XRange >& xRange )
override
1039 class RangeFormulaProcessor :
public RangeProcessor
1043 explicit RangeFormulaProcessor(
const uno::Any& rVal ):m_aVal( rVal ) {}
1044 virtual ~RangeFormulaProcessor() {}
1045 virtual void process(
const uno::Reference< excel::XRange >& xRange )
override
1047 xRange->setFormula( m_aVal );
1051 class RangeCountProcessor :
public RangeProcessor
1055 RangeCountProcessor():nCount(0){}
1056 virtual ~RangeCountProcessor() {}
1057 virtual void process(
const uno::Reference< excel::XRange >& xRange )
override
1059 nCount = nCount + xRange->getCount();
1061 sal_Int32
value() {
return nCount; }
1066 uno::Reference< XCollection > m_Areas;
1068 explicit AreasVisitor(
const uno::Reference< XCollection >& rAreas ):m_Areas( rAreas ){}
1070 void visit( RangeProcessor& processor )
1074 sal_Int32 nItems = m_Areas->getCount();
1077 uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
1078 processor.process( xRange );
1086 uno::Reference< table::XCellRange > m_xCellRange;
1090 explicit RangeHelper(
const uno::Reference< table::XCellRange >& xCellRange ) : m_xCellRange( xCellRange )
1092 if ( !m_xCellRange.is() )
1093 throw uno::RuntimeException();
1096 explicit RangeHelper(
const uno::Any& rCellRange )
1098 m_xCellRange.set(rCellRange, uno::UNO_QUERY_THROW);
1101 uno::Reference< sheet::XSheetCellRange > getSheetCellRange()
const
1103 return uno::Reference< sheet::XSheetCellRange >(m_xCellRange, uno::UNO_QUERY_THROW);
1106 uno::Reference< sheet::XSpreadsheet > getSpreadSheet()
const
1108 return getSheetCellRange()->getSpreadsheet();
1112 uno::Reference< table::XCellRange > getCellRangeFromSheet()
const
1114 return uno::Reference< table::XCellRange >(getSpreadSheet(), uno::UNO_QUERY_THROW );
1118 uno::Reference< sheet::XCellRangeAddressable > getCellRangeAddressable()
const
1120 return uno::Reference< sheet::XCellRangeAddressable >(m_xCellRange, ::uno::UNO_QUERY_THROW);
1125 uno::Reference< sheet::XSheetCellCursor > getSheetCellCursor()
const
1127 return uno::Reference< sheet::XSheetCellCursor >( getSpreadSheet()->createCursorByRange( getSheetCellRange() ), uno::UNO_SET_THROW );
1130 static uno::Reference< excel::XRange > createRangeFromRange(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference<uno::XComponentContext >& xContext,
1131 const uno::Reference< table::XCellRange >& xRange,
const uno::Reference< sheet::XCellRangeAddressable >& xCellRangeAddressable )
1133 return uno::Reference< excel::XRange >(
new ScVbaRange( xParent, xContext,
1134 xRange->getCellRangeByPosition(
1135 xCellRangeAddressable->getRangeAddress().StartColumn,
1136 xCellRangeAddressable->getRangeAddress().StartRow,
1137 xCellRangeAddressable->getRangeAddress().EndColumn,
1138 xCellRangeAddressable->getRangeAddress().EndRow ) ) );
1152 rResFlags = rCellRanges.
Parse( sAddress, rDoc, eConv, 0, cDelimiter );
1164 uno::Reference< beans::XPropertySet > xProps( pDocSh->
GetModel(), uno::UNO_QUERY_THROW );
1165 uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue(
"NamedRanges" ), uno::UNO_QUERY_THROW );
1168 std::vector< OUString > vNames;
1172 OUString aToken = sName.getToken( 0,
',', nIndex );
1173 vNames.push_back( aToken );
1174 }
while ( nIndex >= 0 );
1176 if ( vNames.empty() )
1177 vNames.push_back( sName );
1179 for (
const auto& rName : vNames )
1183 OUString sAddress = rName.trim();
1186 if ( !xNameAccess->hasByName( sAddress ) )
1199 if ( xNameAccess->hasByName( sAddress ) )
1201 uno::Reference< sheet::XNamedRange > xNamed( xNameAccess->getByName( sAddress ), uno::UNO_QUERY_THROW );
1202 sAddress = xNamed->getContent();
1215 for (
size_t i = 0, nRanges = aCellRanges.
size();
i < nRanges; ++
i )
1217 ScRange & rRange = aCellRanges[
i ];
1237 throw uno::RuntimeException();
1239 if ( aCellRanges.
size() == 1 )
1241 uno::Reference< table::XCellRange > xRange(
new ScCellRangeObj( pDocSh, aCellRanges.
front() ) );
1243 return new ScVbaRange( xFixThisParent, xContext, xRange );
1245 uno::Reference< sheet::XSheetCellRangeContainer > xRanges(
new ScCellRangesObj( pDocSh, aCellRanges ) );
1248 return new ScVbaRange( xFixThisParent, xContext, xRanges );
1254 template<
typename RangeType >
1255 table::CellRangeAddress lclGetRangeAddress(
const uno::Reference< RangeType >& rxCellRange )
1257 return uno::Reference< sheet::XCellRangeAddressable >( rxCellRange, uno::UNO_QUERY_THROW )->getRangeAddress();
1261 void lclClearRange(
const uno::Reference< table::XCellRange >& rxCellRange )
1263 using namespace ::com::sun::star::sheet::CellFlags;
1265 uno::Reference< sheet::XSheetOperation > xSheetOperation( rxCellRange, uno::UNO_QUERY_THROW );
1266 xSheetOperation->clearContents( nFlags );
1270 uno::Reference< sheet::XSheetCellRange > lclExpandToMerged(
const uno::Reference< table::XCellRange >& rxCellRange,
bool bRecursive )
1272 uno::Reference< sheet::XSheetCellRange > xNewCellRange( rxCellRange, uno::UNO_QUERY_THROW );
1273 uno::Reference< sheet::XSpreadsheet > xSheet( xNewCellRange->getSpreadsheet(), uno::UNO_SET_THROW );
1274 table::CellRangeAddress aNewAddress = lclGetRangeAddress( xNewCellRange );
1275 table::CellRangeAddress aOldAddress;
1279 aOldAddress = aNewAddress;
1280 uno::Reference< sheet::XSheetCellCursor > xCursor( xSheet->createCursorByRange( xNewCellRange ), uno::UNO_SET_THROW );
1281 xCursor->collapseToMergedArea();
1282 xNewCellRange.set( xCursor, uno::UNO_QUERY_THROW );
1283 aNewAddress = lclGetRangeAddress( xNewCellRange );
1285 while( bRecursive && (aOldAddress != aNewAddress) );
1286 return xNewCellRange;
1290 uno::Reference< sheet::XSheetCellRangeContainer > lclExpandToMerged(
const uno::Reference< sheet::XSheetCellRangeContainer >& rxCellRanges )
1292 if( !rxCellRanges.is() )
1293 throw uno::RuntimeException(
"Missing cell ranges object" );
1294 sal_Int32
nCount = rxCellRanges->getCount();
1296 throw uno::RuntimeException(
"Missing cell ranges object" );
1301 uno::Reference< table::XCellRange > xRange( rxCellRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
1302 table::CellRangeAddress aRangeAddr = lclGetRangeAddress( lclExpandToMerged( xRange,
true ) );
1311 void lclExpandAndMerge(
const uno::Reference< table::XCellRange >& rxCellRange,
bool bMerge )
1313 uno::Reference< util::XMergeable > xMerge( lclExpandToMerged( rxCellRange,
true ), uno::UNO_QUERY_THROW );
1315 xMerge->merge(
false );
1320 table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange );
1321 sal_Int32 nLastColIdx = aRangeAddr.EndColumn - aRangeAddr.StartColumn;
1322 sal_Int32 nLastRowIdx = aRangeAddr.EndRow - aRangeAddr.StartRow;
1324 if( nLastColIdx > 0 )
1325 lclClearRange( rxCellRange->getCellRangeByPosition( 1, 0, nLastColIdx, 0 ) );
1327 if( nLastRowIdx > 0 )
1328 lclClearRange( rxCellRange->getCellRangeByPosition( 0, 1, nLastColIdx, nLastRowIdx ) );
1330 xMerge->merge(
true );
1334 util::TriState lclGetMergedState(
const uno::Reference< table::XCellRange >& rxCellRange )
1340 table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange );
1341 uno::Reference< table::XCellRange > xTopLeft( rxCellRange->getCellRangeByPosition( 0, 0, 0, 0 ), uno::UNO_SET_THROW );
1342 uno::Reference< sheet::XSheetCellRange > xExpanded( lclExpandToMerged( xTopLeft,
false ), uno::UNO_SET_THROW );
1343 table::CellRangeAddress aExpAddr = lclGetRangeAddress( xExpanded );
1345 if( ((aExpAddr.StartColumn < aExpAddr.EndColumn) || (aExpAddr.StartRow < aExpAddr.EndRow)) &&
ScUnoConversion::Contains( aExpAddr, aRangeAddr ) )
1346 return util::TriState_YES;
1356 return bHasMerged ? util::TriState_INDETERMINATE : util::TriState_NO;
1361 css::uno::Reference< excel::XRange >
1363 const uno::Reference< uno::XComponentContext >& xContext,
const OUString& sRangeName,
1366 table::CellRangeAddress refAddr;
1367 return getRangeForName( xContext, sRangeName, pDocSh, refAddr, eConv );
1373 uno::Reference< table::XCellRange > xRangeParam;
1374 switch ( aParam.getValueTypeClass() )
1376 case uno::TypeClass_STRING:
1384 if ( aCellRanges.
size() == 1 )
1386 table::CellRangeAddress aRangeAddress;
1388 return aRangeAddress;
1394 case uno::TypeClass_INTERFACE:
1396 uno::Reference< excel::XRange > xRange;
1399 xRange->getCellRange() >>= xRangeParam;
1404 throw uno::RuntimeException(
"Can't extract CellRangeAddress from type" );
1406 return lclGetRangeAddress( xRangeParam );
1410 static uno::Reference< XCollection >
1411 lcl_setupBorders(
const uno::Reference< excel::XRange >& xParentRange,
const uno::Reference<uno::XComponentContext>& xContext,
const uno::Reference< table::XCellRange >& xRange )
1413 uno::Reference< XHelperInterface > xParent( xParentRange, uno::UNO_QUERY_THROW );
1416 uno::Reference< XCollection > borders(
new ScVbaBorders( xParent, xContext, xRange, aPalette ) );
1421 uno::Reference< uno::XComponentContext>
const & xContext ) :
ScVbaRange_BASE(
getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext,
getXSomethingFromArgs<
beans::
XPropertySet >( args, 1, false ),
getModelFromXIf(
getXSomethingFromArgs<
uno::
XInterface >( args, 1 ) ), true ), mbIsRows( false ), mbIsColumns( false )
1423 mxRange.set( mxPropertySet, uno::UNO_QUERY );
1424 mxRanges.set( mxPropertySet, uno::UNO_QUERY );
1425 uno::Reference< container::XIndexAccess > xIndex;
1428 xIndex =
new SingleRangeIndexAccess( mxRange );
1430 else if ( mxRanges.is() )
1432 xIndex.set( mxRanges, uno::UNO_QUERY_THROW );
1434 m_Areas =
new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns );
1437 ScVbaRange::ScVbaRange(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< table::XCellRange >& xRange,
bool bIsRows,
bool bIsColumns )
1439 mbIsRows( bIsRows ),
1440 mbIsColumns( bIsColumns )
1442 if ( !xContext.is() )
1443 throw lang::IllegalArgumentException(
"context is not set ", uno::Reference< uno::XInterface >() , 1 );
1445 throw lang::IllegalArgumentException(
"range is not set ", uno::Reference< uno::XInterface >() , 1 );
1447 uno::Reference< container::XIndexAccess > xIndex(
new SingleRangeIndexAccess( xRange ) );
1448 m_Areas =
new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns );
1452 ScVbaRange::ScVbaRange(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges,
bool bIsRows,
bool bIsColumns)
1456 uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
1457 m_Areas =
new ScVbaRangeAreas( xParent, mxContext, xIndex, mbIsRows, mbIsColumns );
1469 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
1478 table::CellRangeAddress aRangeAddr = lclGetRangeAddress(
mxRange );
1479 sal_Int32 nRowCount = aRangeAddr.EndRow - aRangeAddr.StartRow + 1;
1480 sal_Int32 nColCount = aRangeAddr.EndColumn - aRangeAddr.StartColumn + 1;
1481 for ( sal_Int32
i=0;
i<nRowCount; ++
i )
1483 for ( sal_Int32 j=0; j<nColCount; ++j )
1485 uno::Reference< table::XCell > xCell(
mxRange->getCellByPosition( j,
i ), uno::UNO_SET_THROW );
1495 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY_THROW );
1502 sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount();
1503 sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
1505 Dim2ArrayValueGetter arrayGetter( nRowCount, nColCount, valueGetter );
1507 return uno::makeAny( script::ArrayWrapper(
false, arrayGetter.getValue() ) );
1517 if (
m_Areas->getCount() > 1 )
1519 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1520 return xRange->getValue();
1523 CellValueGetter valueGetter;
1531 uno::TypeClass aClass = aValue.getValueTypeClass();
1532 if ( aClass == uno::TypeClass_SEQUENCE )
1540 if ( aValue.getValueTypeName().indexOf(
'[') == aValue.getValueTypeName().lastIndexOf(
'[') )
1542 aConverted = xConverter->convertTo( aValue,
cppu::UnoType<uno::Sequence< uno::Any >>::
get() );
1543 Dim1ArrayValueSetter setter( aConverted, valueSetter );
1548 aConverted = xConverter->convertTo( aValue,
cppu::UnoType<uno::Sequence< uno::Sequence< uno::Any > >>::
get() );
1549 Dim2ArrayValueSetter setter( aConverted, valueSetter );
1553 catch (
const uno::Exception& )
1569 if (
m_Areas->getCount() > 1 )
1571 AreasVisitor aVisitor(
m_Areas );
1572 RangeValueProcessor valueProcessor( aValue );
1573 aVisitor.visit( valueProcessor );
1576 CellValueSetter valueSetter( aValue );
1583 using namespace ::com::sun::star::sheet::CellFlags;
1596 if (
m_Areas->getCount() > 1 )
1598 sal_Int32 nItems =
m_Areas->getCount();
1601 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
1604 pRange->ClearContents( nFlags,
false );
1611 uno::Reference< sheet::XSheetOperation > xSheetOperation(
mxRange, uno::UNO_QUERY_THROW);
1612 xSheetOperation->clearContents( nFlags );
1625 using namespace ::com::sun::star::sheet::CellFlags;
1634 using namespace ::com::sun::star::sheet::CellFlags;
1643 if (
m_Areas->getCount() > 1 )
1645 AreasVisitor aVisitor(
m_Areas );
1646 RangeFormulaProcessor valueProcessor( rFormula );
1647 aVisitor.visit( valueProcessor );
1650 CellFormulaValueSetter formulaValueSetter( rFormula,
getScDocument(), eGram );
1651 setValue( rFormula, formulaValueSetter );
1661 if (
m_Areas->getCount() > 1 )
1663 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1664 return xRange->getFormula();
1666 CellFormulaValueGetter valueGetter(
getScDocument(), eGram );
1700 if (
m_Areas->getCount() > 1 )
1702 AreasVisitor aVisitor(
m_Areas );
1703 RangeCountProcessor valueProcessor;
1704 aVisitor.visit( valueProcessor );
1705 return valueProcessor.value();
1707 sal_Int32 rowCount = 0;
1708 sal_Int32 colCount = 0;
1709 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY_THROW );
1710 rowCount = xColumnRowRange->getRows()->getCount();
1711 colCount = xColumnRowRange->getColumns()->getCount();
1717 return rowCount * colCount;
1727 if (
m_Areas->getCount() > 1 )
1729 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1730 return xRange->getRow();
1732 uno::Reference< sheet::XCellAddressable > xCellAddressable(
mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
1733 return xCellAddressable->getCellAddress().Row + 1;
1743 if (
m_Areas->getCount() > 1 )
1745 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1746 return xRange->getColumn();
1748 uno::Reference< sheet::XCellAddressable > xCellAddressable(
mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
1749 return xCellAddressable->getCellAddress().Column + 1;
1755 if (
m_Areas->getCount() > 1 )
1757 sal_Int32 nItems =
m_Areas->getCount();
1761 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
1765 if ( aResult != xRange->HasFormula() )
1767 aResult = xRange->HasFormula();
1768 if (
aNULL() == aResult )
1773 uno::Reference< uno::XInterface > xIf(
mxRange, uno::UNO_QUERY_THROW );
1777 uno::Reference<uno::XInterface> xRanges( pThisRanges->
queryFormulaCells( sheet::FormulaResult::ERROR | sheet::FormulaResult::VALUE | sheet::FormulaResult::STRING ), uno::UNO_QUERY_THROW );
1781 if ( pFormulaRanges->GetRangeList().empty() )
1782 return uno::makeAny(
false);
1786 if ( ( pFormulaRanges->GetRangeList().size() > 1 )
1792 return uno::makeAny(
true );
1795 ScVbaRange::fillSeries( sheet::FillDirection nFillDirection, sheet::FillMode nFillMode, sheet::FillDateMode nFillDateMode,
double fStep,
double fEndValue )
1797 if (
m_Areas->getCount() > 1 )
1800 uno::Reference< XCollection > xCollection(
m_Areas, uno::UNO_SET_THROW );
1801 for ( sal_Int32
index = 1;
index <= xCollection->getCount(); ++
index )
1803 uno::Reference< excel::XRange > xRange( xCollection->Item( uno::makeAny(
index ),
uno::Any() ), uno::UNO_QUERY_THROW );
1805 pThisRange->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
1811 uno::Reference< sheet::XCellSeries > xCellSeries(
mxRange, uno::UNO_QUERY_THROW );
1812 xCellSeries->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
1820 sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
1827 sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
1834 sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
1841 sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
1851 if (
m_Areas->getCount() > 1 )
1853 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1854 return xRange->getText();
1856 uno::Reference< text::XTextRange > xTextRange(
mxRange->getCellByPosition(0,0), uno::UNO_QUERY_THROW );
1857 return xTextRange->getString();
1860 uno::Reference< excel::XRange >
1863 SCROW nRowOffset = 0;
1864 SCCOL nColOffset = 0;
1865 bool bIsRowOffset = ( nRowOff >>= nRowOffset );
1866 bool bIsColumnOffset = ( nColOff >>= nColOffset );
1871 for (
size_t i = 0, nRanges = aCellRanges.
size();
i < nRanges; ++
i )
1873 ScRange & rRange = aCellRanges[
i ];
1874 if ( bIsColumnOffset )
1886 if ( aCellRanges.
size() > 1 )
1888 uno::Reference< sheet::XSheetCellRangeContainer > xRanges(
new ScCellRangesObj( pUnoRangesBase->
GetDocShell(), aCellRanges ) );
1896 uno::Reference< excel::XRange >
1903 if (
m_Areas->getCount() > 1 )
1905 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1906 return xRange->CurrentRegion();
1910 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
1911 helper.getSheetCellCursor();
1912 xSheetCellCursor->collapseToCurrentRegion();
1913 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
1914 return RangeHelper::createRangeFromRange(
mxParent,
mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
1917 uno::Reference< excel::XRange >
1924 if (
m_Areas->getCount() > 1 )
1926 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1927 return xRange->CurrentArray();
1930 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
1931 helper.getSheetCellCursor();
1932 xSheetCellCursor->collapseToCurrentArray();
1933 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
1934 return RangeHelper::createRangeFromRange(
mxParent,
mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
1944 if (
m_Areas->getCount() > 1 )
1946 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1947 return xRange->getFormulaArray();
1955 uno::Reference< sheet::XArrayFormulaRange> xFormulaArray(
mxRange, uno::UNO_QUERY_THROW );
1956 if ( !xFormulaArray->getArrayFormula().isEmpty() )
1957 return uno::makeAny( xFormulaArray->getArrayFormula() );
1959 uno::Reference< sheet::XCellRangeFormula> xCellRangeFormula(
mxRange, uno::UNO_QUERY_THROW );
1964 uno::Sequence< uno::Sequence<OUString> > aTmpSeq = xCellRangeFormula->getFormulaArray();
1965 if ( aTmpSeq.getLength() == 1 )
1968 aSingleValueOrMatrix <<= aTmpSeq[ 0 ][ 0 ];
1971 aSingleValueOrMatrix = xConverter->convertTo( uno::makeAny( aTmpSeq ) ,
cppu::UnoType<uno::Sequence< uno::Sequence< uno::Any > >>::
get() ) ;
1972 return aSingleValueOrMatrix;
1982 if (
m_Areas->getCount() > 1 )
1984 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1985 return xRange->setFormulaArray( rFormula );
1990 uno::Reference< lang::XMultiServiceFactory > xModelFactory(
getUnoModel(), uno::UNO_QUERY_THROW );
1991 uno::Reference< sheet::XFormulaParser > xParser( xModelFactory->createInstance(
"com.sun.star.sheet.FormulaParser" ), uno::UNO_QUERY_THROW );
1992 uno::Reference< sheet::XCellRangeAddressable > xSource(
mxRange, uno::UNO_QUERY_THROW);
1994 table::CellRangeAddress aRangeAddress = xSource->getRangeAddress();
1998 table::CellAddress aAddress;
1999 aAddress.Sheet = aRangeAddress.Sheet;
2000 aAddress.Column = aRangeAddress.StartColumn;
2001 aAddress.Row = aRangeAddress.StartRow;
2003 rFormula >>= sFormula;
2004 uno::Sequence<sheet::FormulaToken> aTokens = xParser->parseFormula( sFormula, aAddress );
2018 if (
m_Areas->getCount() > 1 )
2020 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
2021 return xRange->Characters( Start, Length );
2026 uno::Reference< text::XTextRange > xTextRange(
mxRange, ::uno::UNO_QUERY_THROW );
2027 rString = xTextRange->getString();
2028 if( !( Start >>= nIndex ) && !( Length >>= nCount ) )
2030 if(!( Start >>= nIndex ) )
2032 if(!( Length >>= nCount ) )
2033 nIndex = rString.getLength();
2034 return rString.copy( --nIndex, nCount );
2040 if (
m_Areas->getCount() > 1 )
2043 OUStringBuffer sAddress;
2044 uno::Reference< XCollection > xCollection(
m_Areas, uno::UNO_SET_THROW );
2046 for ( sal_Int32
index = 1;
index <= xCollection->getCount(); ++
index )
2048 uno::Reference< excel::XRange > xRange( xCollection->Item( uno::makeAny(
index ),
uno::Any() ), uno::UNO_QUERY_THROW );
2051 sAddress.append(
",");
2055 aExternalCopy <<=
false;
2057 sAddress.append(xRange->Address( RowAbsolute, ColumnAbsolute, ReferenceStyle, aExternalCopy, RelativeTo ));
2059 return sAddress.makeStringAndClear();
2065 sal_Int32 refStyle = excel::XlReferenceStyle::xlA1;
2066 ReferenceStyle >>= refStyle;
2067 if ( refStyle == excel::XlReferenceStyle::xlR1C1 )
2075 RangeHelper thisRange(
mxRange );
2076 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
2077 ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) );
2084 RowAbsolute >>= bVal;
2091 ColumnAbsolute >>= bVal;
2097 bool bLocal =
false;
2098 External >>= bLocal;
2109 return aRange.
Format(rDoc, nFlags, dDetails);
2112 uno::Reference < excel::XFont >
2115 uno::Reference< beans::XPropertySet > xProps(
mxRange, ::uno::UNO_QUERY );
2118 xProps.set(
mxRange, ::uno::UNO_QUERY );
2120 xProps.set(
mxRanges, ::uno::UNO_QUERY );
2128 catch( uno::Exception& )
2134 uno::Reference< excel::XRange >
2141 if (
m_Areas->getCount() > 1 )
2143 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
2144 return xRange->Cells( nRowIndex, nColumnIndex );
2153 uno::Reference< excel::XRange >
2155 const uno::Reference< ov::XHelperInterface >& xParent,
2156 const uno::Reference< uno::XComponentContext >& xContext,
2157 const uno::Reference< css::table::XCellRange >& xRange,
2160 sal_Int32 nRow = 0, nColumn = 0;
2162 bool bIsIndex = nRowIndex.
hasValue();
2163 bool bIsColumnIndex = nColumnIndex.
hasValue();
2169 if ( nRowIndex.
hasValue() && !( nRowIndex >>= nRow ) )
2171 const uno::Reference< script::XTypeConverter >& xConverter =
getTypeConverter( xContext );
2176 bIsIndex = ( aConverted >>= nRow );
2178 catch( uno::Exception& ) {}
2181 if ( bIsColumnIndex )
2185 if ( nColumnIndex >>= sCol )
2191 throw uno::RuntimeException();
2196 if ( !( nColumnIndex >>= nColumn ) )
2198 const uno::Reference< script::XTypeConverter >& xConverter =
getTypeConverter( xContext );
2203 bIsColumnIndex = ( aConverted >>= nColumn );
2205 catch( uno::Exception& ) {}
2209 RangeHelper thisRange( xRange );
2210 table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
2211 uno::Reference< table::XCellRange > xSheetRange = thisRange.getCellRangeFromSheet();
2212 if( !bIsIndex && !bIsColumnIndex )
2214 return uno::Reference< excel::XRange >(
new ScVbaRange( xParent, xContext, xRange ) );
2216 sal_Int32
nIndex = --nRow;
2217 if( bIsIndex && !bIsColumnIndex )
2219 uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, ::uno::UNO_QUERY_THROW);
2220 sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
2222 if ( !nIndex || nIndex < 0 )
2225 nRow = nIndex / nColCount;
2226 nColumn = nIndex % nColCount;
2230 nRow = nRow + thisRangeAddress.StartRow;
2231 nColumn = nColumn + thisRangeAddress.StartColumn;
2232 return new ScVbaRange( xParent, xContext, xSheetRange->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ) );
2239 if ( !pUnoRangesBase )
2240 throw uno::RuntimeException(
"Failed to access underlying uno range object" );
2245 uno::Reference< frame::XModel >
xModel( pShell->
GetModel(), uno::UNO_SET_THROW );
2246 uno::Reference< view::XSelectionSupplier > xSelection(
xModel->getCurrentController(), uno::UNO_QUERY_THROW );
2255 uno::Reference< frame::XController >
xController(
xModel->getCurrentController(), uno::UNO_SET_THROW );
2256 uno::Reference< frame::XFrame >
xFrame(
xController->getFrame(), uno::UNO_SET_THROW );
2257 uno::Reference< awt::XWindow > xWin(
xFrame->getContainerWindow(), uno::UNO_SET_THROW );
2260 catch( uno::Exception& )
2265 static bool cellInRange(
const table::CellRangeAddress& rAddr, sal_Int32 nCol, sal_Int32 nRow )
2267 return nCol >= rAddr.StartColumn && nCol <= rAddr.EndColumn &&
2268 nRow >= rAddr.StartRow && nRow <= rAddr.EndRow;
2271 static void setCursor(
SCCOL nCol,
SCROW nRow,
const uno::Reference< frame::XModel >& xModel,
bool bInSel =
true )
2287 uno::Reference< table::XCellRange > xCellRange;
2290 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
2291 xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
2294 xCellRange.set(
mxRange, uno::UNO_SET_THROW );
2296 RangeHelper thisRange( xCellRange );
2297 uno::Reference< sheet::XCellRangeAddressable > xThisRangeAddress = thisRange.getCellRangeAddressable();
2298 table::CellRangeAddress thisRangeAddress = xThisRangeAddress->getRangeAddress();
2299 uno::Reference< frame::XModel >
xModel;
2306 throw uno::RuntimeException();
2309 uno::Reference< sheet::XCellRangeAddressable > xRange( xModel->getCurrentSelection(), ::uno::UNO_QUERY);
2311 uno::Reference< sheet::XSheetCellRanges > xRanges( xModel->getCurrentSelection(), ::uno::UNO_QUERY);
2315 const uno::Sequence< table::CellRangeAddress > nAddrs = xRanges->getRangeAddresses();
2316 for (
const auto& rAddr : nAddrs )
2318 if (
cellInRange( rAddr, thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
2320 setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
2327 if ( xRange.is() &&
cellInRange( xRange->getRangeAddress(), thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
2328 setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
2336 setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel,
false );
2343 uno::Reference< excel::XRange >
2354 if( aIndex >>= nValue )
2359 else if ( aIndex >>= sAddress )
2371 throw uno::RuntimeException(
"Illegal param" );
2374 throw uno::RuntimeException(
"Internal failure, illegal param" );
2380 if (
m_Areas->getCount() > 1 )
2385 uno::Reference< excel::XRange >
2396 if ( aIndex >>= nValue )
2402 else if ( aIndex >>= sAddress )
2414 throw uno::RuntimeException(
"Illegal param" );
2417 throw uno::RuntimeException(
"Internal failure, illegal param" );
2431 sal_Int32 nCount =
mxRanges->getCount();
2434 ::std::vector< table::CellRangeAddress > aList;
2437 uno::Reference< sheet::XCellRangeAddressable > xRangeAddr(
mxRanges->getByIndex(
nIndex ), uno::UNO_QUERY_THROW );
2438 table::CellRangeAddress aAddress = xRangeAddr->getRangeAddress();
2439 if (std::any_of(aList.begin(), aList.end(),
2440 [&aAddress](
const table::CellRangeAddress& rAddress)
2443 aList.push_back( aAddress );
2449 uno::Reference< table::XCellRange > xRange(
mxRanges->getByIndex(
nIndex ), uno::UNO_QUERY_THROW );
2450 lclExpandAndMerge( xRange, bMerge );
2456 lclExpandAndMerge(
mxRange, bMerge );
2464 sal_Int32 nCount =
mxRanges->getCount();
2467 uno::Reference< table::XCellRange > xRange(
mxRanges->getByIndex(
nIndex ), uno::UNO_QUERY_THROW );
2468 util::TriState eMerged = lclGetMergedState( xRange );
2472 if( eMerged != util::TriState_NO )
2480 switch( lclGetMergedState(
mxRange ) )
2482 case util::TriState_YES:
return uno::Any(
true );
2483 case util::TriState_NO:
return uno::Any(
false );
2484 default:
return aNULL();
2491 if ( Destination.hasValue() )
2494 if (
m_Areas->getCount() > 1 )
2495 throw uno::RuntimeException(
"That command cannot be used on multiple selections" );
2496 uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW );
2497 uno::Any aRange = xRange->getCellRange();
2498 uno::Reference< table::XCellRange > xCellRange;
2499 aRange >>= xCellRange;
2500 uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW);
2501 uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
2502 uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW );
2503 uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW);
2504 uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition(
2505 xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY_THROW );
2506 uno::Reference< sheet::XCellRangeAddressable > xSource(
mxRange, uno::UNO_QUERY);
2507 xMover->copyRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
2509 pRange->fireChangeEvent();
2520 if (
m_Areas->getCount() > 1 )
2521 throw uno::RuntimeException(
"That command cannot be used on multiple selections" );
2522 if (Destination.hasValue())
2524 uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW );
2525 uno::Reference< table::XCellRange > xCellRange( xRange->getCellRange(), uno::UNO_QUERY_THROW );
2526 uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW );
2527 uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
2528 uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW );
2529 uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW);
2530 uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition(
2531 xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY);
2532 uno::Reference< sheet::XCellRangeAddressable > xSource(
mxRange, uno::UNO_QUERY);
2533 xMover->moveRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
2547 aFormat >>= sFormat;
2548 if (
m_Areas->getCount() > 1 )
2550 sal_Int32 nItems =
m_Areas->getCount();
2553 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
2554 xRange->setNumberFormat( aFormat );
2558 NumFormatHelper numFormat(
mxRange );
2559 numFormat.setNumberFormat( sFormat );
2566 if (
m_Areas->getCount() > 1 )
2568 sal_Int32 nItems =
m_Areas->getCount();
2572 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
2576 if ( aResult != xRange->getNumberFormat() )
2578 aResult = xRange->getNumberFormat();
2579 if (
aNULL() == aResult )
2584 NumFormatHelper numFormat(
mxRange );
2585 OUString sFormat = numFormat.getNumberFormatString();
2586 if ( !sFormat.isEmpty() )
2587 return uno::makeAny( sFormat );
2591 uno::Reference< excel::XRange >
2595 bool bIsRowChanged = ( RowSize >>= nRowSize ), bIsColumnChanged = ( ColumnSize >>= nColumnSize );
2596 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, ::uno::UNO_QUERY_THROW);
2597 uno::Reference< sheet::XSheetCellRange > xSheetRange(
mxRange, ::uno::UNO_QUERY_THROW);
2598 uno::Reference< sheet::XSheetCellCursor > xCursor( xSheetRange->getSpreadsheet()->createCursorByRange(xSheetRange), ::uno::UNO_SET_THROW );
2600 if( !bIsRowChanged )
2601 nRowSize = xColumnRowRange->getRows()->getCount();
2602 if( !bIsColumnChanged )
2603 nColumnSize = xColumnRowRange->getColumns()->getCount();
2605 xCursor->collapseToSize( nColumnSize, nRowSize );
2606 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xCursor, ::uno::UNO_QUERY_THROW );
2607 uno::Reference< table::XCellRange > xRange( xSheetRange->getSpreadsheet(), ::uno::UNO_QUERY_THROW );
2609 xCellRangeAddressable->getRangeAddress().StartColumn,
2610 xCellRangeAddressable->getRangeAddress().StartRow,
2611 xCellRangeAddressable->getRangeAddress().EndColumn,
2612 xCellRangeAddressable->getRangeAddress().EndRow ) );
2618 if (
m_Areas->getCount() > 1 )
2620 sal_Int32 nItems =
m_Areas->getCount();
2623 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
2624 xRange->setWrapText( aIsWrapped );
2629 uno::Reference< beans::XPropertySet > xProps(
mxRange, ::uno::UNO_QUERY_THROW );
2631 xProps->setPropertyValue(
"IsTextWrapped",
uno::Any( bIsWrapped ) );
2637 if (
m_Areas->getCount() > 1 )
2639 sal_Int32 nItems =
m_Areas->getCount();
2643 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
2645 if ( aResult != xRange->getWrapText() )
2647 aResult = xRange->getWrapText();
2655 if ( eState == SfxItemState::DONTCARE )
2658 uno::Reference< beans::XPropertySet > xProps(
mxRange, ::uno::UNO_QUERY_THROW );
2659 uno::Any aValue = xProps->getPropertyValue(
"IsTextWrapped" );
2665 uno::Reference< beans::XPropertySet > xProps(
mxRange, uno::UNO_QUERY_THROW );
2668 uno::Reference< excel::XRange >
2671 return Range( Cell1, Cell2,
false );
2673 uno::Reference< excel::XRange >
2677 uno::Reference< table::XCellRange > xCellRange =
mxRange;
2679 if (
m_Areas->getCount() > 1 )
2681 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
2682 xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
2687 RangeHelper thisRange( xCellRange );
2688 uno::Reference< table::XCellRange > xRanges = thisRange.getCellRangeFromSheet();
2689 uno::Reference< sheet::XCellRangeAddressable > xAddressable( xRanges, uno::UNO_QUERY_THROW );
2691 uno::Reference< table::XCellRange > xReferrer =
2693 xAddressable->getRangeAddress().EndColumn,
2694 xAddressable->getRangeAddress().EndRow );
2696 xAddressable.set( xReferrer, uno::UNO_QUERY_THROW );
2699 throw uno::RuntimeException(
"Invalid Argument" );
2701 table::CellRangeAddress parentRangeAddress = xAddressable->getRangeAddress();
2709 RangeHelper referRange( xReferrer );
2710 table::CellRangeAddress referAddress = referRange.getCellRangeAddressable()->getRangeAddress();
2716 table::CellRangeAddress cell1, cell2;
2724 table::CellRangeAddress resultAddress;
2725 resultAddress.StartColumn = ( cell1.StartColumn < cell2.StartColumn ) ? cell1.StartColumn : cell2.StartColumn;
2726 resultAddress.StartRow = ( cell1.StartRow < cell2.StartRow ) ? cell1.StartRow : cell2.StartRow;
2727 resultAddress.EndColumn = std::max( cell1.EndColumn, cell2.EndColumn );
2728 resultAddress.EndRow = std::max( cell1.EndRow, cell2.EndRow );
2729 if ( bForceUseInpuRangeTab )
2734 if ( cell1.Sheet != cell2.Sheet )
2735 throw uno::RuntimeException();
2736 parentRangeAddress.Sheet = cell1.Sheet;
2743 if ( parentRangeAddress.Sheet != cell1.Sheet
2744 || parentRangeAddress.Sheet != cell2.Sheet
2746 throw uno::RuntimeException();
2760 if ( nStartX <= nEndX && nEndX <= parentAddress.
aEnd.
Col() &&
2761 nStartY <= nEndY && nEndY <= parentAddress.
aEnd.
Row() )
2763 ScRange aNew( static_cast<SCCOL>(nStartX), static_cast<SCROW>(nStartY), parentAddress.
aStart.
Tab(),
2764 static_cast<SCCOL>(nEndX), static_cast<SCROW>(nEndY), parentAddress.
aEnd.
Tab() );
2788 return pVbaRange->getCellRange();
2789 throw uno::RuntimeException();
2796 case excel::XlPasteType::xlPasteComments:
2798 case excel::XlPasteType::xlPasteFormats:
2800 case excel::XlPasteType::xlPasteFormulas:
2802 case excel::XlPasteType::xlPasteFormulasAndNumberFormats :
2803 case excel::XlPasteType::xlPasteValues:
2805 case excel::XlPasteType::xlPasteValuesAndNumberFormats:
2807 case excel::XlPasteType::xlPasteColumnWidths:
2808 case excel::XlPasteType::xlPasteValidation:
2810 case excel::XlPasteType::xlPasteAll:
2811 case excel::XlPasteType::xlPasteAllExceptBorders:
2824 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationAdd:
2826 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationSubtract:
2828 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationMultiply:
2830 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationDivide:
2833 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone:
2838 return nFormulaBits;
2843 if (
m_Areas->getCount() > 1 )
2844 throw uno::RuntimeException(
"That command cannot be used on multiple selections" );
2848 throw uno::RuntimeException(
"That command cannot be used with no ScDocShell" );
2850 uno::Reference< frame::XModel >
xModel(pShell->
GetModel(), uno::UNO_SET_THROW);
2851 uno::Reference< view::XSelectionSupplier > xSelection(
xModel->getCurrentController(), uno::UNO_QUERY_THROW );
2853 xSelection->select( uno::makeAny(
mxRange ) );
2855 sal_Int32 nPaste = excel::XlPasteType::xlPasteAll;
2856 sal_Int32 nOperation = excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone;
2857 bool bTranspose =
false;
2858 bool bSkipBlanks =
false;
2863 Operation >>= nOperation;
2865 SkipBlanks >>= bSkipBlanks;
2867 Transpose >>= bTranspose;
2874 uno::Reference< excel::XRange >
2882 for (
size_t i = 0, nRanges = aCellRanges.
size();
i < nRanges; ++
i )
2884 ScRange & rRange = aCellRanges[
i ];
2896 if ( aCellRanges.
size() > 1 )
2898 uno::Reference< sheet::XSheetCellRangeContainer > xRanges(
new ScCellRangesObj( pUnoRangesBase->
GetDocShell(), aCellRanges ) );
2906 uno::Reference< excel::XRange > SAL_CALL
2912 uno::Reference< excel::XRange > SAL_CALL
2918 uno::Reference< excel::XComment > SAL_CALL
2923 throw uno::RuntimeException();
2927 if( Text.
hasValue() && !(Text >>= aNoteText) )
2928 throw uno::RuntimeException();
2929 if( aNoteText.isEmpty() )
2933 table::CellRangeAddress aRangePos = lclGetRangeAddress(
mxRange );
2934 table::CellAddress aNotePos( aRangePos.Sheet, aRangePos.StartColumn, aRangePos.StartRow );
2935 uno::Reference< sheet::XSheetCellRange > xCellRange(
mxRange, uno::UNO_QUERY_THROW );
2936 uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xCellRange->getSpreadsheet(), uno::UNO_QUERY_THROW );
2937 uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_SET_THROW );
2938 xAnnos->insertNew( aNotePos, aNoteText );
2942 uno::Reference< excel::XComment > SAL_CALL
2955 static uno::Reference< beans::XPropertySet >
2958 uno::Reference< table::XColumnRowRange > xColRow( xCellRange, uno::UNO_QUERY_THROW );
2959 uno::Reference< beans::XPropertySet > xProps;
2961 xProps.set( xColRow->getRows(), uno::UNO_QUERY_THROW );
2963 xProps.set( xColRow->getColumns(), uno::UNO_QUERY_THROW );
2972 if (
m_Areas->getCount() > 1 )
2974 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(sal_Int32(1)),
uno::Any() ), uno::UNO_QUERY_THROW );
2975 return xRange->getHidden();
2977 bool bIsVisible =
false;
2981 if ( !( xProps->getPropertyValue( ISVISIBLE ) >>= bIsVisible ) )
2982 throw uno::RuntimeException(
"Failed to get IsVisible property" );
2984 catch(
const uno::Exception& e )
2987 throw css::lang::WrappedTargetRuntimeException( e.Message,
2990 return uno::makeAny( !bIsVisible );
2996 if (
m_Areas->getCount() > 1 )
2998 sal_Int32 nItems =
m_Areas->getCount();
3001 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
3002 xRange->setHidden( _hidden );
3011 xProps->setPropertyValue( ISVISIBLE,
uno::Any( !bHidden ) );
3013 catch(
const uno::Exception& e )
3016 throw css::lang::WrappedTargetRuntimeException( e.Message,
3024 if (
m_Areas->getCount() > 1 )
3028 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index ),
uno::Any() ), uno::UNO_QUERY_THROW );
3029 xRange->Replace( What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat );
3035 if ( What.isEmpty() )
3036 throw uno::RuntimeException(
"Range::Replace, missing params" );
3043 uno::Reference< util::XReplaceable > xReplace(
mxRange, uno::UNO_QUERY );
3044 if ( xReplace.is() )
3046 uno::Reference< util::XReplaceDescriptor > xDescriptor =
3047 xReplace->createReplaceDescriptor();
3049 xDescriptor->setSearchString( sWhat);
3051 xDescriptor->setReplaceString( Replacement);
3055 sal_Int16 nLook = ::comphelper::getINT16( LookAt );
3056 bool bSearchWords =
false;
3057 if ( nLook == excel::XlLookAt::xlPart )
3058 bSearchWords =
false;
3059 else if ( nLook == excel::XlLookAt::xlWhole )
3060 bSearchWords =
true;
3062 throw uno::RuntimeException(
"Range::Replace, illegal value for LookAt" );
3066 xDescriptor->setPropertyValue(
SC_UNO_SRCHWORDS, uno::makeAny( bSearchWords ) );
3071 sal_Int16 nSearchOrder = ::comphelper::getINT16( SearchOrder );
3072 bool bSearchByRow =
false;
3073 if ( nSearchOrder == excel::XlSearchOrder::xlByColumns )
3074 bSearchByRow =
false;
3075 else if ( nSearchOrder == excel::XlSearchOrder::xlByRows )
3076 bSearchByRow =
true;
3078 throw uno::RuntimeException(
"Range::Replace, illegal value for SearchOrder" );
3081 xDescriptor->setPropertyValue(
SC_UNO_SRCHBYROW, uno::makeAny( bSearchByRow ) );
3085 bool bMatchCase =
false;
3088 MatchCase >>= bMatchCase;
3089 xDescriptor->setPropertyValue(
SC_UNO_SRCHCASE, uno::makeAny( bMatchCase ) );
3096 uno::Reference< container::XIndexAccess > xIndexAccess = xReplace->findAll( xDescriptor );
3097 xReplace->replaceAll( xDescriptor );
3098 if ( xIndexAccess.is() && xIndexAccess->getCount() > 0 )
3100 for ( sal_Int32
i = 0;
i < xIndexAccess->getCount(); ++
i )
3102 uno::Reference< table::XCellRange > xCellRange( xIndexAccess->getByIndex(
i ), uno::UNO_QUERY );
3103 if ( xCellRange.is() )
3106 uno::Reference< container::XEnumerationAccess > xEnumAccess( xRange, uno::UNO_QUERY_THROW );
3107 uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
3108 while ( xEnum->hasMoreElements() )
3110 uno::Reference< excel::XRange > xNextRange( xEnum->nextElement(), uno::UNO_QUERY_THROW );
3122 uno::Reference< excel::XRange > SAL_CALL
3127 sal_Int32 nWhat = 0;
3131 if( What >>= sWhat )
3133 else if( What >>= nWhat )
3135 sWhat = OUString::number( nWhat );
3137 else if( What >>= fWhat )
3139 sWhat = OUString::number( fWhat );
3142 throw uno::RuntimeException(
"Range::Find, missing search-for-what param" );
3149 uno::Reference< util::XSearchable > xSearch(
mxRange, uno::UNO_QUERY );
3152 uno::Reference< util::XSearchDescriptor > xDescriptor = xSearch->createSearchDescriptor();
3153 xDescriptor->setSearchString( sSearch );
3156 uno::Reference< excel::XRange > xAfterRange;
3157 uno::Reference< table::XCellRange > xStartCell;
3158 if( After >>= xAfterRange )
3161 if( xAfterRange->getCount() > 1 )
3162 throw uno::RuntimeException(
"After must be a single cell." );
3163 uno::Reference< excel::XRange > xCell(
Cells( uno::makeAny( xAfterRange->getRow() ), uno::makeAny( xAfterRange->getColumn() ) ), uno::UNO_SET_THROW );
3164 xStartCell.set( xAfterRange->getCellRange(), uno::UNO_QUERY_THROW );
3170 sal_Int32 nLookIn = 0;
3171 if( LookIn >>= nLookIn )
3176 case excel::XlFindLookIn::xlComments :
3177 nSearchType = SvxSearchCellType::NOTE;
3179 case excel::XlFindLookIn::xlFormulas :
3180 nSearchType = SvxSearchCellType::FORMULA;
3182 case excel::XlFindLookIn::xlValues :
3183 nSearchType = SvxSearchCellType::VALUE;
3186 throw uno::RuntimeException(
"Range::Find, illegal value for LookIn." );
3189 xDescriptor->setPropertyValue(
"SearchType", uno::makeAny( static_cast<sal_uInt16>(nSearchType) ) );
3196 sal_Int16 nLookAt = ::comphelper::getINT16( LookAt );
3197 bool bSearchWords =
false;
3198 if ( nLookAt == excel::XlLookAt::xlPart )
3199 bSearchWords =
false;
3200 else if ( nLookAt == excel::XlLookAt::xlWhole )
3201 bSearchWords =
true;
3203 throw uno::RuntimeException(
"Range::Find, illegal value for LookAt" );
3205 xDescriptor->setPropertyValue(
SC_UNO_SRCHWORDS, uno::makeAny( bSearchWords ) );
3211 sal_Int16 nSearchOrder = ::comphelper::getINT16( SearchOrder );
3212 bool bSearchByRow =
false;
3213 if ( nSearchOrder == excel::XlSearchOrder::xlByColumns )
3214 bSearchByRow =
false;
3215 else if ( nSearchOrder == excel::XlSearchOrder::xlByRows )
3216 bSearchByRow =
true;
3218 throw uno::RuntimeException(
"Range::Find, illegal value for SearchOrder" );
3221 xDescriptor->setPropertyValue(
SC_UNO_SRCHBYROW, uno::makeAny( bSearchByRow ) );
3227 sal_Int32 nSearchDirection = 0;
3228 if( SearchDirection >>= nSearchDirection )
3230 bool bSearchBackwards =
false;
3231 if ( nSearchDirection == excel::XlSearchDirection::xlNext )
3232 bSearchBackwards =
false;
3233 else if( nSearchDirection == excel::XlSearchDirection::xlPrevious )
3234 bSearchBackwards =
true;
3236 throw uno::RuntimeException(
"Range::Find, illegal value for SearchDirection" );
3238 xDescriptor->setPropertyValue(
"SearchBackwards", uno::makeAny( bSearchBackwards ) );
3243 bool bMatchCase =
false;
3247 if( !( MatchCase >>= bMatchCase ) )
3248 throw uno::RuntimeException(
"Range::Find illegal value for MatchCase" );
3250 xDescriptor->setPropertyValue(
SC_UNO_SRCHCASE, uno::makeAny( bMatchCase ) );
3258 uno::Reference< uno::XInterface > xInterface = xStartCell.is() ? xSearch->findNext( xStartCell, xDescriptor) : xSearch->findFirst( xDescriptor );
3259 uno::Reference< table::XCellRange > xCellRange( xInterface, uno::UNO_QUERY );
3262 if ( !xCellRange.is() && xStartCell.is() )
3264 xInterface = xSearch->findFirst( xDescriptor );
3265 xCellRange.set( xInterface, uno::UNO_QUERY );
3267 if ( xCellRange.is() )
3270 if( xResultRange.is() )
3272 return xResultRange;
3278 return uno::Reference< excel::XRange >();
3283 uno::Reference< excel::XRange > xKeyRange;
3286 xKeyRange.set( Key, uno::UNO_QUERY_THROW );
3291 OUString sRangeName = ::comphelper::getString( Key );
3292 table::CellRangeAddress aRefAddr;
3294 throw uno::RuntimeException(
"Range::Sort no docshell to calculate key param" );
3295 xKeyRange =
getRangeForName( xContext, sRangeName, pDocSh, aRefAddr );
3298 throw uno::RuntimeException(
"Range::Sort illegal type value for key param" );
3299 uno::Reference< table::XCellRange > xKey;
3300 xKey.set( xKeyRange->getCellRange(), uno::UNO_QUERY_THROW );
3307 const OUString& sPropName )
3309 const beans::PropertyValue* pProp = std::find_if(props.begin(), props.end(),
3310 [&sPropName](
const beans::PropertyValue& rProp) {
return rProp.Name == sPropName; });
3312 if ( pProp == props.end() )
3313 throw uno::RuntimeException(
"Range::Sort unknown sort property" );
3314 return static_cast<sal_Int32
>(std::distance(props.begin(), pProp));
3320 const uno::Reference< table::XCellRange >& xColRowKey, sal_Int16 nOrder,
3321 table::TableSortField& aTableField,
bool bIsSortColumn,
bool bMatchCase )
3323 RangeHelper parentRange( xParentRange );
3324 RangeHelper colRowRange( xColRowKey );
3326 table::CellRangeAddress parentRangeAddress = parentRange.getCellRangeAddressable()->getRangeAddress();
3328 table::CellRangeAddress colRowKeyAddress = colRowRange.getCellRangeAddressable()->getRangeAddress();
3333 ( bIsSortColumn || colRowKeyAddress.StartColumn < parentRangeAddress.StartColumn ||
3334 colRowKeyAddress.StartColumn > parentRangeAddress.EndColumn )
3336 ( !bIsSortColumn || colRowKeyAddress.StartRow < parentRangeAddress.StartRow ||
3337 colRowKeyAddress.StartRow > parentRangeAddress.EndRow )
3339 throw uno::RuntimeException(
"Illegal Key param" );
3342 if ( bIsSortColumn )
3343 aTableField.Field = colRowKeyAddress.StartRow - parentRangeAddress.StartRow;
3345 aTableField.Field = colRowKeyAddress.StartColumn - parentRangeAddress.StartColumn;
3346 aTableField.IsCaseSensitive = bMatchCase;
3348 if ( nOrder == excel::XlSortOrder::xlAscending )
3349 aTableField.IsAscending =
true;
3351 aTableField.IsAscending =
false;
3357 ScVbaRange::Sort(
const uno::Any& Key1,
const uno::Any& Order1,
const uno::Any& Key2,
const uno::Any& ,
const uno::Any& Order2,
const uno::Any& Key3,
const uno::Any& Order3,
const uno::Any& Header,
const uno::Any& OrderCustom,
const uno::Any& MatchCase,
const uno::Any&
Orientation,
const uno::Any& SortMethod,
const uno::Any& DataOption1,
const uno::Any& DataOption2,
const uno::Any& DataOption3 )
3360 if (
m_Areas->getCount() > 1 )
3361 throw uno::RuntimeException(
"That command cannot be used on multiple selections" );
3363 sal_Int16 nDataOption1 = excel::XlSortDataOption::xlSortNormal;
3364 sal_Int16 nDataOption2 = excel::XlSortDataOption::xlSortNormal;
3365 sal_Int16 nDataOption3 = excel::XlSortDataOption::xlSortNormal;
3369 RangeHelper thisRange(
mxRange );
3370 table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3372 SCTAB nTab = thisRangeAddress.Sheet;
3376 DataOption1 >>= nDataOption1;
3378 DataOption2 >>= nDataOption2;
3380 DataOption3 >>= nDataOption3;
3384 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY_THROW );
3388 sal_Int16 nOrder1 = aSortParam.
maKeyState[1].bAscending ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
3389 sal_Int16 nOrder2 = aSortParam.
maKeyState[2].bAscending ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
3390 sal_Int16 nOrder3 = aSortParam.
maKeyState[3].bAscending ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
3393 sal_Int16 nSortMethod = excel::XlSortMethod::xlPinYin;
3397 sal_Int16 nOrientation = aSortParam.
bByRow ? excel::XlSortOrientation::xlSortColumns : excel::XlSortOrientation::xlSortRows;
3404 nOrientation = ::comphelper::getINT16( Orientation );
3406 if ( nOrientation == excel::XlSortOrientation::xlSortRows )
3407 aSortParam.
bByRow =
false;
3409 aSortParam.
bByRow =
true;
3413 bool bIsSortColumns=
false;
3415 if ( nOrientation == excel::XlSortOrientation::xlSortRows )
3416 bIsSortColumns =
true;
3418 bool bContainsHeader =
false;
3422 nHeader = ::comphelper::getINT16( Header );
3426 if ( nHeader == excel::XlYesNoGuess::xlGuess )
3428 bool bHasColHeader = rDoc.
HasColHeader( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet ));
3429 bool bHasRowHeader = rDoc.
HasRowHeader( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet ) );
3430 if ( bHasColHeader || bHasRowHeader )
3431 nHeader = excel::XlYesNoGuess::xlYes;
3433 nHeader = excel::XlYesNoGuess::xlNo;
3437 if ( nHeader == excel::XlYesNoGuess::xlYes )
3438 bContainsHeader =
true;
3442 nSortMethod = ::comphelper::getINT16( SortMethod );
3447 OrderCustom >>= nCustom;
3454 MatchCase >>= bMatchCase;
3460 nOrder1 = ::comphelper::getINT16(Order1);
3461 if ( nOrder1 == excel::XlSortOrder::xlAscending )
3469 nOrder2 = ::comphelper::getINT16(Order2);
3470 if ( nOrder2 == excel::XlSortOrder::xlAscending )
3477 nOrder3 = ::comphelper::getINT16(Order3);
3478 if ( nOrder3 == excel::XlSortOrder::xlAscending )
3484 uno::Reference< table::XCellRange > xKey1;
3485 uno::Reference< table::XCellRange > xKey2;
3486 uno::Reference< table::XCellRange > xKey3;
3490 throw uno::RuntimeException(
"Range::Sort needs a key1 param" );
3497 uno::Reference< util::XSortable > xSort(
mxRange, uno::UNO_QUERY_THROW );
3498 uno::Sequence< beans::PropertyValue > sortDescriptor = xSort->createSortDescriptor();
3501 uno::Sequence< table::TableSortField > sTableFields(1);
3502 sal_Int32 nTableIndex = 0;
3507 sTableFields.realloc( sTableFields.getLength() + 1 );
3512 sTableFields.realloc( sTableFields.getLength() + 1 );
3515 sortDescriptor[ nTableSortFieldIndex ].Value <<= sTableFields;
3518 sortDescriptor[ nIndex ].Value <<= bIsSortColumns;
3521 sortDescriptor[ nIndex ].Value <<= bContainsHeader;
3524 xSort->sort( sortDescriptor );
3531 uno::Reference< excel::XRange > SAL_CALL
3534 if (
m_Areas->getCount() > 1 )
3536 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
3537 return xRange->End( Direction );
3550 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
3551 uno::Reference< excel::XWorksheet > sActiveSheet = xApplication->getActiveSheet();
3552 OUString sActiveCell = xApplication->getActiveCell()->Address(aDft, aDft, aDft, aDft, aDft );
3555 Cells( uno::makeAny( sal_Int32(1) ), uno::makeAny( sal_Int32(1) ) )->Select();
3566 aArgs.
Put( sfxAsync, sfxAsync.
Which() );
3569 sal_uInt16 nSID = 0;
3573 case excel::XlDirection::xlDown:
3574 nSID = SID_CURSORBLKDOWN;
3576 case excel::XlDirection::xlUp:
3577 nSID = SID_CURSORBLKUP;
3579 case excel::XlDirection::xlToLeft:
3580 nSID = SID_CURSORBLKLEFT;
3582 case excel::XlDirection::xlToRight:
3583 nSID = SID_CURSORBLKRIGHT;
3586 throw uno::RuntimeException(
": Invalid ColumnIndex" );
3590 pDispatcher->
Execute( nSID, SfxCallMode::SYNCHRON, aArgs );
3595 OUString sMoved = xApplication->getActiveCell()->Address(aDft, aDft, aDft, aDft, aDft );
3598 uno::Reference< excel::XRange > resultCell;
3599 resultCell.set( xApplication->getActiveSheet()->Range( uno::makeAny( sMoved ), aVoid ), uno::UNO_SET_THROW );
3602 uno::Reference< excel::XRange > xOldActiveCell( sActiveSheet->Range( uno::makeAny( sActiveCell ), aVoid ), uno::UNO_SET_THROW );
3603 xOldActiveCell->Select();
3613 uno::Reference< sheet::XCellRangeAddressable > xAddressable(
mxRange, uno::UNO_QUERY );
3614 if ( xAddressable.is() )
3616 table::CellRangeAddress aRangeAddr = xAddressable->getRangeAddress();
3617 return ( aRangeAddr.EndColumn == aRangeAddr.StartColumn && aRangeAddr.EndRow == aRangeAddr.StartRow );
3622 uno::Reference< excel::XCharacters > SAL_CALL
3626 throw uno::RuntimeException(
"Can't create Characters property for multicell range " );
3627 uno::Reference< text::XSimpleText > xSimple(
mxRange->getCellByPosition(0,0) , uno::UNO_QUERY_THROW );
3637 if (
m_Areas->getCount() > 1 )
3639 sal_Int32 nItems =
m_Areas->getCount();
3642 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
3643 xRange->Delete( Shift );
3647 sheet::CellDeleteMode
mode = sheet::CellDeleteMode_NONE ;
3648 RangeHelper thisRange(
mxRange );
3649 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3652 sal_Int32 nShift = 0;
3656 case excel::XlDeleteShiftDirection::xlShiftUp:
3657 mode = sheet::CellDeleteMode_UP;
3659 case excel::XlDeleteShiftDirection::xlShiftToLeft:
3660 mode = sheet::CellDeleteMode_LEFT;
3663 throw uno::RuntimeException(
"Illegal parameter " );
3669 bool bFullRow = ( thisAddress.StartColumn == 0 && thisAddress.EndColumn == rDoc.
MaxCol() );
3670 sal_Int32 nCols = thisAddress.EndColumn - thisAddress.StartColumn;
3671 sal_Int32 nRows = thisAddress.EndRow - thisAddress.StartRow;
3672 if (
mbIsRows || bFullRow || ( nCols >= nRows ) )
3673 mode = sheet::CellDeleteMode_UP;
3675 mode = sheet::CellDeleteMode_LEFT;
3677 uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
3678 xCellRangeMove->removeRange( thisAddress, mode );
3686 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY );
3687 if ( xColumnRowRange.is() )
3688 if ( xColumnRowRange->getRows()->getCount() ||
3689 xColumnRowRange->getColumns()->getCount() )
3695 uno::Reference< container::XEnumeration > SAL_CALL
3700 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY );
3701 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
3702 sal_Int32 nElems = 0;
3704 nElems = xColumnRowRange->getColumns()->getCount();
3706 nElems = xColumnRowRange->getRows()->getCount();
3707 return new ColumnsRowEnumeration( xRange, nElems );
3724 sal_uInt16 nWidth = rDoc.
GetOriginalWidth( static_cast< SCCOL >( rAddress.StartColumn ), static_cast< SCTAB >( rAddress.Sheet ) );
3734 sal_uInt16 nWidth = rDoc.
GetOriginalHeight( rAddress.StartRow, rAddress.Sheet );
3748 pRefDevice->
SetFont( aDefFont );
3756 sal_Int32 nLen =
m_Areas->getCount();
3759 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
3760 return xRange->getColumnWidth();
3763 double nColWidth = 0;
3768 RangeHelper thisRange(
mxRange );
3769 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3770 sal_Int32 nStartCol = thisAddress.StartColumn;
3771 sal_Int32 nEndCol = thisAddress.EndColumn;
3772 sal_uInt16 nColTwips = 0;
3773 for( sal_Int32 nCol = nStartCol ; nCol <= nEndCol; ++nCol )
3775 thisAddress.StartColumn = nCol;
3776 sal_uInt16 nCurTwips = pShell->
GetDocument().
GetOriginalWidth( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCTAB >( thisAddress.Sheet ) );
3777 if ( nCol == nStartCol )
3778 nColTwips = nCurTwips;
3779 if ( nColTwips != nCurTwips )
3783 if ( nColWidth != 0.0 )
3784 nColWidth = ( nColWidth / defaultCharWidth ) -
fExtraWidth;
3787 return uno::makeAny( nColWidth );
3793 sal_Int32 nLen =
m_Areas->getCount();
3798 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index ),
uno::Any() ), uno::UNO_QUERY_THROW );
3799 xRange->setColumnWidth( _columnwidth );
3803 double nColWidth = 0;
3804 _columnwidth >>= nColWidth;
3810 if ( nColWidth != 0.0 )
3812 RangeHelper thisRange(
mxRange );
3813 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3816 std::vector<sc::ColRowSpan> aColArr(1,
sc::ColRowSpan(thisAddress.StartColumn, thisAddress.EndColumn));
3819 true, aColArr, thisAddress.Sheet,
SC_SIZE_DIRECT, nTwips,
true,
true);
3825 if (
m_Areas->getCount() > 1 )
3827 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
3828 return xRange->getWidth();
3830 uno::Reference< table::XColumnRowRange > xColRowRange(
mxRange, uno::UNO_QUERY_THROW );
3831 uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getColumns(), uno::UNO_QUERY_THROW );
3832 sal_Int32 nElems = xIndexAccess->getCount();
3836 uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex(
index ), uno::UNO_QUERY_THROW );
3837 double nTmpWidth =
getCalcColWidth( xAddressable->getRangeAddress() );
3838 nWidth += nTmpWidth;
3840 return uno::makeAny( nWidth );
3847 return uno::makeAny(
m_Areas );
3851 uno::Reference< excel::XRange >
3855 throw uno::RuntimeException(
"No areas available" );
3856 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( ++nIndex ),
uno::Any() ), uno::UNO_QUERY_THROW );
3870 const css::uno::Any& ColorIndex,
const css::uno::Any&
Color )
3874 for( sal_Int32
i = 0;
i < nCount;
i++ )
3879 case excel::XlBordersIndex::xlEdgeLeft:
3880 case excel::XlBordersIndex::xlEdgeTop:
3881 case excel::XlBordersIndex::xlEdgeBottom:
3882 case excel::XlBordersIndex::xlEdgeRight:
3884 uno::Reference< excel::XBorder > xBorder(
m_Borders->Item( uno::makeAny( nLineType ),
uno::Any() ), uno::UNO_QUERY_THROW );
3885 if( LineStyle.hasValue() )
3887 xBorder->setLineStyle( LineStyle );
3889 if( Weight.hasValue() )
3891 xBorder->setWeight( Weight );
3893 if( ColorIndex.hasValue() )
3895 xBorder->setColorIndex( ColorIndex );
3897 if( Color.hasValue() )
3899 xBorder->setColor( Color );
3903 case excel::XlBordersIndex::xlInsideVertical:
3904 case excel::XlBordersIndex::xlInsideHorizontal:
3905 case excel::XlBordersIndex::xlDiagonalDown:
3906 case excel::XlBordersIndex::xlDiagonalUp:
3909 return uno::makeAny(
false );
3912 return uno::makeAny(
true );
3918 sal_Int32 nLen =
m_Areas->getCount();
3921 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
3922 return xRange->getRowHeight();
3927 RangeHelper thisRange(
mxRange );
3928 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3930 sal_Int32 nStartRow = thisAddress.StartRow;
3931 sal_Int32 nEndRow = thisAddress.EndRow;
3932 sal_uInt16 nRowTwips = 0;
3940 for ( sal_Int32 nRow = nStartRow ; nRow <= nEndRow; ++nRow )
3942 thisAddress.StartRow = nRow;
3944 if ( nRow == nStartRow )
3945 nRowTwips = nCurTwips;
3946 if ( nRowTwips != nCurTwips )
3951 return uno::makeAny( nHeight );
3957 sal_Int32 nLen =
m_Areas->getCount();
3962 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index ),
uno::Any() ), uno::UNO_QUERY_THROW );
3963 xRange->setRowHeight( _rowheight );
3968 _rowheight >>= nHeight;
3970 RangeHelper thisRange(
mxRange );
3971 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3975 std::vector<sc::ColRowSpan> aRowArr(1,
sc::ColRowSpan(thisAddress.StartRow, thisAddress.EndRow));
3983 sal_Int32 nPageBreak = excel::XlPageBreak::xlPageBreakNone;
3987 RangeHelper thisRange(
mxRange );
3988 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3989 bool bColumn =
false;
3991 if (thisAddress.StartRow==0)
4001 nBreak = rDoc.
HasRowBreak(thisAddress.StartRow, thisAddress.Sheet);
4003 nBreak = rDoc.
HasColBreak(thisAddress.StartColumn, thisAddress.Sheet);
4006 nPageBreak = excel::XlPageBreak::xlPageBreakAutomatic;
4009 nPageBreak = excel::XlPageBreak::xlPageBreakManual;
4013 return uno::makeAny( nPageBreak );
4019 sal_Int32 nPageBreak = 0;
4020 _pagebreak >>= nPageBreak;
4026 RangeHelper thisRange(
mxRange );
4027 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4028 if ((thisAddress.StartColumn==0) && (thisAddress.StartRow==0))
4030 bool bColumn =
false;
4032 if (thisAddress.StartRow==0)
4035 ScAddress aAddr( static_cast<SCCOL>(thisAddress.StartColumn), thisAddress.StartRow, thisAddress.Sheet );
4040 if ( nPageBreak == excel::XlPageBreak::xlPageBreakManual )
4042 else if ( nPageBreak == excel::XlPageBreak::xlPageBreakNone )
4050 if (
m_Areas->getCount() > 1 )
4052 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
4053 return xRange->getHeight();
4056 uno::Reference< table::XColumnRowRange > xColRowRange(
mxRange, uno::UNO_QUERY_THROW );
4057 uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getRows(), uno::UNO_QUERY_THROW );
4058 sal_Int32 nElems = xIndexAccess->getCount();
4062 uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex(
index ), uno::UNO_QUERY_THROW );
4065 return uno::makeAny( nHeight );
4072 uno::Reference< beans::XPropertySet > xProps;
4074 xProps.set(
mxRange, uno::UNO_QUERY_THROW );
4076 xProps.set(
mxRanges, uno::UNO_QUERY_THROW );
4077 xProps->getPropertyValue(
"Position" ) >>= aPoint;
4084 if (
m_Areas->getCount() > 1 )
4085 return getArea( 0 )->getLeft();
4094 if (
m_Areas->getCount() > 1 )
4095 return getArea( 0 )->getTop();
4100 static uno::Reference< sheet::XCellRangeReferrer >
getNamedRange(
const uno::Reference< uno::XInterface >& xIf,
const uno::Reference< table::XCellRange >& thisRange )
4102 uno::Reference< beans::XPropertySet > xProps( xIf, uno::UNO_QUERY_THROW );
4103 uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue(
"NamedRanges" ), uno::UNO_QUERY_THROW );
4105 const uno::Sequence< OUString > sNames = xNameAccess->getElementNames();
4107 uno::Reference< sheet::XCellRangeReferrer > xNamedRange;
4108 for (
const auto& rName : sNames )
4110 uno::Reference< sheet::XCellRangeReferrer > xName( xNameAccess->getByName( rName ), uno::UNO_QUERY );
4113 if ( thisRange == xName->getReferredCells() )
4115 xNamedRange = xName;
4123 uno::Reference< excel::XName >
4126 uno::Reference< beans::XPropertySet > xProps(
getUnoModel(), uno::UNO_QUERY );
4127 uno::Reference< table::XCellRange > thisRange(
getCellRange(), uno::UNO_QUERY_THROW );
4129 uno::Reference< sheet::XCellRangeReferrer > xNamedRange =
getNamedRange( xProps, thisRange );
4131 if ( !xNamedRange.is() )
4135 RangeHelper aRange( thisRange );
4136 uno::Reference< sheet::XSpreadsheet > xSheet = aRange.getSpreadSheet();
4137 xProps.set( xSheet, uno::UNO_QUERY );
4141 if ( xProps.is() && xNamedRange.is() )
4143 uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps, uno::UNO_QUERY_THROW );
4144 uno::Reference< sheet::XNamedRange > xName( xNamedRange, uno::UNO_QUERY_THROW );
4147 return uno::Reference< excel::XName >();
4150 uno::Reference< excel::XWorksheet >
4155 uno::Reference< excel::XWorksheet > xSheet(
getParent(), uno::UNO_QUERY );
4158 uno::Reference< table::XCellRange > xRange =
mxRange;
4162 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
4163 xRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
4166 RangeHelper rHelper(xRange);
4175 uno::Reference< excel::XRange >
4193 OUString sRangeName;
4194 Cell1 >>= sRangeName;
4195 if ( Cell1.hasValue() && !Cell2.hasValue() && !sRangeName.isEmpty() )
4197 uno::Reference< beans::XPropertySet > xPropSet(
getCurrentExcelDoc(xContext), uno::UNO_QUERY_THROW );
4199 uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue(
"NamedRanges" ), uno::UNO_QUERY_THROW );
4200 uno::Reference< sheet::XCellRangeReferrer > xReferrer;
4203 xReferrer.set ( xNamed->getByName( sRangeName ), uno::UNO_QUERY );
4205 catch( uno::Exception& )
4209 if ( xReferrer.is() )
4211 uno::Reference< table::XCellRange > xRange = xReferrer->getReferredCells();
4220 uno::Reference<table::XCellRange> xSheetRange;
4224 uno::Reference<sheet::XSpreadsheetView> xView(
4227 xSheetRange.set(xView->getActiveSheet(), uno::UNO_QUERY_THROW);
4229 catch (
const uno::Exception&)
4231 return uno::Reference<excel::XRange>();
4235 return pRange->Range( Cell1, Cell2,
true );
4258 pViewData = pViewSh ? &pViewSh->
GetViewData() :
nullptr;
4292 sCriteria1 = sCriteria1.trim();
4301 if ( sCriteria1.startsWith( EQUALS ) )
4303 if ( sCriteria1.getLength() ==
static_cast<sal_Int32
>(strlen(EQUALS)) )
4304 rFilterField.Operator = sheet::FilterOperator2::EMPTY;
4307 rFilterField.Operator = sheet::FilterOperator2::EQUAL;
4308 sCriteria1 = sCriteria1.copy( strlen(EQUALS) );
4311 if ( xDescProps.is() )
4312 xDescProps->setPropertyValue(
"UseRegularExpressions",
uno::Any(
true ) );
4316 else if ( sCriteria1.startsWith( NOTEQUALS ) )
4318 if ( sCriteria1.getLength() ==
static_cast<sal_Int32
>(strlen(NOTEQUALS)) )
4319 rFilterField.Operator = sheet::FilterOperator2::NOT_EMPTY;
4322 rFilterField.Operator = sheet::FilterOperator2::NOT_EQUAL;
4323 sCriteria1 = sCriteria1.copy( strlen(NOTEQUALS) );
4326 if ( xDescProps.is() )
4327 xDescProps->setPropertyValue(
"UseRegularExpressions",
uno::Any(
true ) );
4330 else if ( sCriteria1.startsWith( GREATERTHAN ) )
4332 if ( sCriteria1.startsWith( GREATERTHANEQUALS ) )
4334 sCriteria1 = sCriteria1.copy( strlen(GREATERTHANEQUALS) );
4335 rFilterField.Operator = sheet::FilterOperator2::GREATER_EQUAL;
4339 sCriteria1 = sCriteria1.copy( strlen(GREATERTHAN) );
4340 rFilterField.Operator = sheet::FilterOperator2::GREATER;
4344 else if ( sCriteria1.startsWith( LESSTHAN ) )
4346 if ( sCriteria1.startsWith( LESSTHANEQUALS ) )
4348 sCriteria1 = sCriteria1.copy( strlen(LESSTHANEQUALS) );
4349 rFilterField.Operator = sheet::FilterOperator2::LESS_EQUAL;
4353 sCriteria1 = sCriteria1.copy( strlen(LESSTHAN) );
4354 rFilterField.Operator = sheet::FilterOperator2::LESS;
4359 rFilterField.Operator = sheet::FilterOperator2::EQUAL;
4363 sal_Int32 nParseEnd = 0;
4364 rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
4366 if ( nParseEnd == sCriteria1.getLength() && eStatus == rtl_math_ConversionStatus_Ok )
4368 rFilterField.IsNumeric =
true;
4369 rFilterField.NumericValue = fValue;
4373 eStatus = rtl_math_ConversionStatus_Ok;
4374 fValue = ::rtl::math::stringToDouble( sCriteria1,
'.', 0, &eStatus, &nParseEnd );
4375 if ( nParseEnd == sCriteria1.getLength() && eStatus == rtl_math_ConversionStatus_Ok )
4377 rFilterField.IsNumeric =
true;
4378 rFilterField.NumericValue = fValue;
4382 rFilterField.StringValue = sCriteria1;
4389 RangeHelper thisRange(
mxRange );
4390 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4391 sal_Int16 nSheet = thisAddress.Sheet;
4393 bool bHasAuto =
false;
4395 if ( xDataBaseRange.is() )
4400 if (
m_Areas->getCount() > 1 )
4403 table::CellRangeAddress autoFiltAddress;
4407 uno::Reference< excel::XRange > xCurrent(
CurrentRegion() );
4408 if ( xCurrent.is() )
4414 throw uno::RuntimeException(
"Can't create AutoFilter" );
4415 RangeHelper currentRegion( pRange->
mxRange );
4416 autoFiltAddress = currentRegion.getCellRangeAddressable()->getRangeAddress();
4422 RangeHelper multiCellRange(
mxRange );
4423 autoFiltAddress = multiCellRange.getCellRangeAddressable()->getRangeAddress();
4428 SCCOL nStartCol = autoFiltAddress.StartColumn;
4429 SCROW nStartRow = autoFiltAddress.StartRow;
4430 SCCOL nEndCol = autoFiltAddress.EndColumn;
4431 SCROW nEndRow = autoFiltAddress.EndRow;
4432 pDocument->
GetDataArea( autoFiltAddress.Sheet, nStartCol, nStartRow, nEndCol, nEndRow,
true,
true );
4433 autoFiltAddress.StartColumn = nStartCol;
4434 autoFiltAddress.StartRow = nStartRow;
4435 autoFiltAddress.EndColumn = nEndCol;
4436 autoFiltAddress.EndRow = nEndRow;
4441 if ( xDBRanges.is() )
4443 if ( !xDBRanges->hasByTable( nSheet ) )
4444 xDBRanges->setByTable( autoFiltAddress );
4445 xDataBaseRange.set( xDBRanges->getByTable(nSheet ), uno::UNO_QUERY_THROW );
4447 if ( !xDataBaseRange.is() )
4448 throw uno::RuntimeException(
"Failed to find the autofilter placeholder range" );
4450 uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
4452 xDBRangeProps->setPropertyValue(
"AutoFilter",
uno::Any(
true) );
4454 uno::Reference< beans::XPropertySet > xFiltProps( xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY_THROW );
4455 xFiltProps->setPropertyValue(
"ContainsHeader",
uno::Any(
true ) );
4458 sal_Int32 nField = 0;
4459 sal_Int32 nOperator = excel::XlAutoFilterOperator::xlAnd;
4461 sheet::FilterConnection nConn = sheet::FilterConnection_AND;
4462 double nCriteria1 = 0;
4464 bool bHasCritValue = Criteria1.
hasValue();
4465 bool bCritHasNumericValue =
false;
4466 if ( bHasCritValue )
4467 bCritHasNumericValue = ( Criteria1 >>= nCriteria1 );
4470 throw uno::RuntimeException();
4472 if ( !( Field >>= nField ) )
4479 catch( uno::Exception& )
4486 if ( Field >>= nField )
4488 uno::Reference< sheet::XSheetFilterDescriptor2 > xDesc(
4489 xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY );
4492 OUString sCriteria1;
4493 bool bAcceptCriteria2 =
true;
4495 uno::Sequence< sheet::TableFilterField2 > sTabFilts;
4496 uno::Reference< beans::XPropertySet > xDescProps( xDesc, uno::UNO_QUERY_THROW );
4499 sTabFilts.realloc( 1 );
4500 sTabFilts[0].Operator = sheet::FilterOperator2::EQUAL;
4501 if ( !bCritHasNumericValue )
4503 Criteria1 >>= sCriteria1;
4504 if ( sCriteria1.isEmpty() )
4506 uno::Sequence< OUString > aCriteria1;
4507 Criteria1 >>= aCriteria1;
4508 sal_uInt16
nLength = aCriteria1.getLength();
4512 bAcceptCriteria2 =
false;
4514 sTabFilts.realloc( nLength );
4515 for ( sal_uInt16
i = 0;
i < nLength; ++
i )
4518 sTabFilts[i].Connection = sheet::FilterConnection_OR;
4519 sTabFilts[i].Field = (nField - 1);
4527 sTabFilts[0].IsNumeric = bCritHasNumericValue;
4528 if ( bHasCritValue && !sCriteria1.isEmpty() )
4536 sTabFilts[0].IsNumeric =
true;
4537 sTabFilts[0].NumericValue = nCriteria1;
4544 if ( Operator.
hasValue() && ( Operator >>= nOperator ) )
4548 if ( !bCritHasNumericValue && sCriteria1.isEmpty() && ( nOperator != excel::XlAutoFilterOperator::xlOr ) && ( nOperator != excel::XlAutoFilterOperator::xlAnd ) )
4550 sTabFilts[0].IsNumeric =
true;
4551 sTabFilts[0].NumericValue = 10;
4554 switch ( nOperator )
4556 case excel::XlAutoFilterOperator::xlBottom10Items:
4557 sTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_VALUES;
4559 case excel::XlAutoFilterOperator::xlBottom10Percent:
4560 sTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_PERCENT;
4562 case excel::XlAutoFilterOperator::xlTop10Items:
4563 sTabFilts[0].Operator = sheet::FilterOperator2::TOP_VALUES;
4565 case excel::XlAutoFilterOperator::xlTop10Percent:
4566 sTabFilts[0].Operator = sheet::FilterOperator2::TOP_PERCENT;
4568 case excel::XlAutoFilterOperator::xlOr:
4569 nConn = sheet::FilterConnection_OR;
4571 case excel::XlAutoFilterOperator::xlAnd:
4572 nConn = sheet::FilterConnection_AND;
4575 throw uno::RuntimeException(
"UnknownOption" );
4580 if ( !bAll && bAcceptCriteria2 )
4582 sTabFilts[0].Connection = sheet::FilterConnection_AND;
4583 sTabFilts[0].Field = (nField - 1);
4585 uno::Sequence< OUString > aCriteria2;
4588 sTabFilts.realloc(2);
4589 sTabFilts[1].Field = sTabFilts[0].Field;
4590 sTabFilts[1].Connection = nConn;
4592 OUString sCriteria2;
4593 if ( Criteria2 >>= sCriteria2 )
4595 if ( !sCriteria2.isEmpty() )
4597 uno::Reference< beans::XPropertySet > xProps;
4599 sTabFilts[1].IsNumeric =
false;
4602 else if ( Criteria2 >>= aCriteria2 )
4604 sal_uInt16
nLength = aCriteria2.getLength();
4613 Criteria2 >>= sTabFilts[1].NumericValue;
4614 sTabFilts[1].IsNumeric =
true;
4615 sTabFilts[1].Operator = sheet::FilterOperator2::EQUAL;
4620 xDesc->setFilterFields2( sTabFilts );
4623 xDataBaseRange->refresh();
4635 uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
4647 uno::Reference< sheet::XSheetFilterDescriptor2 > xSheetFilterDescriptor(
4648 xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY );
4649 if( xSheetFilterDescriptor.is() )
4650 xSheetFilterDescriptor->setFilterFields2( uno::Sequence< sheet::TableFilterField2 >() );
4652 xDBRangeProps->setPropertyValue(
"AutoFilter",
uno::Any(!bHasAuto) );
4666 sheet::CellInsertMode
mode = sheet::CellInsertMode_NONE;
4669 sal_Int32 nShift = 0;
4673 case excel::XlInsertShiftDirection::xlShiftToRight:
4674 mode = sheet::CellInsertMode_RIGHT;
4676 case excel::XlInsertShiftDirection::xlShiftDown:
4677 mode = sheet::CellInsertMode_DOWN;
4680 throw uno::RuntimeException(
"Illegal parameter " );
4686 mode = sheet::CellInsertMode_DOWN;
4688 mode = sheet::CellInsertMode_RIGHT;
4690 RangeHelper thisRange(
mxRange );
4691 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4692 uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
4693 xCellRangeMove->insertCells( thisAddress, mode );
4702 ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) );
4712 sal_Int32 nLen =
m_Areas->getCount();
4717 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index ),
uno::Any() ), uno::UNO_QUERY_THROW );
4731 RangeHelper thisRange(
mxRange );
4732 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4734 std::vector<sc::ColRowSpan> aColArr(1,
sc::ColRowSpan(thisAddress.StartColumn,thisAddress.EndColumn));
4735 bool bDirection =
true;
4739 aColArr[0].mnStart = thisAddress.StartRow;
4740 aColArr[0].mnEnd = thisAddress.EndRow;
4742 pDocShell->GetDocFunc().SetWidthOrHeight(
4743 bDirection, aColArr, thisAddress.Sheet,
SC_SIZE_OPTIMAL, 0,
true,
true);
4754 uno::Reference< excel::XWorksheet > xWorksheet(
getParent(), uno::UNO_QUERY_THROW );
4755 uno::Reference< excel::XHyperlinks > xSheetHlinks( xWorksheet->Hyperlinks(
uno::Any() ), uno::UNO_QUERY_THROW );
4756 ScVbaHyperlinksRef xScSheetHlinks( dynamic_cast< ScVbaHyperlinks* >( xSheetHlinks.get() ) );
4757 if( !xScSheetHlinks.is() )
4758 throw uno::RuntimeException(
"Cannot obtain hyperlinks implementation object" );
4763 return xHlinks->Item( aIndex,
uno::Any() );
4764 return uno::Any( uno::Reference< excel::XHyperlinks >( xHlinks.get() ) );
4767 css::uno::Reference< excel::XValidation > SAL_CALL
4778 sal_Unicode lclGetPrefixChar(
const uno::Reference< table::XCell >& rxCell )
4788 return (rxCell->getType() == table::CellContentType_TEXT) ?
'\'' : 0;
4792 sal_Unicode lclGetPrefixChar(
const uno::Reference< table::XCellRange >& rxRange )
4801 table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxRange );
4802 sal_Int32 nEndCol = aRangeAddr.EndColumn - aRangeAddr.StartColumn;
4803 sal_Int32 nEndRow = aRangeAddr.EndRow - aRangeAddr.StartRow;
4804 for( sal_Int32 nRow = 0; nRow <= nEndRow; ++nRow )
4806 for( sal_Int32 nCol = 0; nCol <= nEndCol; ++nCol )
4808 uno::Reference< table::XCell > xCell( rxRange->getCellByPosition( nCol, nRow ), uno::UNO_SET_THROW );
4809 sal_Unicode cNewPrefix = lclGetPrefixChar( xCell );
4810 if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) )
4812 cCurrPrefix = cNewPrefix;
4820 sal_Unicode lclGetPrefixChar(
const uno::Reference< sheet::XSheetCellRangeContainer >& rxRanges )
4823 uno::Reference< container::XEnumerationAccess > xRangesEA( rxRanges, uno::UNO_QUERY_THROW );
4824 uno::Reference< container::XEnumeration > xRangesEnum( xRangesEA->createEnumeration(), uno::UNO_SET_THROW );
4825 while( xRangesEnum->hasMoreElements() )
4827 uno::Reference< table::XCellRange > xRange( xRangesEnum->nextElement(), uno::UNO_QUERY_THROW );
4828 sal_Unicode cNewPrefix = lclGetPrefixChar( xRange );
4829 if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) )
4831 cCurrPrefix = cNewPrefix;
4839 return uno::Any( (cPrefixChar == 0) ? OUString() : OUString( cPrefixChar ) );
4863 return lclGetPrefixVariant( lclGetPrefixChar(
mxRange ) );
4865 return lclGetPrefixVariant( lclGetPrefixChar(
mxRanges ) );
4866 throw uno::RuntimeException(
"Unexpected empty Range object" );
4875 throw uno::RuntimeException(
"Can not get Range.ShowDetail attribute " );
4878 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor();
4879 xSheetCellCursor->collapseToCurrentRegion();
4880 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
4881 table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress();
4884 table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress();
4885 if( (thisAddress.StartRow != thisAddress.EndRow || thisAddress.EndRow != aOutlineAddress.EndRow ) &&
4886 (thisAddress.StartColumn != thisAddress.EndColumn || thisAddress.EndColumn != aOutlineAddress.EndColumn ))
4888 throw uno::RuntimeException(
"Can not set Range.ShowDetail attribute" );
4891 bool bColumn = thisAddress.StartRow != thisAddress.EndRow;
4895 SCCOLROW nPos = bColumn ?
static_cast<SCCOLROW>(thisAddress.EndColumn-1):static_cast<SCCOLROW>(thisAddress.EndRow-1);
4899 const bool bShowDetail = !pEntry->
IsHidden();
4900 return uno::makeAny( bShowDetail );
4912 throw uno::RuntimeException(
"Can not set Range.ShowDetail attribute" );
4917 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor();
4918 xSheetCellCursor->collapseToCurrentRegion();
4919 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
4920 table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress();
4923 table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress();
4924 if( (thisAddress.StartRow != thisAddress.EndRow || thisAddress.EndRow != aOutlineAddress.EndRow ) &&
4925 (thisAddress.StartColumn != thisAddress.EndColumn || thisAddress.EndColumn != aOutlineAddress.EndColumn ))
4927 throw uno::RuntimeException(
"Can not set Range.ShowDetail attribute" );
4932 uno::Reference< sheet::XSheetOutline > xSheetOutline( helper.getSpreadSheet(), uno::UNO_QUERY_THROW );
4934 xSheetOutline->showDetail( aOutlineAddress );
4936 xSheetOutline->hideDetail( aOutlineAddress );
4940 uno::Reference< excel::XRange > SAL_CALL
4943 uno::Reference< sheet::XSheetCellRange > xMergeShellCellRange(
mxRange->getCellRangeByPosition(0,0,0,0), uno::UNO_QUERY_THROW);
4944 uno::Reference< sheet::XSheetCellCursor > xMergeSheetCursor(xMergeShellCellRange->getSpreadsheet()->createCursorByRange( xMergeShellCellRange ), uno::UNO_SET_THROW);
4945 if( xMergeSheetCursor.is() )
4947 xMergeSheetCursor->collapseToMergedArea();
4948 uno::Reference<sheet::XCellRangeAddressable> xMergeCellAddress(xMergeSheetCursor, uno::UNO_QUERY_THROW);
4949 table::CellRangeAddress aCellAddress = xMergeCellAddress->getRangeAddress();
4950 if( aCellAddress.StartColumn ==0 && aCellAddress.EndColumn==0 &&
4951 aCellAddress.StartRow==0 && aCellAddress.EndRow==0)
4957 ScRange refRange( static_cast< SCCOL >( aCellAddress.StartColumn ), static_cast< SCROW >( aCellAddress.StartRow ), static_cast< SCTAB >( aCellAddress.Sheet ),
4958 static_cast< SCCOL >( aCellAddress.EndColumn ), static_cast< SCROW >( aCellAddress.EndRow ), static_cast< SCTAB >( aCellAddress.Sheet ) );
4971 sal_Int32 nItems =
m_Areas->getCount();
4972 uno::Sequence< table::CellRangeAddress > printAreas( nItems );
4973 uno::Reference< sheet::XPrintAreas > xPrintAreas;
4976 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
4978 RangeHelper thisRange( xRange->getCellRange() );
4979 table::CellRangeAddress rangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4985 xPrintAreas.set( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
4987 printAreas[
index - 1 ] = rangeAddress;
4989 if ( pShell && xPrintAreas.is() )
4991 xPrintAreas->setPrintAreas( printAreas );
5000 uno::Reference< excel::XRange > xDest( Destination, uno::UNO_SET_THROW );
5002 RangeHelper destRangeHelper( pRange->
mxRange );
5003 table::CellRangeAddress destAddress = destRangeHelper.getCellRangeAddressable()->getRangeAddress();
5005 RangeHelper thisRange(
mxRange );
5006 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
5017 ScRange aSourceRange( destRange );
5023 if ( sourceRange != destRange )
5031 aSourceRange.
aEnd.
SetCol( static_cast<SCCOL>( aSourceRange.
aStart.
Col() + nSourceCount - 1 ) );
5037 aSourceRange.
aEnd.
SetRow( static_cast<SCROW>( aSourceRange.
aStart.
Row() + nSourceCount ) - 1 );
5043 else if ( aSourceRange.
aEnd == destRange.
aEnd )
5047 aSourceRange.
aStart.
SetRow( static_cast<SCROW>( aSourceRange.
aEnd.
Row() - nSourceCount + 1 ) );
5055 aSourceRange.
aStart.
SetCol( static_cast<SCCOL>( aSourceRange.
aEnd.
Col() - nSourceCount + 1 ) );
5068 sal_Int16 nFillType = excel::XlAutoFillType::xlFillDefault;
5070 switch ( nFillType )
5072 case excel::XlAutoFillType::xlFillCopy:
5076 case excel::XlAutoFillType::xlFillDays:
5079 case excel::XlAutoFillType::xlFillMonths:
5083 case excel::XlAutoFillType::xlFillWeekdays:
5087 case excel::XlAutoFillType::xlFillYears:
5091 case excel::XlAutoFillType::xlGrowthTrend:
5094 case excel::XlAutoFillType::xlFillFormats:
5095 throw uno::RuntimeException(
"xlFillFormat not supported for AutoFill" );
5096 case excel::XlAutoFillType::xlFillValues:
5097 case excel::XlAutoFillType::xlFillSeries:
5098 case excel::XlAutoFillType::xlLinearTrend:
5101 case excel::XlAutoFillType::xlFillDefault:
5117 if ( pDocShell && pRange )
5119 uno::Reference< sheet::XGoalSeek > xGoalSeek( pDocShell->
GetModel(), uno::UNO_QUERY_THROW );
5120 RangeHelper thisRange(
mxRange );
5121 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
5122 RangeHelper changingCellRange( pRange->
mxRange );
5123 table::CellRangeAddress changingCellAddr = changingCellRange.getCellRangeAddressable()->getRangeAddress();
5125 table::CellAddress thisCell( thisAddress.Sheet, thisAddress.StartColumn, thisAddress.StartRow );
5126 table::CellAddress changingCell( changingCellAddr.Sheet, changingCellAddr.StartColumn, changingCellAddr.StartRow );
5127 sheet::GoalResult res = xGoalSeek->seekGoal( thisCell, changingCell, sGoal );
5128 ChangingCell->setValue( uno::makeAny( res.Result ) );
5133 if ( ( res.Divergence != 0.0 ) && ( res.Result == 0.0 ) )
5147 uno::Reference< excel::XRange > SAL_CALL
5154 uno::Reference< excel::XRange > xRange;
5158 xRange =
Rows( row );
5161 return Cells( row, column );
5169 if (
m_Areas->getCount() > 1 )
5176 RangeHelper thisRange(
mxRange );
5177 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
5181 uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
5182 xSheetOutline->autoOutline( thisAddress );
5191 if (
m_Areas->getCount() > 1 )
5193 sal_Int32 nItems =
m_Areas->getCount();
5196 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
5197 xRange->ClearOutline();
5201 RangeHelper thisRange(
mxRange );
5202 uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
5203 xSheetOutline->clearOutline();
5209 if (
m_Areas->getCount() > 1 )
5211 table::TableOrientation nOrient = table::TableOrientation_ROWS;
5213 nOrient = table::TableOrientation_COLUMNS;
5214 RangeHelper thisRange(
mxRange );
5215 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
5216 uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
5218 xSheetOutline->ungroup( thisAddress, nOrient );
5220 xSheetOutline->group( thisAddress, nOrient );
5237 uno::Reference< util::XMergeable > xMergeable( xCellRange, uno::UNO_QUERY_THROW );
5238 xMergeable->merge(_bMerge);
5243 if (
m_Areas->getCount() > 1 )
5245 sal_Int32 nItems =
m_Areas->getCount();
5248 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
5249 xRange->Merge(Across);
5253 bool bAcross =
false;
5259 uno::Reference< excel::XRange > oRangeRowsImpl =
Rows(
uno::Any() );
5261 for (sal_Int32
i=1;
i <= oRangeRowsImpl->getCount();
i++)
5263 oRangeRowsImpl->Cells( uno::makeAny(
i ),
uno::Any() )->Merge( uno::makeAny(
false ) );
5271 if (
m_Areas->getCount() > 1 )
5273 sal_Int32 nItems =
m_Areas->getCount();
5276 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
5287 if (
m_Areas->getCount() > 1 )
5289 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ),
uno::Any() ), uno::UNO_QUERY_THROW );
5290 return xRange->getStyle();
5292 uno::Reference< beans::XPropertySet > xProps(
mxRange, uno::UNO_QUERY_THROW );
5293 OUString sStyleName;
5294 xProps->getPropertyValue( CELLSTYLE ) >>= sStyleName;
5298 return uno::makeAny( xStyle );
5303 if (
m_Areas->getCount() > 1 )
5305 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ),
uno::Any() ), uno::UNO_QUERY_THROW );
5306 xRange->setStyle( _style );
5309 uno::Reference< beans::XPropertySet > xProps(
mxRange, uno::UNO_QUERY_THROW );
5310 uno::Reference< excel::XStyle > xStyle;
5313 xProps->setPropertyValue( CELLSTYLE, uno::makeAny( xStyle->getName() ) );
5316 uno::Reference< excel::XRange >
5321 RangeHelper thisRange(
mxRange );
5324 markedRange. SetMarkArea( refRange );
5325 short nMove = bIsPrevious ? -1 : 1;
5332 rDoc.
GetNextPos( nNewX,nNewY, nTab, nMove,0,
true,
true, markedRange );
5345 uno::Reference< excel::XRange > SAL_CALL
5348 if (
m_Areas->getCount() > 1 )
5350 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ),
uno::Any() ) , uno::UNO_QUERY_THROW );
5351 return xRange->Next();
5356 uno::Reference< excel::XRange > SAL_CALL
5359 if (
m_Areas->getCount() > 1 )
5361 uno::Reference< excel::XRange > xRange(
m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ),
uno::Any() ), uno::UNO_QUERY_THROW );
5362 return xRange->Previous();
5367 uno::Reference< excel::XRange > SAL_CALL
5371 bool bIsMultiArea = (
m_Areas->getCount() > 1 );
5373 uno::Reference< excel::XRange > xUsedRange(
getWorksheet()->getUsedRange() );
5374 sal_Int32 nType = 0;
5375 if ( !( _oType >>= nType ) )
5379 case excel::XlCellType::xlCellTypeSameFormatConditions:
5380 case excel::XlCellType::xlCellTypeAllValidation:
5381 case excel::XlCellType::xlCellTypeSameValidation:
5384 case excel::XlCellType::xlCellTypeBlanks:
5385 case excel::XlCellType::xlCellTypeComments:
5386 case excel::XlCellType::xlCellTypeConstants:
5387 case excel::XlCellType::xlCellTypeFormulas:
5388 case excel::XlCellType::xlCellTypeVisible:
5389 case excel::XlCellType::xlCellTypeLastCell:
5395 std::vector< table::CellRangeAddress > rangeResults;
5396 sal_Int32 nItems =
m_Areas->getCount() + 1;