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 bd1391e667f34985dcb47fecf22af14325311783 Author: Pedro Giffuni <[email protected]> AuthorDate: Fri Nov 6 01:14:12 2026 -0500 Improve VBA API comments with MS VBA spec and compliance notes --- main/sc/source/ui/vba/vbadictionary.cxx | 24 +++++++++++++++++++ main/sc/source/ui/vba/vbadictionary.hxx | 19 ++++++++++++++- main/sc/source/ui/vba/vbaformatcondition.cxx | 10 ++++++++ main/sc/source/ui/vba/vbaformatcondition.hxx | 35 +++++++++++++++++----------- main/sc/source/ui/vba/vbaquerytable.cxx | 17 ++++++++++++++ main/sc/source/ui/vba/vbaquerytable.hxx | 33 ++++++++++++++++++-------- main/sc/source/ui/vba/vbaworkbook.cxx | 15 ++++++++++-- main/sc/source/ui/vba/vbaworkbook.hxx | 12 ++++++++-- 8 files changed, 136 insertions(+), 29 deletions(-) diff --git a/main/sc/source/ui/vba/vbadictionary.cxx b/main/sc/source/ui/vba/vbadictionary.cxx index 767d023295..0b05d3eb5f 100644 --- a/main/sc/source/ui/vba/vbadictionary.cxx +++ b/main/sc/source/ui/vba/vbadictionary.cxx @@ -142,6 +142,10 @@ sal_Int32 ScVbaDictionary::findKeyIndex(const uno::Any& aKey) return -1; } +// MS VBA: Adds a key and item pair to a Dictionary object. +// Remarks (MS): An error occurs if the key already exists. +// AOO: Throws BasicErrorException with error code 457 ("Duplicate key") on duplicate, +// matching VBA's "This key is already associated with an element of this collection". void ScVbaDictionary::Add(const uno::Any& Key, const uno::Any& Item) { sal_Int32 nIndex = findKeyIndex(Key); @@ -164,11 +168,18 @@ void ScVbaDictionary::Add(const uno::Any& Key, const uno::Any& Item) maEntries.push_back(entry); } +// MS VBA: Returns True if a specified key exists in the Dictionary object; False if it does not. sal_Bool ScVbaDictionary::Exists(const uno::Any& Key) { return findKeyIndex(Key) >= 0; } +// MS VBA: Sets or returns an item for a specified key in a Dictionary object. +// Remarks (MS): If key is not found when changing an item, a new key is created with the +// specified newitem. If key is not found when attempting to return an existing item, a new +// key is created and its corresponding item is left empty. +// AOO (getItem): Returns an empty Any for missing key (approximates VBA's empty variant +// behavior for reads; VBA's default-property semantics for writes are handled via invoke/setItem). uno::Any ScVbaDictionary::getItem(const uno::Any& Key) { sal_Int32 nIndex = findKeyIndex(Key); @@ -351,6 +362,7 @@ uno::Reference< beans::XIntrospectionAccess > SAL_CALL ScVbaDictionary::getIntro return uno::Reference< beans::XIntrospectionAccess >(); } +// MS VBA: Returns an array containing all existing keys in a Dictionary object. uno::Any ScVbaDictionary::Keys() { uno::Sequence< uno::Any > aKeys(maEntries.size()); @@ -363,6 +375,7 @@ uno::Any ScVbaDictionary::Keys() return aResult; } +// MS VBA: Returns an array containing all the items in a Dictionary object. uno::Any ScVbaDictionary::Items() { uno::Sequence< uno::Any > aItems(maEntries.size()); @@ -375,6 +388,9 @@ uno::Any ScVbaDictionary::Items() return aResult; } +// MS VBA: Removes a key/item pair from a Dictionary object. +// Remarks (MS): An error occurs if the specified key/item pair does not exist. +// AOO: Throws BasicErrorException with error code 32811 on missing key. void ScVbaDictionary::Remove(const uno::Any& Key) { sal_Int32 nIndex = findKeyIndex(Key); @@ -390,6 +406,7 @@ void ScVbaDictionary::Remove(const uno::Any& Key) maEntries.erase(maEntries.begin() + nIndex); } +// MS VBA: Removes all key, item pairs from a Dictionary object. void ScVbaDictionary::RemoveAll() { maEntries.clear(); @@ -404,6 +421,13 @@ void SAL_CALL ScVbaDictionary::setCount(sal_Int32 /*nCount*/) { } +// MS VBA: CompareMode property - sets and returns the comparison mode for comparing string keys. +// Values (MS): vbUseCompareOption (-1), vbBinaryCompare (0), vbTextCompare (1), vbDatabaseCompare (2). +// Remarks (MS): An error occurs if you try to change the comparison mode of a Dictionary object +// that already contains data. +// AOO: Stores the mode but does NOT enforce "cannot change when non-empty" (compliance gap). +// Compare behavior: mode 0 treated as case-sensitive/binary-like; others use case-insensitive +// string comparison for string keys. vbUseCompareOption/vbDatabaseCompare semantics are partial. sal_Int32 ScVbaDictionary::getCompareMode() { return mnCompareMode; diff --git a/main/sc/source/ui/vba/vbadictionary.hxx b/main/sc/source/ui/vba/vbadictionary.hxx index 30b34d64b7..6c0efcf205 100644 --- a/main/sc/source/ui/vba/vbadictionary.hxx +++ b/main/sc/source/ui/vba/vbadictionary.hxx @@ -79,16 +79,33 @@ public: explicit ScVbaDictionary(const uno::Reference< uno::XComponentContext >& xContext); virtual ~ScVbaDictionary() {} - // XDictionary + // XDictionary (Scripting.Dictionary compatibility) + // MS VBA: Adds a key and item pair to a Dictionary object. + // Remarks: An error occurs if the key already exists (runtime error 457). virtual void SAL_CALL Add(const uno::Any& Key, const uno::Any& Item); + // MS VBA: Returns True if a specified key exists in the Dictionary object; False if it does not. virtual sal_Bool SAL_CALL Exists(const uno::Any& Key); + // MS VBA: Returns an array containing all the items in a Dictionary object. virtual uno::Any SAL_CALL Items(); + // MS VBA: Returns an array containing all existing keys in a Dictionary object. virtual uno::Any SAL_CALL Keys(); + // MS VBA: Removes a key/item pair from a Dictionary object. + // Remarks: An error occurs if the specified key/item pair does not exist. virtual void SAL_CALL Remove(const uno::Any& Key); + // MS VBA: Removes all key, item pairs from a Dictionary object. virtual void SAL_CALL RemoveAll(); + // MS VBA: Sets or returns an item for a specified key in a Dictionary object. + // Remarks: If key is not found when changing an item, a new key is created with the specified newitem. + // If key is not found when attempting to return an existing item, a new key is created and its + // corresponding item is left empty. virtual uno::Any SAL_CALL Item(const uno::Any& Key); + // MS VBA: Returns a Long containing the number of items in a Dictionary object. Read-only. virtual sal_Int32 SAL_CALL getCount(); virtual void SAL_CALL setCount(sal_Int32 /*nCount*/); + // MS VBA: Sets and returns the comparison mode for comparing string keys in a Dictionary object. + // Values: vbUseCompareOption (-1), vbBinaryCompare (0), vbTextCompare (1), vbDatabaseCompare (2). + // Remarks: An error occurs if you try to change the comparison mode of a Dictionary object that + // already contains data. virtual sal_Int32 SAL_CALL getCompareMode(); virtual void SAL_CALL setCompareMode(sal_Int32 CompareMode); diff --git a/main/sc/source/ui/vba/vbaformatcondition.cxx b/main/sc/source/ui/vba/vbaformatcondition.cxx index d7ee4135d0..8c8e4a317b 100644 --- a/main/sc/source/ui/vba/vbaformatcondition.cxx +++ b/main/sc/source/ui/vba/vbaformatcondition.cxx @@ -50,6 +50,9 @@ ScVbaFormatCondition::ScVbaFormatCondition( const uno::Reference< XHelperInterf } +// MS VBA: FormatCondition.Delete - Deletes the object. +// Compliance: implemented - removes the condition (and its style) via FormatConditions helper, +// then notifies the parent range to refresh conditional format state. void SAL_CALL ScVbaFormatCondition::Delete( ) { @@ -58,6 +61,13 @@ ScVbaFormatCondition::Delete( ) notifyRange(); } +// MS VBA: FormatCondition.Modify - Modifies an existing conditional format. +// Parameters (MS): Type (Required, XlFormatConditionType: xlCellValue=1, xlExpression=2), +// Operator (Optional, XlFormatConditionOperator; ignored if Type is xlExpression), +// Formula1 (Optional, Variant: constant/string/cell ref/formula), +// Formula2 (Optional, Variant: used for xlBetween/xlNotBetween). +// Compliance: implemented via remove+re-add pattern. Removes the existing condition (keeping +// style state as handled by helper) and re-adds with new parameters and the current style. void SAL_CALL ScVbaFormatCondition::Modify( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2 ) { diff --git a/main/sc/source/ui/vba/vbaformatcondition.hxx b/main/sc/source/ui/vba/vbaformatcondition.hxx index fd892f7df6..0e29fc3e72 100644 --- a/main/sc/source/ui/vba/vbaformatcondition.hxx +++ b/main/sc/source/ui/vba/vbaformatcondition.hxx @@ -60,40 +60,47 @@ public: static css::sheet::ConditionOperator retrieveAPIType(sal_Int32 _nVBAType, const css::uno::Reference< css::sheet::XSheetCondition >& _xSheetCondition ); // MS Excel VBA: Methods - FormatCondition actions - // MS Excel VBA: Deletes the formatting condition and its associated XStyle. - // Status: implemented + // MS VBA: Deletes the FormatCondition object. + // Status: implemented - removes the condition entry and its associated style, notifies range. virtual void SAL_CALL Delete( ); - // MS Excel VBA: Modifies an existing conditional formatting rule's type and parameters. - // Status: implemented - updates Type, Operator, Formula1, Formula2 + // MS VBA: Modifies an existing conditional format. + // Parameters: + // Type (Required, XlFormatConditionType): xlCellValue or xlExpression. + // Operator (Optional, XlFormatConditionOperator): xlBetween, xlEqual, xlGreater, + // xlGreaterEqual, xlLess, xlLessEqual, xlNotBetween, xlNotEqual. Ignored if Type is xlExpression. + // Formula1 (Optional, Variant): Value or expression associated with the conditional format. + // Can be a constant value, string value, cell reference, or formula. + // Formula2 (Optional, Variant): Second value/expression when Operator is xlBetween/xlNotBetween. + // Status: implemented - removes old condition, re-adds via FormatConditions.Add, notifies range. virtual void SAL_CALL Modify( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2 ); - // MS Excel VBA: Returns the condition type (xlCellValue or xlExpression). + // MS VBA: Returns the condition type (xlCellValue=1 or xlExpression=2). // Status: implemented virtual ::sal_Int32 SAL_CALL Type( ); - // MS Excel VBA: Returns the comparison operator type for the condition. + // MS VBA: Returns the comparison operator type for the condition. // Status: implemented - non-const overload for internal use virtual ::sal_Int32 Operator( sal_Bool ); - // MS Excel VBA: Returns the comparison operator type for the condition. + // MS VBA: Returns the comparison operator type for the condition. // Status: implemented virtual ::sal_Int32 SAL_CALL Operator( ); - // MS Excel VBA: Returns the first formula (or value) for the condition. + // MS VBA: Returns the first formula (or value) for the condition. // Status: implemented virtual rtl::OUString SAL_CALL Formula1( ); - // MS Excel VBA: Returns the second formula (or value) for the condition. + // MS VBA: Returns the second formula (or value) for the condition. // Status: implemented virtual rtl::OUString SAL_CALL Formula2( ); - // MS Excel VBA: Sets the first formula (or value) for the condition. + // MS VBA: Sets the first formula (or value) for the condition. // Status: implemented virtual void setFormula1( const css::uno::Any& _aFormula1); - // MS Excel VBA: Sets the second formula (or value) for the condition. + // MS VBA: Sets the second formula (or value) for the condition. // Status: implemented virtual void setFormula2( const css::uno::Any& _aFormula2); - // MS Excel VBA: Returns the Interior object (fill color, pattern) for the condition. + // MS VBA: Returns the Interior object (fill color, pattern) for the condition. // Status: implemented virtual css::uno::Reference< ::ooo::vba::excel::XInterior > SAL_CALL Interior( ); - // MS Excel VBA: Returns the Borders collection for the condition. + // MS VBA: Returns the Borders collection for the condition. // Status: implemented virtual css::uno::Any SAL_CALL Borders( const css::uno::Any& Index ); - // MS Excel VBA: Returns the Font object for the condition's text. + // MS VBA: Returns the Font object for the condition's text. // Status: implemented virtual css::uno::Reference< ::ooo::vba::excel::XFont > SAL_CALL Font( ); // XHelperInterface diff --git a/main/sc/source/ui/vba/vbaquerytable.cxx b/main/sc/source/ui/vba/vbaquerytable.cxx index 8245974017..2f7d706bb6 100644 --- a/main/sc/source/ui/vba/vbaquerytable.cxx +++ b/main/sc/source/ui/vba/vbaquerytable.cxx @@ -56,6 +56,20 @@ ScVbaQueryTable::~ScVbaQueryTable() { } +// MS VBA: QueryTable.Refresh - Updates an external data range in a QueryTable object. +// Parameters (MS): BackgroundQuery (Optional, Variant) - True for async/background update, +// False for synchronous; if omitted, BackgroundQuery property determines the mode. +// Return value (MS): Boolean - True if query successfully completed or started; +// False if user cancels a connection or parameter dialog box. +// Remarks (MS): Connects to data source, executes SQL query, returns data to the range. +// Uses Connection property; may prompt for missing connection info/parameters unless +// DisplayAlerts is False. Stores completed connection string for session reuse. +// Compliance: partial. AOO searches the document's LinkManager for an ScAreaLink whose +// destination range contains the parent range's address, and calls pBase->Update(). +// BackgroundQuery is read but not used to control async/sync behavior (area link update +// semantics differ from Excel's ODBC/SQL query model). Returns True if any matching +// area link was found and updated; False if no link exists or parent/document is missing. +// No Connection/CommandText/parameter/prompting/DisplayAlerts behavior is implemented. sal_Bool SAL_CALL ScVbaQueryTable::Refresh( const css::uno::Any& aBackgroundQuery ) throw ( css::uno::RuntimeException ) { @@ -96,6 +110,9 @@ ScVbaQueryTable::Refresh( const css::uno::Any& aBackgroundQuery ) throw ( css::u return bFoundLink ? sal_True : sal_False; } +// MS VBA: QueryTable.Delete - Deletes the object. +// Compliance: implemented for the area-link-backed subset. Removes the matching ScAreaLink +// from the LinkManager for the parent range. No-op if parent/document missing or no link found. void SAL_CALL ScVbaQueryTable::Delete() throw ( css::uno::RuntimeException ) { diff --git a/main/sc/source/ui/vba/vbaquerytable.hxx b/main/sc/source/ui/vba/vbaquerytable.hxx index 51e54a4bcf..44c604b406 100644 --- a/main/sc/source/ui/vba/vbaquerytable.hxx +++ b/main/sc/source/ui/vba/vbaquerytable.hxx @@ -27,8 +27,14 @@ namespace css = ::com::sun::star; -// MS Excel VBA: Represents a worksheet table built from data returned from an external data source. -// Status: partial - only Refresh and Delete implemented; CommandText, Connection, Destination, etc. missing +// MS Excel VBA: Represents a worksheet table built from data returned from an external data source +// (e.g. SQL server or Microsoft Access database). +// Status: partial - only Refresh and Delete implemented per XQueryTable.idl. +// Missing (per MS docs): CommandText, CommandType, Connection, Destination, Name, Parameters, +// BackgroundQuery, RefreshOnFileOpen, RefreshPeriod, RefreshStyle, SaveData, SavePassword, +// EnableEditing, EnableRefresh, FieldNames, FillAdjacentFormulas, PreserveFormatting, +// AdjustColumnWidth, ListObject, WorkbookConnection, and TextFile*/Web* import properties. +// Events not implemented: AfterRefresh, BeforeRefresh. typedef InheritedHelperInterfaceImpl1< ooo::vba::excel::XQueryTable > ScVbaQueryTableImpl_BASE; class ScDocument; @@ -56,18 +62,25 @@ public: virtual ~ScVbaQueryTable(); // MS Excel VBA: Methods - QueryTable actions - // MS Excel VBA: Reloads the query table from the external data source. - // Status: implemented - delegates to area link update + // MS VBA: Updates an external data range in a QueryTable object. + // Parameters: BackgroundQuery - Used only with QueryTables based on SQL query results. + // True to return control as soon as connection is made and query submitted (background). + // False to return control only after all data has been fetched. + // If omitted, the BackgroundQuery property setting determines the query mode. + // Return value: Boolean - True if query is successfully completed or started; False if + // user cancels a connection or parameter dialog box. + // Remarks (MS): Refresh causes Excel to connect to the data source, execute the SQL query, + // and return data to the range. Unless called, the QueryTable doesn't communicate with + // the data source. + // Status: partial - checks for area links in the destination range and updates them; + // returns True if a link was found/updated, False otherwise. Does not implement full + // SQL/ODBC connection semantics, parameter binding, or BackgroundQuery async behavior. virtual sal_Bool SAL_CALL Refresh( const css::uno::Any& aBackgroundQuery ) throw ( css::uno::RuntimeException ); - // MS Excel VBA: Deletes the query table and removes it from the worksheet. - // Status: implemented - calls LinkManager::Remove() + // MS VBA: Deletes the QueryTable object. + // Status: implemented - removes matching area link from LinkManager for the parent range. virtual void SAL_CALL Delete() throw ( css::uno::RuntimeException ); - // Missing properties (per MS Excel VBA reference): - // CommandText, CommandType, Connection, Destination, RefreshOnFileOpen, - // RefreshPeriod, RefreshStyle, SaveData, SavePassword, TextFile*, Web* - // XHelperInterface // MS Excel VBA: Returns the implementation name for UNO service identification. // Status: implemented - returns "ScVbaQueryTable" diff --git a/main/sc/source/ui/vba/vbaworkbook.cxx b/main/sc/source/ui/vba/vbaworkbook.cxx index da3cb59ac6..2576aaa2df 100644 --- a/main/sc/source/ui/vba/vbaworkbook.cxx +++ b/main/sc/source/ui/vba/vbaworkbook.cxx @@ -327,8 +327,19 @@ ScVbaWorkbook::SaveCopyAs( const rtl::OUString& sFileName ) xStor->storeToURL( aURL, storeProps ); } -// MS Excel VBA: Saves the workbook with specified options. -// Status: partial - only uses FileName and FileFormat; Password/WriteResPassword/ReadOnlyRecommended/CreateBackup ignored +// MS VBA: Workbook.SaveAs - Saves changes to the workbook in a different file. +// Syntax (MS): expression.SaveAs(FileName, FileFormat, Password, WriteResPassword, +// ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, +// TextCodepage, TextVisualLayout, Local) +// Parameters implemented: FileName, FileFormat (mapped to AOO filter names; defaults to +// xlExcel9795/MS Excel 97 when omitted), Password, WriteResPassword, ReadOnlyRecommended, +// CreateBackup. Extension appended if FileName has no dot. +// Not implemented (IDL takes 6 params): AccessMode, ConflictResolution, AddToMru, +// TextCodepage, TextVisualLayout, Local. +// Remarks (MS): If no FileName path, Excel saves in current folder. FileFormat defaults to +// last format for existing file or Excel version format for new file. +// Compliance: partial - core save-as with common formats works; several MS parameters and +// default-format semantics differ from Excel. void SAL_CALL ScVbaWorkbook::SaveAs( const css::uno::Any& FileName, const css::uno::Any& FileFormat, const css::uno::Any& Password, const css::uno::Any& WriteResPassword, const css::uno::Any& ReadOnlyRecommended, const css::uno::Any& CreateBackup ) { diff --git a/main/sc/source/ui/vba/vbaworkbook.hxx b/main/sc/source/ui/vba/vbaworkbook.hxx index 2159935aad..73cef7e43d 100644 --- a/main/sc/source/ui/vba/vbaworkbook.hxx +++ b/main/sc/source/ui/vba/vbaworkbook.hxx @@ -106,8 +106,16 @@ public: // MS Excel VBA: Saves a copy of the workbook to the specified filename. // Status: implemented - uses storeToURL with MS Excel 97 filter virtual void SAL_CALL SaveCopyAs( const rtl::OUString& Filename ); - // MS Excel VBA: Saves the workbook with specified options. - // Status: partial - only uses FileName and FileFormat parameters; Password/WriteResPassword/ReadOnlyRecommended/CreateBackup ignored + // MS Excel VBA: Saves changes to the workbook in a different file. + // Parameters (per MS docs): FileName, FileFormat, Password, WriteResPassword, + // ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, + // TextCodepage, TextVisualLayout, Local. + // Remarks (MS): For an existing file, default format is the last file format specified; + // for a new file, default is the format of the version of Excel being used. + // Status: partial - implements FileName, FileFormat, Password, WriteResPassword, + // ReadOnlyRecommended, CreateBackup. AccessMode, ConflictResolution, AddToMru, + // TextCodepage, TextVisualLayout, Local are not implemented (XWorkbook.SaveAs takes + // only 6 parameters in the current IDL). virtual void SAL_CALL SaveAs( const css::uno::Any& FileName, const css::uno::Any& FileFormat, const css::uno::Any& Password, const css::uno::Any& WriteResPassword, const css::uno::Any& ReadOnlyRecommended, const css::uno::Any& CreateBackup ); // code name // MS Excel VBA: Returns the code name of the workbook.
