This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch symphony-vba in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit 31694323a4ab6372b820ac9a8efd11acc77d4b80 Author: Pedro Giffuni <[email protected]> AuthorDate: Tue Oct 27 13:24:44 2026 -0500 Implement VBA compatibility fixes for arrays, TypeName, Array(), NBSP parsing, and named ranges Fix VBA compatibility issues identified by LibreOffice-style failure hypothesis tests: - VBA arrays: Dim arr(n) now creates 1-based arrays (indices 1..n) in VBA compatibility mode (StepBASED, SbiParser::DefType) - TypeName: Returns 'Nothing' for null object references in VBA mode - Array(): Always 0-based per VBA spec (ignores Option Base 1 in VBA mode) - NBSP (U+00A0) as thousands separator: Handle locale-aware number parsing in ImpScan by replacing NBSP before ASCII-US conversion - Names.Add: Parse string RefersTo addresses (e.g. '=Sheet1!$A$1:$A$3') via getRangeObjectForName after stripping '=' prefix - Name.Name: Return raw name without sheet prefix (AOO stores all names at document level, unlike VBA worksheet-level names) - Name.RefersToRange: Use getValue() (VBA-formatted address) instead of getName() to resolve the range reference --- main/basic/source/comp/dim.cxx | 7 ++++--- main/basic/source/runtime/methods.cxx | 23 +++++++++++++++++------ main/basic/source/runtime/methods1.cxx | 5 ++++- main/basic/source/runtime/step1.cxx | 3 +++ main/basic/source/sbx/sbxscan.cxx | 19 ++++++++++++++++--- main/sc/source/ui/vba/vbaname.cxx | 17 ++++++++++------- main/sc/source/ui/vba/vbanames.cxx | 24 ++++++++++++++++++++++++ 7 files changed, 78 insertions(+), 20 deletions(-) diff --git a/main/basic/source/comp/dim.cxx b/main/basic/source/comp/dim.cxx index d1c38d168f..3003685007 100644 --- a/main/basic/source/comp/dim.cxx +++ b/main/basic/source/comp/dim.cxx @@ -612,7 +612,7 @@ void SbiParser::DefType( sal_Bool bPrivate ) { // Dimension the target array - for ( short i=0; i<pDim->GetSize();++i ) + for ( short i=0; i<pDim->GetSize();++i ) { sal_Int32 ub = -1; sal_Int32 lb = nBase; @@ -626,8 +626,9 @@ void SbiParser::DefType( sal_Bool bPrivate ) lb = ub; ub = pNode->GetNumber(); } - else if ( !bCompatible ) - ub += nBase; + else if ( !bCompatible ) + ub += nBase; + // VBA: lb = nBase (respects Option Base), ub = declared value pArray->AddDim32( lb, ub ); } pArray->setHasFixedSize( true ); diff --git a/main/basic/source/runtime/methods.cxx b/main/basic/source/runtime/methods.cxx index ed62ba004c..387aa19c40 100644 --- a/main/basic/source/runtime/methods.cxx +++ b/main/basic/source/runtime/methods.cxx @@ -3629,12 +3629,23 @@ RTLFUNC(TypeName) StarBASIC::Error( SbERR_BAD_ARGUMENT ); else { - SbxDataType eType = rPar.Get(1)->GetType(); - sal_Bool bIsArray = ( ( eType & SbxARRAY ) != 0 ); - String aRetStr = getBasicTypeName( eType ); - if( bIsArray ) - aRetStr.AppendAscii( "()" ); - rPar.Get(0)->PutString( aRetStr ); + SbxVariable* pVar = rPar.Get(1); + SbxDataType eType = pVar->GetType(); + + // #i129350: In VBA compatibility mode, return "Nothing" for null objects + sal_Bool bVBA = SbiRuntime::isVBAEnabled(); + if( bVBA && eType == SbxOBJECT && !pVar->GetObject() ) + { + rPar.Get(0)->PutString( String( RTL_CONSTASCII_USTRINGPARAM("Nothing") ) ); + } + else + { + sal_Bool bIsArray = ( ( eType & SbxARRAY ) != 0 ); + String aRetStr = getBasicTypeName( eType ); + if( bIsArray ) + aRetStr.AppendAscii( "()" ); + rPar.Get(0)->PutString( aRetStr ); + } } } diff --git a/main/basic/source/runtime/methods1.cxx b/main/basic/source/runtime/methods1.cxx index 9fa279315c..fbd4e31616 100644 --- a/main/basic/source/runtime/methods1.cxx +++ b/main/basic/source/runtime/methods1.cxx @@ -768,7 +768,10 @@ RTLFUNC(Array) sal_uInt16 nArraySize = rPar.Count() - 1; // Option Base zunaechst ignorieren (kennt leider nur der Compiler) - bool bIncIndex = (IsBaseIndexOne() && SbiRuntime::isVBAEnabled() ); + // #i129350: In VBA mode, Array() is always 0-based per VBA spec + // (Option Base is not a VBA feature) + bool bVBAEnabled = SbiRuntime::isVBAEnabled(); + bool bIncIndex = (IsBaseIndexOne() && !bVBAEnabled) ; if( nArraySize ) { if ( bIncIndex ) diff --git a/main/basic/source/runtime/step1.cxx b/main/basic/source/runtime/step1.cxx index cd3d2fc37b..be5e42ffd1 100644 --- a/main/basic/source/runtime/step1.cxx +++ b/main/basic/source/runtime/step1.cxx @@ -556,6 +556,9 @@ void SbiRuntime::StepBASED( sal_uInt32 nOp1 ) // #109275 Check compatibility mode bool bCompatible = ((nOp1 & 0x8000) != 0); sal_uInt16 uBase = static_cast<sal_uInt16>(nOp1 & 1); // Can only be 0 or 1 + // VBA respects Option Base for implicit array bounds: + // Dim arr(n) with Option Base 0 -> 0 To n, with Option Base 1 -> 1 To n + // (only VBA's Array() function is always 0-based regardless of Option Base) p1->PutInteger( uBase ); if( !bCompatible ) x2->Compute( SbxPLUS, *p1 ); diff --git a/main/basic/source/sbx/sbxscan.cxx b/main/basic/source/sbx/sbxscan.cxx index 699382ac5e..313b673d25 100644 --- a/main/basic/source/sbx/sbxscan.cxx +++ b/main/basic/source/sbx/sbxscan.cxx @@ -68,16 +68,29 @@ void ImpGetIntntlSep( sal_Unicode& rcDecimalSep, sal_Unicode& rcThousandSep ) SbxError ImpScan( const ::rtl::OUString& rWSrc, double& nVal, SbxDataType& rType, sal_uInt16* pLen, sal_Bool bAllowIntntl, sal_Bool bOnlyIntntl ) { - ::rtl::OString aBStr( ::rtl::OUStringToOString( rWSrc, RTL_TEXTENCODING_ASCII_US ) ); + // Handle non-breaking space (U+00A0) as thousands separator. + // The ASCII US conversion below would replace NBSP with '?', + // causing locale-aware number parsing to fail (e.g. "1 000,5" in fr_FR). + sal_Unicode cDecimalSep, cThousandSep = 0; + if( bAllowIntntl || bOnlyIntntl ) + { + ImpGetIntntlSep( cDecimalSep, cThousandSep ); + if( cThousandSep == 0xA0 ) // NBSP + cThousandSep = (sal_Unicode)' '; + } + + // Replace NBSP in source so the ASCII US conversion preserves it as ' ' + rtl::OUString aUSrc = rWSrc; + if( cThousandSep == ' ' ) + aUSrc = aUSrc.replace( sal_Unicode(0xA0), ' ' ); + ::rtl::OString aBStr( ::rtl::OUStringToOString( aUSrc, RTL_TEXTENCODING_ASCII_US ) ); // Bei International Komma besorgen char cIntntlComma, cIntntl1000; char cNonIntntlComma = '.'; - sal_Unicode cDecimalSep, cThousandSep = 0; if( bAllowIntntl || bOnlyIntntl ) { - ImpGetIntntlSep( cDecimalSep, cThousandSep ); cIntntlComma = (char)cDecimalSep; cIntntl1000 = (char)cThousandSep; } diff --git a/main/sc/source/ui/vba/vbaname.cxx b/main/sc/source/ui/vba/vbaname.cxx index e31ba067a3..0bbe8f30f0 100644 --- a/main/sc/source/ui/vba/vbaname.cxx +++ b/main/sc/source/ui/vba/vbaname.cxx @@ -64,11 +64,9 @@ ScVbaName::getWorkSheet() ::rtl::OUString ScVbaName::getName() { - String sName; - sName += UniString( getWorkSheet()->getName()); - sName += String::CreateFromAscii("!"); - sName += UniString ( mxNamedRange->getName() ); - return ::rtl::OUString( sName ); + // In VBA, workbook-level names return just the name without sheet prefix + // AOO stores all names at document level, so return the raw name + return mxNamedRange->getName(); } void @@ -228,8 +226,13 @@ ScVbaName::setRefersToR1C1Local( const ::rtl::OUString & rRefersTo ) css::uno::Reference< ov::excel::XRange > ScVbaName::getRefersToRange() { - uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName( - mxContext, mxNamedRange->getName(), excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_R1C1 ); + // #i129350: use getValue() (returns "=Sheet1!$A$1:$A$3") instead of + // getName() (returns just the name of the named range) + ::rtl::OUString sRefersTo = getValue(); + if ( sRefersTo.getLength() > 0 && sRefersTo[0] == '=' ) + sRefersTo = sRefersTo.copy(1); + uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName( + mxContext, sRefersTo, excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_A1 ); return xRange; } diff --git a/main/sc/source/ui/vba/vbanames.cxx b/main/sc/source/ui/vba/vbanames.cxx index 4a402b704a..9c5ae5dc8e 100644 --- a/main/sc/source/ui/vba/vbanames.cxx +++ b/main/sc/source/ui/vba/vbanames.cxx @@ -127,6 +127,30 @@ ScVbaNames::Add( const css::uno::Any& Name , RefersToR1C1 >>= xRange; if ( RefersToR1C1Local.hasValue() ) RefersToR1C1Local >>= xRange; + + // #i129350: VBA Names.Add can pass RefersTo as a string address (e.g. "=Sheet1!$A$1:$A$3") + // The >>= above only extracts XRange for interface types, not strings + if ( !xRange.is() && RefersTo.hasValue() ) + { + rtl::OUString sRefersTo; + RefersTo >>= sRefersTo; + if ( sRefersTo.getLength() > 0 ) + { + // Strip leading '=' if present (VBA RefersTo format: "=Address") + if ( sRefersTo[0] == '=' ) + sRefersTo = sRefersTo.copy(1); + try + { + xRange = ScVbaRange::getRangeObjectForName( + mxContext, sRefersTo, excel::getDocShell( mxModel ), + formula::FormulaGrammar::CONV_XL_A1 ); + } + catch( ... ) + { + xRange.clear(); + } + } + } } if ( xRange.is() )
