26 #include <rtl/math.hxx>
30 #include <com/sun/star/script/ArrayWrapper.hpp>
31 #include <com/sun/star/script/XTypeConverter.hpp>
32 #include <com/sun/star/script/vba/VBAEventId.hpp>
33 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
34 #include <com/sun/star/sheet/XDatabaseRange.hpp>
35 #include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
36 #include <com/sun/star/sheet/XGoalSeek.hpp>
37 #include <com/sun/star/sheet/XSheetOperation.hpp>
38 #include <com/sun/star/sheet/CellFlags.hpp>
39 #include <com/sun/star/table/XColumnRowRange.hpp>
40 #include <com/sun/star/sheet/XCellAddressable.hpp>
41 #include <com/sun/star/table/CellContentType.hpp>
42 #include <com/sun/star/sheet/XCellSeries.hpp>
43 #include <com/sun/star/text/XTextRange.hpp>
44 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
45 #include <com/sun/star/table/CellAddress.hpp>
46 #include <com/sun/star/table/CellRangeAddress.hpp>
47 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
48 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
49 #include <com/sun/star/sheet/XSheetCellRange.hpp>
50 #include <com/sun/star/sheet/XSpreadsheet.hpp>
51 #include <com/sun/star/sheet/XSheetCellCursor.hpp>
52 #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
53 #include <com/sun/star/sheet/XNamedRange.hpp>
54 #include <com/sun/star/sheet/XNamedRanges.hpp>
55 #include <com/sun/star/sheet/XPrintAreas.hpp>
56 #include <com/sun/star/sheet/XCellRangesQuery.hpp>
57 #include <com/sun/star/beans/XPropertySet.hpp>
58 #include <com/sun/star/frame/XModel.hpp>
59 #include <com/sun/star/view/XSelectionSupplier.hpp>
60 #include <com/sun/star/table/XTableRows.hpp>
61 #include <com/sun/star/table/XTableColumns.hpp>
62 #include <com/sun/star/table/TableSortField.hpp>
63 #include <com/sun/star/util/XMergeable.hpp>
64 #include <com/sun/star/uno/XComponentContext.hpp>
65 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
66 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
67 #include <com/sun/star/util/XNumberFormats.hpp>
68 #include <com/sun/star/util/NumberFormat.hpp>
69 #include <com/sun/star/util/XNumberFormatTypes.hpp>
70 #include <com/sun/star/util/XReplaceable.hpp>
71 #include <com/sun/star/util/XSortable.hpp>
72 #include <com/sun/star/sheet/XCellRangeMovement.hpp>
73 #include <com/sun/star/sheet/FormulaResult.hpp>
74 #include <com/sun/star/sheet/FilterOperator2.hpp>
75 #include <com/sun/star/sheet/TableFilterField2.hpp>
76 #include <com/sun/star/sheet/XSheetFilterDescriptor2.hpp>
77 #include <com/sun/star/sheet/FilterConnection.hpp>
78 #include <com/sun/star/util/TriState.hpp>
80 #include <com/sun/star/sheet/XSubTotalCalculatable.hpp>
81 #include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
82 #include <com/sun/star/sheet/GeneralFunction.hpp>
84 #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
85 #include <com/sun/star/sheet/XSheetAnnotations.hpp>
87 #include <ooo/vba/excel/XlPasteSpecialOperation.hpp>
88 #include <ooo/vba/excel/XlPasteType.hpp>
89 #include <ooo/vba/excel/XlFindLookIn.hpp>
90 #include <ooo/vba/excel/XlLookAt.hpp>
91 #include <ooo/vba/excel/XlSearchOrder.hpp>
92 #include <ooo/vba/excel/XlSortOrder.hpp>
93 #include <ooo/vba/excel/XlYesNoGuess.hpp>
94 #include <ooo/vba/excel/XlSortOrientation.hpp>
95 #include <ooo/vba/excel/XlSortMethod.hpp>
96 #include <ooo/vba/excel/XlDirection.hpp>
97 #include <ooo/vba/excel/XlSortDataOption.hpp>
98 #include <ooo/vba/excel/XlDeleteShiftDirection.hpp>
99 #include <ooo/vba/excel/XlInsertShiftDirection.hpp>
100 #include <ooo/vba/excel/XlReferenceStyle.hpp>
101 #include <ooo/vba/excel/XlBordersIndex.hpp>
102 #include <ooo/vba/excel/XlPageBreak.hpp>
103 #include <ooo/vba/excel/XlAutoFilterOperator.hpp>
104 #include <ooo/vba/excel/XlAutoFillType.hpp>
105 #include <ooo/vba/excel/XlCellType.hpp>
106 #include <ooo/vba/excel/XlSpecialCellsValue.hpp>
107 #include <ooo/vba/excel/XlConsolidationFunction.hpp>
108 #include <ooo/vba/excel/XlSearchDirection.hpp>
114 #include <docfunc.hxx>
124 #include <unonames.hxx>
140 #include <compiler.hxx>
149 #include <global.hxx>
156 #include <com/sun/star/bridge/oleautomation/Date.hpp>
157 #include <tokenarray.hxx>
169 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 };
173 nVal = nVal *
static_cast<double>(20);
174 short nTwips =
static_cast<short>(nVal);
179 double nPoints = nVal;
185 nVal = (nVal * double(100));
187 if ( ( nVal - tmp ) >= 0.5 )
189 nVal = double(tmp)/100;
193 static uno::Any lcl_makeRange(
const uno::Reference< XHelperInterface >& rParent,
const uno::Reference< uno::XComponentContext >& rContext,
const uno::Any& rAny,
bool bIsRows,
bool bIsColumns )
195 uno::Reference< table::XCellRange > xCellRange(rAny, uno::UNO_QUERY_THROW);
196 return uno::Any( uno::Reference< excel::XRange >(
new ScVbaRange( rParent, rContext, xCellRange, bIsRows, bIsColumns ) ) );
199 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 )
201 uno::Reference< excel::XRange > xRange;
202 const uno::Sequence< table::CellRangeAddress > sAddresses = xLocSheetCellRanges->getRangeAddresses();
204 if ( sAddresses.hasElements() )
206 for (
const auto& rAddress : sAddresses )
213 if ( aCellRanges.
size() == 1 )
215 uno::Reference< table::XCellRange > xTmpRange(
new ScCellRangeObj( pDoc, aCellRanges.
front() ) );
216 xRange =
new ScVbaRange( xParent, xContext, xTmpRange );
220 uno::Reference< sheet::XSheetCellRangeContainer > xRanges(
new ScCellRangesObj( pDoc, aCellRanges ) );
221 xRange =
new ScVbaRange( xParent, xContext, xRanges );
230 return comphelper::getFromUnoTunnel<ScCellRangesBase>(
mxRanges );
232 return comphelper::getFromUnoTunnel<ScCellRangesBase>(
mxRange );
233 throw uno::RuntimeException(
"General Error creating range - Unknown" );
245 throw uno::RuntimeException(
"Can't access Itemset for range" );
255 const uno::Reference< script::vba::XVBAEventProcessor >& xVBAEvents = rDoc.
GetVbaEventProcessor();
256 if( xVBAEvents.is() )
try
258 uno::Sequence< uno::Any > aArgs{
uno::Any(uno::Reference< excel::XRange >(
this )) };
259 xVBAEvents->processVbaEvent( script::vba::VBAEventId::WORKSHEET_CHANGE, aArgs );
261 catch( uno::Exception& )
270 uno::Reference< table::XCellRange > m_xRange;
274 explicit SingleRangeEnumeration(
const uno::Reference< table::XCellRange >& xRange ) : m_xRange( xRange ), bHasMore( true ) { }
275 virtual sal_Bool SAL_CALL hasMoreElements( )
override {
return bHasMore; }
276 virtual uno::Any SAL_CALL nextElement( )
override
279 throw container::NoSuchElementException();
288 class SingleRangeIndexAccess :
public ::cppu::WeakImplHelper< container::XIndexAccess,
289 container::XEnumerationAccess >
292 uno::Reference< table::XCellRange > m_xRange;
295 explicit SingleRangeIndexAccess(
const uno::Reference< table::XCellRange >& xRange ) : m_xRange( xRange ) {}
297 virtual ::sal_Int32 SAL_CALL getCount()
override {
return 1; }
298 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
301 throw lang::IndexOutOfBoundsException();
306 virtual sal_Bool SAL_CALL hasElements()
override {
return true; }
308 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration()
override {
return new SingleRangeEnumeration( m_xRange ); }
318 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 ) {}
319 virtual uno::Any SAL_CALL nextElement( )
override
321 return lcl_makeRange( m_xParent, m_xContext, m_xEnumeration->nextElement(), mbIsRows, mbIsColumns );
330 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 ) {}
333 virtual uno::Reference< container::XEnumeration > SAL_CALL
createEnumeration()
override;
342 virtual uno::Sequence< OUString >
getServiceNames()
override {
return uno::Sequence< OUString >(); }
348 uno::Reference< container::XEnumeration > SAL_CALL
349 ScVbaRangeAreas::createEnumeration()
351 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
352 return new RangesEnumerationImpl( mxParent, mxContext, xEnumAccess->createEnumeration(), mbIsRows, mbIsColumns );
356 ScVbaRangeAreas::createCollectionObject(
const uno::Any& aSource )
358 return lcl_makeRange( mxParent, mxContext, aSource, mbIsRows, mbIsColumns );
366 ScCellRangesBase* pUno = comphelper::getFromUnoTunnel<ScCellRangesBase>( xIf );
368 throw uno::RuntimeException(
"Failed to access underlying uno range object" );
377 uno::Reference< uno::XInterface > xIf( xRange );
386 uno::Reference< uno::XInterface > xIf( xRanges );
391 static uno::Reference< frame::XModel >
getModelFromXIf(
const uno::Reference< uno::XInterface >& xIf )
398 static uno::Reference< frame::XModel >
getModelFromRange(
const uno::Reference< table::XCellRange >& xRange )
401 uno::Reference< uno::XInterface > xIf( xRange );
410 throw uno::RuntimeException(
"Failed to access underlying docshell from uno range object" );
420 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
421 uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
432 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
433 uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
442 return dynamic_cast< ScVbaRange*
>( rxRange.get() );
448 return pDocShell->GetModel();
449 throw uno::RuntimeException();
455 return pScVbaRange->getUnoModel();
456 throw uno::RuntimeException();
462 return pScRangesBase->GetRangeList();
463 throw uno::RuntimeException(
"Cannot obtain UNO range implementation object" );
469 return pScVbaRange->getScRangeList();
470 throw uno::RuntimeException(
"Cannot obtain VBA range implementation object" );
475 class NumFormatHelper
477 uno::Reference< util::XNumberFormatsSupplier > mxSupplier;
478 uno::Reference< beans::XPropertySet > mxRangeProps;
479 uno::Reference< util::XNumberFormats > mxFormats;
481 explicit NumFormatHelper(
const uno::Reference< table::XCellRange >& xRange )
484 mxRangeProps.set( xRange, uno::UNO_QUERY_THROW);
485 mxFormats = mxSupplier->getNumberFormats();
487 uno::Reference< beans::XPropertySet > getNumberProps()
490 uno::Any aValue = mxRangeProps->getPropertyValue(
"NumberFormat" );
491 aValue >>= nIndexKey;
493 if ( mxFormats.is() )
494 return mxFormats->getByKey( nIndexKey );
495 return uno::Reference< beans::XPropertySet > ();
501 return (getNumberFormat() & util::NumberFormat::LOGICAL) != 0;
506 sal_Int16
nType = getNumberFormat();
507 return ( nType & util::NumberFormat::DATETIME ) != 0;
510 OUString getNumberFormatString()
512 uno::Reference< uno::XInterface > xIf( mxRangeProps, uno::UNO_QUERY_THROW );
513 ScCellRangesBase* pUnoCellRange = comphelper::getFromUnoTunnel<ScCellRangesBase>( xIf );
517 SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( pUnoCellRange );
521 if ( eState == SfxItemState::DONTCARE )
525 uno::Reference< beans::XPropertySet > xNumberProps( getNumberProps(), uno::UNO_SET_THROW );
526 OUString aFormatString;
527 uno::Any aString = xNumberProps->getPropertyValue(
"FormatString" );
528 aString >>= aFormatString;
529 return aFormatString;
532 sal_Int16 getNumberFormat()
534 uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps();
535 sal_Int16 nType = ::comphelper::getINT16(
536 xNumberProps->getPropertyValue(
"Type" ) );
540 void setNumberFormat(
const OUString& rFormat )
543 sal_Int32 nNewIndex = 0;
544 if( !rFormat.equalsIgnoreAsciiCase(
"General" ) )
546 lang::Locale aLocale;
547 uno::Reference< beans::XPropertySet > xNumProps = getNumberProps();
548 xNumProps->getPropertyValue(
"Locale" ) >>= aLocale;
549 nNewIndex = mxFormats->queryKey( rFormat, aLocale,
false );
550 if ( nNewIndex == -1 )
551 nNewIndex = mxFormats->addNew( rFormat, aLocale );
553 mxRangeProps->setPropertyValue(
"NumberFormat",
uno::Any( nNewIndex ) );
556 void setNumberFormat( sal_Int16 nType )
558 uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps();
559 lang::Locale aLocale;
560 xNumberProps->getPropertyValue(
"Locale" ) >>= aLocale;
561 uno::Reference<util::XNumberFormatTypes> xTypes( mxFormats, uno::UNO_QUERY );
564 sal_Int32 nNewIndex = xTypes->getStandardFormat( nType, aLocale );
565 mxRangeProps->setPropertyValue(
"NumberFormat",
uno::Any( nNewIndex ) );
573 CellPos( sal_Int32 nRow, sal_Int32 nCol, sal_Int32 nArea ):m_nRow(nRow), m_nCol(nCol), m_nArea( nArea ) {};
591 class ColumnsRowEnumeration:
public CellsEnumeration_BASE
593 uno::Reference< excel::XRange > mxRange;
598 ColumnsRowEnumeration(
const uno::Reference< excel::XRange >& xRange, sal_Int32 nElems ) : mxRange( xRange ), mMaxElems( nElems ), mCurElem( 0 )
602 virtual sal_Bool SAL_CALL hasMoreElements()
override {
return mCurElem < mMaxElems; }
604 virtual uno::Any SAL_CALL nextElement()
override
606 if ( !hasMoreElements() )
607 throw container::NoSuchElementException();
608 sal_Int32 vbaIndex = 1 + mCurElem++;
613 class CellsEnumeration :
public CellsEnumeration_BASE
615 uno::WeakReference< XHelperInterface >
mxParent;
616 uno::Reference< uno::XComponentContext >
mxContext;
617 uno::Reference< XCollection > m_xAreas;
618 vCellPos m_CellPositions;
619 vCellPos::const_iterator m_it;
622 uno::Reference< table::XCellRange >
getArea( sal_Int32 nVBAIndex )
624 if ( nVBAIndex < 1 || nVBAIndex > m_xAreas->getCount() )
625 throw uno::RuntimeException();
626 uno::Reference< excel::XRange > xRange( m_xAreas->Item(
uno::Any(nVBAIndex),
uno::Any() ), uno::UNO_QUERY_THROW );
631 void populateArea( sal_Int32 nVBAIndex )
633 uno::Reference< table::XCellRange > xRange =
getArea( nVBAIndex );
634 uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, uno::UNO_QUERY_THROW );
635 sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount();
636 sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
637 for ( sal_Int32
i=0;
i<nRowCount; ++
i )
639 for ( sal_Int32 j=0; j<nColCount; ++j )
640 m_CellPositions.emplace_back(
i,j,nVBAIndex );
644 CellsEnumeration(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< XCollection >& xAreas ): mxParent( xParent ), mxContext( xContext ), m_xAreas( xAreas )
646 sal_Int32 nItems = m_xAreas->getCount();
649 populateArea(
index );
651 m_it = m_CellPositions.begin();
653 virtual sal_Bool SAL_CALL hasMoreElements()
override {
return m_it != m_CellPositions.end(); }
655 virtual uno::Any SAL_CALL nextElement()
override
657 if ( !hasMoreElements() )
658 throw container::NoSuchElementException();
659 CellPos aPos = *m_it++;
661 uno::Reference< table::XCellRange > xRangeArea =
getArea( aPos.m_nArea );
662 uno::Reference< table::XCellRange > xCellRange( xRangeArea->getCellByPosition( aPos.m_nCol, aPos.m_nRow ), uno::UNO_QUERY_THROW );
663 return uno::Any( uno::Reference< excel::XRange >(
new ScVbaRange( mxParent, mxContext, xCellRange ) ) );
687 explicit CellValueSetter(
const uno::Any& aValue );
688 virtual bool processValue(
const uno::Any& aValue,
const uno::Reference< table::XCell >& xCell )
override;
689 virtual void visitNode( sal_Int32
x, sal_Int32
y,
const uno::Reference< table::XCell >& xCell )
override;
695 CellValueSetter::CellValueSetter(
const uno::Any& aValue ):
maValue( aValue ) {}
698 CellValueSetter::visitNode( sal_Int32 , sal_Int32 ,
const uno::Reference< table::XCell >& xCell )
700 processValue( maValue, xCell );
704 CellValueSetter::processValue(
const uno::Any& aValue,
const uno::Reference< table::XCell >& xCell )
707 bool isExtracted =
false;
708 switch ( aValue.getValueTypeClass() )
710 case uno::TypeClass_BOOLEAN:
713 if ( aValue >>= bState )
715 uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
717 xCell->setValue(
double(1) );
719 xCell->setValue(
double(0) );
720 NumFormatHelper cellNumFormat( xRange );
721 cellNumFormat.setNumberFormat( util::NumberFormat::LOGICAL );
725 case uno::TypeClass_STRING:
728 if ( aValue >>= aString )
737 if ( aString.toChar() ==
'\'' )
739 OUString aRemainder( aString.copy(1) );
740 uno::Reference< text::XTextRange > xTextRange( xCell, uno::UNO_QUERY_THROW );
741 xTextRange->setString( aRemainder );
757 double nDouble = 0.0;
758 if ( aValue >>= nDouble )
760 uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
761 NumFormatHelper cellFormat( xRange );
765 if ( cellFormat.isBooleanType() )
766 cellFormat.setNumberFormat(
"General");
767 xCell->setValue( nDouble );
786 virtual void visitNode( sal_Int32 x, sal_Int32 y,
const uno::Reference< table::XCell >& xCell )
override;
795 CellValueGetter::processValue(
const uno::Any& aValue )
799 void CellValueGetter::visitNode( sal_Int32 , sal_Int32 ,
const uno::Reference< table::XCell >& xCell )
802 table::CellContentType
eType = xCell->getType();
803 if( eType == table::CellContentType_VALUE || eType == table::CellContentType_FORMULA )
805 if ( eType == table::CellContentType_FORMULA )
808 OUString
sFormula = xCell->getFormula();
809 if ( sFormula ==
"=TRUE()" )
811 else if ( sFormula ==
"=FALSE()" )
815 uno::Reference< beans::XPropertySet > xProp( xCell, uno::UNO_QUERY_THROW );
817 sal_Int32 nResultType = sheet::FormulaResult::VALUE;
819 xProp->getPropertyValue(
"FormulaResultType2" ) >>= nResultType;
821 if ( nResultType == sheet::FormulaResult::STRING )
823 uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW);
824 aValue <<= xTextRange->getString();
827 aValue <<= xCell->getValue();
832 uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
833 NumFormatHelper cellFormat( xRange );
834 if ( cellFormat.isBooleanType() )
835 aValue <<= ( xCell->getValue() != 0.0 );
836 else if ( cellFormat.isDateType() )
837 aValue <<= bridge::oleautomation::Date( xCell->getValue() );
839 aValue <<= xCell->getValue();
842 if( eType == table::CellContentType_TEXT )
844 uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW);
845 aValue <<= xTextRange->getString();
847 processValue( aValue );
852 class CellFormulaValueSetter :
public CellValueSetter
860 bool processValue(
const uno::Any& aValue,
const uno::Reference< table::XCell >& xCell )
override
863 double aDblValue = 0.0;
864 if ( aValue >>= sFormula )
872 uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW );
874 if ( pUnoRangesBase )
879 std::unique_ptr<ScTokenArray> pArray(aCompiler.CompileString(sFormula));
883 aCompiler.CreateStringFromTokenArray(sConverted);
884 sFormula = EQUALS + sConverted;
888 xCell->setFormula( sFormula );
891 else if ( aValue >>= aDblValue )
893 xCell->setValue( aDblValue );
901 class CellFormulaValueGetter :
public CellValueGetter
908 virtual void visitNode( sal_Int32 , sal_Int32 ,
const uno::Reference< table::XCell >& xCell )
override
911 aValue <<= xCell->getFormula();
913 if ((xCell->getType() == table::CellContentType_FORMULA)
916 uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW );
925 std::unique_ptr<ScTokenArray> pArray(aCompiler.CompileString(sVal));
929 aCompiler.CreateStringFromTokenArray(sConverted);
930 sVal = EQUALS + sConverted;
935 processValue( aValue );
945 void processValue( sal_Int32 x, sal_Int32 y,
const uno::Any& aValue )
947 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));
948 aMatrix.getArray()[
x].getArray()[
y] = aValue;
952 Dim2ArrayValueGetter(sal_Int32 nRowCount, sal_Int32 nColCount,
ValueGetter& rValueGetter ): mValueGetter(rValueGetter)
954 uno::Sequence< uno::Sequence< uno::Any > > aMatrix;
955 aMatrix.realloc( nRowCount );
956 auto pMatrix = aMatrix.getArray();
957 for ( sal_Int32 index = 0;
index < nRowCount; ++
index )
958 pMatrix[index].realloc( nColCount );
961 void visitNode( sal_Int32 x, sal_Int32 y,
const uno::Reference< table::XCell >& xCell )
override
965 processValue( x, y, mValueGetter.
getValue() );
973 constexpr OUStringLiteral
sNA =
u"#N/A";
979 uno::Sequence< uno::Any > aMatrix;
983 Dim1ArrayValueSetter(
const uno::Any& aValue,
ValueSetter& rCellValueSetter ):mCellValueSetter( rCellValueSetter )
986 nColCount = aMatrix.getLength();
988 virtual void visitNode( sal_Int32 , sal_Int32
y,
const uno::Reference< table::XCell >& xCell )
override
999 uno::Sequence< uno::Sequence< uno::Any > > aMatrix;
1001 sal_Int32 nRowCount;
1002 sal_Int32 nColCount;
1004 Dim2ArrayValueSetter(
const uno::Any& aValue,
ValueSetter& rCellValueSetter ) : mCellValueSetter( rCellValueSetter )
1007 nRowCount = aMatrix.getLength();
1008 nColCount = aMatrix[0].getLength();
1011 virtual void visitNode( sal_Int32
x, sal_Int32
y,
const uno::Reference< table::XCell >& xCell )
override
1013 if ( x < nRowCount && y < nColCount )
1014 mCellValueSetter.
processValue( aMatrix[ x ][ y ], xCell );
1021 class RangeProcessor
1024 virtual void process(
const uno::Reference< excel::XRange >& xRange ) = 0;
1027 ~RangeProcessor() {}
1030 class RangeValueProcessor :
public RangeProcessor
1034 explicit RangeValueProcessor(
const uno::Any& rVal ):m_aVal( rVal ) {}
1035 virtual ~RangeValueProcessor() {}
1036 virtual void process(
const uno::Reference< excel::XRange >& xRange )
override
1042 class RangeFormulaProcessor :
public RangeProcessor
1046 explicit RangeFormulaProcessor(
const uno::Any& rVal ):m_aVal( rVal ) {}
1047 virtual ~RangeFormulaProcessor() {}
1048 virtual void process(
const uno::Reference< excel::XRange >& xRange )
override
1050 xRange->setFormula( m_aVal );
1054 class RangeCountProcessor :
public RangeProcessor
1058 RangeCountProcessor():nCount(0){}
1059 virtual ~RangeCountProcessor() {}
1060 virtual void process(
const uno::Reference< excel::XRange >& xRange )
override
1062 nCount = nCount + xRange->getCount();
1064 sal_Int32
value() {
return nCount; }
1069 uno::Reference< XCollection > m_Areas;
1071 explicit AreasVisitor(
const uno::Reference< XCollection >& rAreas ):m_Areas( rAreas ){}
1073 void visit( RangeProcessor& processor )
1077 sal_Int32 nItems = m_Areas->getCount();
1080 uno::Reference< excel::XRange > xRange( m_Areas->Item(
uno::Any(
index),
uno::Any() ), uno::UNO_QUERY_THROW );
1081 processor.process( xRange );
1089 uno::Reference< table::XCellRange > m_xCellRange;
1093 explicit RangeHelper(
const uno::Reference< table::XCellRange >& xCellRange ) : m_xCellRange( xCellRange )
1095 if ( !m_xCellRange.is() )
1096 throw uno::RuntimeException();
1099 explicit RangeHelper(
const uno::Any& rCellRange )
1101 m_xCellRange.set(rCellRange, uno::UNO_QUERY_THROW);
1104 uno::Reference< sheet::XSheetCellRange > getSheetCellRange()
const
1106 return uno::Reference< sheet::XSheetCellRange >(m_xCellRange, uno::UNO_QUERY_THROW);
1109 uno::Reference< sheet::XSpreadsheet > getSpreadSheet()
const
1111 return getSheetCellRange()->getSpreadsheet();
1115 uno::Reference< table::XCellRange > getCellRangeFromSheet()
const
1117 return uno::Reference< table::XCellRange >(getSpreadSheet(), uno::UNO_QUERY_THROW );
1121 uno::Reference< sheet::XCellRangeAddressable > getCellRangeAddressable()
const
1123 return uno::Reference< sheet::XCellRangeAddressable >(m_xCellRange, ::uno::UNO_QUERY_THROW);
1128 uno::Reference< sheet::XSheetCellCursor > getSheetCellCursor()
const
1130 return uno::Reference< sheet::XSheetCellCursor >( getSpreadSheet()->createCursorByRange( getSheetCellRange() ), uno::UNO_SET_THROW );
1133 static uno::Reference< excel::XRange > createRangeFromRange(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference<uno::XComponentContext >& xContext,
1134 const uno::Reference< table::XCellRange >& xRange,
const uno::Reference< sheet::XCellRangeAddressable >& xCellRangeAddressable )
1136 return uno::Reference< excel::XRange >(
new ScVbaRange( xParent, xContext,
1137 xRange->getCellRangeByPosition(
1138 xCellRangeAddressable->getRangeAddress().StartColumn,
1139 xCellRangeAddressable->getRangeAddress().StartRow,
1140 xCellRangeAddressable->getRangeAddress().EndColumn,
1141 xCellRangeAddressable->getRangeAddress().EndRow ) ) );
1155 rResFlags = rCellRanges.
Parse( sAddress, rDoc, eConv, 0, cDelimiter );
1167 uno::Reference< beans::XPropertySet > xProps( pDocSh->
GetModel(), uno::UNO_QUERY_THROW );
1168 uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue(
"NamedRanges" ), uno::UNO_QUERY_THROW );
1171 std::vector< OUString > vNames;
1175 OUString aToken = sName.getToken( 0,
',', nIndex );
1176 vNames.push_back( aToken );
1177 }
while ( nIndex >= 0 );
1179 if ( vNames.empty() )
1180 vNames.push_back( sName );
1182 for (
const auto& rName : vNames )
1186 OUString sAddress = rName.trim();
1189 if ( !xNameAccess->hasByName( sAddress ) )
1202 if ( xNameAccess->hasByName( sAddress ) )
1204 uno::Reference< sheet::XNamedRange > xNamed( xNameAccess->getByName( sAddress ), uno::UNO_QUERY_THROW );
1205 sAddress = xNamed->getContent();
1218 for (
size_t i = 0, nRanges = aCellRanges.
size();
i < nRanges; ++
i )
1220 ScRange & rRange = aCellRanges[
i ];
1240 throw uno::RuntimeException();
1242 if ( aCellRanges.
size() == 1 )
1244 uno::Reference< table::XCellRange > xRange(
new ScCellRangeObj( pDocSh, aCellRanges.
front() ) );
1246 return new ScVbaRange( xFixThisParent, xContext, xRange );
1248 uno::Reference< sheet::XSheetCellRangeContainer > xRanges(
new ScCellRangesObj( pDocSh, aCellRanges ) );
1251 return new ScVbaRange( xFixThisParent, xContext, xRanges );
1257 template<
typename RangeType >
1258 table::CellRangeAddress lclGetRangeAddress(
const uno::Reference< RangeType >& rxCellRange )
1260 return uno::Reference< sheet::XCellRangeAddressable >( rxCellRange, uno::UNO_QUERY_THROW )->getRangeAddress();
1264 void lclClearRange(
const uno::Reference< table::XCellRange >& rxCellRange )
1266 using namespace ::com::sun::star::sheet::CellFlags;
1268 uno::Reference< sheet::XSheetOperation > xSheetOperation( rxCellRange, uno::UNO_QUERY_THROW );
1269 xSheetOperation->clearContents( nFlags );
1273 uno::Reference< sheet::XSheetCellRange > lclExpandToMerged(
const uno::Reference< table::XCellRange >& rxCellRange,
bool bRecursive )
1275 uno::Reference< sheet::XSheetCellRange > xNewCellRange( rxCellRange, uno::UNO_QUERY_THROW );
1276 uno::Reference< sheet::XSpreadsheet > xSheet( xNewCellRange->getSpreadsheet(), uno::UNO_SET_THROW );
1277 table::CellRangeAddress aNewAddress = lclGetRangeAddress( xNewCellRange );
1278 table::CellRangeAddress aOldAddress;
1282 aOldAddress = aNewAddress;
1283 uno::Reference< sheet::XSheetCellCursor > xCursor( xSheet->createCursorByRange( xNewCellRange ), uno::UNO_SET_THROW );
1284 xCursor->collapseToMergedArea();
1285 xNewCellRange.set( xCursor, uno::UNO_QUERY_THROW );
1286 aNewAddress = lclGetRangeAddress( xNewCellRange );
1288 while( bRecursive && (aOldAddress != aNewAddress) );
1289 return xNewCellRange;
1293 uno::Reference< sheet::XSheetCellRangeContainer > lclExpandToMerged(
const uno::Reference< sheet::XSheetCellRangeContainer >& rxCellRanges )
1295 if( !rxCellRanges.is() )
1296 throw uno::RuntimeException(
"Missing cell ranges object" );
1297 sal_Int32
nCount = rxCellRanges->getCount();
1299 throw uno::RuntimeException(
"Missing cell ranges object" );
1304 uno::Reference< table::XCellRange > xRange( rxCellRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
1305 table::CellRangeAddress aRangeAddr = lclGetRangeAddress( lclExpandToMerged( xRange,
true ) );
1314 void lclExpandAndMerge(
const uno::Reference< table::XCellRange >& rxCellRange,
bool bMerge )
1316 uno::Reference< util::XMergeable > xMerge( lclExpandToMerged( rxCellRange,
true ), uno::UNO_QUERY_THROW );
1318 xMerge->merge(
false );
1323 table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange );
1324 sal_Int32 nLastColIdx = aRangeAddr.EndColumn - aRangeAddr.StartColumn;
1325 sal_Int32 nLastRowIdx = aRangeAddr.EndRow - aRangeAddr.StartRow;
1327 if( nLastColIdx > 0 )
1328 lclClearRange( rxCellRange->getCellRangeByPosition( 1, 0, nLastColIdx, 0 ) );
1330 if( nLastRowIdx > 0 )
1331 lclClearRange( rxCellRange->getCellRangeByPosition( 0, 1, nLastColIdx, nLastRowIdx ) );
1333 xMerge->merge(
true );
1337 util::TriState lclGetMergedState(
const uno::Reference< table::XCellRange >& rxCellRange )
1343 table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange );
1344 uno::Reference< table::XCellRange > xTopLeft( rxCellRange->getCellRangeByPosition( 0, 0, 0, 0 ), uno::UNO_SET_THROW );
1345 uno::Reference< sheet::XSheetCellRange > xExpanded( lclExpandToMerged( xTopLeft,
false ), uno::UNO_SET_THROW );
1346 table::CellRangeAddress aExpAddr = lclGetRangeAddress( xExpanded );
1348 if( ((aExpAddr.StartColumn < aExpAddr.EndColumn) || (aExpAddr.StartRow < aExpAddr.EndRow)) &&
ScUnoConversion::Contains( aExpAddr, aRangeAddr ) )
1349 return util::TriState_YES;
1359 return bHasMerged ? util::TriState_INDETERMINATE : util::TriState_NO;
1364 css::uno::Reference< excel::XRange >
1366 const uno::Reference< uno::XComponentContext >& xContext,
const OUString& sRangeName,
1369 table::CellRangeAddress refAddr;
1370 return getRangeForName( xContext, sRangeName, pDocSh, refAddr, eConv );
1376 uno::Reference< table::XCellRange > xRangeParam;
1377 switch ( aParam.getValueTypeClass() )
1379 case uno::TypeClass_STRING:
1387 if ( aCellRanges.
size() == 1 )
1389 table::CellRangeAddress aRangeAddress;
1391 return aRangeAddress;
1397 case uno::TypeClass_INTERFACE:
1399 uno::Reference< excel::XRange > xRange;
1402 xRange->getCellRange() >>= xRangeParam;
1407 throw uno::RuntimeException(
"Can't extract CellRangeAddress from type" );
1409 return lclGetRangeAddress( xRangeParam );
1413 static uno::Reference< XCollection >
1414 lcl_setupBorders(
const uno::Reference< excel::XRange >& xParentRange,
const uno::Reference<uno::XComponentContext>& xContext,
const uno::Reference< table::XCellRange >& xRange )
1416 uno::Reference< XHelperInterface > xParent( xParentRange, uno::UNO_QUERY_THROW );
1419 uno::Reference< XCollection > borders(
new ScVbaBorders( xParent, xContext, xRange, aPalette ) );
1424 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 )
1426 mxRange.set( mxPropertySet, uno::UNO_QUERY );
1427 mxRanges.set( mxPropertySet, uno::UNO_QUERY );
1428 uno::Reference< container::XIndexAccess > xIndex;
1431 xIndex =
new SingleRangeIndexAccess( mxRange );
1433 else if ( mxRanges.is() )
1435 xIndex.set( mxRanges, uno::UNO_QUERY_THROW );
1437 m_Areas =
new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns );
1440 ScVbaRange::ScVbaRange(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< table::XCellRange >& xRange,
bool bIsRows,
bool bIsColumns )
1442 mbIsRows( bIsRows ),
1443 mbIsColumns( bIsColumns )
1445 if ( !xContext.is() )
1446 throw lang::IllegalArgumentException(
"context is not set ", uno::Reference< uno::XInterface >() , 1 );
1448 throw lang::IllegalArgumentException(
"range is not set ", uno::Reference< uno::XInterface >() , 1 );
1450 uno::Reference< container::XIndexAccess > xIndex(
new SingleRangeIndexAccess( xRange ) );
1451 m_Areas =
new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns );
1455 ScVbaRange::ScVbaRange(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges,
bool bIsRows,
bool bIsColumns)
1459 uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
1460 m_Areas =
new ScVbaRangeAreas( xParent, mxContext, xIndex, mbIsRows, mbIsColumns );
1472 uno::Reference< excel::XRange > xRange(
m_Areas->Item(
uno::Any( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
1483 pDocSh = range->GetDocShell();
1486 table::CellRangeAddress aRangeAddr = lclGetRangeAddress(
mxRange );
1487 sal_Int32 nRowCount = aRangeAddr.EndRow - aRangeAddr.StartRow + 1;
1488 sal_Int32 nColCount = aRangeAddr.EndColumn - aRangeAddr.StartColumn + 1;
1489 for ( sal_Int32
i=0;
i<nRowCount; ++
i )
1491 for ( sal_Int32 j=0; j<nColCount; ++j )
1493 uno::Reference< table::XCell > xCell(
mxRange->getCellByPosition( j,
i ), uno::UNO_SET_THROW );
1505 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY_THROW );
1512 sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount();
1513 sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
1515 Dim2ArrayValueGetter arrayGetter( nRowCount, nColCount, valueGetter );
1517 return uno::Any( script::ArrayWrapper(
false, arrayGetter.getValue() ) );
1527 if (
m_Areas->getCount() > 1 )
1529 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1530 return xRange->getValue();
1533 CellValueGetter valueGetter;
1541 uno::TypeClass aClass = aValue.getValueTypeClass();
1542 if ( aClass == uno::TypeClass_SEQUENCE )
1550 if ( aValue.getValueTypeName().indexOf(
'[') == aValue.getValueTypeName().lastIndexOf(
'[') )
1552 aConverted = xConverter->convertTo( aValue,
cppu::UnoType<uno::Sequence< uno::Any >>::
get() );
1553 Dim1ArrayValueSetter setter( aConverted, valueSetter );
1558 aConverted = xConverter->convertTo( aValue,
cppu::UnoType<uno::Sequence< uno::Sequence< uno::Any > >>::
get() );
1559 Dim2ArrayValueSetter setter( aConverted, valueSetter );
1563 catch (
const uno::Exception& )
1579 if (
m_Areas->getCount() > 1 )
1581 AreasVisitor aVisitor(
m_Areas );
1582 RangeValueProcessor valueProcessor( aValue );
1583 aVisitor.visit( valueProcessor );
1586 CellValueSetter valueSetter( aValue );
1593 using namespace ::com::sun::star::sheet::CellFlags;
1606 if (
m_Areas->getCount() > 1 )
1608 sal_Int32 nItems =
m_Areas->getCount();
1614 pRange->ClearContents( nFlags,
false );
1621 uno::Reference< sheet::XSheetOperation > xSheetOperation(
mxRange, uno::UNO_QUERY_THROW);
1622 xSheetOperation->clearContents( nFlags );
1635 using namespace ::com::sun::star::sheet::CellFlags;
1644 using namespace ::com::sun::star::sheet::CellFlags;
1653 if (
m_Areas->getCount() > 1 )
1655 AreasVisitor aVisitor(
m_Areas );
1656 RangeFormulaProcessor valueProcessor( rFormula );
1657 aVisitor.visit( valueProcessor );
1660 CellFormulaValueSetter formulaValueSetter( rFormula,
getScDocument(), eGram );
1661 setValue( rFormula, formulaValueSetter );
1671 if (
m_Areas->getCount() > 1 )
1673 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1674 return xRange->getFormula();
1676 CellFormulaValueGetter valueGetter(
getScDocument(), eGram );
1733 if (
m_Areas->getCount() > 1 )
1735 AreasVisitor aVisitor(
m_Areas );
1736 RangeCountProcessor valueProcessor;
1737 aVisitor.visit( valueProcessor );
1738 return valueProcessor.value();
1740 sal_Int32 rowCount = 0;
1741 sal_Int32 colCount = 0;
1742 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY_THROW );
1743 rowCount = xColumnRowRange->getRows()->getCount();
1744 colCount = xColumnRowRange->getColumns()->getCount();
1750 return rowCount * colCount;
1760 if (
m_Areas->getCount() > 1 )
1762 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1763 return xRange->getRow();
1765 uno::Reference< sheet::XCellAddressable > xCellAddressable(
mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
1766 return xCellAddressable->getCellAddress().Row + 1;
1776 if (
m_Areas->getCount() > 1 )
1778 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1779 return xRange->getColumn();
1781 uno::Reference< sheet::XCellAddressable > xCellAddressable(
mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
1782 return xCellAddressable->getCellAddress().Column + 1;
1788 if (
m_Areas->getCount() > 1 )
1790 sal_Int32 nItems =
m_Areas->getCount();
1798 if ( aResult != xRange->HasFormula() )
1800 aResult = xRange->HasFormula();
1801 if (
aNULL() == aResult )
1806 uno::Reference< uno::XInterface > xIf(
mxRange, uno::UNO_QUERY_THROW );
1810 uno::Reference<uno::XInterface> xRanges( pThisRanges->
queryFormulaCells( sheet::FormulaResult::ERROR | sheet::FormulaResult::VALUE | sheet::FormulaResult::STRING ), uno::UNO_QUERY_THROW );
1812 assert(pFormulaRanges);
1814 if ( pFormulaRanges->GetRangeList().empty() )
1819 if ( ( pFormulaRanges->GetRangeList().size() > 1 )
1828 ScVbaRange::fillSeries( sheet::FillDirection nFillDirection, sheet::FillMode nFillMode, sheet::FillDateMode nFillDateMode,
double fStep,
double fEndValue )
1830 if (
m_Areas->getCount() > 1 )
1833 uno::Reference< XCollection > xCollection(
m_Areas, uno::UNO_SET_THROW );
1834 for ( sal_Int32
index = 1;
index <= xCollection->getCount(); ++
index )
1836 uno::Reference< excel::XRange > xRange( xCollection->Item(
uno::Any(
index ),
uno::Any() ), uno::UNO_QUERY_THROW );
1838 pThisRange->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
1844 uno::Reference< sheet::XCellSeries > xCellSeries(
mxRange, uno::UNO_QUERY_THROW );
1845 xCellSeries->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
1853 sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
1860 sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
1867 sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
1874 sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
1884 if (
m_Areas->getCount() > 1 )
1886 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1887 return xRange->getText();
1889 uno::Reference< text::XTextRange > xTextRange(
mxRange->getCellByPosition(0,0), uno::UNO_QUERY_THROW );
1890 return xTextRange->getString();
1893 uno::Reference< excel::XRange >
1896 SCROW nRowOffset = 0;
1897 SCCOL nColOffset = 0;
1898 bool bIsRowOffset = ( nRowOff >>= nRowOffset );
1899 bool bIsColumnOffset = ( nColOff >>= nColOffset );
1904 for (
size_t i = 0, nRanges = aCellRanges.
size();
i < nRanges; ++
i )
1906 ScRange & rRange = aCellRanges[
i ];
1907 if ( bIsColumnOffset )
1919 if ( aCellRanges.
size() > 1 )
1921 uno::Reference< sheet::XSheetCellRangeContainer > xRanges(
new ScCellRangesObj( pUnoRangesBase->
GetDocShell(), aCellRanges ) );
1929 uno::Reference< excel::XRange >
1936 if (
m_Areas->getCount() > 1 )
1938 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1939 return xRange->CurrentRegion();
1943 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
1944 helper.getSheetCellCursor();
1945 xSheetCellCursor->collapseToCurrentRegion();
1946 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
1947 return RangeHelper::createRangeFromRange(
mxParent,
mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
1950 uno::Reference< excel::XRange >
1957 if (
m_Areas->getCount() > 1 )
1959 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1960 return xRange->CurrentArray();
1963 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
1964 helper.getSheetCellCursor();
1965 xSheetCellCursor->collapseToCurrentArray();
1966 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
1967 return RangeHelper::createRangeFromRange(
mxParent,
mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
1977 if (
m_Areas->getCount() > 1 )
1979 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
1980 return xRange->getFormulaArray();
1988 uno::Reference< sheet::XArrayFormulaRange> xFormulaArray(
mxRange, uno::UNO_QUERY_THROW );
1989 if ( !xFormulaArray->getArrayFormula().isEmpty() )
1990 return uno::Any( xFormulaArray->getArrayFormula() );
1992 uno::Reference< sheet::XCellRangeFormula> xCellRangeFormula(
mxRange, uno::UNO_QUERY_THROW );
1997 uno::Sequence< uno::Sequence<OUString> > aTmpSeq = xCellRangeFormula->getFormulaArray();
1998 if ( aTmpSeq.getLength() == 1 )
2001 aSingleValueOrMatrix <<= aTmpSeq[ 0 ][ 0 ];
2004 aSingleValueOrMatrix = xConverter->convertTo(
uno::Any( aTmpSeq ) ,
cppu::UnoType<uno::Sequence< uno::Sequence< uno::Any > >>::
get() ) ;
2005 return aSingleValueOrMatrix;
2015 if (
m_Areas->getCount() > 1 )
2017 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
2018 return xRange->setFormulaArray( rFormula );
2023 uno::Reference< lang::XMultiServiceFactory > xModelFactory(
getUnoModel(), uno::UNO_QUERY_THROW );
2024 uno::Reference< sheet::XFormulaParser > xParser( xModelFactory->createInstance(
"com.sun.star.sheet.FormulaParser" ), uno::UNO_QUERY_THROW );
2025 uno::Reference< sheet::XCellRangeAddressable > xSource(
mxRange, uno::UNO_QUERY_THROW);
2027 table::CellRangeAddress aRangeAddress = xSource->getRangeAddress();
2031 table::CellAddress aAddress;
2032 aAddress.Sheet = aRangeAddress.Sheet;
2033 aAddress.Column = aRangeAddress.StartColumn;
2034 aAddress.Row = aRangeAddress.StartRow;
2036 rFormula >>= sFormula;
2037 uno::Sequence<sheet::FormulaToken> aTokens = xParser->parseFormula( sFormula, aAddress );
2051 if (
m_Areas->getCount() > 1 )
2053 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
2054 return xRange->Characters( Start, Length );
2059 uno::Reference< text::XTextRange > xTextRange(
mxRange, ::uno::UNO_QUERY_THROW );
2060 rString = xTextRange->getString();
2061 if( !( Start >>= nIndex ) && !( Length >>= nCount ) )
2063 if(!( Start >>= nIndex ) )
2065 if(!( Length >>= nCount ) )
2066 nIndex = rString.getLength();
2067 return rString.copy( --nIndex, nCount );
2073 if (
m_Areas->getCount() > 1 )
2076 OUStringBuffer sAddress;
2077 uno::Reference< XCollection > xCollection(
m_Areas, uno::UNO_SET_THROW );
2079 for ( sal_Int32
index = 1;
index <= xCollection->getCount(); ++
index )
2081 uno::Reference< excel::XRange > xRange( xCollection->Item(
uno::Any(
index ),
uno::Any() ), uno::UNO_QUERY_THROW );
2084 sAddress.append(
",");
2088 aExternalCopy <<=
false;
2090 sAddress.append(xRange->Address( RowAbsolute, ColumnAbsolute, ReferenceStyle, aExternalCopy, RelativeTo ));
2092 return sAddress.makeStringAndClear();
2098 sal_Int32 refStyle = excel::XlReferenceStyle::xlA1;
2099 ReferenceStyle >>= refStyle;
2100 if ( refStyle == excel::XlReferenceStyle::xlR1C1 )
2108 RangeHelper thisRange(
mxRange );
2109 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
2110 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 ) );
2117 RowAbsolute >>= bVal;
2124 ColumnAbsolute >>= bVal;
2130 bool bLocal =
false;
2131 External >>= bLocal;
2142 return aRange.
Format(rDoc, nFlags, dDetails);
2145 uno::Reference < excel::XFont >
2148 uno::Reference< beans::XPropertySet > xProps(
mxRange, ::uno::UNO_QUERY );
2151 xProps.set(
mxRange, ::uno::UNO_QUERY );
2153 xProps.set(
mxRanges, ::uno::UNO_QUERY );
2161 catch( uno::Exception& )
2167 uno::Reference< excel::XRange >
2174 if (
m_Areas->getCount() > 1 )
2176 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
2177 return xRange->Cells( nRowIndex, nColumnIndex );
2186 uno::Reference< excel::XRange >
2188 const uno::Reference< ov::XHelperInterface >& xParent,
2189 const uno::Reference< uno::XComponentContext >& xContext,
2190 const uno::Reference< css::table::XCellRange >& xRange,
2193 sal_Int32 nRow = 0, nColumn = 0;
2195 bool bIsIndex = nRowIndex.
hasValue();
2196 bool bIsColumnIndex = nColumnIndex.
hasValue();
2202 if ( nRowIndex.
hasValue() && !( nRowIndex >>= nRow ) )
2204 const uno::Reference< script::XTypeConverter >& xConverter =
getTypeConverter( xContext );
2209 bIsIndex = ( aConverted >>= nRow );
2211 catch( uno::Exception& ) {}
2214 if ( bIsColumnIndex )
2218 if ( nColumnIndex >>= sCol )
2224 throw uno::RuntimeException();
2229 if ( !( nColumnIndex >>= nColumn ) )
2231 const uno::Reference< script::XTypeConverter >& xConverter =
getTypeConverter( xContext );
2236 bIsColumnIndex = ( aConverted >>= nColumn );
2238 catch( uno::Exception& ) {}
2242 RangeHelper thisRange( xRange );
2243 table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
2244 uno::Reference< table::XCellRange > xSheetRange = thisRange.getCellRangeFromSheet();
2245 if( !bIsIndex && !bIsColumnIndex )
2247 return uno::Reference< excel::XRange >(
new ScVbaRange( xParent, xContext, xRange ) );
2249 sal_Int32
nIndex = --nRow;
2250 if( bIsIndex && !bIsColumnIndex )
2252 uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, ::uno::UNO_QUERY_THROW);
2253 sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
2255 if ( !nIndex || nIndex < 0 )
2258 nRow = nIndex / nColCount;
2259 nColumn = nIndex % nColCount;
2263 nRow = nRow + thisRangeAddress.StartRow;
2264 nColumn = nColumn + thisRangeAddress.StartColumn;
2265 return new ScVbaRange( xParent, xContext, xSheetRange->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ) );
2272 if ( !pUnoRangesBase )
2273 throw uno::RuntimeException(
"Failed to access underlying uno range object" );
2278 uno::Reference< frame::XModel >
xModel( pShell->
GetModel(), uno::UNO_SET_THROW );
2279 uno::Reference< view::XSelectionSupplier > xSelection(
xModel->getCurrentController(), uno::UNO_QUERY_THROW );
2288 uno::Reference< frame::XController >
xController(
xModel->getCurrentController(), uno::UNO_SET_THROW );
2289 uno::Reference< frame::XFrame >
xFrame(
xController->getFrame(), uno::UNO_SET_THROW );
2290 uno::Reference< awt::XWindow > xWin(
xFrame->getContainerWindow(), uno::UNO_SET_THROW );
2293 catch( uno::Exception& )
2298 static bool cellInRange(
const table::CellRangeAddress& rAddr, sal_Int32 nCol, sal_Int32 nRow )
2300 return nCol >= rAddr.StartColumn && nCol <= rAddr.EndColumn &&
2301 nRow >= rAddr.StartRow && nRow <= rAddr.EndRow;
2304 static void setCursor(
SCCOL nCol,
SCROW nRow,
const uno::Reference< frame::XModel >& xModel,
bool bInSel =
true )
2320 uno::Reference< table::XCellRange > xCellRange;
2323 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
2324 xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
2327 xCellRange.set(
mxRange, uno::UNO_SET_THROW );
2329 RangeHelper thisRange( xCellRange );
2330 uno::Reference< sheet::XCellRangeAddressable > xThisRangeAddress = thisRange.getCellRangeAddressable();
2331 table::CellRangeAddress thisRangeAddress = xThisRangeAddress->getRangeAddress();
2332 uno::Reference< frame::XModel >
xModel;
2339 throw uno::RuntimeException();
2342 uno::Reference< sheet::XCellRangeAddressable > xRange( xModel->getCurrentSelection(), ::uno::UNO_QUERY);
2344 uno::Reference< sheet::XSheetCellRanges > xRanges( xModel->getCurrentSelection(), ::uno::UNO_QUERY);
2348 const uno::Sequence< table::CellRangeAddress > nAddrs = xRanges->getRangeAddresses();
2349 for (
const auto& rAddr : nAddrs )
2351 if (
cellInRange( rAddr, thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
2353 setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
2360 if ( xRange.is() &&
cellInRange( xRange->getRangeAddress(), thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
2361 setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
2369 setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel,
false );
2376 uno::Reference< excel::XRange >
2387 if( aIndex >>= nValue )
2392 else if ( aIndex >>= sAddress )
2404 throw uno::RuntimeException(
"Illegal param" );
2407 throw uno::RuntimeException(
"Internal failure, illegal param" );
2413 if (
m_Areas->getCount() > 1 )
2418 uno::Reference< excel::XRange >
2429 if ( aIndex >>= nValue )
2435 else if ( aIndex >>= sAddress )
2447 throw uno::RuntimeException(
"Illegal param" );
2450 throw uno::RuntimeException(
"Internal failure, illegal param" );
2464 sal_Int32 nCount =
mxRanges->getCount();
2467 ::std::vector< table::CellRangeAddress > aList;
2470 uno::Reference< sheet::XCellRangeAddressable > xRangeAddr(
mxRanges->getByIndex(
nIndex ), uno::UNO_QUERY_THROW );
2471 table::CellRangeAddress aAddress = xRangeAddr->getRangeAddress();
2472 if (std::any_of(aList.begin(), aList.end(),
2473 [&aAddress](
const table::CellRangeAddress& rAddress)
2476 aList.push_back( aAddress );
2482 uno::Reference< table::XCellRange > xRange(
mxRanges->getByIndex(
nIndex ), uno::UNO_QUERY_THROW );
2483 lclExpandAndMerge( xRange, bMerge );
2489 lclExpandAndMerge(
mxRange, bMerge );
2497 sal_Int32 nCount =
mxRanges->getCount();
2500 uno::Reference< table::XCellRange > xRange(
mxRanges->getByIndex(
nIndex ), uno::UNO_QUERY_THROW );
2501 util::TriState eMerged = lclGetMergedState( xRange );
2505 if( eMerged != util::TriState_NO )
2513 switch( lclGetMergedState(
mxRange ) )
2515 case util::TriState_YES:
return uno::Any(
true );
2516 case util::TriState_NO:
return uno::Any(
false );
2517 default:
return aNULL();
2524 if ( Destination.hasValue() )
2527 if (
m_Areas->getCount() > 1 )
2528 throw uno::RuntimeException(
"That command cannot be used on multiple selections" );
2529 uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW );
2530 uno::Any aRange = xRange->getCellRange();
2531 uno::Reference< table::XCellRange > xCellRange;
2532 aRange >>= xCellRange;
2533 uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW);
2534 uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
2535 uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW );
2536 uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW);
2537 uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition(
2538 xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY_THROW );
2539 uno::Reference< sheet::XCellRangeAddressable > xSource(
mxRange, uno::UNO_QUERY);
2540 xMover->copyRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
2542 pRange->fireChangeEvent();
2554 if (
m_Areas->getCount() > 1 )
2555 throw uno::RuntimeException(
"That command cannot be used on multiple selections" );
2556 if (Destination.hasValue())
2558 uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW );
2559 uno::Reference< table::XCellRange > xCellRange( xRange->getCellRange(), uno::UNO_QUERY_THROW );
2560 uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW );
2561 uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
2562 uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW );
2563 uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW);
2564 uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition(
2565 xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY);
2566 uno::Reference< sheet::XCellRangeAddressable > xSource(
mxRange, uno::UNO_QUERY);
2567 xMover->moveRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
2581 aFormat >>= sFormat;
2582 if (
m_Areas->getCount() > 1 )
2584 sal_Int32 nItems =
m_Areas->getCount();
2588 xRange->setNumberFormat( aFormat );
2592 NumFormatHelper numFormat(
mxRange );
2593 numFormat.setNumberFormat( sFormat );
2600 if (
m_Areas->getCount() > 1 )
2602 sal_Int32 nItems =
m_Areas->getCount();
2610 if ( aResult != xRange->getNumberFormat() )
2612 aResult = xRange->getNumberFormat();
2613 if (
aNULL() == aResult )
2618 NumFormatHelper numFormat(
mxRange );
2619 OUString sFormat = numFormat.getNumberFormatString();
2620 if ( !sFormat.isEmpty() )
2625 uno::Reference< excel::XRange >
2629 bool bIsRowChanged = ( RowSize >>= nRowSize ), bIsColumnChanged = ( ColumnSize >>= nColumnSize );
2630 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, ::uno::UNO_QUERY_THROW);
2631 uno::Reference< sheet::XSheetCellRange > xSheetRange(
mxRange, ::uno::UNO_QUERY_THROW);
2632 uno::Reference< sheet::XSheetCellCursor > xCursor( xSheetRange->getSpreadsheet()->createCursorByRange(xSheetRange), ::uno::UNO_SET_THROW );
2634 if( !bIsRowChanged )
2635 nRowSize = xColumnRowRange->getRows()->getCount();
2636 if( !bIsColumnChanged )
2637 nColumnSize = xColumnRowRange->getColumns()->getCount();
2639 xCursor->collapseToSize( nColumnSize, nRowSize );
2640 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xCursor, ::uno::UNO_QUERY_THROW );
2641 uno::Reference< table::XCellRange > xRange( xSheetRange->getSpreadsheet(), ::uno::UNO_QUERY_THROW );
2643 xCellRangeAddressable->getRangeAddress().StartColumn,
2644 xCellRangeAddressable->getRangeAddress().StartRow,
2645 xCellRangeAddressable->getRangeAddress().EndColumn,
2646 xCellRangeAddressable->getRangeAddress().EndRow ) );
2652 if (
m_Areas->getCount() > 1 )
2654 sal_Int32 nItems =
m_Areas->getCount();
2658 xRange->setWrapText( aIsWrapped );
2663 uno::Reference< beans::XPropertySet > xProps(
mxRange, ::uno::UNO_QUERY_THROW );
2665 xProps->setPropertyValue(
"IsTextWrapped",
uno::Any( bIsWrapped ) );
2671 if (
m_Areas->getCount() > 1 )
2673 sal_Int32 nItems =
m_Areas->getCount();
2679 if ( aResult != xRange->getWrapText() )
2681 aResult = xRange->getWrapText();
2689 if ( eState == SfxItemState::DONTCARE )
2692 uno::Reference< beans::XPropertySet > xProps(
mxRange, ::uno::UNO_QUERY_THROW );
2693 uno::Any aValue = xProps->getPropertyValue(
"IsTextWrapped" );
2699 uno::Reference< beans::XPropertySet > xProps(
mxRange, uno::UNO_QUERY_THROW );
2702 uno::Reference< excel::XRange >
2705 return Range( Cell1, Cell2,
false );
2707 uno::Reference< excel::XRange >
2711 uno::Reference< table::XCellRange > xCellRange =
mxRange;
2713 if (
m_Areas->getCount() > 1 )
2715 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
2716 xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
2721 RangeHelper thisRange( xCellRange );
2722 uno::Reference< table::XCellRange > xRanges = thisRange.getCellRangeFromSheet();
2723 uno::Reference< sheet::XCellRangeAddressable > xAddressable( xRanges, uno::UNO_QUERY_THROW );
2725 uno::Reference< table::XCellRange > xReferrer =
2727 xAddressable->getRangeAddress().EndColumn,
2728 xAddressable->getRangeAddress().EndRow );
2730 xAddressable.set( xReferrer, uno::UNO_QUERY_THROW );
2733 throw uno::RuntimeException(
"Invalid Argument" );
2735 table::CellRangeAddress parentRangeAddress = xAddressable->getRangeAddress();
2743 RangeHelper referRange( xReferrer );
2744 table::CellRangeAddress referAddress = referRange.getCellRangeAddressable()->getRangeAddress();
2750 table::CellRangeAddress cell1, cell2;
2758 table::CellRangeAddress resultAddress;
2759 resultAddress.StartColumn = ( cell1.StartColumn < cell2.StartColumn ) ? cell1.StartColumn : cell2.StartColumn;
2760 resultAddress.StartRow = ( cell1.StartRow < cell2.StartRow ) ? cell1.StartRow : cell2.StartRow;
2761 resultAddress.EndColumn = std::max( cell1.EndColumn, cell2.EndColumn );
2762 resultAddress.EndRow = std::max( cell1.EndRow, cell2.EndRow );
2763 if ( bForceUseInpuRangeTab )
2768 if ( cell1.Sheet != cell2.Sheet )
2769 throw uno::RuntimeException();
2770 parentRangeAddress.Sheet = cell1.Sheet;
2777 if ( parentRangeAddress.Sheet != cell1.Sheet
2778 || parentRangeAddress.Sheet != cell2.Sheet
2780 throw uno::RuntimeException();
2794 if ( nStartX <= nEndX && nEndX <= parentAddress.
aEnd.
Col() &&
2795 nStartY <= nEndY && nEndY <= parentAddress.
aEnd.
Row() )
2797 ScRange aNew( static_cast<SCCOL>(nStartX), static_cast<SCROW>(nStartY), parentAddress.
aStart.
Tab(),
2798 static_cast<SCCOL>(nEndX), static_cast<SCROW>(nEndY), parentAddress.
aEnd.
Tab() );
2822 return pVbaRange->getCellRange();
2823 throw uno::RuntimeException();
2830 case excel::XlPasteType::xlPasteComments:
2832 case excel::XlPasteType::xlPasteFormats:
2834 case excel::XlPasteType::xlPasteFormulas:
2836 case excel::XlPasteType::xlPasteFormulasAndNumberFormats :
2837 case excel::XlPasteType::xlPasteValues:
2839 case excel::XlPasteType::xlPasteValuesAndNumberFormats:
2841 case excel::XlPasteType::xlPasteColumnWidths:
2842 case excel::XlPasteType::xlPasteValidation:
2844 case excel::XlPasteType::xlPasteAll:
2845 case excel::XlPasteType::xlPasteAllExceptBorders:
2858 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationAdd:
2860 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationSubtract:
2862 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationMultiply:
2864 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationDivide:
2867 case excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone:
2872 return nFormulaBits;
2877 if (
m_Areas->getCount() > 1 )
2878 throw uno::RuntimeException(
"That command cannot be used on multiple selections" );
2882 throw uno::RuntimeException(
"That command cannot be used with no ScDocShell" );
2884 uno::Reference< frame::XModel >
xModel(pShell->
GetModel(), uno::UNO_SET_THROW);
2885 uno::Reference< view::XSelectionSupplier > xSelection(
xModel->getCurrentController(), uno::UNO_QUERY_THROW );
2889 sal_Int32 nPaste = excel::XlPasteType::xlPasteAll;
2890 sal_Int32 nOperation = excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone;
2891 bool bTranspose =
false;
2892 bool bSkipBlanks =
false;
2897 Operation >>= nOperation;
2899 SkipBlanks >>= bSkipBlanks;
2901 Transpose >>= bTranspose;
2909 uno::Reference< excel::XRange >
2917 for (
size_t i = 0, nRanges = aCellRanges.
size();
i < nRanges; ++
i )
2919 ScRange & rRange = aCellRanges[
i ];
2931 if ( aCellRanges.
size() > 1 )
2933 uno::Reference< sheet::XSheetCellRangeContainer > xRanges(
new ScCellRangesObj( pUnoRangesBase->
GetDocShell(), aCellRanges ) );
2941 uno::Reference< excel::XRange > SAL_CALL
2947 uno::Reference< excel::XRange > SAL_CALL
2953 uno::Reference< excel::XComment > SAL_CALL
2958 throw uno::RuntimeException();
2962 if( Text.
hasValue() && !(Text >>= aNoteText) )
2963 throw uno::RuntimeException();
2964 if( aNoteText.isEmpty() )
2968 table::CellRangeAddress aRangePos = lclGetRangeAddress(
mxRange );
2969 table::CellAddress aNotePos( aRangePos.Sheet, aRangePos.StartColumn, aRangePos.StartRow );
2970 uno::Reference< sheet::XSheetCellRange > xCellRange(
mxRange, uno::UNO_QUERY_THROW );
2971 uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xCellRange->getSpreadsheet(), uno::UNO_QUERY_THROW );
2972 uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_SET_THROW );
2973 xAnnos->insertNew( aNotePos, aNoteText );
2977 uno::Reference< excel::XComment > SAL_CALL
2990 static uno::Reference< beans::XPropertySet >
2993 uno::Reference< table::XColumnRowRange > xColRow( xCellRange, uno::UNO_QUERY_THROW );
2994 uno::Reference< beans::XPropertySet > xProps;
2996 xProps.set( xColRow->getRows(), uno::UNO_QUERY_THROW );
2998 xProps.set( xColRow->getColumns(), uno::UNO_QUERY_THROW );
3007 if (
m_Areas->getCount() > 1 )
3009 uno::Reference< excel::XRange > xRange(
m_Areas->Item(
uno::Any(sal_Int32(1)),
uno::Any() ), uno::UNO_QUERY_THROW );
3010 return xRange->getHidden();
3012 bool bIsVisible =
false;
3016 if ( !( xProps->getPropertyValue( ISVISIBLE ) >>= bIsVisible ) )
3017 throw uno::RuntimeException(
"Failed to get IsVisible property" );
3019 catch(
const uno::Exception& e )
3022 throw css::lang::WrappedTargetRuntimeException( e.Message,
3031 if (
m_Areas->getCount() > 1 )
3033 sal_Int32 nItems =
m_Areas->getCount();
3037 xRange->setHidden( _hidden );
3046 xProps->setPropertyValue( ISVISIBLE,
uno::Any( !bHidden ) );
3048 catch(
const uno::Exception& e )
3051 throw css::lang::WrappedTargetRuntimeException( e.Message,
3059 if (
m_Areas->getCount() > 1 )
3064 xRange->Replace( What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat );
3070 if ( What.isEmpty() )
3071 throw uno::RuntimeException(
"Range::Replace, missing params" );
3078 uno::Reference< util::XReplaceable > xReplace(
mxRange, uno::UNO_QUERY );
3079 if ( xReplace.is() )
3081 uno::Reference< util::XReplaceDescriptor > xDescriptor =
3082 xReplace->createReplaceDescriptor();
3084 xDescriptor->setSearchString( sWhat);
3086 xDescriptor->setReplaceString( Replacement);
3090 sal_Int16 nLook = ::comphelper::getINT16( LookAt );
3091 bool bSearchWords =
false;
3092 if ( nLook == excel::XlLookAt::xlPart )
3093 bSearchWords =
false;
3094 else if ( nLook == excel::XlLookAt::xlWhole )
3095 bSearchWords =
true;
3097 throw uno::RuntimeException(
"Range::Replace, illegal value for LookAt" );
3106 sal_Int16 nSearchOrder = ::comphelper::getINT16( SearchOrder );
3107 bool bSearchByRow =
false;
3108 if ( nSearchOrder == excel::XlSearchOrder::xlByColumns )
3109 bSearchByRow =
false;
3110 else if ( nSearchOrder == excel::XlSearchOrder::xlByRows )
3111 bSearchByRow =
true;
3113 throw uno::RuntimeException(
"Range::Replace, illegal value for SearchOrder" );
3120 bool bMatchCase =
false;
3123 MatchCase >>= bMatchCase;
3131 uno::Reference< container::XIndexAccess > xIndexAccess = xReplace->findAll( xDescriptor );
3132 xReplace->replaceAll( xDescriptor );
3133 if ( xIndexAccess.is() && xIndexAccess->getCount() > 0 )
3135 for ( sal_Int32
i = 0;
i < xIndexAccess->getCount(); ++
i )
3137 uno::Reference< table::XCellRange > xCellRange( xIndexAccess->getByIndex(
i ), uno::UNO_QUERY );
3138 if ( xCellRange.is() )
3141 uno::Reference< container::XEnumerationAccess > xEnumAccess( xRange, uno::UNO_QUERY_THROW );
3142 uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
3143 while ( xEnum->hasMoreElements() )
3145 uno::Reference< excel::XRange > xNextRange( xEnum->nextElement(), uno::UNO_QUERY_THROW );
3157 uno::Reference< excel::XRange > SAL_CALL
3162 sal_Int32 nWhat = 0;
3166 if( What >>= sWhat )
3168 else if( What >>= nWhat )
3170 sWhat = OUString::number( nWhat );
3172 else if( What >>= fWhat )
3174 sWhat = OUString::number( fWhat );
3177 throw uno::RuntimeException(
"Range::Find, missing search-for-what param" );
3184 uno::Reference< util::XSearchable > xSearch(
mxRange, uno::UNO_QUERY );
3187 uno::Reference< util::XSearchDescriptor > xDescriptor = xSearch->createSearchDescriptor();
3188 xDescriptor->setSearchString( sSearch );
3191 uno::Reference< excel::XRange > xAfterRange;
3192 uno::Reference< table::XCellRange > xStartCell;
3193 if( After >>= xAfterRange )
3196 if( xAfterRange->getCount() > 1 )
3197 throw uno::RuntimeException(
"After must be a single cell." );
3198 uno::Reference< excel::XRange > xCell(
Cells(
uno::Any( xAfterRange->getRow() ),
uno::Any( xAfterRange->getColumn() ) ), uno::UNO_SET_THROW );
3199 xStartCell.set( xAfterRange->getCellRange(), uno::UNO_QUERY_THROW );
3205 sal_Int32 nLookIn = 0;
3206 if( LookIn >>= nLookIn )
3211 case excel::XlFindLookIn::xlComments :
3212 nSearchType = SvxSearchCellType::NOTE;
3214 case excel::XlFindLookIn::xlFormulas :
3215 nSearchType = SvxSearchCellType::FORMULA;
3217 case excel::XlFindLookIn::xlValues :
3218 nSearchType = SvxSearchCellType::VALUE;
3221 throw uno::RuntimeException(
"Range::Find, illegal value for LookIn." );
3224 xDescriptor->setPropertyValue(
"SearchType",
uno::Any( static_cast<sal_uInt16>(nSearchType) ) );
3231 sal_Int16 nLookAt = ::comphelper::getINT16( LookAt );
3232 bool bSearchWords =
false;
3233 if ( nLookAt == excel::XlLookAt::xlPart )
3234 bSearchWords =
false;
3235 else if ( nLookAt == excel::XlLookAt::xlWhole )
3236 bSearchWords =
true;
3238 throw uno::RuntimeException(
"Range::Find, illegal value for LookAt" );
3246 sal_Int16 nSearchOrder = ::comphelper::getINT16( SearchOrder );
3247 bool bSearchByRow =
false;
3248 if ( nSearchOrder == excel::XlSearchOrder::xlByColumns )
3249 bSearchByRow =
false;
3250 else if ( nSearchOrder == excel::XlSearchOrder::xlByRows )
3251 bSearchByRow =
true;
3253 throw uno::RuntimeException(
"Range::Find, illegal value for SearchOrder" );
3262 sal_Int32 nSearchDirection = 0;
3263 if( SearchDirection >>= nSearchDirection )
3265 bool bSearchBackwards =
false;
3266 if ( nSearchDirection == excel::XlSearchDirection::xlNext )
3267 bSearchBackwards =
false;
3268 else if( nSearchDirection == excel::XlSearchDirection::xlPrevious )
3269 bSearchBackwards =
true;
3271 throw uno::RuntimeException(
"Range::Find, illegal value for SearchDirection" );
3273 xDescriptor->setPropertyValue(
"SearchBackwards",
uno::Any( bSearchBackwards ) );
3278 bool bMatchCase =
false;
3282 if( !( MatchCase >>= bMatchCase ) )
3283 throw uno::RuntimeException(
"Range::Find illegal value for MatchCase" );
3293 uno::Reference< uno::XInterface > xInterface = xStartCell.is() ? xSearch->findNext( xStartCell, xDescriptor) : xSearch->findFirst( xDescriptor );
3294 uno::Reference< table::XCellRange > xCellRange( xInterface, uno::UNO_QUERY );
3297 if ( !xCellRange.is() && xStartCell.is() )
3299 xInterface = xSearch->findFirst( xDescriptor );
3300 xCellRange.set( xInterface, uno::UNO_QUERY );
3302 if ( xCellRange.is() )
3305 if( xResultRange.is() )
3307 return xResultRange;
3313 return uno::Reference< excel::XRange >();
3318 uno::Reference< excel::XRange > xKeyRange;
3321 xKeyRange.set( Key, uno::UNO_QUERY_THROW );
3326 OUString sRangeName = ::comphelper::getString( Key );
3327 table::CellRangeAddress aRefAddr;
3329 throw uno::RuntimeException(
"Range::Sort no docshell to calculate key param" );
3330 xKeyRange =
getRangeForName( xContext, sRangeName, pDocSh, aRefAddr );
3333 throw uno::RuntimeException(
"Range::Sort illegal type value for key param" );
3334 uno::Reference< table::XCellRange > xKey;
3335 xKey.set( xKeyRange->getCellRange(), uno::UNO_QUERY_THROW );
3342 const OUString& sPropName )
3344 const beans::PropertyValue* pProp = std::find_if(props.begin(), props.end(),
3345 [&sPropName](
const beans::PropertyValue& rProp) {
return rProp.Name == sPropName; });
3347 if ( pProp == props.end() )
3348 throw uno::RuntimeException(
"Range::Sort unknown sort property" );
3349 return static_cast<sal_Int32
>(std::distance(props.begin(), pProp));
3355 const uno::Reference< table::XCellRange >& xColRowKey, sal_Int16 nOrder,
3356 table::TableSortField& aTableField,
bool bIsSortColumn,
bool bMatchCase )
3358 RangeHelper parentRange( xParentRange );
3359 RangeHelper colRowRange( xColRowKey );
3361 table::CellRangeAddress parentRangeAddress = parentRange.getCellRangeAddressable()->getRangeAddress();
3363 table::CellRangeAddress colRowKeyAddress = colRowRange.getCellRangeAddressable()->getRangeAddress();
3368 ( bIsSortColumn || colRowKeyAddress.StartColumn < parentRangeAddress.StartColumn ||
3369 colRowKeyAddress.StartColumn > parentRangeAddress.EndColumn )
3371 ( !bIsSortColumn || colRowKeyAddress.StartRow < parentRangeAddress.StartRow ||
3372 colRowKeyAddress.StartRow > parentRangeAddress.EndRow )
3374 throw uno::RuntimeException(
"Illegal Key param" );
3377 if ( bIsSortColumn )
3378 aTableField.Field = colRowKeyAddress.StartRow - parentRangeAddress.StartRow;
3380 aTableField.Field = colRowKeyAddress.StartColumn - parentRangeAddress.StartColumn;
3381 aTableField.IsCaseSensitive = bMatchCase;
3383 if ( nOrder == excel::XlSortOrder::xlAscending )
3384 aTableField.IsAscending =
true;
3386 aTableField.IsAscending =
false;
3392 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 )
3395 if (
m_Areas->getCount() > 1 )
3396 throw uno::RuntimeException(
"That command cannot be used on multiple selections" );
3398 sal_Int16 nDataOption1 = excel::XlSortDataOption::xlSortNormal;
3399 sal_Int16 nDataOption2 = excel::XlSortDataOption::xlSortNormal;
3400 sal_Int16 nDataOption3 = excel::XlSortDataOption::xlSortNormal;
3404 RangeHelper thisRange(
mxRange );
3405 table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3407 SCTAB nTab = thisRangeAddress.Sheet;
3411 DataOption1 >>= nDataOption1;
3413 DataOption2 >>= nDataOption2;
3415 DataOption3 >>= nDataOption3;
3419 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY_THROW );
3423 sal_Int16 nOrder1 = aSortParam.
maKeyState[0].bAscending ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
3424 sal_Int16 nOrder2 = aSortParam.
maKeyState[1].bAscending ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
3425 sal_Int16 nOrder3 = aSortParam.
maKeyState[2].bAscending ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
3428 sal_Int16 nSortMethod = excel::XlSortMethod::xlPinYin;
3432 sal_Int16 nOrientation = aSortParam.
bByRow ? excel::XlSortOrientation::xlSortColumns : excel::XlSortOrientation::xlSortRows;
3439 nOrientation = ::comphelper::getINT16( Orientation );
3441 if ( nOrientation == excel::XlSortOrientation::xlSortRows )
3442 aSortParam.
bByRow =
false;
3444 aSortParam.
bByRow =
true;
3448 bool bIsSortColumns=
false;
3450 if ( nOrientation == excel::XlSortOrientation::xlSortRows )
3451 bIsSortColumns =
true;
3453 bool bContainsHeader =
false;
3457 nHeader = ::comphelper::getINT16( Header );
3461 if ( nHeader == excel::XlYesNoGuess::xlGuess )
3463 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 ));
3464 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 ) );
3465 if ( bHasColHeader || bHasRowHeader )
3466 nHeader = excel::XlYesNoGuess::xlYes;
3468 nHeader = excel::XlYesNoGuess::xlNo;
3472 if ( nHeader == excel::XlYesNoGuess::xlYes )
3473 bContainsHeader =
true;
3477 nSortMethod = ::comphelper::getINT16( SortMethod );
3482 OrderCustom >>= nCustom;
3489 MatchCase >>= bMatchCase;
3495 nOrder1 = ::comphelper::getINT16(Order1);
3496 if ( nOrder1 == excel::XlSortOrder::xlAscending )
3504 nOrder2 = ::comphelper::getINT16(Order2);
3505 if ( nOrder2 == excel::XlSortOrder::xlAscending )
3512 nOrder3 = ::comphelper::getINT16(Order3);
3513 if ( nOrder3 == excel::XlSortOrder::xlAscending )
3519 uno::Reference< table::XCellRange > xKey1;
3520 uno::Reference< table::XCellRange > xKey2;
3521 uno::Reference< table::XCellRange > xKey3;
3525 throw uno::RuntimeException(
"Range::Sort needs a key1 param" );
3532 uno::Reference< util::XSortable > xSort(
mxRange, uno::UNO_QUERY_THROW );
3533 uno::Sequence< beans::PropertyValue > sortDescriptor = xSort->createSortDescriptor();
3534 auto psortDescriptor = sortDescriptor.getArray();
3537 uno::Sequence< table::TableSortField > sTableFields(1);
3538 sal_Int32 nTableIndex = 0;
3543 sTableFields.realloc( sTableFields.getLength() + 1 );
3548 sTableFields.realloc( sTableFields.getLength() + 1 );
3551 psortDescriptor[ nTableSortFieldIndex ].Value <<= sTableFields;
3554 psortDescriptor[ nIndex ].Value <<= bIsSortColumns;
3557 psortDescriptor[ nIndex ].Value <<= bContainsHeader;
3560 xSort->sort( sortDescriptor );
3567 uno::Reference< excel::XRange > SAL_CALL
3570 if (
m_Areas->getCount() > 1 )
3572 uno::Reference< excel::XRange > xRange(
getArea( 0 ), uno::UNO_SET_THROW );
3573 return xRange->End( Direction );
3586 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
3587 uno::Reference< excel::XWorksheet > sActiveSheet = xApplication->getActiveSheet();
3588 OUString sActiveCell = xApplication->getActiveCell()->Address(aDft, aDft, aDft, aDft, aDft );
3602 aArgs.
Put( sfxAsync, sfxAsync.
Which() );
3605 sal_uInt16 nSID = 0;
3609 case excel::XlDirection::xlDown:
3610 nSID = SID_CURSORBLKDOWN;
3612 case excel::XlDirection::xlUp:
3613 nSID = SID_CURSORBLKUP;
3615 case excel::XlDirection::xlToLeft:
3616 nSID = SID_CURSORBLKLEFT;
3618 case excel::XlDirection::xlToRight:
3619 nSID = SID_CURSORBLKRIGHT;
3622 throw uno::RuntimeException(
": Invalid ColumnIndex" );
3626 pDispatcher->
Execute( nSID, SfxCallMode::SYNCHRON, aArgs );
3631 OUString sMoved = xApplication->getActiveCell()->Address(aDft, aDft, aDft, aDft, aDft );
3634 uno::Reference< excel::XRange > resultCell;
3635 resultCell.set( xApplication->getActiveSheet()->Range(
uno::Any( sMoved ), aVoid ), uno::UNO_SET_THROW );
3638 uno::Reference< excel::XRange > xOldActiveCell( sActiveSheet->Range(
uno::Any( sActiveCell ), aVoid ), uno::UNO_SET_THROW );
3639 xOldActiveCell->Select();
3649 uno::Reference< sheet::XCellRangeAddressable > xAddressable(
mxRange, uno::UNO_QUERY );
3650 if ( xAddressable.is() )
3652 table::CellRangeAddress aRangeAddr = xAddressable->getRangeAddress();
3653 return ( aRangeAddr.EndColumn == aRangeAddr.StartColumn && aRangeAddr.EndRow == aRangeAddr.StartRow );
3658 uno::Reference< excel::XCharacters > SAL_CALL
3662 throw uno::RuntimeException(
"Can't create Characters property for multicell range " );
3663 uno::Reference< text::XSimpleText > xSimple(
mxRange->getCellByPosition(0,0) , uno::UNO_QUERY_THROW );
3673 if (
m_Areas->getCount() > 1 )
3675 sal_Int32 nItems =
m_Areas->getCount();
3679 xRange->Delete( Shift );
3683 sheet::CellDeleteMode
mode = sheet::CellDeleteMode_NONE ;
3684 RangeHelper thisRange(
mxRange );
3685 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3688 sal_Int32 nShift = 0;
3692 case excel::XlDeleteShiftDirection::xlShiftUp:
3693 mode = sheet::CellDeleteMode_UP;
3695 case excel::XlDeleteShiftDirection::xlShiftToLeft:
3696 mode = sheet::CellDeleteMode_LEFT;
3699 throw uno::RuntimeException(
"Illegal parameter " );
3705 bool bFullRow = ( thisAddress.StartColumn == 0 && thisAddress.EndColumn == rDoc.
MaxCol() );
3706 sal_Int32 nCols = thisAddress.EndColumn - thisAddress.StartColumn;
3707 sal_Int32 nRows = thisAddress.EndRow - thisAddress.StartRow;
3708 if (
mbIsRows || bFullRow || ( nCols >= nRows ) )
3709 mode = sheet::CellDeleteMode_UP;
3711 mode = sheet::CellDeleteMode_LEFT;
3713 uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
3714 xCellRangeMove->removeRange( thisAddress, mode );
3722 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY );
3723 if ( xColumnRowRange.is() )
3724 if ( xColumnRowRange->getRows()->getCount() ||
3725 xColumnRowRange->getColumns()->getCount() )
3731 uno::Reference< container::XEnumeration > SAL_CALL
3736 uno::Reference< table::XColumnRowRange > xColumnRowRange(
mxRange, uno::UNO_QUERY );
3737 uno::Reference< excel::XRange > xRange(
m_Areas->Item(
uno::Any( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
3738 sal_Int32 nElems = 0;
3740 nElems = xColumnRowRange->getColumns()->getCount();
3742 nElems = xColumnRowRange->getRows()->getCount();
3743 return new ColumnsRowEnumeration( xRange, nElems );
3760 sal_uInt16 nWidth = rDoc.
GetOriginalWidth( static_cast< SCCOL >( rAddress.StartColumn ), static_cast< SCTAB >( rAddress.Sheet ) );
3770 sal_uInt16 nWidth = rDoc.
GetOriginalHeight( rAddress.StartRow, rAddress.Sheet );
3784 pRefDevice->
SetFont( aDefFont );
3792 sal_Int32 nLen =
m_Areas->getCount();
3795 uno::Reference< excel::XRange > xRange(
m_Areas->Item(
uno::Any( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
3796 return xRange->getColumnWidth();
3799 double nColWidth = 0;
3804 RangeHelper thisRange(
mxRange );
3805 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3806 sal_Int32 nStartCol = thisAddress.StartColumn;
3807 sal_Int32 nEndCol = thisAddress.EndColumn;
3808 sal_uInt16 nColTwips = 0;
3809 for( sal_Int32 nCol = nStartCol ; nCol <= nEndCol; ++nCol )
3811 thisAddress.StartColumn = nCol;
3812 sal_uInt16 nCurTwips = pShell->
GetDocument().
GetOriginalWidth( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCTAB >( thisAddress.Sheet ) );
3813 if ( nCol == nStartCol )
3814 nColTwips = nCurTwips;
3815 if ( nColTwips != nCurTwips )
3819 if ( nColWidth != 0.0 )
3820 nColWidth = ( nColWidth / defaultCharWidth ) -
fExtraWidth;
3829 sal_Int32 nLen =
m_Areas->getCount();
3835 xRange->setColumnWidth( _columnwidth );
3839 double nColWidth = 0;
3840 _columnwidth >>= nColWidth;
3846 if ( nColWidth != 0.0 )
3848 RangeHelper thisRange(
mxRange );
3849 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3852 std::vector<sc::ColRowSpan> aColArr(1,
sc::ColRowSpan(thisAddress.StartColumn, thisAddress.EndColumn));
3855 true, aColArr, thisAddress.Sheet,
SC_SIZE_DIRECT, nTwips,
true,
true);
3861 if (
m_Areas->getCount() > 1 )
3863 uno::Reference< excel::XRange > xRange(
m_Areas->Item(
uno::Any( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
3864 return xRange->getWidth();
3866 uno::Reference< table::XColumnRowRange > xColRowRange(
mxRange, uno::UNO_QUERY_THROW );
3867 uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getColumns(), uno::UNO_QUERY_THROW );
3868 sal_Int32 nElems = xIndexAccess->getCount();
3872 uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex(
index ), uno::UNO_QUERY_THROW );
3873 double nTmpWidth =
getCalcColWidth( xAddressable->getRangeAddress() );
3874 nWidth += nTmpWidth;
3887 uno::Reference< excel::XRange >
3891 throw uno::RuntimeException(
"No areas available" );
3892 uno::Reference< excel::XRange > xRange(
m_Areas->Item(
uno::Any( ++nIndex ),
uno::Any() ), uno::UNO_QUERY_THROW );
3906 const css::uno::Any& ColorIndex,
const css::uno::Any&
Color )
3910 for( sal_Int32
i = 0;
i < nCount;
i++ )
3915 case excel::XlBordersIndex::xlEdgeLeft:
3916 case excel::XlBordersIndex::xlEdgeTop:
3917 case excel::XlBordersIndex::xlEdgeBottom:
3918 case excel::XlBordersIndex::xlEdgeRight:
3921 if( LineStyle.hasValue() )
3923 xBorder->setLineStyle( LineStyle );
3925 if( Weight.hasValue() )
3927 xBorder->setWeight( Weight );
3929 if( ColorIndex.hasValue() )
3931 xBorder->setColorIndex( ColorIndex );
3933 if( Color.hasValue() )
3935 xBorder->setColor( Color );
3939 case excel::XlBordersIndex::xlInsideVertical:
3940 case excel::XlBordersIndex::xlInsideHorizontal:
3941 case excel::XlBordersIndex::xlDiagonalDown:
3942 case excel::XlBordersIndex::xlDiagonalUp:
3954 sal_Int32 nLen =
m_Areas->getCount();
3957 uno::Reference< excel::XRange > xRange(
m_Areas->Item(
uno::Any( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
3958 return xRange->getRowHeight();
3963 RangeHelper thisRange(
mxRange );
3964 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
3966 sal_Int32 nStartRow = thisAddress.StartRow;
3967 sal_Int32 nEndRow = thisAddress.EndRow;
3968 sal_uInt16 nRowTwips = 0;
3976 for ( sal_Int32 nRow = nStartRow ; nRow <= nEndRow; ++nRow )
3978 thisAddress.StartRow = nRow;
3980 if ( nRow == nStartRow )
3981 nRowTwips = nCurTwips;
3982 if ( nRowTwips != nCurTwips )
3993 sal_Int32 nLen =
m_Areas->getCount();
3999 xRange->setRowHeight( _rowheight );
4004 _rowheight >>= nHeight;
4006 RangeHelper thisRange(
mxRange );
4007 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4011 std::vector<sc::ColRowSpan> aRowArr(1,
sc::ColRowSpan(thisAddress.StartRow, thisAddress.EndRow));
4019 sal_Int32 nPageBreak = excel::XlPageBreak::xlPageBreakNone;
4023 RangeHelper thisRange(
mxRange );
4024 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4025 bool bColumn =
false;
4027 if (thisAddress.StartRow==0)
4037 nBreak = rDoc.
HasRowBreak(thisAddress.StartRow, thisAddress.Sheet);
4039 nBreak = rDoc.
HasColBreak(thisAddress.StartColumn, thisAddress.Sheet);
4042 nPageBreak = excel::XlPageBreak::xlPageBreakAutomatic;
4045 nPageBreak = excel::XlPageBreak::xlPageBreakManual;
4055 sal_Int32 nPageBreak = 0;
4056 _pagebreak >>= nPageBreak;
4062 RangeHelper thisRange(
mxRange );
4063 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4064 if ((thisAddress.StartColumn==0) && (thisAddress.StartRow==0))
4066 bool bColumn =
false;
4068 if (thisAddress.StartRow==0)
4071 ScAddress aAddr( static_cast<SCCOL>(thisAddress.StartColumn), thisAddress.StartRow, thisAddress.Sheet );
4076 if ( nPageBreak == excel::XlPageBreak::xlPageBreakManual )
4078 else if ( nPageBreak == excel::XlPageBreak::xlPageBreakNone )
4086 if (
m_Areas->getCount() > 1 )
4088 uno::Reference< excel::XRange > xRange(
m_Areas->Item(
uno::Any( sal_Int32(1) ),
uno::Any() ), uno::UNO_QUERY_THROW );
4089 return xRange->getHeight();
4092 uno::Reference< table::XColumnRowRange > xColRowRange(
mxRange, uno::UNO_QUERY_THROW );
4093 uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getRows(), uno::UNO_QUERY_THROW );
4094 sal_Int32 nElems = xIndexAccess->getCount();
4098 uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex(
index ), uno::UNO_QUERY_THROW );
4108 uno::Reference< beans::XPropertySet > xProps;
4110 xProps.set(
mxRange, uno::UNO_QUERY_THROW );
4112 xProps.set(
mxRanges, uno::UNO_QUERY_THROW );
4113 xProps->getPropertyValue(
"Position" ) >>= aPoint;
4120 if (
m_Areas->getCount() > 1 )
4121 return getArea( 0 )->getLeft();
4130 if (
m_Areas->getCount() > 1 )
4131 return getArea( 0 )->getTop();
4136 static uno::Reference< sheet::XCellRangeReferrer >
getNamedRange(
const uno::Reference< uno::XInterface >& xIf,
const uno::Reference< table::XCellRange >& thisRange )
4138 uno::Reference< beans::XPropertySet > xProps( xIf, uno::UNO_QUERY_THROW );
4139 uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue(
"NamedRanges" ), uno::UNO_QUERY_THROW );
4141 const uno::Sequence< OUString > sNames = xNameAccess->getElementNames();
4143 uno::Reference< sheet::XCellRangeReferrer > xNamedRange;
4144 for (
const auto& rName : sNames )
4146 uno::Reference< sheet::XCellRangeReferrer > xName( xNameAccess->getByName( rName ), uno::UNO_QUERY );
4149 if ( thisRange == xName->getReferredCells() )
4151 xNamedRange = xName;
4159 uno::Reference< excel::XName >
4162 uno::Reference< beans::XPropertySet > xProps(
getUnoModel(), uno::UNO_QUERY );
4163 uno::Reference< table::XCellRange > thisRange(
getCellRange(), uno::UNO_QUERY_THROW );
4165 uno::Reference< sheet::XCellRangeReferrer > xNamedRange =
getNamedRange( xProps, thisRange );
4167 if ( !xNamedRange.is() )
4171 RangeHelper aRange( thisRange );
4172 uno::Reference< sheet::XSpreadsheet > xSheet = aRange.getSpreadSheet();
4173 xProps.set( xSheet, uno::UNO_QUERY );
4177 if ( xProps.is() && xNamedRange.is() )
4179 uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps, uno::UNO_QUERY_THROW );
4180 uno::Reference< sheet::XNamedRange > xName( xNamedRange, uno::UNO_QUERY_THROW );
4183 return uno::Reference< excel::XName >();
4186 uno::Reference< excel::XWorksheet >
4191 uno::Reference< excel::XWorksheet > xSheet(
getParent(), uno::UNO_QUERY );
4194 uno::Reference< table::XCellRange > xRange =
mxRange;
4198 uno::Reference< container::XIndexAccess > xIndex(
mxRanges, uno::UNO_QUERY_THROW );
4199 xRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
4202 RangeHelper rHelper(xRange);
4211 uno::Reference< excel::XRange >
4229 OUString sRangeName;
4230 Cell1 >>= sRangeName;
4231 if ( Cell1.hasValue() && !Cell2.hasValue() && !sRangeName.isEmpty() )
4233 uno::Reference< beans::XPropertySet > xPropSet(
getCurrentExcelDoc(xContext), uno::UNO_QUERY_THROW );
4235 uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue(
"NamedRanges" ), uno::UNO_QUERY_THROW );
4236 uno::Reference< sheet::XCellRangeReferrer > xReferrer;
4239 xReferrer.set ( xNamed->getByName( sRangeName ), uno::UNO_QUERY );
4241 catch( uno::Exception& )
4245 if ( xReferrer.is() )
4247 uno::Reference< table::XCellRange > xRange = xReferrer->getReferredCells();
4256 uno::Reference<table::XCellRange> xSheetRange;
4260 uno::Reference<sheet::XSpreadsheetView> xView(
4263 xSheetRange.set(xView->getActiveSheet(), uno::UNO_QUERY_THROW);
4265 catch (
const uno::Exception&)
4267 return uno::Reference<excel::XRange>();
4271 return pRange->Range( Cell1, Cell2,
true );
4294 pViewData = pViewSh ? &pViewSh->
GetViewData() :
nullptr;
4328 sCriteria1 = sCriteria1.trim();
4337 if ( sCriteria1.startsWith( EQUALS ) )
4339 if ( sCriteria1.getLength() ==
static_cast<sal_Int32
>(strlen(EQUALS)) )
4340 rFilterField.Operator = sheet::FilterOperator2::EMPTY;
4343 rFilterField.Operator = sheet::FilterOperator2::EQUAL;
4344 sCriteria1 = sCriteria1.copy( strlen(EQUALS) );
4347 if ( xDescProps.is() )
4348 xDescProps->setPropertyValue(
"UseRegularExpressions",
uno::Any(
true ) );
4352 else if ( sCriteria1.startsWith( NOTEQUALS ) )
4354 if ( sCriteria1.getLength() ==
static_cast<sal_Int32
>(strlen(NOTEQUALS)) )
4355 rFilterField.Operator = sheet::FilterOperator2::NOT_EMPTY;
4358 rFilterField.Operator = sheet::FilterOperator2::NOT_EQUAL;
4359 sCriteria1 = sCriteria1.copy( strlen(NOTEQUALS) );
4362 if ( xDescProps.is() )
4363 xDescProps->setPropertyValue(
"UseRegularExpressions",
uno::Any(
true ) );
4366 else if ( sCriteria1.startsWith( GREATERTHAN ) )
4368 if ( sCriteria1.startsWith( GREATERTHANEQUALS ) )
4370 sCriteria1 = sCriteria1.copy( strlen(GREATERTHANEQUALS) );
4371 rFilterField.Operator = sheet::FilterOperator2::GREATER_EQUAL;
4375 sCriteria1 = sCriteria1.copy( strlen(GREATERTHAN) );
4376 rFilterField.Operator = sheet::FilterOperator2::GREATER;
4380 else if ( sCriteria1.startsWith( LESSTHAN ) )
4382 if ( sCriteria1.startsWith( LESSTHANEQUALS ) )
4384 sCriteria1 = sCriteria1.copy( strlen(LESSTHANEQUALS) );
4385 rFilterField.Operator = sheet::FilterOperator2::LESS_EQUAL;
4389 sCriteria1 = sCriteria1.copy( strlen(LESSTHAN) );
4390 rFilterField.Operator = sheet::FilterOperator2::LESS;
4395 rFilterField.Operator = sheet::FilterOperator2::EQUAL;
4399 sal_Int32 nParseEnd = 0;
4400 rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
4402 if ( nParseEnd == sCriteria1.getLength() && eStatus == rtl_math_ConversionStatus_Ok )
4404 rFilterField.IsNumeric =
true;
4405 rFilterField.NumericValue = fValue;
4409 eStatus = rtl_math_ConversionStatus_Ok;
4410 fValue = ::rtl::math::stringToDouble( sCriteria1,
'.', 0, &eStatus, &nParseEnd );
4411 if ( nParseEnd == sCriteria1.getLength() && eStatus == rtl_math_ConversionStatus_Ok )
4413 rFilterField.IsNumeric =
true;
4414 rFilterField.NumericValue = fValue;
4418 rFilterField.StringValue = sCriteria1;
4425 RangeHelper thisRange(
mxRange );
4426 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4427 sal_Int16 nSheet = thisAddress.Sheet;
4429 bool bHasAuto =
false;
4431 if ( xDataBaseRange.is() )
4436 if (
m_Areas->getCount() > 1 )
4439 table::CellRangeAddress autoFiltAddress;
4443 uno::Reference< excel::XRange > xCurrent(
CurrentRegion() );
4444 if ( xCurrent.is() )
4450 throw uno::RuntimeException(
"Can't create AutoFilter" );
4451 RangeHelper currentRegion( pRange->
mxRange );
4452 autoFiltAddress = currentRegion.getCellRangeAddressable()->getRangeAddress();
4458 RangeHelper multiCellRange(
mxRange );
4459 autoFiltAddress = multiCellRange.getCellRangeAddressable()->getRangeAddress();
4464 SCCOL nStartCol = autoFiltAddress.StartColumn;
4465 SCROW nStartRow = autoFiltAddress.StartRow;
4466 SCCOL nEndCol = autoFiltAddress.EndColumn;
4467 SCROW nEndRow = autoFiltAddress.EndRow;
4468 pDocument->
GetDataArea( autoFiltAddress.Sheet, nStartCol, nStartRow, nEndCol, nEndRow,
true,
true );
4469 autoFiltAddress.StartColumn = nStartCol;
4470 autoFiltAddress.StartRow = nStartRow;
4471 autoFiltAddress.EndColumn = nEndCol;
4472 autoFiltAddress.EndRow = nEndRow;
4477 if ( xDBRanges.is() )
4479 if ( !xDBRanges->hasByTable( nSheet ) )
4480 xDBRanges->setByTable( autoFiltAddress );
4481 xDataBaseRange.set( xDBRanges->getByTable(nSheet ), uno::UNO_QUERY_THROW );
4483 if ( !xDataBaseRange.is() )
4484 throw uno::RuntimeException(
"Failed to find the autofilter placeholder range" );
4486 uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
4488 xDBRangeProps->setPropertyValue(
"AutoFilter",
uno::Any(
true) );
4490 uno::Reference< beans::XPropertySet > xFiltProps( xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY_THROW );
4491 xFiltProps->setPropertyValue(
"ContainsHeader",
uno::Any(
true ) );
4494 sal_Int32 nField = 0;
4495 sal_Int32 nOperator = excel::XlAutoFilterOperator::xlAnd;
4497 sheet::FilterConnection nConn = sheet::FilterConnection_AND;
4498 double nCriteria1 = 0;
4500 bool bHasCritValue = Criteria1.
hasValue();
4501 bool bCritHasNumericValue =
false;
4502 if ( bHasCritValue )
4503 bCritHasNumericValue = ( Criteria1 >>= nCriteria1 );
4506 throw uno::RuntimeException();
4508 if ( !( Field >>= nField ) )
4515 catch( uno::Exception& )
4522 if ( Field >>= nField )
4524 uno::Reference< sheet::XSheetFilterDescriptor2 > xDesc(
4525 xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY );
4528 OUString sCriteria1;
4529 bool bAcceptCriteria2 =
true;
4531 uno::Sequence< sheet::TableFilterField2 > sTabFilts;
4532 sheet::TableFilterField2* pTabFilts =
nullptr;
4533 uno::Reference< beans::XPropertySet > xDescProps( xDesc, uno::UNO_QUERY_THROW );
4536 sTabFilts.realloc( 1 );
4537 pTabFilts = sTabFilts.getArray();
4538 pTabFilts[0].Operator = sheet::FilterOperator2::EQUAL;
4539 if ( !bCritHasNumericValue )
4541 Criteria1 >>= sCriteria1;
4542 if ( sCriteria1.isEmpty() )
4544 uno::Sequence< OUString > aCriteria1;
4545 Criteria1 >>= aCriteria1;
4546 sal_uInt16
nLength = aCriteria1.getLength();
4550 bAcceptCriteria2 =
false;
4552 auto pCriteria1 = aCriteria1.getArray();
4553 sTabFilts.realloc( nLength );
4554 pTabFilts = sTabFilts.getArray();
4555 for ( sal_uInt16
i = 0;
i < nLength; ++
i )
4558 pTabFilts[i].Connection = sheet::FilterConnection_OR;
4559 pTabFilts[i].Field = (nField - 1);
4567 pTabFilts[0].IsNumeric = bCritHasNumericValue;
4568 if ( bHasCritValue && !sCriteria1.isEmpty() )
4576 pTabFilts[0].IsNumeric =
true;
4577 pTabFilts[0].NumericValue = nCriteria1;
4584 if ( Operator.
hasValue() && ( Operator >>= nOperator ) )
4588 if ( !bCritHasNumericValue && sCriteria1.isEmpty() && ( nOperator != excel::XlAutoFilterOperator::xlOr ) && ( nOperator != excel::XlAutoFilterOperator::xlAnd ) )
4590 pTabFilts[0].IsNumeric =
true;
4591 pTabFilts[0].NumericValue = 10;
4594 switch ( nOperator )
4596 case excel::XlAutoFilterOperator::xlBottom10Items:
4597 pTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_VALUES;
4599 case excel::XlAutoFilterOperator::xlBottom10Percent:
4600 pTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_PERCENT;
4602 case excel::XlAutoFilterOperator::xlTop10Items:
4603 pTabFilts[0].Operator = sheet::FilterOperator2::TOP_VALUES;
4605 case excel::XlAutoFilterOperator::xlTop10Percent:
4606 pTabFilts[0].Operator = sheet::FilterOperator2::TOP_PERCENT;
4608 case excel::XlAutoFilterOperator::xlOr:
4609 nConn = sheet::FilterConnection_OR;
4611 case excel::XlAutoFilterOperator::xlAnd:
4612 nConn = sheet::FilterConnection_AND;
4615 throw uno::RuntimeException(
"UnknownOption" );
4620 if ( !bAll && bAcceptCriteria2 )
4622 pTabFilts[0].Connection = sheet::FilterConnection_AND;
4623 pTabFilts[0].Field = (nField - 1);
4625 uno::Sequence< OUString > aCriteria2;
4628 sTabFilts.realloc(2);
4629 pTabFilts = sTabFilts.getArray();
4630 pTabFilts[1].Field = sTabFilts[0].Field;
4631 pTabFilts[1].Connection = nConn;
4633 OUString sCriteria2;
4634 if ( Criteria2 >>= sCriteria2 )
4636 if ( !sCriteria2.isEmpty() )
4638 uno::Reference< beans::XPropertySet > xProps;
4640 pTabFilts[1].IsNumeric =
false;
4643 else if ( Criteria2 >>= aCriteria2 )
4645 sal_uInt16
nLength = aCriteria2.getLength();
4654 Criteria2 >>= pTabFilts[1].NumericValue;
4655 pTabFilts[1].IsNumeric =
true;
4656 pTabFilts[1].Operator = sheet::FilterOperator2::EQUAL;
4661 xDesc->setFilterFields2( sTabFilts );
4664 xDataBaseRange->refresh();
4676 uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
4688 uno::Reference< sheet::XSheetFilterDescriptor2 > xSheetFilterDescriptor(
4689 xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY );
4690 if( xSheetFilterDescriptor.is() )
4691 xSheetFilterDescriptor->setFilterFields2( uno::Sequence< sheet::TableFilterField2 >() );
4693 xDBRangeProps->setPropertyValue(
"AutoFilter",
uno::Any(!bHasAuto) );
4707 sheet::CellInsertMode
mode = sheet::CellInsertMode_NONE;
4710 sal_Int32 nShift = 0;
4714 case excel::XlInsertShiftDirection::xlShiftToRight:
4715 mode = sheet::CellInsertMode_RIGHT;
4717 case excel::XlInsertShiftDirection::xlShiftDown:
4718 mode = sheet::CellInsertMode_DOWN;
4721 throw uno::RuntimeException(
"Illegal parameter " );
4727 mode = sheet::CellInsertMode_DOWN;
4729 mode = sheet::CellInsertMode_RIGHT;
4731 RangeHelper thisRange(
mxRange );
4732 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4733 uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
4734 xCellRangeMove->insertCells( thisAddress, mode );
4743 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 ) );
4753 sal_Int32 nLen =
m_Areas->getCount();
4772 RangeHelper thisRange(
mxRange );
4773 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
4775 std::vector<sc::ColRowSpan> aColArr(1,
sc::ColRowSpan(thisAddress.StartColumn,thisAddress.EndColumn));
4776 bool bDirection =
true;
4780 aColArr[0].mnStart = thisAddress.StartRow;
4781 aColArr[0].mnEnd = thisAddress.EndRow;
4783 pDocShell->GetDocFunc().SetWidthOrHeight(
4784 bDirection, aColArr, thisAddress.Sheet,
SC_SIZE_OPTIMAL, 0,
true,
true);
4795 uno::Reference< excel::XWorksheet > xWorksheet(
getParent(), uno::UNO_QUERY_THROW );
4796 uno::Reference< excel::XHyperlinks > xSheetHlinks( xWorksheet->Hyperlinks(
uno::Any() ), uno::UNO_QUERY_THROW );
4797 ScVbaHyperlinksRef xScSheetHlinks( dynamic_cast< ScVbaHyperlinks* >( xSheetHlinks.get() ) );
4798 if( !xScSheetHlinks.is() )
4799 throw uno::RuntimeException(
"Cannot obtain hyperlinks implementation object" );
4804 return xHlinks->Item( aIndex,
uno::Any() );
4805 return uno::Any( uno::Reference< excel::XHyperlinks >( xHlinks ) );
4808 css::uno::Reference< excel::XValidation > SAL_CALL
4819 sal_Unicode lclGetPrefixChar(
const uno::Reference< table::XCell >& rxCell )
4829 return (rxCell->getType() == table::CellContentType_TEXT) ?
'\'' : 0;
4833 sal_Unicode lclGetPrefixChar(
const uno::Reference< table::XCellRange >& rxRange )
4842 table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxRange );
4843 sal_Int32 nEndCol = aRangeAddr.EndColumn - aRangeAddr.StartColumn;
4844 sal_Int32 nEndRow = aRangeAddr.EndRow - aRangeAddr.StartRow;
4845 for( sal_Int32 nRow = 0; nRow <= nEndRow; ++nRow )
4847 for( sal_Int32 nCol = 0; nCol <= nEndCol; ++nCol )
4849 uno::Reference< table::XCell > xCell( rxRange->getCellByPosition( nCol, nRow ), uno::UNO_SET_THROW );
4850 sal_Unicode cNewPrefix = lclGetPrefixChar( xCell );
4851 if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) )
4853 cCurrPrefix = cNewPrefix;
4861 sal_Unicode lclGetPrefixChar(
const uno::Reference< sheet::XSheetCellRangeContainer >& rxRanges )
4864 uno::Reference< container::XEnumerationAccess > xRangesEA( rxRanges, uno::UNO_QUERY_THROW );
4865 uno::Reference< container::XEnumeration > xRangesEnum( xRangesEA->createEnumeration(), uno::UNO_SET_THROW );
4866 while( xRangesEnum->hasMoreElements() )
4868 uno::Reference< table::XCellRange > xRange( xRangesEnum->nextElement(), uno::UNO_QUERY_THROW );
4869 sal_Unicode cNewPrefix = lclGetPrefixChar( xRange );
4870 if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) )
4872 cCurrPrefix = cNewPrefix;
4880 return uno::Any( (cPrefixChar == 0) ? OUString() : OUString( cPrefixChar ) );
4904 return lclGetPrefixVariant( lclGetPrefixChar(
mxRange ) );
4906 return lclGetPrefixVariant( lclGetPrefixChar(
mxRanges ) );
4907 throw uno::RuntimeException(
"Unexpected empty Range object" );
4916 throw uno::RuntimeException(
"Can not get Range.ShowDetail attribute " );
4919 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor();
4920 xSheetCellCursor->collapseToCurrentRegion();
4921 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
4922 table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress();
4925 table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress();
4926 if( (thisAddress.StartRow != thisAddress.EndRow || thisAddress.EndRow != aOutlineAddress.EndRow ) &&
4927 (thisAddress.StartColumn != thisAddress.EndColumn || thisAddress.EndColumn != aOutlineAddress.EndColumn ))
4929 throw uno::RuntimeException(
"Can not set Range.ShowDetail attribute" );
4932 bool bColumn = thisAddress.StartRow != thisAddress.EndRow;
4936 SCCOLROW nPos = bColumn ?
static_cast<SCCOLROW>(thisAddress.EndColumn-1):static_cast<SCCOLROW>(thisAddress.EndRow-1);
4940 const bool bShowDetail = !pEntry->
IsHidden();
4953 throw uno::RuntimeException(
"Can not set Range.ShowDetail attribute" );
4958 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor();
4959 xSheetCellCursor->collapseToCurrentRegion();
4960 uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
4961 table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress();
4964 table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress();
4965 if( (thisAddress.StartRow != thisAddress.EndRow || thisAddress.EndRow != aOutlineAddress.EndRow ) &&
4966 (thisAddress.StartColumn != thisAddress.EndColumn || thisAddress.EndColumn != aOutlineAddress.EndColumn ))
4968 throw uno::RuntimeException(
"Can not set Range.ShowDetail attribute" );
4973 uno::Reference< sheet::XSheetOutline > xSheetOutline( helper.getSpreadSheet(), uno::UNO_QUERY_THROW );
4975 xSheetOutline->showDetail( aOutlineAddress );
4977 xSheetOutline->hideDetail( aOutlineAddress );
4981 uno::Reference< excel::XRange > SAL_CALL
4984 uno::Reference< sheet::XSheetCellRange > xMergeShellCellRange(
mxRange->getCellRangeByPosition(0,0,0,0), uno::UNO_QUERY_THROW);
4985 uno::Reference< sheet::XSheetCellCursor > xMergeSheetCursor(xMergeShellCellRange->getSpreadsheet()->createCursorByRange( xMergeShellCellRange ), uno::UNO_SET_THROW);
4986 if( xMergeSheetCursor.is() )
4988 xMergeSheetCursor->collapseToMergedArea();
4989 uno::Reference<sheet::XCellRangeAddressable> xMergeCellAddress(xMergeSheetCursor, uno::UNO_QUERY_THROW);
4990 table::CellRangeAddress aCellAddress = xMergeCellAddress->getRangeAddress();
4991 if( aCellAddress.StartColumn ==0 && aCellAddress.EndColumn==0 &&
4992 aCellAddress.StartRow==0 && aCellAddress.EndRow==0)
4998 ScRange refRange( static_cast< SCCOL >( aCellAddress.StartColumn ), static_cast< SCROW >( aCellAddress.StartRow ), static_cast< SCTAB >( aCellAddress.Sheet ),
4999 static_cast< SCCOL >( aCellAddress.EndColumn ), static_cast< SCROW >( aCellAddress.EndRow ), static_cast< SCTAB >( aCellAddress.Sheet ) );
5012 sal_Int32 nItems =
m_Areas->getCount();
5013 uno::Sequence< table::CellRangeAddress > printAreas( nItems );
5014 auto printAreasRange = asNonConstRange(printAreas);
5015 uno::Reference< sheet::XPrintAreas > xPrintAreas;
5020 RangeHelper thisRange( xRange->getCellRange() );
5021 table::CellRangeAddress rangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
5027 xPrintAreas.set( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
5029 printAreasRange[
index - 1 ] = rangeAddress;
5031 if ( pShell && xPrintAreas.is() )
5033 xPrintAreas->setPrintAreas( printAreas );
5042 uno::Reference< excel::XRange > xDest( Destination, uno::UNO_SET_THROW );
5044 RangeHelper destRangeHelper( pRange->
mxRange );
5045 table::CellRangeAddress destAddress = destRangeHelper.getCellRangeAddressable()->getRangeAddress();
5047 RangeHelper thisRange(
mxRange );
5048 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
5059 ScRange aSourceRange( destRange );
5065 if ( sourceRange != destRange )
5073 aSourceRange.
aEnd.
SetCol( static_cast<SCCOL>( aSourceRange.
aStart.
Col() + nSourceCount - 1 ) );
5079 aSourceRange.
aEnd.
SetRow( static_cast<SCROW>( aSourceRange.
aStart.
Row() + nSourceCount ) - 1 );
5085 else if ( aSourceRange.
aEnd == destRange.
aEnd )
5089 aSourceRange.
aStart.
SetRow( static_cast<SCROW>( aSourceRange.
aEnd.
Row() - nSourceCount + 1 ) );
5097 aSourceRange.
aStart.
SetCol( static_cast<SCCOL>( aSourceRange.
aEnd.
Col() - nSourceCount + 1 ) );
5110 sal_Int16 nFillType = excel::XlAutoFillType::xlFillDefault;
5112 switch ( nFillType )
5114 case excel::XlAutoFillType::xlFillCopy:
5118 case excel::XlAutoFillType::xlFillDays:
5121 case excel::XlAutoFillType::xlFillMonths:
5125 case excel::XlAutoFillType::xlFillWeekdays:
5129 case excel::XlAutoFillType::xlFillYears:
5133 case excel::XlAutoFillType::xlGrowthTrend:
5136 case excel::XlAutoFillType::xlFillFormats:
5137 throw uno::RuntimeException(
"xlFillFormat not supported for AutoFill" );
5138 case excel::XlAutoFillType::xlFillValues:
5139 case excel::XlAutoFillType::xlFillSeries:
5140 case excel::XlAutoFillType::xlLinearTrend:
5143 case excel::XlAutoFillType::xlFillDefault:
5159 if ( pDocShell && pRange )
5161 uno::Reference< sheet::XGoalSeek > xGoalSeek( pDocShell->
GetModel(), uno::UNO_QUERY_THROW );
5162 RangeHelper thisRange(
mxRange );
5163 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
5164 RangeHelper changingCellRange( pRange->
mxRange );
5165 table::CellRangeAddress changingCellAddr = changingCellRange.getCellRangeAddressable()->getRangeAddress();
5167 table::CellAddress thisCell( thisAddress.Sheet, thisAddress.StartColumn, thisAddress.StartRow );
5168 table::CellAddress changingCell( changingCellAddr.Sheet, changingCellAddr.StartColumn, changingCellAddr.StartRow );
5169 sheet::GoalResult res = xGoalSeek->seekGoal( thisCell, changingCell, sGoal );
5170 ChangingCell->setValue(
uno::Any( res.Result ) );
5175 if ( ( res.Divergence != 0.0 ) && ( res.Result == 0.0 ) )
5189 uno::Reference< excel::XRange > SAL_CALL
5196 uno::Reference< excel::XRange > xRange;
5200 xRange =
Rows( row );
5203 return Cells( row, column );
5211 if (
m_Areas->getCount() > 1 )
5218 RangeHelper thisRange(
mxRange );
5219 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
5223 uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
5224 xSheetOutline->autoOutline( thisAddress );
5233 if (
m_Areas->getCount() > 1 )
5235 sal_Int32 nItems =
m_Areas->getCount();
5239 xRange->ClearOutline();
5243 RangeHelper thisRange(
mxRange );
5244 uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
5245 xSheetOutline->clearOutline();
5251 if (
m_Areas->getCount() > 1 )
5253 table::TableOrientation nOrient = table::TableOrientation_ROWS;
5255 nOrient = table::TableOrientation_COLUMNS;
5256 RangeHelper thisRange(
mxRange );
5257 table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
5258 uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
5260 xSheetOutline->ungroup( thisAddress, nOrient );
5262 xSheetOutline->group( thisAddress, nOrient );
5279 uno::Reference< util::XMergeable > xMergeable( xCellRange, uno::UNO_QUERY_THROW );
5280 xMergeable->merge(_bMerge);
5285 if (
m_Areas->getCount() > 1 )
5287 sal_Int32 nItems =
m_Areas->getCount();
5291 xRange->Merge(Across);
5295 bool bAcross =
false;
5301 uno::Reference< excel::XRange > oRangeRowsImpl =
Rows(
uno::Any() );
5303 for (sal_Int32
i=1;
i <= oRangeRowsImpl->getCount();
i++)
5313 if (
m_Areas->getCount() > 1 )
5315 sal_Int32 nItems =
m_Areas->getCount();
5329 if (
m_Areas->getCount() > 1 )
5331 uno::Reference< excel::XRange > xRange(
m_Areas->Item(
uno::Any( sal_Int32( 1 ) ),