I recently had a requirement to export data from the TAM Rebate Workbench form to Excel. The challenge was that all tables used by the data entity were configured as cross-company tables: TAMRebateTrans ,ТAMRebateDateTrans and TAMRebateTable. Additionally, the source form (TAMRebateWorkbench) is a standard system form. Because the underlying tables are cross-company, the standard Excel Add-in export returned records from multiple legal entities. My requirement was to export only the records belonging to the currently selected legal entity. I first looked for a solution directly within the data entity lifecycle methods. However, due to the way the Excel Add-in generates and retrieves data for cross-company entities, the standard entity methods were not sufficient for this scenario. Instead, I used OfficeFormRunHelper and replaced the standard Office export menu with a custom export option.
The approach consists of three steps:
1. Subscribe to the Office menu initialization event - During form initialization, subscribe to the OfficeMenuInitializing event using OfficeFormRunHelper.

2. Replace the standard export option - Inside the Office menu initialization handler, remove the standard data entity export options and add a custom export menu item.
3. Apply a legal entity filter - When the Excel Add-in requests the data entity context, dynamically apply a filter on the RefCompanyId field using the current legal entity.

The custom Excel export now returns only records for the currently selected legal entity, even though the underlying tables and entity are configured as cross-company.
This approach can be useful whenever:
- The entity is based on cross-company tables.
- Standard entity filtering is not sufficient.
- The export is initiated from a form.
- You need complete control over the Excel Add-in export context.
I hope this helps anyone facing similar Excel Add-in filtering challenges in D365FO.
"If anyone knows an alternative approach directly through the data entity framework, I would be interested to hear it."