[Libreoffice-commits] core.git: sc/qa sc/source

Arkadiy Illarionov (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 9 14:59:27 UTC 2019


 sc/qa/unit/helper/qahelper.cxx                   |    4 
 sc/source/core/data/documen5.cxx                 |   10 --
 sc/source/core/data/dpobject.cxx                 |   10 --
 sc/source/core/data/dpoutput.cxx                 |   22 +---
 sc/source/core/data/dpresfilter.cxx              |   10 --
 sc/source/core/data/dptabsrc.cxx                 |   24 ++--
 sc/source/core/data/tabprotection.cxx            |   11 --
 sc/source/core/tool/addincol.cxx                 |   64 ++++---------
 sc/source/core/tool/appoptio.cxx                 |    4 
 sc/source/core/tool/charthelper.cxx              |    9 +
 sc/source/core/tool/rangeseq.cxx                 |   18 +--
 sc/source/core/tool/rangeutl.cxx                 |    4 
 sc/source/core/tool/unitconv.cxx                 |    6 -
 sc/source/core/tool/userlist.cxx                 |    8 -
 sc/source/filter/excel/xechart.cxx               |   72 ++++++--------
 sc/source/filter/excel/xeescher.cxx              |   16 +--
 sc/source/filter/ftools/fapihelper.cxx           |    7 -
 sc/source/filter/oox/formulabase.cxx             |   12 --
 sc/source/filter/oox/workbookhelper.cxx          |   18 +--
 sc/source/filter/xcl97/xcl97esc.cxx              |    7 -
 sc/source/filter/xcl97/xcl97rec.cxx              |    4 
 sc/source/filter/xml/XMLCodeNameProvider.cxx     |    7 -
 sc/source/filter/xml/XMLExportDatabaseRanges.cxx |   11 --
 sc/source/filter/xml/xmlcvali.cxx                |   16 +--
 sc/source/filter/xml/xmlimprt.cxx                |   69 ++++++--------
 sc/source/filter/xml/xmlstyli.cxx                |    4 
 sc/source/ui/Accessibility/AccessibleCell.cxx    |   13 --
 sc/source/ui/Accessibility/AccessibleGlobal.cxx  |   11 --
 sc/source/ui/cctrl/tbzoomsliderctrl.cxx          |    7 -
 sc/source/ui/dbgui/dapidata.cxx                  |   10 --
 sc/source/ui/dbgui/tpsort.cxx                    |    4 
 sc/source/ui/docshell/docsh2.cxx                 |    7 -
 sc/source/ui/miscdlgs/optsolver.cxx              |   16 +--
 sc/source/ui/miscdlgs/solveroptions.cxx          |    4 
 sc/source/ui/miscdlgs/solverutil.cxx             |    3 
 sc/source/ui/unoobj/appluno.cxx                  |    5 -
 sc/source/ui/unoobj/celllistsource.cxx           |    9 +
 sc/source/ui/unoobj/cellsuno.cxx                 |   85 ++++++-----------
 sc/source/ui/unoobj/cellvaluebinding.cxx         |    9 +
 sc/source/ui/unoobj/chart2uno.cxx                |   41 ++++----
 sc/source/ui/unoobj/chartuno.cxx                 |   31 +-----
 sc/source/ui/unoobj/condformatuno.cxx            |    8 -
 sc/source/ui/unoobj/cursuno.cxx                  |    4 
 sc/source/ui/unoobj/dapiuno.cxx                  |   39 +++----
 sc/source/ui/unoobj/datauno.cxx                  |   18 +--
 sc/source/ui/unoobj/defltuno.cxx                 |    6 -
 sc/source/ui/unoobj/dispuno.cxx                  |   10 --
 sc/source/ui/unoobj/docuno.cxx                   |   66 +++++--------
 sc/source/ui/unoobj/eventuno.cxx                 |    4 
 sc/source/ui/unoobj/filtuno.cxx                  |    5 -
 sc/source/ui/unoobj/fmtuno.cxx                   |    6 -
 sc/source/ui/unoobj/funcuno.cxx                  |    7 -
 sc/source/ui/unoobj/shapeuno.cxx                 |   19 +--
 sc/source/ui/unoobj/styleuno.cxx                 |   28 ++---
 sc/source/ui/unoobj/viewuno.cxx                  |    5 -
 sc/source/ui/vba/vbachart.cxx                    |    7 -
 sc/source/ui/vba/vbachartobjects.cxx             |   14 +-
 sc/source/ui/vba/vbaeventshelper.cxx             |   10 --
 sc/source/ui/vba/vbapagebreaks.cxx               |   18 +--
 sc/source/ui/vba/vbapagesetup.cxx                |    7 -
 sc/source/ui/vba/vbarange.cxx                    |   27 ++---
 sc/source/ui/vba/vbasheetobject.cxx              |   13 +-
 sc/source/ui/vba/vbaworkbook.cxx                 |   69 ++++++--------
 sc/source/ui/vba/vbaworksheets.cxx               |    5 -
 sc/source/ui/vba/vbawsfunction.cxx               |    6 -
 sc/source/ui/view/dbfunc3.cxx                    |    7 -
 sc/source/ui/view/drawvie4.cxx                   |   14 +-
 sc/source/ui/view/viewdata.cxx                   |  113 +++++++++++------------
 68 files changed, 494 insertions(+), 743 deletions(-)

New commits:
commit fca94779872b8ba0b0583d0b7068f1a46beb88c5
Author:     Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sat Aug 3 22:59:04 2019 +0300
Commit:     Arkadiy Illarionov <qarkai at gmail.com>
CommitDate: Fri Aug 9 16:58:06 2019 +0200

    Simplify Sequence iterations in sc
    
    Use range-based loops, STL and comphelper functions
    
    Change-Id: I047fb2e6ec9591166339b9748c5013a32185f14b
    Reviewed-on: https://gerrit.libreoffice.org/76912
    Tested-by: Jenkins
    Reviewed-by: Arkadiy Illarionov <qarkai at gmail.com>

diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index c5f183161a78..219d47635feb 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -11,6 +11,7 @@
 #include "csv_handler.hxx"
 #include "debughelper.hxx"
 #include <drwlayer.hxx>
+#include <comphelper/sequence.hxx>
 #include <compiler.hxx>
 #include <conditio.hxx>
 #include <stlsheet.hxx>
@@ -375,8 +376,7 @@ std::vector<OUString> getChartRangeRepresentations(const SdrOle2Obj& rChartObj)
     }
 
     Sequence<OUString> aRangeRepSeqs = xDataRec->getUsedRangeRepresentations();
-    for (sal_Int32 i = 0, n = aRangeRepSeqs.getLength(); i < n; ++i)
-        aRangeReps.push_back(aRangeRepSeqs[i]);
+    comphelper::sequenceToContainer(aRangeReps, aRangeRepSeqs);
 
     return aRangeReps;
 }
diff --git a/sc/source/core/data/documen5.cxx b/sc/source/core/data/documen5.cxx
index ea449fc6cdda..198cba53017e 100644
--- a/sc/source/core/data/documen5.cxx
+++ b/sc/source/core/data/documen5.cxx
@@ -57,11 +57,8 @@ static void lcl_GetChartParameters( const uno::Reference< chart2::XChartDocument
     {
         uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xDataSource ) );
 
-        const beans::PropertyValue* pPropArray = aArgs.getConstArray();
-        long nPropCount = aArgs.getLength();
-        for (long i = 0; i < nPropCount; i++)
+        for (const beans::PropertyValue& rProp : aArgs)
         {
-            const beans::PropertyValue& rProp = pPropArray[i];
             OUString aPropName(rProp.Name);
 
             if ( aPropName == "CellRangeRepresentation" )
@@ -377,12 +374,11 @@ void ScDocument::RestoreChartListener( const OUString& rName )
         {
             uno::Sequence<OUString> aRepresentations( xReceiver->getUsedRangeRepresentations() );
             ScRangeListRef aRanges = new ScRangeList;
-            sal_Int32 nRangeCount = aRepresentations.getLength();
-            for ( sal_Int32 i=0; i<nRangeCount; i++ )
+            for ( const auto& rRepresentation : aRepresentations )
             {
                 ScRange aRange;
                 ScAddress::Details aDetails(GetAddressConvention(), 0, 0);
-                if ( aRange.ParseAny( aRepresentations[i], this, aDetails ) & ScRefFlags::VALID )
+                if ( aRange.ParseAny( rRepresentation, this, aDetails ) & ScRefFlags::VALID )
                     aRanges->push_back( aRange );
             }
 
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 57c1b7723c71..16e8e794d019 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -1175,10 +1175,8 @@ bool ScDPObject::IsDimNameInUse(const OUString& rName) const
 
     Reference<container::XNameAccess> xDims = xSource->getDimensions();
     Sequence<OUString> aDimNames = xDims->getElementNames();
-    sal_Int32 n = aDimNames.getLength();
-    for (sal_Int32 i = 0; i < n; ++i)
+    for (const OUString& rDimName : aDimNames)
     {
-        const OUString& rDimName = aDimNames[i];
         if (rDimName.equalsIgnoreAsciiCase(rName))
             return true;
 
@@ -2121,10 +2119,8 @@ static PivotFunc lcl_FirstSubTotal( const uno::Reference<beans::XPropertySet>& x
                 if ( aSubAny >>= aSeq )
                 {
                     PivotFunc nMask = PivotFunc::NONE;
-                    const sal_Int16* pArray = aSeq.getConstArray();
-                    long nCount = aSeq.getLength();
-                    for (long i=0; i<nCount; i++)
-                        nMask |= ScDataPilotConversion::FunctionBit(pArray[i]);
+                    for (const sal_Int16 nElem : aSeq)
+                        nMask |= ScDataPilotConversion::FunctionBit(nElem);
                     return nMask;
                 }
             }
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index cb117b6a6f90..1fc5a06a4739 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -443,13 +443,9 @@ bool lcl_MemberEmpty( const uno::Sequence<sheet::MemberResult>& rSeq )
 {
     //  used to skip levels that have no members
 
-    long nLen = rSeq.getLength();
-    const sheet::MemberResult* pArray = rSeq.getConstArray();
-    for (long i=0; i<nLen; i++)
-        if (pArray[i].Flags & sheet::MemberResultFlags::HASMEMBER)
-            return false;
-
-    return true;    // no member data -> empty
+    return std::none_of(rSeq.begin(), rSeq.end(),
+        [](const sheet::MemberResult& rMem) {
+            return rMem.Flags & sheet::MemberResultFlags::HASMEMBER; });
 }
 
 /**
@@ -471,9 +467,8 @@ uno::Sequence<sheet::MemberResult> getVisiblePageMembersAsResults( const uno::Re
 
     std::vector<sheet::MemberResult> aRes;
     uno::Sequence<OUString> aNames = xNA->getElementNames();
-    for (sal_Int32 i = 0; i < aNames.getLength(); ++i)
+    for (const OUString& rName : aNames)
     {
-        const OUString& rName = aNames[i];
         xNA->getByName(rName);
 
         uno::Reference<beans::XPropertySet> xMemPS(xNA->getByName(rName), UNO_QUERY);
@@ -1188,13 +1183,10 @@ void ScDPOutput::GetMemberResultNames(ScDPUniqueStringSet& rNames, long nDimensi
 
     if ( bFound )
     {
-        const sheet::MemberResult* pArray = aMemberResults.getConstArray();
-        long nResultCount = aMemberResults.getLength();
-
-        for (long nItem=0; nItem<nResultCount; nItem++)
+        for (const sheet::MemberResult& rMemberResult : aMemberResults)
         {
-            if ( pArray[nItem].Flags & sheet::MemberResultFlags::HASMEMBER )
-                rNames.insert(pArray[nItem].Name);
+            if ( rMemberResult.Flags & sheet::MemberResultFlags::HASMEMBER )
+                rNames.insert(rMemberResult.Name);
         }
     }
 }
diff --git a/sc/source/core/data/dpresfilter.cxx b/sc/source/core/data/dpresfilter.cxx
index 2efb4563f8ee..1e6da5ee3410 100644
--- a/sc/source/core/data/dpresfilter.cxx
+++ b/sc/source/core/data/dpresfilter.cxx
@@ -199,13 +199,11 @@ void ScDPResultTree::clear()
 const ScDPResultTree::ValuesType* ScDPResultTree::getResults(
     const uno::Sequence<sheet::DataPilotFieldFilter>& rFilters) const
 {
-    const sheet::DataPilotFieldFilter* p = rFilters.getConstArray();
-    const sheet::DataPilotFieldFilter* pEnd = p + static_cast<size_t>(rFilters.getLength());
     const MemberNode* pMember = mpRoot.get();
-    for (; p != pEnd; ++p)
+    for (const sheet::DataPilotFieldFilter& rFilter : rFilters)
     {
         auto itDim = pMember->maChildDimensions.find(
-            ScGlobal::pCharClass->uppercase(p->FieldName));
+            ScGlobal::pCharClass->uppercase(rFilter.FieldName));
 
         if (itDim == pMember->maChildDimensions.end())
             // Specified dimension not found.
@@ -213,12 +211,12 @@ const ScDPResultTree::ValuesType* ScDPResultTree::getResults(
 
         const DimensionNode* pDim = itDim->second.get();
         MembersType::const_iterator itMem( pDim->maChildMembersValueNames.find(
-                    ScGlobal::pCharClass->uppercase( p->MatchValueName)));
+                    ScGlobal::pCharClass->uppercase( rFilter.MatchValueName)));
 
         if (itMem == pDim->maChildMembersValueNames.end())
         {
             // Specified member name not found, try locale independent value.
-            itMem = pDim->maChildMembersValues.find( ScGlobal::pCharClass->uppercase( p->MatchValue));
+            itMem = pDim->maChildMembersValues.find( ScGlobal::pCharClass->uppercase( rFilter.MatchValue));
 
             if (itMem == pDim->maChildMembersValues.end())
                 // Specified member not found.
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index c72f34a559cc..fac81c88e24a 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -433,10 +433,8 @@ Sequence< Sequence<Any> > SAL_CALL ScDPSource::getDrillDownData(const Sequence<s
     long nColumnCount = GetData()->GetColumnCount();
 
     vector<ScDPFilteredCache::Criterion> aFilterCriteria;
-    sal_Int32 nFilterCount = aFilters.getLength();
-    for (sal_Int32 i = 0; i < nFilterCount; ++i)
+    for (const sheet::DataPilotFieldFilter& rFilter : aFilters)
     {
-        const sheet::DataPilotFieldFilter& rFilter = aFilters[i];
         const OUString& aFieldName = rFilter.FieldName;
         for (long nCol = 0; nCol < nColumnCount; ++nCol)
         {
@@ -2091,10 +2089,9 @@ void SAL_CALL ScDPLevel::setPropertyValue( const OUString& aPropertyName, const
         uno::Sequence<sheet::GeneralFunction> aSeq;
         aValue >>= aSeq;
         aSubTotals.realloc(aSeq.getLength());
-        for (sal_Int32 nIndex = 0; nIndex < aSeq.getLength(); nIndex++)
-        {
-            aSubTotals[nIndex] = static_cast<sal_Int16>(aSeq[nIndex]);
-        }
+        std::transform(aSeq.begin(), aSeq.end(), aSubTotals.begin(),
+            [](const sheet::GeneralFunction& rFunc) -> sal_Int16 {
+                return static_cast<sal_Int16>(rFunc); });
     }
     else if ( aPropertyName == SC_UNO_DP_SUBTOTAL2 )
         aValue >>= aSubTotals;
@@ -2122,13 +2119,12 @@ uno::Any SAL_CALL ScDPLevel::getPropertyValue( const OUString& aPropertyName )
         uno::Sequence<sal_Int16> aSeq = getSubTotals();
         uno::Sequence<sheet::GeneralFunction> aNewSeq;
         aNewSeq.realloc(aSeq.getLength());
-        for (sal_Int32 nIndex = 0; nIndex < aSeq.getLength(); nIndex++)
-        {
-            if (aSeq[nIndex] == sheet::GeneralFunction2::MEDIAN)
-                aNewSeq[nIndex] = sheet::GeneralFunction_NONE;
-            else
-                aNewSeq[nIndex] = static_cast<sheet::GeneralFunction>(aSeq[nIndex]);
-        }
+        std::transform(aSeq.begin(), aSeq.end(), aNewSeq.begin(),
+            [](const sal_Int16 nFunc) -> sheet::GeneralFunction {
+                if (nFunc == sheet::GeneralFunction2::MEDIAN)
+                    return sheet::GeneralFunction_NONE;
+                return static_cast<sheet::GeneralFunction>(nFunc);
+            });
 
         aRet <<= aNewSeq;
     }
diff --git a/sc/source/core/data/tabprotection.cxx b/sc/source/core/data/tabprotection.cxx
index ea211bed1173..bf6076327bc7 100644
--- a/sc/source/core/data/tabprotection.cxx
+++ b/sc/source/core/data/tabprotection.cxx
@@ -21,6 +21,7 @@
 #include <svl/PasswordHelper.hxx>
 #include <comphelper/docpasswordhelper.hxx>
 #include <comphelper/hash.hxx>
+#include <comphelper/sequence.hxx>
 #include <osl/diagnose.h>
 #include <document.hxx>
 
@@ -186,11 +187,7 @@ Sequence<sal_Int8> ScTableProtectionImpl::hashPassword(
     // TODO: Right now, we only support double-hash by SHA1.
     if (eHash == PASSHASH_SHA1)
     {
-        vector<sal_Char> aChars;
-        sal_Int32 n = rPassHash.getLength();
-        aChars.reserve(n);
-        for (sal_Int32 i = 0; i < n; ++i)
-            aChars.push_back(static_cast<sal_Char>(rPassHash[i]));
+        auto aChars = comphelper::sequenceToContainer<vector<sal_Char>>(rPassHash);
 
         Sequence<sal_Int8> aNewHash;
         SvPasswordHelper::GetHashPassword(aNewHash, aChars.data(), aChars.size());
@@ -328,8 +325,8 @@ void ScTableProtectionImpl::setPasswordHash(
     maPassHash = aPassword;
 
 #if DEBUG_TAB_PROTECTION
-    for (sal_Int32 i = 0; i < nLen; ++i)
-        printf("%2.2X ", static_cast<sal_uInt8>(aPassword[i]));
+    for (sal_Int8 n : aPassword)
+        printf("%2.2X ", static_cast<sal_uInt8>(n));
     printf("\n");
 #endif
 }
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx
index 7279aa4029ec..63eb607e9264 100644
--- a/sc/source/core/tool/addincol.cxx
+++ b/sc/source/core/tool/addincol.cxx
@@ -115,16 +115,11 @@ const ::std::vector<ScUnoAddInFuncData::LocalizedName>& ScUnoAddInFuncData::GetC
                 OUString aMethodName = xFunction->getName();
                 uno::Sequence< sheet::LocalizedName> aCompNames( xComp->getCompatibilityNames( aMethodName ));
                 maCompNames.clear();
-                sal_Int32 nSeqLen = aCompNames.getLength();
-                if ( nSeqLen )
+                for (const sheet::LocalizedName& rCompName : aCompNames)
                 {
-                    const sheet::LocalizedName* pArray = aCompNames.getArray();
-                    for (sal_Int32 i=0; i<nSeqLen; i++)
-                    {
-                        maCompNames.emplace_back(
-                                    LanguageTag::convertToBcp47( pArray[i].Locale, false),
-                                    pArray[i].Name);
-                    }
+                    maCompNames.emplace_back(
+                                LanguageTag::convertToBcp47( rCompName.Locale, false),
+                                rCompName.Name);
                 }
             }
         }
@@ -355,10 +350,8 @@ void ScUnoAddInCollection::ReadConfiguration()
     // get the list of add-ins (services)
     uno::Sequence<OUString> aServiceNames = rAddInConfig.GetNodeNames( "" );
 
-    sal_Int32 nServiceCount = aServiceNames.getLength();
-    for ( sal_Int32 nService = 0; nService < nServiceCount; nService++ )
+    for ( const OUString& aServiceName : aServiceNames )
     {
-        OUString aServiceName = aServiceNames[nService];
         ScUnoAddInHelpIdGenerator aHelpIdGenerator( aServiceName );
 
         OUString aFunctionsPath(aServiceName + sSlash + CFGSTR_ADDINFUNCTIONS);
@@ -446,17 +439,14 @@ void ScUnoAddInCollection::ReadConfiguration()
                     uno::Sequence<beans::PropertyValue> aLocalEntries;
                     if ( aCompProperties[0] >>= aLocalEntries )
                     {
-                        sal_Int32 nLocaleCount = aLocalEntries.getLength();
-                        const beans::PropertyValue* pConfigArray = aLocalEntries.getConstArray();
-
-                        for ( sal_Int32 nLocale = 0; nLocale < nLocaleCount; nLocale++ )
+                        for ( const beans::PropertyValue& rConfig : aLocalEntries )
                         {
                             // PropertyValue name is the locale ("convert" from
                             // string to canonicalize)
-                            OUString aLocale( LanguageTag( pConfigArray[nLocale].Name, true).getBcp47( false));
+                            OUString aLocale( LanguageTag( rConfig.Name, true).getBcp47( false));
                             // PropertyValue value is the localized value (string in this case)
                             OUString aName;
-                            pConfigArray[nLocale].Value >>= aName;
+                            rConfig.Value >>= aName;
                             aCompNames.emplace_back( aLocale, aName);
                         }
                     }
@@ -477,14 +467,12 @@ void ScUnoAddInCollection::ReadConfiguration()
                     uno::Sequence<OUString> aArgPropNames( nArgumentCount * 2 );
                     OUString* pPropNameArray = aArgPropNames.getArray();
 
-                    sal_Int32 nArgument;
                     sal_Int32 nIndex = 0;
-                    const OUString* pArgNameArray = aArgumentNames.getConstArray();
-                    for ( nArgument = 0; nArgument < nArgumentCount; nArgument++ )
+                    for ( const OUString& rArgName : aArgumentNames )
                     {
                         OUString aOneArgPath = aArgumentsPath;
                         aOneArgPath += sSlash;
-                        aOneArgPath += pArgNameArray[nArgument];
+                        aOneArgPath += rArgName;
                         aOneArgPath += sSlash;
 
                         pPropNameArray[nIndex++] = aOneArgPath
@@ -496,6 +484,7 @@ void ScUnoAddInCollection::ReadConfiguration()
                     uno::Sequence<uno::Any> aArgProperties = rAddInConfig.GetProperties( aArgPropNames );
                     if ( aArgProperties.getLength() == aArgPropNames.getLength() )
                     {
+                        const OUString* pArgNameArray = aArgumentNames.getConstArray();
                         const uno::Any* pPropArray = aArgProperties.getConstArray();
                         OUString sDisplayName;
                         OUString sDescription;
@@ -508,7 +497,7 @@ void ScUnoAddInCollection::ReadConfiguration()
                         pVisibleArgs.reset(new ScAddInArgDesc[nVisibleCount]);
 
                         nIndex = 0;
-                        for ( nArgument = 0; nArgument < nArgumentCount; nArgument++ )
+                        for ( sal_Int32 nArgument = 0; nArgument < nArgumentCount; nArgument++ )
                         {
                             pPropArray[nIndex++] >>= sDisplayName;
                             pPropArray[nIndex++] >>= sDescription;
@@ -998,11 +987,8 @@ void ScUnoAddInCollection::UpdateFromAddIn( const uno::Reference<uno::XInterface
     {
         uno::Sequence< uno::Reference<reflection::XIdlMethod> > aMethods =
                 xAcc->getMethods( beans::MethodConcept::ALL );
-        long nMethodCount = aMethods.getLength();
-        const uno::Reference<reflection::XIdlMethod>* pArray = aMethods.getConstArray();
-        for (long nFuncPos=0; nFuncPos<nMethodCount; nFuncPos++)
+        for (const uno::Reference<reflection::XIdlMethod>& xFunc : aMethods)
         {
-            uno::Reference<reflection::XIdlMethod> xFunc = pArray[nFuncPos];
             if (xFunc.is())
             {
                 OUString aFuncU = xFunc->getName();
@@ -1031,8 +1017,7 @@ void ScUnoAddInCollection::UpdateFromAddIn( const uno::Reference<uno::XInterface
                             xFunc->getParameterInfos();
                     long nParamCount = aParams.getLength();
                     const reflection::ParamInfo* pParArr = aParams.getConstArray();
-                    long nParamPos;
-                    for (nParamPos=0; nParamPos<nParamCount; nParamPos++)
+                    for (long nParamPos=0; nParamPos<nParamCount; nParamPos++)
                     {
                         if ( pParArr[nParamPos].aMode != reflection::ParamMode_IN )
                             bValid = false;
@@ -1054,15 +1039,15 @@ void ScUnoAddInCollection::UpdateFromAddIn( const uno::Reference<uno::XInterface
                             ScAddInArgDesc aDesc;
                             pVisibleArgs.reset(new ScAddInArgDesc[nVisibleCount]);
                             long nDestPos = 0;
-                            for (nParamPos=0; nParamPos<nParamCount; nParamPos++)
+                            for (const auto& rParam : aParams)
                             {
                                 uno::Reference<reflection::XIdlClass> xParClass =
-                                    pParArr[nParamPos].aType;
+                                    rParam.aType;
                                 ScAddInArgumentType eArgType = lcl_GetArgType( xParClass );
                                 if ( eArgType != SC_ADDINARG_CALLER )
                                 {
                                     const ScAddInArgDesc* pOldArgDesc =
-                                        lcl_FindArgDesc( *pOldData, pParArr[nParamPos].aName );
+                                        lcl_FindArgDesc( *pOldData, rParam.aName );
                                     if ( pOldArgDesc )
                                     {
                                         aDesc.aName = pOldArgDesc->aName;
@@ -1078,7 +1063,7 @@ void ScUnoAddInCollection::UpdateFromAddIn( const uno::Reference<uno::XInterface
                                     aDesc.eType = eArgType;
                                     aDesc.bOptional = bOptional;
                                     //TODO: initialize aInternalName only from config?
-                                    aDesc.aInternalName = pParArr[nParamPos].aName;
+                                    aDesc.aInternalName = rParam.aName;
 
                                     pVisibleArgs[nDestPos++] = aDesc;
                                 }
@@ -1400,16 +1385,9 @@ void ScUnoAddInCall::ExecuteCall()
         uno::Sequence<uno::Any> aRealArgs( nDestLen );
         uno::Any* pDest = aRealArgs.getArray();
 
-        const uno::Any* pSource = aArgs.getConstArray();
-        long nSrcPos = 0;
-
-        for ( long nDestPos = 0; nDestPos < nDestLen; nDestPos++ )
-        {
-            if ( nDestPos == nCallPos )
-                pDest[nDestPos] = aCallerAny;
-            else
-                pDest[nDestPos] = pSource[nSrcPos++];
-        }
+        pDest = std::copy_n(aArgs.begin(), nCallPos, pDest);
+        *pDest = aCallerAny;
+        std::copy(std::next(aArgs.begin(), nCallPos), aArgs.end(), std::next(pDest));
 
         ExecuteCallWithArgs( aRealArgs );
     }
diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx
index c5cb0591bbaf..d181a450b795 100644
--- a/sc/source/core/tool/appoptio.cxx
+++ b/sc/source/core/tool/appoptio.cxx
@@ -176,9 +176,9 @@ static void lcl_SetSortList( const Any& rValue )
         {
             aList.clear();
 
-            for (long i=0; i<nCount; i++)
+            for (const auto& rStr : aSeq)
             {
-                ScUserListData* pNew = new ScUserListData( pArray[i] );
+                ScUserListData* pNew = new ScUserListData( rStr );
                 aList.push_back(pNew);
             }
         }
diff --git a/sc/source/core/tool/charthelper.cxx b/sc/source/core/tool/charthelper.cxx
index f6e065152d5d..b9a2de4f0ac5 100644
--- a/sc/source/core/tool/charthelper.cxx
+++ b/sc/source/core/tool/charthelper.cxx
@@ -203,9 +203,8 @@ void ScChartHelper::GetChartRanges( const uno::Reference< chart2::XChartDocument
 
     uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aLabeledDataSequences( xDataSource->getDataSequences() );
     rRanges.reserve(2*aLabeledDataSequences.getLength());
-    for( sal_Int32 nN=0;nN<aLabeledDataSequences.getLength();nN++)
+    for(const uno::Reference<chart2::data::XLabeledDataSequence>& xLabeledSequence : aLabeledDataSequences)
     {
-        uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aLabeledDataSequences[nN] );
         if(!xLabeledSequence.is())
             continue;
         uno::Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel());
@@ -236,9 +235,11 @@ void ScChartHelper::SetChartRanges( const uno::Reference< chart2::XChartDocument
 
         uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aLabeledDataSequences( xDataSource->getDataSequences() );
         sal_Int32 nRange=0;
-        for( sal_Int32 nN=0; (nN<aLabeledDataSequences.getLength()) && (nRange<rRanges.getLength()); nN++ )
+        for( uno::Reference<chart2::data::XLabeledDataSequence>& xLabeledSequence : aLabeledDataSequences )
         {
-            uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aLabeledDataSequences[nN] );
+            if( nRange >= rRanges.getLength() )
+                break;
+
             if(!xLabeledSequence.is())
                 continue;
             uno::Reference< beans::XPropertySet > xLabel( xLabeledSequence->getLabel(), uno::UNO_QUERY );
diff --git a/sc/source/core/tool/rangeseq.cxx b/sc/source/core/tool/rangeseq.cxx
index 33c90d9c67df..86b614b0853a 100644
--- a/sc/source/core/tool/rangeseq.cxx
+++ b/sc/source/core/tool/rangeseq.cxx
@@ -360,17 +360,17 @@ ScMatrixRef ScSequenceToMatrix::CreateMixedMatrix( const css::uno::Any & rAny )
     if ( rAny >>= aSequence )
     {
         sal_Int32 nRowCount = aSequence.getLength();
-        const uno::Sequence<uno::Any>* pRowArr = aSequence.getConstArray();
         sal_Int32 nMaxColCount = 0;
-        sal_Int32 nCol, nRow;
-        for (nRow=0; nRow<nRowCount; nRow++)
+        if (nRowCount)
         {
-            sal_Int32 nTmp = pRowArr[nRow].getLength();
-            if ( nTmp > nMaxColCount )
-                nMaxColCount = nTmp;
+            auto pRow = std::max_element(aSequence.begin(), aSequence.end(),
+                [](const uno::Sequence<uno::Any>& a, const uno::Sequence<uno::Any>& b) {
+                    return a.getLength() < b.getLength(); });
+            nMaxColCount = pRow->getLength();
         }
         if ( nMaxColCount && nRowCount )
         {
+            const uno::Sequence<uno::Any>* pRowArr = aSequence.getConstArray();
             OUString aUStr;
             xMatrix = new ScMatrix(
                     static_cast<SCSIZE>(nMaxColCount),
@@ -382,11 +382,11 @@ ScMatrixRef ScSequenceToMatrix::CreateMixedMatrix( const css::uno::Any & rAny )
                 OSL_FAIL( "ScSequenceToMatrix::CreateMixedMatrix: matrix exceeded max size, returning NULL matrix");
                 return nullptr;
             }
-            for (nRow=0; nRow<nRowCount; nRow++)
+            for (sal_Int32 nRow=0; nRow<nRowCount; nRow++)
             {
                 sal_Int32 nColCount = pRowArr[nRow].getLength();
                 const uno::Any* pColArr = pRowArr[nRow].getConstArray();
-                for (nCol=0; nCol<nColCount; nCol++)
+                for (sal_Int32 nCol=0; nCol<nColCount; nCol++)
                 {
                     double fVal;
                     uno::TypeClass eClass;
@@ -416,7 +416,7 @@ ScMatrixRef ScSequenceToMatrix::CreateMixedMatrix( const css::uno::Any & rAny )
                                     static_cast<SCSIZE>(nRow) );
                     }
                 }
-                for (nCol=nColCount; nCol<nMaxColCount; nCol++)
+                for (sal_Int32 nCol=nColCount; nCol<nMaxColCount; nCol++)
                 {
                     xMatrix->PutEmpty(
                             static_cast<SCSIZE>(nCol),
diff --git a/sc/source/core/tool/rangeutl.cxx b/sc/source/core/tool/rangeutl.cxx
index a29b33907869..a2058a3023fd 100644
--- a/sc/source/core/tool/rangeutl.cxx
+++ b/sc/source/core/tool/rangeutl.cxx
@@ -696,10 +696,8 @@ void ScRangeStringConverter::GetStringFromRangeList(
         sal_Unicode cSeparator )
 {
     OUString sRangeListStr;
-    sal_Int32 nCount = rRangeSeq.getLength();
-    for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
+    for( const table::CellRangeAddress& rRange : rRangeSeq )
     {
-        const table::CellRangeAddress& rRange = rRangeSeq[ nIndex ];
         GetStringFromRange( sRangeListStr, rRange, pDocument, eConv, cSeparator, true );
     }
     rString = sRangeListStr;
diff --git a/sc/source/core/tool/unitconv.cxx b/sc/source/core/tool/unitconv.cxx
index 544542c207da..0030bbc86772 100644
--- a/sc/source/core/tool/unitconv.cxx
+++ b/sc/source/core/tool/unitconv.cxx
@@ -62,16 +62,14 @@ ScUnitConverter::ScUnitConverter()
     long nNodeCount = aNodeNames.getLength();
     if ( nNodeCount )
     {
-        const OUString* pNodeArray = aNodeNames.getConstArray();
         Sequence<OUString> aValNames( nNodeCount * 3 );
         OUString* pValNameArray = aValNames.getArray();
         const OUString sSlash('/');
 
         long nIndex = 0;
-        for (long i=0; i<nNodeCount; i++)
+        for (const OUString& rNode : aNodeNames)
         {
-            OUString sPrefix = pNodeArray[i];
-            sPrefix += sSlash;
+            OUString sPrefix = rNode + sSlash;
 
             pValNameArray[nIndex++] = sPrefix + CFGSTR_UNIT_FROM;
             pValNameArray[nIndex++] = sPrefix + CFGSTR_UNIT_TO;
diff --git a/sc/source/core/tool/userlist.cxx b/sc/source/core/tool/userlist.cxx
index f4ae75ee844e..049fadbe47b4 100644
--- a/sc/source/core/tool/userlist.cxx
+++ b/sc/source/core/tool/userlist.cxx
@@ -207,9 +207,9 @@ ScUserList::ScUserList()
     uno::Sequence< i18n::Calendar2 > xCalendars(
             ScGlobal::pLocaleData->getAllCalendars() );
 
-    for ( sal_Int32 j = 0; j < xCalendars.getLength(); ++j )
+    for ( const auto& rCalendar : xCalendars )
     {
-        xCal = xCalendars[j].Days;
+        xCal = rCalendar.Days;
         if ( xCal.hasElements() )
         {
             OUStringBuffer aDayShortBuf, aDayLongBuf;
@@ -218,7 +218,7 @@ ScUserList::ScUserList()
             sal_Int16 nStart = sal::static_int_cast<sal_Int16>(nLen);
             while (nStart > 0)
             {
-                if (xCal[--nStart].ID == xCalendars[j].StartOfWeek)
+                if (xCal[--nStart].ID == rCalendar.StartOfWeek)
                     break;
             }
             sal_Int16 nLast = sal::static_int_cast<sal_Int16>( (nStart + nLen - 1) % nLen );
@@ -241,7 +241,7 @@ ScUserList::ScUserList()
                 maData.push_back( std::make_unique<ScUserListData>( aDayLong ));
         }
 
-        xCal = xCalendars[j].Months;
+        xCal = rCalendar.Months;
         if ( xCal.hasElements() )
         {
             OUStringBuffer aMonthShortBuf, aMonthLongBuf;
diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx
index c87d46dc928d..0d3733d6e722 100644
--- a/sc/source/filter/excel/xechart.cxx
+++ b/sc/source/filter/excel/xechart.cxx
@@ -961,17 +961,15 @@ sal_uInt16 XclExpChSourceLink::ConvertStringSequence( const Sequence< Reference<
         namespace ApiScriptType = ::com::sun::star::i18n::ScriptType;
 
         // convert all formatted string entries from the sequence
-        const Reference< XFormattedString >* pBeg = rStringSeq.getConstArray();
-        const Reference< XFormattedString >* pEnd = pBeg + rStringSeq.getLength();
-        for( const Reference< XFormattedString >* pIt = pBeg; pIt != pEnd; ++pIt )
+        for( const Reference< XFormattedString >& rString : rStringSeq )
         {
-            if( pIt->is() )
+            if( rString.is() )
             {
                 sal_uInt16 nWstrnFontIdx = EXC_FONT_NOTFOUND;
                 sal_uInt16 nAsianFontIdx = EXC_FONT_NOTFOUND;
                 sal_uInt16 nCmplxFontIdx = EXC_FONT_NOTFOUND;
-                OUString aText = (*pIt)->getString();
-                ScfPropertySet aStrProp( *pIt );
+                OUString aText = rString->getString();
+                ScfPropertySet aStrProp( rString );
 
                 // #i63255# get script type for leading weak characters
                 sal_Int16 nLastScript = XclExpStringHelper::GetLeadingScriptType( GetRoot(), aText );
@@ -1766,15 +1764,16 @@ bool XclExpChSerErrorBar::Convert( XclExpChSourceLink& rValueLink, sal_uInt16& r
                     Reference< XDataSequence > xValueSeq;
 
                     Sequence< Reference< XLabeledDataSequence > > aLabeledSeqVec = xDataSource->getDataSequences();
-                    const Reference< XLabeledDataSequence >* pBeg = aLabeledSeqVec.getConstArray();
-                    const Reference< XLabeledDataSequence >* pEnd = pBeg + aLabeledSeqVec.getLength();
-                    for( const Reference< XLabeledDataSequence >* pIt = pBeg; !xValueSeq.is() && (pIt != pEnd); ++pIt )
+                    for( const Reference< XLabeledDataSequence >& rLabeledSeq : aLabeledSeqVec )
                     {
-                        Reference< XDataSequence > xTmpValueSeq = (*pIt)->getValues();
+                        Reference< XDataSequence > xTmpValueSeq = rLabeledSeq->getValues();
                         ScfPropertySet aValueProp( xTmpValueSeq );
                         OUString aCurrRole;
                         if( aValueProp.GetProperty( aCurrRole, EXC_CHPROP_ROLE ) && (aCurrRole == aRole) )
+                        {
                             xValueSeq = xTmpValueSeq;
+                            break;
+                        }
                     }
                     if( xValueSeq.is() )
                     {
@@ -1847,11 +1846,9 @@ bool XclExpChSeries::ConvertDataSeries(
 
         // find first sequence with role 'values-y'
         Sequence< Reference< XLabeledDataSequence > > aLabeledSeqVec = xDataSource->getDataSequences();
-        const Reference< XLabeledDataSequence >* pBeg = aLabeledSeqVec.getConstArray();
-        const Reference< XLabeledDataSequence >* pEnd = pBeg + aLabeledSeqVec.getLength();
-        for( const Reference< XLabeledDataSequence >* pIt = pBeg; pIt != pEnd; ++pIt )
+        for( const Reference< XLabeledDataSequence >& rLabeledSeq : aLabeledSeqVec )
         {
-            Reference< XDataSequence > xTmpValueSeq = (*pIt)->getValues();
+            Reference< XDataSequence > xTmpValueSeq = rLabeledSeq->getValues();
             ScfPropertySet aValueProp( xTmpValueSeq );
             OUString aRole;
             if( aValueProp.GetProperty( aRole, EXC_CHPROP_ROLE ) )
@@ -1860,7 +1857,7 @@ bool XclExpChSeries::ConvertDataSeries(
                 {
                     xYValueSeq = xTmpValueSeq;
                     if( !xTitleSeq.is() )
-                        xTitleSeq = (*pIt)->getLabel(); // ignore role of label sequence
+                        xTitleSeq = rLabeledSeq->getLabel(); // ignore role of label sequence
                 }
                 else if( !xXValueSeq.is() && !rTypeInfo.mbCategoryAxis && (aRole == EXC_CHPROP_ROLE_XVALUES) )
                 {
@@ -1869,7 +1866,7 @@ bool XclExpChSeries::ConvertDataSeries(
                 else if( !xBubbleSeq.is() && (rTypeInfo.meTypeId == EXC_CHTYPEID_BUBBLES) && (aRole == EXC_CHPROP_ROLE_SIZEVALUES) )
                 {
                     xBubbleSeq = xTmpValueSeq;
-                    xTitleSeq = (*pIt)->getLabel();     // ignore role of label sequence
+                    xTitleSeq = rLabeledSeq->getLabel();     // ignore role of label sequence
                 }
             }
         }
@@ -1939,12 +1936,12 @@ bool XclExpChSeries::ConvertDataSeries(
                 Sequence< sal_Int32 > aPointIndexes;
                 if( aSeriesProp.GetProperty( aPointIndexes, EXC_CHPROP_ATTRIBDATAPOINTS ) && aPointIndexes.hasElements() )
                 {
-                    const sal_Int32* pnBeg = aPointIndexes.getConstArray();
-                    const sal_Int32* pnEnd = pnBeg + aPointIndexes.getLength();
-                    for( const sal_Int32* pnIt = pnBeg; (pnIt != pnEnd) && (*pnIt < nMaxPointCount); ++pnIt )
+                    for( const sal_Int32 nPointIndex : aPointIndexes )
                     {
-                        aPointPos.mnPointIdx = static_cast< sal_uInt16 >( *pnIt );
-                        ScfPropertySet aPointProp = lclGetPointPropSet( xDataSeries, *pnIt );
+                        if (nPointIndex >= nMaxPointCount)
+                            break;
+                        aPointPos.mnPointIdx = static_cast< sal_uInt16 >( nPointIndex );
+                        ScfPropertySet aPointProp = lclGetPointPropSet( xDataSeries, nPointIndex );
                         XclExpChDataFormatRef xPointFmt( new XclExpChDataFormat( GetChRoot(), aPointPos, nFormatIdx ) );
                         xPointFmt->ConvertDataSeries( aPointProp, rTypeInfo );
                         maPointFmts.AppendRecord( xPointFmt );
@@ -1967,17 +1964,16 @@ bool XclExpChSeries::ConvertStockSeries( css::uno::Reference< css::chart2::XData
 
         // find first sequence with passed role
         Sequence< Reference< XLabeledDataSequence > > aLabeledSeqVec = xDataSource->getDataSequences();
-        const Reference< XLabeledDataSequence >* pBeg = aLabeledSeqVec.getConstArray();
-        const Reference< XLabeledDataSequence >* pEnd = pBeg + aLabeledSeqVec.getLength();
-        for( const Reference< XLabeledDataSequence >* pIt = pBeg; !xYValueSeq.is() && (pIt != pEnd); ++pIt )
+        for( const Reference< XLabeledDataSequence >& rLabeledSeq : aLabeledSeqVec )
         {
-            Reference< XDataSequence > xTmpValueSeq = (*pIt)->getValues();
+            Reference< XDataSequence > xTmpValueSeq = rLabeledSeq->getValues();
             ScfPropertySet aValueProp( xTmpValueSeq );
             OUString aRole;
             if( aValueProp.GetProperty( aRole, EXC_CHPROP_ROLE ) && (aRole == rValueRole) )
             {
                 xYValueSeq = xTmpValueSeq;
-                xTitleSeq = (*pIt)->getLabel();     // ignore role of label sequence
+                xTitleSeq = rLabeledSeq->getLabel();     // ignore role of label sequence
+                break;
             }
         }
 
@@ -2070,12 +2066,10 @@ void XclExpChSeries::CreateTrendLines( css::uno::Reference< css::chart2::XDataSe
     if( xRegCurveCont.is() )
     {
         Sequence< Reference< XRegressionCurve > > aRegCurveSeq = xRegCurveCont->getRegressionCurves();
-        const Reference< XRegressionCurve >* pBeg = aRegCurveSeq.getConstArray();
-        const Reference< XRegressionCurve >* pEnd = pBeg + aRegCurveSeq.getLength();
-        for( const Reference< XRegressionCurve >* pIt = pBeg; pIt != pEnd; ++pIt )
+        for( const Reference< XRegressionCurve >& rRegCurve : aRegCurveSeq )
         {
             XclExpChSeriesRef xSeries = GetChartData().CreateSeries();
-            if( xSeries && !xSeries->ConvertTrendLine( *this, *pIt ) )
+            if( xSeries && !xSeries->ConvertTrendLine( *this, rRegCurve ) )
                 GetChartData().RemoveLastSeries();
         }
     }
@@ -2434,14 +2428,12 @@ void XclExpChTypeGroup::ConvertSeries(
 
         // copy data series attached to the current axes set to the vector
         Sequence< Reference< XDataSeries > > aSeriesSeq = xSeriesCont->getDataSeries();
-        const Reference< XDataSeries >* pBeg = aSeriesSeq.getConstArray();
-        const Reference< XDataSeries >* pEnd = pBeg + aSeriesSeq.getLength();
-        for( const Reference< XDataSeries >* pIt = pBeg; pIt != pEnd; ++pIt )
+        for( const Reference< XDataSeries >& rSeries : aSeriesSeq )
         {
-            ScfPropertySet aSeriesProp( *pIt );
+            ScfPropertySet aSeriesProp( rSeries );
             sal_Int32 nSeriesAxesSetIdx(0);
             if( aSeriesProp.GetProperty( nSeriesAxesSetIdx, EXC_CHPROP_ATTAXISINDEX ) && (nSeriesAxesSetIdx == nGroupAxesSetIdx) )
-                aSeriesVec.push_back( *pIt );
+                aSeriesVec.push_back( rSeries );
         }
 
         // Are there any series in the current axes set?
@@ -3124,23 +3116,21 @@ sal_uInt16 XclExpChAxesSet::Convert( Reference< XDiagram > const & xDiagram, sal
             if( xChartTypeCont.is() )
             {
                 Sequence< Reference< XChartType > > aChartTypeSeq = xChartTypeCont->getChartTypes();
-                const Reference< XChartType >* pBeg = aChartTypeSeq.getConstArray();
-                const Reference< XChartType >* pEnd = pBeg + aChartTypeSeq.getLength();
-                for( const Reference< XChartType >* pIt = pBeg; pIt != pEnd; ++pIt )
+                for( const Reference< XChartType >& rChartType : aChartTypeSeq )
                 {
                     XclExpChTypeGroupRef xTypeGroup( new XclExpChTypeGroup( GetChRoot(), nGroupIdx ) );
-                    xTypeGroup->ConvertType( xDiagram, *pIt, nApiAxesSetIdx, b3dChart, bSwappedAxesSet, bHasXLabels );
+                    xTypeGroup->ConvertType( xDiagram, rChartType, nApiAxesSetIdx, b3dChart, bSwappedAxesSet, bHasXLabels );
                     /*  If new chart type group cannot be inserted into a combination
                         chart with existing type groups, insert all series into last
                         contained chart type group instead of creating a new group. */
                     XclExpChTypeGroupRef xLastGroup = GetLastTypeGroup();
                     if( xLastGroup && !(xTypeGroup->IsCombinable2d() && xLastGroup->IsCombinable2d()) )
                     {
-                        xLastGroup->ConvertSeries( xDiagram, *pIt, nApiAxesSetIdx, bPercent, bConnectBars );
+                        xLastGroup->ConvertSeries( xDiagram, rChartType, nApiAxesSetIdx, bPercent, bConnectBars );
                     }
                     else
                     {
-                        xTypeGroup->ConvertSeries( xDiagram, *pIt, nApiAxesSetIdx, bPercent, bConnectBars );
+                        xTypeGroup->ConvertSeries( xDiagram, rChartType, nApiAxesSetIdx, bPercent, bConnectBars );
                         if( xTypeGroup->IsValidGroup() )
                         {
                             maTypeGroups.AppendRecord( xTypeGroup );
diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
index 3787b75ad6f8..0e2e3e0ff919 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -62,6 +62,7 @@
 #include <svx/xfillit0.hxx>
 #include <svx/xflclit.hxx>
 
+#include <comphelper/sequence.hxx>
 #include <oox/token/tokens.hxx>
 #include <oox/token/relationship.hxx>
 #include <oox/export/drawingml.hxx>
@@ -811,13 +812,10 @@ XclExpTbxControlObj::XclExpTbxControlObj( XclExpObjectManager& rRoot, Reference<
             Sequence< sal_Int16 > aSelection;
             if( aCtrlProp.GetProperty( aSelection, "SelectedItems" ) )
             {
-                sal_Int32 nLen = aSelection.getLength();
-                if( nLen > 0 )
+                if( aSelection.hasElements() )
                 {
                     mnSelEntry = aSelection[ 0 ] + 1;
-                    maMultiSel.resize( nLen );
-                    const sal_Int16* pnBegin = aSelection.getConstArray();
-                    ::std::copy( pnBegin, pnBegin + nLen, maMultiSel.begin() );
+                    comphelper::sequenceToContainer(maMultiSel, aSelection);
                 }
             }
 
@@ -835,11 +833,9 @@ XclExpTbxControlObj::XclExpTbxControlObj( XclExpObjectManager& rRoot, Reference<
                 aCtrlProp.GetProperty( aDefText, "Text" ) &&
                 aStringList.hasElements() && !aDefText.isEmpty() )
             {
-                const OUString* pBegin = aStringList.getConstArray();
-                const OUString* pEnd = pBegin + aStringList.getLength();
-                const OUString* pString = ::std::find( pBegin, pEnd, aDefText );
-                if( pString != pEnd )
-                    mnSelEntry = static_cast< sal_Int16 >( pString - pBegin + 1 );  // 1-based
+                auto nIndex = comphelper::findValue(aStringList, aDefText);
+                if( nIndex != -1 )
+                    mnSelEntry = static_cast< sal_Int16 >( nIndex + 1 );  // 1-based
                 if( mnSelEntry > 0 )
                     maMultiSel.resize( 1, mnSelEntry - 1 );
             }
diff --git a/sc/source/filter/ftools/fapihelper.cxx b/sc/source/filter/ftools/fapihelper.cxx
index 5e2ce066a286..bd5aac4ae5ef 100644
--- a/sc/source/filter/ftools/fapihelper.cxx
+++ b/sc/source/filter/ftools/fapihelper.cxx
@@ -217,12 +217,9 @@ void ScfPropertySet::GetProperties( Sequence< Any >& rValues, const Sequence< OU
         else if( mxPropSet.is() )
         {
             sal_Int32 nLen = rPropNames.getLength();
-            const OUString* pPropName = rPropNames.getConstArray();
-            const OUString* pPropNameEnd = pPropName + nLen;
             rValues.realloc( nLen );
-            Any* pValue = rValues.getArray();
-            for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
-                *pValue = mxPropSet->getPropertyValue( *pPropName );
+            std::transform(rPropNames.begin(), rPropNames.end(), rValues.begin(),
+                [this](const OUString& rPropName) -> Any { return mxPropSet->getPropertyValue(rPropName); });
         }
     }
     catch( Exception& )
diff --git a/sc/source/filter/oox/formulabase.cxx b/sc/source/filter/oox/formulabase.cxx
index 1a7822e7942f..f20cfb82a679 100644
--- a/sc/source/filter/oox/formulabase.cxx
+++ b/sc/source/filter/oox/formulabase.cxx
@@ -1238,10 +1238,8 @@ bool OpCodeProviderImpl::fillTokenMap( ApiTokenMap& orTokenMap, OpCodeEntrySeque
     orTokenMap.clear();
     if( fillEntrySeq( orEntrySeq, rxMapper, nMapGroup ) )
     {
-        const FormulaOpCodeMapEntry* pEntry = orEntrySeq.getConstArray();
-        const FormulaOpCodeMapEntry* pEntryEnd = pEntry + orEntrySeq.getLength();
-        for( ; pEntry != pEntryEnd; ++pEntry )
-            orTokenMap[ pEntry->Name ] = pEntry->Token;
+        for( const FormulaOpCodeMapEntry& rEntry : orEntrySeq )
+            orTokenMap[ rEntry.Name ] = rEntry.Token;
     }
     return orEntrySeq.hasElements();
 }
@@ -1252,10 +1250,8 @@ bool OpCodeProviderImpl::fillFuncTokenMaps( ApiTokenMap& orIntFuncTokenMap, ApiT
     orExtFuncTokenMap.clear();
     if( fillEntrySeq( orEntrySeq, rxMapper, css::sheet::FormulaMapGroup::FUNCTIONS ) )
     {
-        const FormulaOpCodeMapEntry* pEntry = orEntrySeq.getConstArray();
-        const FormulaOpCodeMapEntry* pEntryEnd = pEntry + orEntrySeq.getLength();
-        for( ; pEntry != pEntryEnd; ++pEntry )
-            ((pEntry->Token.OpCode == OPCODE_EXTERNAL) ? orExtFuncTokenMap : orIntFuncTokenMap)[ pEntry->Name ] = pEntry->Token;
+        for( const FormulaOpCodeMapEntry& rEntry : orEntrySeq )
+            ((rEntry.Token.OpCode == OPCODE_EXTERNAL) ? orExtFuncTokenMap : orIntFuncTokenMap)[ rEntry.Name ] = rEntry.Token;
     }
     return orEntrySeq.hasElements();
 }
diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx
index be05789251e3..00936636335d 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -733,13 +733,12 @@ void WorkbookHelper::finalizeWorkbookImport()
             {
                 OUString sTabName;
                 Reference< XNameAccess > xSheetsNC;
-                sal_Int32 nCount (aSeq.getLength());
-                for (sal_Int32 i = 0; i < nCount; ++i)
+                for (const auto& rProp : aSeq)
                 {
-                    OUString sName(aSeq[i].Name);
+                    OUString sName(rProp.Name);
                     if (sName == SC_ACTIVETABLE)
                     {
-                        if(aSeq[i].Value >>= sTabName)
+                        if(rProp.Value >>= sTabName)
                         {
                             SCTAB nTab(0);
                             if (getScDocument().GetTable(sTabName, nTab))
@@ -748,7 +747,7 @@ void WorkbookHelper::finalizeWorkbookImport()
                     }
                     else if (sName == SC_TABLES)
                     {
-                        aSeq[i].Value >>= xSheetsNC;
+                        rProp.Value >>= xSheetsNC;
                     }
                 }
                 if (xSheetsNC.is() && xSheetsNC->hasByName(sTabName))
@@ -757,20 +756,19 @@ void WorkbookHelper::finalizeWorkbookImport()
                     Any aAny = xSheetsNC->getByName(sTabName);
                     if ( aAny >>= aProperties )
                     {
-                        nCount = aProperties.getLength();
-                        for (sal_Int32 i = 0; i < nCount; ++i)
+                        for (const auto& rProp : aProperties)
                         {
-                            OUString sName(aProperties[i].Name);
+                            OUString sName(rProp.Name);
                             if (sName == SC_POSITIONLEFT)
                             {
                                 SCCOL nPosLeft;
-                                aProperties[i].Value >>= nPosLeft;
+                                rProp.Value >>= nPosLeft;
                                 getScDocument().SetPosLeft(nPosLeft);
                             }
                             else if (sName == SC_POSITIONTOP)
                             {
                                 SCROW nPosTop;
-                                aProperties[i].Value >>= nPosTop;
+                                rProp.Value >>= nPosTop;
                                 getScDocument().SetPosTop(nPosTop);
                             }
                         }
diff --git a/sc/source/filter/xcl97/xcl97esc.cxx b/sc/source/filter/xcl97/xcl97esc.cxx
index 9ca76ae49c58..0602ae8d7fca 100644
--- a/sc/source/filter/xcl97/xcl97esc.cxx
+++ b/sc/source/filter/xcl97/xcl97esc.cxx
@@ -482,12 +482,11 @@ void XclEscherEx::ConvertTbxMacro( XclExpTbxControlObj& rTbxCtrlObj, Reference<
             Reference< XEventAttacherManager > xEventMgr( xFormIA, UNO_QUERY_THROW );
             // loop over all events attached to the found control
             const Sequence< ScriptEventDescriptor > aEventSeq( xEventMgr->getScriptEvents( nFoundIdx ) );
-            bool bFound = false;
-            for( sal_Int32 nEventIdx = 0, nEventCount = aEventSeq.getLength();
-                    !bFound && (nEventIdx < nEventCount); ++nEventIdx )
+            for( const auto& rEvent : aEventSeq )
             {
                 // try to set the event data at the Excel control object, returns true on success
-                bFound = rTbxCtrlObj.SetMacroLink( aEventSeq[ nEventIdx ] );
+                if (rTbxCtrlObj.SetMacroLink( rEvent ))
+                    break;
             }
         }
     }
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index 1b82c93065b0..f7b27bfc8f15 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -194,9 +194,9 @@ bool IsValidObject( const XclObj& rObj )
         if (!xCooSysSeq.hasElements())
             return false;
 
-        for (sal_Int32 nCooSys = 0; nCooSys < xCooSysSeq.getLength(); ++nCooSys)
+        for (const auto& rCooSys : xCooSysSeq)
         {
-            Reference<chart2::XChartTypeContainer> xChartTypeCont(xCooSysSeq[nCooSys], uno::UNO_QUERY);
+            Reference<chart2::XChartTypeContainer> xChartTypeCont(rCooSys, uno::UNO_QUERY);
             if (!xChartTypeCont.is())
                 return false;
 
diff --git a/sc/source/filter/xml/XMLCodeNameProvider.cxx b/sc/source/filter/xml/XMLCodeNameProvider.cxx
index ef8f829bcbb1..4f71732450f1 100644
--- a/sc/source/filter/xml/XMLCodeNameProvider.cxx
+++ b/sc/source/filter/xml/XMLCodeNameProvider.cxx
@@ -30,13 +30,12 @@ bool XMLCodeNameProvider::_getCodeName( const uno::Any& aAny, OUString& rCodeNam
     if( !(aAny >>= aProps) )
         return false;
 
-    sal_Int32 nPropCount = aProps.getLength();
-    for( sal_Int32 i=0; i<nPropCount; i++ )
+    for( const auto& rProp : aProps )
     {
-        if( aProps[i].Name == "CodeName" )
+        if( rProp.Name == "CodeName" )
         {
             OUString sCodeName;
-            if( aProps[i].Value >>= sCodeName )
+            if( rProp.Value >>= sCodeName )
             {
                 rCodeName = sCodeName;
                 return true;
diff --git a/sc/source/filter/xml/XMLExportDatabaseRanges.cxx b/sc/source/filter/xml/XMLExportDatabaseRanges.cxx
index c9b154409055..4ab20b0932f6 100644
--- a/sc/source/filter/xml/XMLExportDatabaseRanges.cxx
+++ b/sc/source/filter/xml/XMLExportDatabaseRanges.cxx
@@ -142,10 +142,8 @@ ScMyEmptyDatabaseRangesContainer ScXMLExportDatabaseRanges::GetEmptyDatabaseRang
             if (xDatabaseRanges.is())
             {
                 uno::Sequence <OUString> aRanges(xDatabaseRanges->getElementNames());
-                sal_Int32 nDatabaseRangesCount = aRanges.getLength();
-                for (sal_Int32 i = 0; i < nDatabaseRangesCount; ++i)
+                for (const OUString& sDatabaseRangeName : aRanges)
                 {
-                    OUString sDatabaseRangeName(aRanges[i]);
                     uno::Reference <sheet::XDatabaseRange> xDatabaseRange(xDatabaseRanges->getByName(sDatabaseRangeName), uno::UNO_QUERY);
                     if (xDatabaseRange.is())
                     {
@@ -154,11 +152,10 @@ ScMyEmptyDatabaseRangesContainer ScXMLExportDatabaseRanges::GetEmptyDatabaseRang
                             ::cppu::any2bool(xDatabaseRangePropertySet->getPropertyValue(SC_UNONAME_STRIPDAT)))
                         {
                             uno::Sequence <beans::PropertyValue> aImportProperties(xDatabaseRange->getImportDescriptor());
-                            sal_Int32 nLength = aImportProperties.getLength();
                             sheet::DataImportMode nSourceType = sheet::DataImportMode_NONE;
-                            for (sal_Int32 j = 0; j < nLength; ++j)
-                                if ( aImportProperties[j].Name == SC_UNONAME_SRCTYPE )
-                                    aImportProperties[j].Value >>= nSourceType;
+                            for (const auto& rProp : aImportProperties)
+                                if ( rProp.Name == SC_UNONAME_SRCTYPE )
+                                    rProp.Value >>= nSourceType;
                             if (nSourceType != sheet::DataImportMode_NONE)
                             {
                                 table::CellRangeAddress aArea = xDatabaseRange->getDataArea();
diff --git a/sc/source/filter/xml/xmlcvali.cxx b/sc/source/filter/xml/xmlcvali.cxx
index 58a6e588dbc0..78dc7fd49597 100644
--- a/sc/source/filter/xml/xmlcvali.cxx
+++ b/sc/source/filter/xml/xmlcvali.cxx
@@ -387,17 +387,11 @@ void SAL_CALL ScXMLContentValidationContext::endFastElement( sal_Int32 /*nElemen
         uno::Sequence<beans::PropertyValue> aValues;
         pEvents->GetEventSequence( "OnError", aValues );
 
-        sal_Int32 nLength = aValues.getLength();
-        for( sal_Int32 i = 0; i < nLength; i++ )
-        {
-            // #i47525# must allow "MacroName" or "Script"
-            if ( aValues[i].Name == "MacroName" ||
-                 aValues[i].Name == "Script" )
-            {
-                aValues[i].Value >>= sErrorTitle;
-                break;
-            }
-        }
+        auto pValue = std::find_if(aValues.begin(), aValues.end(),
+            [](const beans::PropertyValue& rValue) {
+                return rValue.Name == "MacroName" || rValue.Name == "Script"; });
+        if (pValue != aValues.end())
+            pValue->Value >>= sErrorTitle;
     }
 
     ScMyImportValidation aValidation;
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 2c3f4d40e75a..dd4ac8a37ed1 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -811,8 +811,7 @@ SvXMLImportContext *ScXMLImport::CreateScriptContext(
     return pContext;
 }
 
-void ScXMLImport::SetStatistics(
-                                const uno::Sequence<beans::NamedValue> & i_rStats)
+void ScXMLImport::SetStatistics(const uno::Sequence<beans::NamedValue> & i_rStats)
 {
     static const char* s_stats[] =
     { "TableCount", "CellCount", "ObjectCount", nullptr };
@@ -820,11 +819,11 @@ void ScXMLImport::SetStatistics(
     SvXMLImport::SetStatistics(i_rStats);
 
     sal_uInt32 nCount(0);
-    for (sal_Int32 i = 0; i < i_rStats.getLength(); ++i) {
+    for (const auto& rStat : i_rStats) {
         for (const char** pStat = s_stats; *pStat != nullptr; ++pStat) {
-            if (i_rStats[i].Name.equalsAscii(*pStat)) {
+            if (rStat.Name.equalsAscii(*pStat)) {
                 sal_Int32 val = 0;
-                if (i_rStats[i].Value >>= val) {
+                if (rStat.Value >>= val) {
                     nCount += val;
                 } else {
                     OSL_FAIL("ScXMLImport::SetStatistics: invalid entry");
@@ -960,32 +959,31 @@ void ScXMLImport::SetChangeTrackingViewSettings(const css::uno::Sequence<css::be
 {
     if (pDoc)
     {
-        sal_Int32 nCount(rChangeProps.getLength());
-        if (nCount)
+        if (rChangeProps.hasElements())
         {
             ScXMLImport::MutexGuard aGuard(*this);
             sal_Int16 nTemp16(0);
             std::unique_ptr<ScChangeViewSettings> pViewSettings(new ScChangeViewSettings());
-            for (sal_Int32 i = 0; i < nCount; ++i)
+            for (const auto& rChangeProp : rChangeProps)
             {
-                OUString sName(rChangeProps[i].Name);
+                OUString sName(rChangeProp.Name);
                 if (sName == "ShowChanges")
-                    pViewSettings->SetShowChanges(::cppu::any2bool(rChangeProps[i].Value));
+                    pViewSettings->SetShowChanges(::cppu::any2bool(rChangeProp.Value));
                 else if (sName == "ShowAcceptedChanges")
-                    pViewSettings->SetShowAccepted(::cppu::any2bool(rChangeProps[i].Value));
+                    pViewSettings->SetShowAccepted(::cppu::any2bool(rChangeProp.Value));
                 else if (sName == "ShowRejectedChanges")
-                    pViewSettings->SetShowRejected(::cppu::any2bool(rChangeProps[i].Value));
+                    pViewSettings->SetShowRejected(::cppu::any2bool(rChangeProp.Value));
                 else if (sName == "ShowChangesByDatetime")
-                    pViewSettings->SetHasDate(::cppu::any2bool(rChangeProps[i].Value));
+                    pViewSettings->SetHasDate(::cppu::any2bool(rChangeProp.Value));
                 else if (sName == "ShowChangesByDatetimeMode")
                 {
-                    if (rChangeProps[i].Value >>= nTemp16)
+                    if (rChangeProp.Value >>= nTemp16)
                         pViewSettings->SetTheDateMode(static_cast<SvxRedlinDateMode>(nTemp16));
                 }
                 else if (sName == "ShowChangesByDatetimeFirstDatetime")
                 {
                     util::DateTime aDateTime;
-                    if (rChangeProps[i].Value >>= aDateTime)
+                    if (rChangeProp.Value >>= aDateTime)
                     {
                         pViewSettings->SetTheFirstDateTime(::DateTime(aDateTime));
                     }
@@ -993,37 +991,37 @@ void ScXMLImport::SetChangeTrackingViewSettings(const css::uno::Sequence<css::be
                 else if (sName == "ShowChangesByDatetimeSecondDatetime")
                 {
                     util::DateTime aDateTime;
-                    if (rChangeProps[i].Value >>= aDateTime)
+                    if (rChangeProp.Value >>= aDateTime)
                     {
                         pViewSettings->SetTheLastDateTime(::DateTime(aDateTime));
                     }
                 }
                 else if (sName == "ShowChangesByAuthor")
-                    pViewSettings->SetHasAuthor(::cppu::any2bool(rChangeProps[i].Value));
+                    pViewSettings->SetHasAuthor(::cppu::any2bool(rChangeProp.Value));
                 else if (sName == "ShowChangesByAuthorName")
                 {
                     OUString sOUName;
-                    if (rChangeProps[i].Value >>= sOUName)
+                    if (rChangeProp.Value >>= sOUName)
                     {
                         pViewSettings->SetTheAuthorToShow(sOUName);
                     }
                 }
                 else if (sName == "ShowChangesByComment")
-                    pViewSettings->SetHasComment(::cppu::any2bool(rChangeProps[i].Value));
+                    pViewSettings->SetHasComment(::cppu::any2bool(rChangeProp.Value));
                 else if (sName == "ShowChangesByCommentText")
                 {
                     OUString sOUComment;
-                    if (rChangeProps[i].Value >>= sOUComment)
+                    if (rChangeProp.Value >>= sOUComment)
                     {
                         pViewSettings->SetTheComment(sOUComment);
                     }
                 }
                 else if (sName == "ShowChangesByRanges")
-                    pViewSettings->SetHasRange(::cppu::any2bool(rChangeProps[i].Value));
+                    pViewSettings->SetHasRange(::cppu::any2bool(rChangeProp.Value));
                 else if (sName == "ShowChangesByRangesList")
                 {
                     OUString sRanges;
-                    if ((rChangeProps[i].Value >>= sRanges) && !sRanges.isEmpty())
+                    if ((rChangeProp.Value >>= sRanges) && !sRanges.isEmpty())
                     {
                         ScRangeList aRangeList;
                         ScRangeStringConverter::GetRangeListFromString(
@@ -1039,26 +1037,25 @@ void ScXMLImport::SetChangeTrackingViewSettings(const css::uno::Sequence<css::be
 
 void ScXMLImport::SetViewSettings(const uno::Sequence<beans::PropertyValue>& aViewProps)
 {
-    sal_Int32 nCount(aViewProps.getLength());
     sal_Int32 nHeight(0);
     sal_Int32 nLeft(0);
     sal_Int32 nTop(0);
     sal_Int32 nWidth(0);
-    for (sal_Int32 i = 0; i < nCount; ++i)
+    for (const auto& rViewProp : aViewProps)
     {
-        OUString sName(aViewProps[i].Name);
+        OUString sName(rViewProp.Name);
         if (sName == "VisibleAreaHeight")
-            aViewProps[i].Value >>= nHeight;
+            rViewProp.Value >>= nHeight;
         else if (sName == "VisibleAreaLeft")
-            aViewProps[i].Value >>= nLeft;
+            rViewProp.Value >>= nLeft;
         else if (sName == "VisibleAreaTop")
-            aViewProps[i].Value >>= nTop;
+            rViewProp.Value >>= nTop;
         else if (sName == "VisibleAreaWidth")
-            aViewProps[i].Value >>= nWidth;
+            rViewProp.Value >>= nWidth;
         else if (sName == "TrackedChangesViewSettings")
         {
             uno::Sequence<beans::PropertyValue> aChangeProps;
-            if(aViewProps[i].Value >>= aChangeProps)
+            if(rViewProp.Value >>= aChangeProps)
                 SetChangeTrackingViewSettings(aChangeProps);
         }
     }
@@ -1089,8 +1086,7 @@ void ScXMLImport::SetConfigurationSettings(const uno::Sequence<beans::PropertyVa
         if (xMultiServiceFactory.is())
         {
             sal_Int32 nCount(aConfigProps.getLength());
-            css::uno::Sequence<css::beans::PropertyValue> aFilteredProps(
-                aConfigProps.getLength());
+            css::uno::Sequence<css::beans::PropertyValue> aFilteredProps(nCount);
             sal_Int32 nFilteredPropsLen = 0;
             for (sal_Int32 i = nCount - 1; i >= 0; --i)
             {
@@ -1721,20 +1717,19 @@ void SAL_CALL ScXMLImport::endDocument()
                     uno::Sequence< beans::PropertyValue > aSeq;
                     if (xIndexAccess->getByIndex(0) >>= aSeq)
                     {
-                        sal_Int32 nCount (aSeq.getLength());
-                        for (sal_Int32 i = 0; i < nCount; ++i)
+                        for (const auto& rProp : aSeq)
                         {
-                            OUString sName(aSeq[i].Name);
+                            OUString sName(rProp.Name);
                             if (sName == SC_ACTIVETABLE)
                             {
                                 OUString sTabName;
-                                if(aSeq[i].Value >>= sTabName)
+                                if(rProp.Value >>= sTabName)
                                 {
                                     SCTAB nTab(0);
                                     if (pDoc->GetTable(sTabName, nTab))
                                     {
                                         pDoc->SetVisibleTab(nTab);
-                                        i = nCount;
+                                        break;
                                     }
                                 }
                             }
diff --git a/sc/source/filter/xml/xmlstyli.cxx b/sc/source/filter/xml/xmlstyli.cxx
index d3d2ac76e1c1..792e59594bc7 100644
--- a/sc/source/filter/xml/xmlstyli.cxx
+++ b/sc/source/filter/xml/xmlstyli.cxx
@@ -478,10 +478,8 @@ void XMLTableStyleContext::ApplyCondFormat( const uno::Sequence<table::CellRange
         return;
 
     ScRangeList aRangeList;
-    sal_Int32 nRanges = xCellRanges.getLength();
-    for(sal_Int32 i = 0; i < nRanges; ++i)
+    for(const table::CellRangeAddress& aAddress : xCellRanges)
     {
-        table::CellRangeAddress aAddress = xCellRanges[i];
         ScRange aRange( aAddress.StartColumn, aAddress.StartRow, aAddress.Sheet, aAddress.EndColumn, aAddress.EndRow, aAddress.Sheet );
         aRangeList.Join( aRange );
     }
diff --git a/sc/source/ui/Accessibility/AccessibleCell.cxx b/sc/source/ui/Accessibility/AccessibleCell.cxx
index e053ed209751..8922919f694a 100644
--- a/sc/source/ui/Accessibility/AccessibleCell.cxx
+++ b/sc/source/ui/Accessibility/AccessibleCell.cxx
@@ -520,19 +520,14 @@ uno::Sequence< beans::PropertyValue > SAL_CALL ScAccessibleCell::getCharacterAtt
     SolarMutexGuard aGuard;
 
     uno::Sequence< beans::PropertyValue > aAttribs = AccessibleStaticTextBase::getCharacterAttributes( nIndex, aRequestedAttributes );
-    beans::PropertyValue *pAttribs = aAttribs.getArray();
 
     sal_uInt16 nParaIndent = mpDoc->GetAttr( maCellAddress, ATTR_INDENT )->GetValue();
     if (nParaIndent > 0)
     {
-        for (int i = 0; i < aAttribs.getLength(); ++i)
-        {
-            if ("ParaLeftMargin" == pAttribs[i].Name)
-            {
-                pAttribs[i].Value <<= nParaIndent;
-                break;
-            }
-        }
+        auto pAttrib = std::find_if(aAttribs.begin(), aAttribs.end(),
+            [](const beans::PropertyValue& rAttrib) { return "ParaLeftMargin" == rAttrib.Name; });
+        if (pAttrib != aAttribs.end())
+            pAttrib->Value <<= nParaIndent;
     }
     return aAttribs;
 }
diff --git a/sc/source/ui/Accessibility/AccessibleGlobal.cxx b/sc/source/ui/Accessibility/AccessibleGlobal.cxx
index 31d810bd2d0b..472197382c1f 100644
--- a/sc/source/ui/Accessibility/AccessibleGlobal.cxx
+++ b/sc/source/ui/Accessibility/AccessibleGlobal.cxx
@@ -48,15 +48,8 @@ sal_Bool SAL_CALL ScAccessibleStateSet::contains(sal_Int16 nState)
 sal_Bool SAL_CALL ScAccessibleStateSet::containsAll(
     const Sequence<sal_Int16>& aStateSet)
 {
-    sal_Int32 n = aStateSet.getLength();
-    for (sal_Int32 i = 0; i < n; ++i)
-    {
-        if (!maStates.count(aStateSet[i]))
-            // This state is not set.
-            return false;
-    }
-    // All specified states are set.
-    return true;
+    return std::all_of(aStateSet.begin(), aStateSet.end(),
+        [this](const sal_Int16 nState) { return maStates.count(nState) != 0; });
 }
 
 Sequence<sal_Int16> SAL_CALL ScAccessibleStateSet::getStates()
diff --git a/sc/source/ui/cctrl/tbzoomsliderctrl.cxx b/sc/source/ui/cctrl/tbzoomsliderctrl.cxx
index b97f5e4c85d3..77d7067b2dd4 100644
--- a/sc/source/ui/cctrl/tbzoomsliderctrl.cxx
+++ b/sc/source/ui/cctrl/tbzoomsliderctrl.cxx
@@ -337,11 +337,8 @@ void ScZoomSliderWnd::UpdateFromItem( const SvxZoomSliderItem* pZoomSliderItem )
 
         // get all snapping points:
         std::set< sal_uInt16 > aTmpSnappingPoints;
-        for ( sal_Int32 j = 0; j < rSnappingPoints.getLength(); ++j )
-        {
-            const sal_Int32 nSnappingPoint = rSnappingPoints[j];
-            aTmpSnappingPoints.insert( static_cast<sal_uInt16>(nSnappingPoint) );
-        }
+        std::transform(rSnappingPoints.begin(), rSnappingPoints.end(), std::inserter(aTmpSnappingPoints, aTmpSnappingPoints.end()),
+            [](const sal_Int32 nSnappingPoint) -> sal_uInt16 { return static_cast<sal_uInt16>(nSnappingPoint); });
 
         // remove snapping points that are too close to each other:
         long nLastOffset = 0;
diff --git a/sc/source/ui/dbgui/dapidata.cxx b/sc/source/ui/dbgui/dapidata.cxx
index 06d360a163ac..638d6a20b8f3 100644
--- a/sc/source/ui/dbgui/dapidata.cxx
+++ b/sc/source/ui/dbgui/dapidata.cxx
@@ -55,11 +55,8 @@ ScDataPilotDatabaseDlg::ScDataPilotDatabaseDlg(weld::Window* pParent)
         uno::Reference<sdb::XDatabaseContext> xContext = sdb::DatabaseContext::create(
                 comphelper::getProcessComponentContext() );
         uno::Sequence<OUString> aNames = xContext->getElementNames();
-        long nCount = aNames.getLength();
-        const OUString* pArray = aNames.getConstArray();
-        for (long nPos = 0; nPos < nCount; nPos++)
+        for( const OUString& aName : aNames )
         {
-            OUString aName = pArray[nPos];
             m_xLbDatabase->append_text(aName);
         }
     }
@@ -162,11 +159,8 @@ void ScDataPilotDatabaseDlg::FillObjects()
 
         //  fill list
 
-        long nCount = aNames.getLength();
-        const OUString* pArray = aNames.getConstArray();
-        for( long nPos=0; nPos<nCount; nPos++ )
+        for( const OUString& aName : aNames )
         {
-            OUString aName = pArray[nPos];
             m_xCbObject->append_text(aName);
         }
     }
diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx
index 1bf89c164644..d4654e3b83f4 100644
--- a/sc/source/ui/dbgui/tpsort.cxx
+++ b/sc/source/ui/dbgui/tpsort.cxx
@@ -890,10 +890,8 @@ void ScTabPageSortOptions::FillAlgor()
         uno::Sequence<OUString> aAlgos = m_xColWrap->listCollatorAlgorithms( aLocale );
 
         long nCount = aAlgos.getLength();
-        const OUString* pArray = aAlgos.getConstArray();
-        for (long i=0; i<nCount; i++)
+        for (const OUString& sAlg : aAlgos)
         {
-            OUString sAlg = pArray[i];
             OUString sUser = m_xColRes->GetTranslation( sAlg );
             m_xLbAlgorithm->append_text(sUser);
         }
diff --git a/sc/source/ui/docshell/docsh2.cxx b/sc/source/ui/docshell/docsh2.cxx
index 4b872f0548de..00ecfe4b293d 100644
--- a/sc/source/ui/docshell/docsh2.cxx
+++ b/sc/source/ui/docshell/docsh2.cxx
@@ -129,12 +129,11 @@ void ScDocShell::InitItems()
                 std::shared_ptr<SvxForbiddenCharactersTable> xForbiddenTable(
                     SvxForbiddenCharactersTable::makeForbiddenCharactersTable(comphelper::getProcessComponentContext()));
 
-                const lang::Locale* pLocales = aLocales.getConstArray();
-                for (sal_Int32 i = 0; i < aLocales.getLength(); i++)
+                for (const lang::Locale& rLocale : aLocales)
                 {
                     i18n::ForbiddenCharacters aForbidden;
-                    aAsian.GetStartEndChars( pLocales[i], aForbidden.beginLine, aForbidden.endLine );
-                    LanguageType eLang = LanguageTag::convertToLanguageType(pLocales[i]);
+                    aAsian.GetStartEndChars( rLocale, aForbidden.beginLine, aForbidden.endLine );
+                    LanguageType eLang = LanguageTag::convertToLanguageType(rLocale);
 
                     xForbiddenTable->SetForbiddenCharacters( eLang, aForbidden );
                 }
diff --git a/sc/source/ui/miscdlgs/optsolver.cxx b/sc/source/ui/miscdlgs/optsolver.cxx
index 17b760d65a1f..09ad93d1a666 100644
--- a/sc/source/ui/miscdlgs/optsolver.cxx
+++ b/sc/source/ui/miscdlgs/optsolver.cxx
@@ -942,12 +942,12 @@ bool ScOptSolverDlg::CallSolver()       // return true -> close dialog after cal
     sal_Int32 nVarCount = aVariables.getLength();
     uno::Sequence<double> aOldValues;
     aOldValues.realloc( nVarCount );
-    for (nVarPos=0; nVarPos<nVarCount; ++nVarPos)
-    {
-        ScAddress aCellPos;
-        ScUnoConversion::FillScAddress( aCellPos, aVariables[nVarPos] );
-        aOldValues[nVarPos] = mrDoc.GetValue( aCellPos );
-    }
+    std::transform(aVariables.begin(), aVariables.end(), aOldValues.begin(),
+        [this](const table::CellAddress& rVariable) -> double {
+            ScAddress aCellPos;
+            ScUnoConversion::FillScAddress( aCellPos, rVariable );
+            return mrDoc.GetValue( aCellPos );
+        });
 
     // create and initialize solver
 
@@ -966,10 +966,8 @@ bool ScOptSolverDlg::CallSolver()       // return true -> close dialog after cal
     uno::Reference<beans::XPropertySet> xOptProp(xSolver, uno::UNO_QUERY);
     if ( xOptProp.is() )
     {
-        sal_Int32 nPropCount = maProperties.getLength();
-        for (sal_Int32 nProp=0; nProp<nPropCount; ++nProp)
+        for (const beans::PropertyValue& rValue : maProperties)
         {
-            const beans::PropertyValue& rValue = maProperties[nProp];
             try
             {
                 xOptProp->setPropertyValue( rValue.Name, rValue.Value );
diff --git a/sc/source/ui/miscdlgs/solveroptions.cxx b/sc/source/ui/miscdlgs/solveroptions.cxx
index e4b92356edcc..66115e8eeca2 100644
--- a/sc/source/ui/miscdlgs/solveroptions.cxx
+++ b/sc/source/ui/miscdlgs/solveroptions.cxx
@@ -163,8 +163,8 @@ void ScSolverOptionsDialog::FillListBox()
 
     uno::Sequence<beans::PropertyValue> aNewSeq;
     aNewSeq.realloc( nCount );
-    for (sal_Int32 nPos=0; nPos<nCount; nPos++)
-        aNewSeq[nPos] = maProperties[ aDescriptions[nPos].nPosition ];
+    std::transform(aDescriptions.begin(), aDescriptions.end(), aNewSeq.begin(),
+        [this](const ScSolverOptionsEntry& rDescr) -> beans::PropertyValue { return maProperties[ rDescr.nPosition ]; });
     maProperties = aNewSeq;
 
     // fill the list box
diff --git a/sc/source/ui/miscdlgs/solverutil.cxx b/sc/source/ui/miscdlgs/solverutil.cxx
index 3cddf1effbd5..48af88892c21 100644
--- a/sc/source/ui/miscdlgs/solverutil.cxx
+++ b/sc/source/ui/miscdlgs/solverutil.cxx
@@ -156,9 +156,8 @@ uno::Sequence<beans::PropertyValue> ScSolverUtil::GetDefaults( const OUString& r
     const sal_Int32 nSize = aPropSeq.getLength();
     aDefaults.realloc(nSize);
     sal_Int32 nValid = 0;
-    for (sal_Int32 nPos=0; nPos<nSize; ++nPos)
+    for (const beans::Property& rProp : aPropSeq)
     {
-        const beans::Property& rProp = aPropSeq[nPos];
         uno::Any aValue = xPropSet->getPropertyValue( rProp.Name );
         uno::TypeClass eClass = aValue.getValueTypeClass();
         // only use properties of supported types
diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx
index 6cddcc87988b..69fd6381d252 100644
--- a/sc/source/ui/unoobj/appluno.cxx
+++ b/sc/source/ui/unoobj/appluno.cxx
@@ -349,11 +349,8 @@ void SAL_CALL ScSpreadsheetSettings::setPropertyValue(
             //  ScGlobal::SetUseTabCol does not do much else
 
             pUserList->clear();
-            sal_uInt16 nCount = static_cast<sal_uInt16>(aSeq.getLength());
-            const OUString* pAry = aSeq.getConstArray();
-            for (sal_uInt16 i=0; i<nCount; i++)
+            for (const OUString& aEntry : aSeq)
             {
-                OUString aEntry = pAry[i];
                 ScUserListData* pData = new ScUserListData(aEntry);
                 pUserList->push_back(pData);
             }
diff --git a/sc/source/ui/unoobj/celllistsource.cxx b/sc/source/ui/unoobj/celllistsource.cxx
index dde68149c511..bc79178d4909 100644
--- a/sc/source/ui/unoobj/celllistsource.cxx
+++ b/sc/source/ui/unoobj/celllistsource.cxx
@@ -352,17 +352,18 @@ namespace calc
         CellRangeAddress aRangeAddress;
         bool bFoundAddress = false;
 
-        const Any* pLoop = _rArguments.getConstArray();
-        const Any* pLoopEnd = _rArguments.getConstArray() + _rArguments.getLength();
-        for ( ; ( pLoop != pLoopEnd ) && !bFoundAddress; ++pLoop )
+        for ( const Any& rArg : _rArguments )
         {
             NamedValue aValue;
-            if ( *pLoop >>= aValue )
+            if ( rArg >>= aValue )
             {
                 if ( aValue.Name == "CellRange" )
                 {
                     if ( aValue.Value >>= aRangeAddress )
+                    {
                         bFoundAddress = true;
+                        break;
+                    }
                 }
             }
         }
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 3301ddc2fcf5..dcef6d854d05 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -905,11 +905,9 @@ static void lcl_CopyProperties( beans::XPropertySet& rDest, beans::XPropertySet&
     if (xInfo.is())
     {
         uno::Sequence<beans::Property> aSeq(xInfo->getProperties());
-        const beans::Property* pAry = aSeq.getConstArray();
-        sal_uLong nCount = aSeq.getLength();
-        for (sal_uLong i=0; i<nCount; i++)
+        for (const beans::Property& rProp : aSeq)
         {
-            OUString aName(pAry[i].Name);
+            OUString aName(rProp.Name);
             rDest.setPropertyValue( aName, rSource.getPropertyValue( aName ) );
         }
     }
@@ -1136,18 +1134,15 @@ static bool lcl_PutDataArray( ScDocShell& rDocShell, const ScRange& rRange,
 
     bool bError = false;
     SCROW nDocRow = nStartRow;
-    for (long nRow=0; nRow<nRows; nRow++)
+    for (const uno::Sequence<uno::Any>& rColSeq : aData)
     {
-        const uno::Sequence<uno::Any>& rColSeq = pArray[nRow];
         if ( rColSeq.getLength() == nCols )
         {
             SCCOL nDocCol = nStartCol;
-            const uno::Any* pColArr = rColSeq.getConstArray();
-            for (long nCol=0; nCol<nCols; nCol++)
+            for (const uno::Any& rElement : rColSeq)
             {
                 ScAddress aPos(nDocCol, nDocRow, nTab);
 
-                const uno::Any& rElement = pColArr[nCol];
                 switch( rElement.getValueTypeClass() )
                 {
                     case uno::TypeClass_VOID:
@@ -1275,16 +1270,13 @@ static bool lcl_PutFormulaArray( ScDocShell& rDocShell, const ScRange& rRange,
 
     bool bError = false;
     SCROW nDocRow = nStartRow;
-    for (long nRow=0; nRow<nRows; nRow++)
+    for (const uno::Sequence<OUString>& rColSeq : aData)
     {
-        const uno::Sequence<OUString>& rColSeq = pArray[nRow];
         if ( rColSeq.getLength() == nCols )
         {
             SCCOL nDocCol = nStartCol;
-            const OUString* pColArr = rColSeq.getConstArray();
-            for (long nCol=0; nCol<nCols; nCol++)
+            for (const OUString& aText : rColSeq)
             {
-                OUString aText(pColArr[nCol]);
                 ScAddress aPos( nDocCol, nDocRow, nTab );
 
                 ScInputStringType aRes =
@@ -1941,14 +1933,13 @@ uno::Sequence<beans::PropertyState> SAL_CALL ScCellRangesBase::getPropertyStates
     const SfxItemPropertyMap& rPropertyMap = GetItemPropertyMap();     // from derived class
 
     uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
-    beans::PropertyState* pStates = aRet.getArray();
-    for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
-    {
-        sal_uInt16 nItemWhich = 0;
-        const SfxItemPropertySimpleEntry* pEntry  = rPropertyMap.getByName( aPropertyNames[i] );
-        lcl_GetPropertyWhich( pEntry, nItemWhich );
-        pStates[i] = GetOnePropertyState(nItemWhich, pEntry);
-    }
+    std::transform(aPropertyNames.begin(), aPropertyNames.end(), aRet.begin(),
+        [this, &rPropertyMap](const auto& rName) -> beans::PropertyState {
+            sal_uInt16 nItemWhich = 0;
+            const SfxItemPropertySimpleEntry* pEntry  = rPropertyMap.getByName( rName );
+            lcl_GetPropertyWhich( pEntry, nItemWhich );
+            return GetOnePropertyState(nItemWhich, pEntry);
+        });
     return aRet;
 }
 
@@ -4266,34 +4257,24 @@ void SAL_CALL ScCellRangesObj::addRangeAddresses( const uno::Sequence<table::Cel
                                     sal_Bool bMergeRanges )
 {
     SolarMutexGuard aGuard;
-    sal_Int32 nCount(rRanges.getLength());
-    if (nCount)
+    for (const table::CellRangeAddress& rRange : rRanges)
     {
-        const table::CellRangeAddress* pRanges = rRanges.getConstArray();
-        for (sal_Int32 i = 0; i < rRanges.getLength(); i++, pRanges++)
-        {
-            ScRange aRange(static_cast<SCCOL>(pRanges->StartColumn),
-                    static_cast<SCROW>(pRanges->StartRow),
-                    static_cast<SCTAB>(pRanges->Sheet),
-                    static_cast<SCCOL>(pRanges->EndColumn),
-                    static_cast<SCROW>(pRanges->EndRow),
-                    static_cast<SCTAB>(pRanges->Sheet));
-            AddRange(aRange, bMergeRanges);
-        }
+        ScRange aRange(static_cast<SCCOL>(rRange.StartColumn),
+                static_cast<SCROW>(rRange.StartRow),
+                static_cast<SCTAB>(rRange.Sheet),
+                static_cast<SCCOL>(rRange.EndColumn),
+                static_cast<SCROW>(rRange.EndRow),
+                static_cast<SCTAB>(rRange.Sheet));
+        AddRange(aRange, bMergeRanges);
     }
 }
 
 void SAL_CALL ScCellRangesObj::removeRangeAddresses( const uno::Sequence<table::CellRangeAddress >& rRangeSeq )
 {
     // use sometimes a better/faster implementation
-    sal_uInt32 nCount(rRangeSeq.getLength());
-    if (nCount)
+    for (const table::CellRangeAddress& rRange : rRangeSeq)
     {
-        const table::CellRangeAddress* pRanges = rRangeSeq.getConstArray();
-        for (sal_uInt32 i=0; i < nCount; ++i, ++pRanges)
-        {
-            removeRangeAddress(*pRanges);
-        }
+        removeRangeAddress(rRange);
     }
 }
 
@@ -7177,10 +7158,9 @@ void SAL_CALL ScTableSheetObj::setPrintAreas(
         if (nCount)
         {
             ScRange aPrintRange;
-            const table::CellRangeAddress* pAry = aPrintAreas.getConstArray();
-            for (sal_uInt16 i=0; i<nCount; i++)
+            for (const table::CellRangeAddress& rPrintArea : aPrintAreas)
             {
-                ScUnoConversion::FillScRange( aPrintRange, pAry[i] );
+                ScUnoConversion::FillScRange( aPrintRange, rPrintArea );
                 rDoc.AddPrintRange( nTab, aPrintRange );
             }
         }
@@ -7768,18 +7748,13 @@ void SAL_CALL ScTableSheetObj::addRanges( const uno::Sequence<table::CellRangeAd
             ScMarkData aMarkData;
             aMarkData.SelectTable( nTab, true );
 
-            sal_uInt16 nRangeCount = static_cast<sal_uInt16>(rScenRanges.getLength());
-            if (nRangeCount)
+            for (const table::CellRangeAddress& rRange : rScenRanges)
             {
-                const table::CellRangeAddress* pAry = rScenRanges.getConstArray();
-                for (sal_uInt16 i=0; i<nRangeCount; i++)
-                {
-                    OSL_ENSURE( pAry[i].Sheet == nTab, "addRanges with wrong Tab" );
-                    ScRange aOneRange( static_cast<SCCOL>(pAry[i].StartColumn), static_cast<SCROW>(pAry[i].StartRow), nTab,
-                                       static_cast<SCCOL>(pAry[i].EndColumn),   static_cast<SCROW>(pAry[i].EndRow),   nTab );
+                OSL_ENSURE( rRange.Sheet == nTab, "addRanges with wrong Tab" );
+                ScRange aOneRange( static_cast<SCCOL>(rRange.StartColumn), static_cast<SCROW>(rRange.StartRow), nTab,
+                                   static_cast<SCCOL>(rRange.EndColumn),   static_cast<SCROW>(rRange.EndRow),   nTab );
 
-                    aMarkData.SetMultiMarkArea( aOneRange );
-                }
+                aMarkData.SetMultiMarkArea( aOneRange );
             }
 
             //  Scenario ranges are tagged with attribute
diff --git a/sc/source/ui/unoobj/cellvaluebinding.cxx b/sc/source/ui/unoobj/cellvaluebinding.cxx
index 6a33f492e535..63012c3b9aef 100644
--- a/sc/source/ui/unoobj/cellvaluebinding.cxx
+++ b/sc/source/ui/unoobj/cellvaluebinding.cxx
@@ -495,17 +495,18 @@ namespace calc
         CellAddress aAddress;
         bool bFoundAddress = false;
 
-        const Any* pLoop = _rArguments.getConstArray();
-        const Any* pLoopEnd = _rArguments.getConstArray() + _rArguments.getLength();
-        for ( ; ( pLoop != pLoopEnd ) && !bFoundAddress; ++pLoop )
+        for ( const Any& rArg : _rArguments )
         {
             NamedValue aValue;
-            if ( *pLoop >>= aValue )
+            if ( rArg >>= aValue )
             {
                 if ( aValue.Name == "BoundCell" )
                 {
                     if ( aValue.Value >>= aAddress )
+                    {
                         bFoundAddress = true;
+                        break;
+                    }
                 }
             }
         }
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 65117563285e..797784786db0 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -988,11 +988,11 @@ sal_Bool SAL_CALL ScChart2DataProvider::createDataSourcePossible( const uno::Seq
         return false;
 
     OUString aRangeRepresentation;
-    for(sal_Int32 i = 0; i < aArguments.getLength(); ++i)
+    for(const auto& rArgument : aArguments)
     {
-        if ( aArguments[i].Name == "CellRangeRepresentation" )
+        if ( rArgument.Name == "CellRangeRepresentation" )
         {
-            aArguments[i].Value >>= aRangeRepresentation;
+            rArgument.Value >>= aRangeRepresentation;
         }
     }
 
@@ -1392,38 +1392,38 @@ ScChart2DataProvider::createDataSource(
     OUString aRangeRepresentation;
     uno::Sequence< sal_Int32 > aSequenceMapping;
     bool bTimeBased = false;
-    for(sal_Int32 i = 0; i < aArguments.getLength(); ++i)
+    for(const auto& rArgument : aArguments)
     {
-        if ( aArguments[i].Name == "DataRowSource" )
+        if ( rArgument.Name == "DataRowSource" )
         {
             chart::ChartDataRowSource eSource = chart::ChartDataRowSource_COLUMNS;
-            if( ! (aArguments[i].Value >>= eSource))
+            if( ! (rArgument.Value >>= eSource))
             {
                 sal_Int32 nSource(0);
-                if( aArguments[i].Value >>= nSource )
+                if( rArgument.Value >>= nSource )
                     eSource = static_cast< chart::ChartDataRowSource >( nSource );
             }
             bOrientCol = (eSource == chart::ChartDataRowSource_COLUMNS);
         }
-        else if ( aArguments[i].Name == "FirstCellAsLabel" )
+        else if ( rArgument.Name == "FirstCellAsLabel" )
         {
-            bLabel = ::cppu::any2bool(aArguments[i].Value);
+            bLabel = ::cppu::any2bool(rArgument.Value);
         }
-        else if ( aArguments[i].Name == "HasCategories" )
+        else if ( rArgument.Name == "HasCategories" )
         {
-            bCategories = ::cppu::any2bool(aArguments[i].Value);
+            bCategories = ::cppu::any2bool(rArgument.Value);
         }
-        else if ( aArguments[i].Name == "CellRangeRepresentation" )
+        else if ( rArgument.Name == "CellRangeRepresentation" )
         {
-            aArguments[i].Value >>= aRangeRepresentation;
+            rArgument.Value >>= aRangeRepresentation;
         }
-        else if ( aArguments[i].Name == "SequenceMapping" )
+        else if ( rArgument.Name == "SequenceMapping" )
         {
-            aArguments[i].Value >>= aSequenceMapping;
+            rArgument.Value >>= aSequenceMapping;
         }
-        else if ( aArguments[i].Name == "TimeBased" )
+        else if ( rArgument.Name == "TimeBased" )
         {
-            aArguments[i].Value >>= bTimeBased;
+            rArgument.Value >>= bTimeBased;
         }
     }
 
@@ -1531,10 +1531,10 @@ ScChart2DataProvider::createDataSource(
         aSeqVector.push_back(aSeq);
     }
 
-    for( sal_Int32 nNewIndex = 0; nNewIndex < aSequenceMapping.getLength(); nNewIndex++ )
+    for( const sal_Int32 nNewIndex : aSequenceMapping )
     {
         // note: assuming that the values in the sequence mapping are always non-negative
-        ::std::vector< uno::Reference< chart2::data::XLabeledDataSequence > >::size_type nOldIndex( static_cast< sal_uInt32 >( aSequenceMapping[nNewIndex] ) );
+        ::std::vector< uno::Reference< chart2::data::XLabeledDataSequence > >::size_type nOldIndex( static_cast< sal_uInt32 >( nNewIndex ) );
         if( nOldIndex < aSeqVector.size() )
         {
             pDS->AddLabeledSequence( aSeqVector[nOldIndex] );
@@ -1749,9 +1749,8 @@ uno::Sequence< beans::PropertyValue > SAL_CALL ScChart2DataProvider::detectArgum
         Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aSequences( xDataSource->getDataSequences());
         const sal_Int32 nCount( aSequences.getLength());
         RangeAnalyzer aPrevLabel,aPrevValues;
-        for( sal_Int32 nIdx=0; nIdx<nCount; ++nIdx )
+        for( const uno::Reference< chart2::data::XLabeledDataSequence >& xLS : aSequences )
         {
-            uno::Reference< chart2::data::XLabeledDataSequence > xLS(aSequences[nIdx]);
             if( xLS.is() )
             {
                 bool bThisIsCategories = false;
diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx
index 405cc31ec55c..9818888a7197 100644
--- a/sc/source/ui/unoobj/chartuno.cxx
+++ b/sc/source/ui/unoobj/chartuno.cxx
@@ -158,16 +158,11 @@ void SAL_CALL ScChartsObj::addNewByName( const OUString& rName,
     }
 
     ScRangeList* pList = new ScRangeList;
-    sal_Int32 nRangeCount = aRanges.getLength();
-    if (nRangeCount)
+    for (const table::CellRangeAddress& rRange : aRanges)
     {
-        const table::CellRangeAddress* pAry = aRanges.getConstArray();
-        for (sal_Int32 i=0; i<nRangeCount; i++)
-        {
-            ScRange aRange( static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow, pAry[i].Sheet,
-                            static_cast<SCCOL>(pAry[i].EndColumn),   pAry[i].EndRow,   pAry[i].Sheet );
-            pList->push_back( aRange );
-        }
+        ScRange aRange( static_cast<SCCOL>(rRange.StartColumn), rRange.StartRow, rRange.Sheet,
+                        static_cast<SCCOL>(rRange.EndColumn),   rRange.EndRow,   rRange.Sheet );
+        pList->push_back( aRange );
     }
     ScRangeListRef xNewRanges( pList );
 
@@ -457,11 +452,8 @@ void ScChartObj::GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool&
                 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
                 bool bHasCategories=false;
                 bool bFirstCellAsLabel=false;
-                const beans::PropertyValue* pPropArray = aArgs.getConstArray();
-                long nPropCount = aArgs.getLength();
-                for (long i = 0; i < nPropCount; i++)
+                for (const beans::PropertyValue& rProp : aArgs)
                 {
-                    const beans::PropertyValue& rProp = pPropArray[i];
                     OUString aPropName(rProp.Name);
 
                     if (aPropName == "CellRangeRepresentation")
@@ -689,16 +681,11 @@ void SAL_CALL ScChartObj::setRanges( const uno::Sequence<table::CellRangeAddress
     GetData_Impl( xOldRanges, bColHeaders, bRowHeaders );
 
     ScRangeList* pList = new ScRangeList;
-    sal_uInt16 nRangeCount = static_cast<sal_uInt16>(aRanges.getLength());
-    if (nRangeCount)
+    for (const table::CellRangeAddress& rRange : aRanges)
     {
-        const table::CellRangeAddress* pAry = aRanges.getConstArray();
-        for (sal_uInt16 i=0; i<nRangeCount; i++)
-        {
-            ScRange aRange( static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow, pAry[i].Sheet,
-                            static_cast<SCCOL>(pAry[i].EndColumn),   pAry[i].EndRow,   pAry[i].Sheet );
-            pList->push_back( aRange );
-        }
+        ScRange aRange( static_cast<SCCOL>(rRange.StartColumn), rRange.StartRow, rRange.Sheet,
+                        static_cast<SCCOL>(rRange.EndColumn),   rRange.EndRow,   rRange.Sheet );
+        pList->push_back( aRange );
     }
     ScRangeListRef xNewRanges( pList );
 
diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx
index 680eada26772..747b31402778 100644
--- a/sc/source/ui/unoobj/condformatuno.cxx
+++ b/sc/source/ui/unoobj/condformatuno.cxx
@@ -344,10 +344,10 @@ sal_Int32 ScCondFormatsObj::createByRange(const uno::Reference< sheet::XSheetCel
         xRanges->getRangeAddresses();
 
     ScRangeList aCoreRange;
-    for (sal_Int32 i = 0, n = aRanges.getLength(); i < n; ++i)
+    for (const auto& rRange : aRanges)
     {
         ScRange aRange;
-        ScUnoConversion::FillScRange(aRange, aRanges[i]);
+        ScUnoConversion::FillScRange(aRange, rRange);
         aCoreRange.Join(aRange);
     }
 
@@ -579,10 +579,10 @@ void SAL_CALL ScCondFormatObj::setPropertyValue(
                 uno::Sequence<table::CellRangeAddress> aRanges =
                     xRange->getRangeAddresses();
                 ScRangeList aTargetRange;
-                for (size_t i = 0, n = aRanges.getLength(); i < n; ++i)
+                for (const auto& rRange : aRanges)
                 {
                     ScRange aRange;
-                    ScUnoConversion::FillScRange(aRange, aRanges[i]);
+                    ScUnoConversion::FillScRange(aRange, rRange);
                     aTargetRange.Join(aRange);
                 }
                 pFormat->SetRange(aTargetRange);
diff --git a/sc/source/ui/unoobj/cursuno.cxx b/sc/source/ui/unoobj/cursuno.cxx
index 0839e754e69d..af8fa73a767f 100644
--- a/sc/source/ui/unoobj/cursuno.cxx
+++ b/sc/source/ui/unoobj/cursuno.cxx
@@ -442,7 +442,6 @@ uno::Sequence<OUString> SAL_CALL ScCellCursorObj::getSupportedServiceNames()
     //  get all service names from cell range
     uno::Sequence<OUString> aParentSeq(ScCellRangeObj::getSupportedServiceNames());
     sal_Int32 nParentLen = aParentSeq.getLength();
-    const OUString* pParentArr = aParentSeq.getConstArray();
 
     //  SheetCellCursor should be first (?)
     uno::Sequence<OUString> aTotalSeq( nParentLen + 2 );
@@ -451,8 +450,7 @@ uno::Sequence<OUString> SAL_CALL ScCellCursorObj::getSupportedServiceNames()
     pTotalArr[1] = SCCELLCURSOR_SERVICE;
 
     //  append cell range services
-    for (long i=0; i<nParentLen; i++)
-        pTotalArr[i+2] = pParentArr[i];
+    std::copy_n(aParentSeq.begin(), nParentLen, std::next(aTotalSeq.begin(), 2));
 
     return aTotalSeq;
 }
diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index 0d1a4c5f62fe..8228df10868c 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -836,10 +836,8 @@ void SAL_CALL ScDataPilotDescriptorBase::setPropertyValue( const OUString& aProp
                         aServiceDesc = *pOldDesc;
 
                     OUString aStrVal;
-                    sal_Int32 nArgs = aArgSeq.getLength();
-                    for (sal_Int32 nArgPos=0; nArgPos<nArgs; ++nArgPos)
+                    for (const beans::PropertyValue& rProp : aArgSeq)
                     {
-                        const beans::PropertyValue& rProp = aArgSeq[nArgPos];
                         OUString aPropName(rProp.Name);
 
                         if (aPropName == SC_UNO_DP_SOURCENAME)
@@ -1778,11 +1776,11 @@ void SAL_CALL ScDataPilotFieldObj::setPropertyValue( const OUString& aPropertyNa
         if( aValue >>= aSeq)
         {
             std::vector< ScGeneralFunction > aSubTotals(aSeq.getLength());
-            for (sal_Int32 nIndex = 0; nIndex < aSeq.getLength(); nIndex++)
-            {
-                const int nValAsInt = static_cast<int>(aSeq[nIndex]);
-                aSubTotals[nIndex] = static_cast<ScGeneralFunction>(nValAsInt);
-            }
+            std::transform(aSeq.begin(), aSeq.end(), aSubTotals.begin(),
+                [](const sheet::GeneralFunction& rValue) -> ScGeneralFunction {
+                    const int nValAsInt = static_cast<int>(rValue);
+                    return static_cast<ScGeneralFunction>(nValAsInt);
+                });
             setSubtotals( aSubTotals );
         }
     }
@@ -1792,10 +1790,8 @@ void SAL_CALL ScDataPilotFieldObj::setPropertyValue( const OUString& aPropertyNa
         if( aValue >>= aSeq )
         {
             std::vector< ScGeneralFunction > aSubTotals(aSeq.getLength());
-            for (sal_Int32 nIndex = 0; nIndex < aSeq.getLength(); nIndex++)
-            {
-                aSubTotals[nIndex] = static_cast<ScGeneralFunction>(aSeq[nIndex]);
-            }
+            std::transform(aSeq.begin(), aSeq.end(), aSubTotals.begin(),
+                [](sal_Int16 nValue) -> ScGeneralFunction { return static_cast<ScGeneralFunction>(nValue); });
             setSubtotals( aSubTotals );
         }
     }
@@ -1912,13 +1908,12 @@ Any SAL_CALL ScDataPilotFieldObj::getPropertyValue( const OUString& aPropertyNam
         uno::Sequence<sal_Int16> aSeq = getSubtotals();
         uno::Sequence<sheet::GeneralFunction>  aNewSeq;
         aNewSeq.realloc(aSeq.getLength());
-        for (sal_Int32 nIndex = 0; nIndex < aSeq.getLength(); nIndex++)
-        {
-            if (aSeq[nIndex] == sheet::GeneralFunction2::MEDIAN)
-                aNewSeq[nIndex] = sheet::GeneralFunction_NONE;
-            else
-                aNewSeq[nIndex] = static_cast<sheet::GeneralFunction>(aSeq[nIndex]);
-        }
+        std::transform(aSeq.begin(), aSeq.end(), aNewSeq.begin(),
+            [](sal_Int16 nFunc) -> sheet::GeneralFunction {
+                if (nFunc == sheet::GeneralFunction2::MEDIAN)
+                    return sheet::GeneralFunction_NONE;
+                return static_cast<sheet::GeneralFunction>(nFunc);
+            });
         aRet <<= aNewSeq;
     }
     else if ( aPropertyName == SC_UNONAME_SUBTOTALS2 )
@@ -2509,9 +2504,8 @@ Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( cons
         // (empty groups are removed, too)
         if ( pGroupDimension )
         {
-            for (sal_Int32 nEntry = 0; nEntry < rItems.getLength(); nEntry++)
+            for (const OUString& aEntryName : rItems)
             {
-                const OUString& aEntryName = rItems[nEntry];
                 if ( pBaseGroupDim )
                 {
                     // for each selected (intermediate) group, remove all its items
@@ -2564,9 +2558,8 @@ Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( cons
 
         OUString aGroupName = pGroupDimension->CreateGroupName( ScResId(STR_PIVOT_GROUP) );
         ScDPSaveGroupItem aGroup( aGroupName );
-        for (sal_Int32 nEntry = 0; nEntry < rItems.getLength(); nEntry++)
+        for (const OUString& aEntryName : rItems)
         {
-            OUString aEntryName(rItems[nEntry]);
             if ( pBaseGroupDim )
             {
                 // for each selected (intermediate) group, add all its items
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index f7f8d30dbc8c..89064f898c31 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -204,11 +204,8 @@ void ScImportDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rS
 void ScImportDescriptor::FillImportParam( ScImportParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq )
 {
     OUString aStrVal;
-    const beans::PropertyValue* pPropArray = rSeq.getConstArray();
-    long nPropCount = rSeq.getLength();
-    for (long i = 0; i < nPropCount; i++)
+    for (const beans::PropertyValue& rProp : rSeq)
     {
-        const beans::PropertyValue& rProp = pPropArray[i];
         OUString aPropName(rProp.Name);
 
         if (aPropName == SC_UNONAME_ISNATIVE)
@@ -323,13 +320,10 @@ void ScSortDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rSeq
 
 void ScSortDescriptor::FillSortParam( ScSortParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq )
 {
-    const beans::PropertyValue* pPropArray = rSeq.getConstArray();
-    long nPropCount = rSeq.getLength();
     sal_Int16 nSortSize = rParam.GetSortKeyCount();
 
-    for (long nProp = 0; nProp < nPropCount; nProp++)
+    for (const beans::PropertyValue& rProp : rSeq)
     {
-        const beans::PropertyValue& rProp = pPropArray[nProp];
         OUString aPropName(rProp.Name);
 
         if (aPropName == SC_UNONAME_ORIENT)
@@ -1125,12 +1119,12 @@ void fillQueryParam(
             ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
             rItems.clear();
             const uno::Sequence<sheet::FilterFieldValue>& rVals = pAry[i].Values;
-            for (sal_Int32 j = 0, n = rVals.getLength(); j < n; ++j)
+            for (const auto& rVal : rVals)
             {
                 ScQueryEntry::Item aItem;
-                aItem.meType   = rVals[j].IsNumeric ? ScQueryEntry::ByValue : ScQueryEntry::ByString;
-                aItem.mfVal    = rVals[j].NumericValue;
-                aItem.maString = rPool.intern(rVals[j].StringValue);
+                aItem.meType   = rVal.IsNumeric ? ScQueryEntry::ByValue : ScQueryEntry::ByString;

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list