Task Pane and Data across multiple instance of Excel

Add-in Express™ Support Service
That's what is more important than anything else

Task Pane and Data across multiple instance of Excel
 
Jamil Nawaz




Posts: 22
Joined: 2018-02-10
Hi,

I am using the Add-In Express for building a COM Add-In for Excel. In my use case, we have an Excel Tab, where user can click on Login button, system opens a Popup (model popup) to prompt user to login, and user enter user name and password and it authenticate and then it loads some data based on the login and and some general data. We have a Task Pane that displays when a button is clicked after login.

Now when I am logged in, and task pane is visible. At this point, when I try to open another excel instance, then in the ribbon tab, it still shows the ribbon in the state when I am not logged In but Task pane is keep displaying. And since task pane displays the data that I load after login, and in new excel instance that data is not there so all controls are blank.

How can I handle this correctly?

Either we load the new excel instance so that take pane state is hidden or we share the login info and data across multiple instances of excel.

Please guide me.

Regards,
Jamil
Posted 12 Jul, 2018 01:32:56 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Jamil,

I suppose what you call "to open another excel instance" actually means "to open another excel workbook window". To find whether this is the case or not just open the Task Manager window and check the number of EXCEL.EXE instances on the Processes tab.

Jamil Nawaz writes:
in the ribbon tab, it still shows the ribbon in the state when I am not logged In


You need to check section Updating ribbon controls at run time; see https://www.add-in-express.com/docs/net-ribbon-components.php#properties-events.


Andrei Smolin
Add-in Express Team Leader
Posted 12 Jul, 2018 04:08:47 Top
Jamil Nawaz




Posts: 22
Joined: 2018-02-10
Hi Andrei,

New Instance means, I run Excel again from the Start Menu. I notice that there is always one EXCEL.EXE in the processes.

When I click on the ribbon button. I am doing this:
adxColumnMappingTaskPane.Visible = true;

Here, "adxColumnMappingTaskPane" is my task pane name that I define the AddInModule Designer > Right Click > Properties > TaskPanes collection.

The only thing that will solve my problem is, when I open another blank workbook, it should not have that task pane to be visible because there are certain pre-conditions before opening this task pane.

e.g: We should have any active excel table defined in the worksheet and based on that Task Pane does some actions.

Please suggest?

Regards,
Jamil
Posted 12 Jul, 2018 04:45:06 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Jamil Nawaz writes:
New Instance means, I run Excel again from the Start Menu. I notice that there is always one EXCEL.EXE in the processes.


This means there's no new instance and the Ribbon-related issue you described in your first post should be solved using the machinery we describe in that section of the Add-in Express manual.

Jamil Nawaz writes:
When I click on the ribbon button. I am doing this: adxColumnMappingTaskPane.Visible = true;


This sets the visible property on *all* custom task pane instances. If you need to do this on a task pane window shown in that specific window, you start with getting the Excel window by getting the context of your Ribbon control (e.g. in the Click event of the control) as shown in section Determining a ribbon control's context at https://www.add-in-express.com/docs/net-ribbon-components.php#context. The next step is to get the custom task pane instance in that window. You get it via adxColumnMappingTaskPane[{an Excel window object}]; see also section Custom task panes in Office 2016 - 2007 at https://www.add-in-express.com/docs/net-office-custom-task-panes.php. Finally, you show/hide the custom task pane instance.

Jamil Nawaz writes:
The only thing that will solve my problem


May I ask you to define what your problem is?


Andrei Smolin
Add-in Express Team Leader
Posted 12 Jul, 2018 05:40:28 Top
Jamil Nawaz




Posts: 22
Joined: 2018-02-10
Hi Andrei,

Thanks! for the clarification.

Yes first issue is resolved (ribbon buttons state).

By using the ribbon context, the 2nd issue also resolved, which was basically getting the instance of the task pane based on the active workbook. So I use the context of the active ribbon click handler to get active the window's task pane instance and set it to false so it works that way I needed it.

Now the question is, how would I determine the context when I am in the Task Pane control? or When I am in the custom popup window.

eg: We have an excel table, we define table column mapping with a database table columns. When all done, we upload the file to the server so that all data can be imported to the database. For that I have a model popup window, that opens when user click on Upload button. When file upload is completed and server is taking some time to process the request, we need to lock the excel. Lock the excel means, we are hiding the active window's task pane instance and also disable the ribbon buttons for that active workbook, so that no more changes can be made until the server completes it's processing. But meanwhile, the user can continue to define mapping on another workbook.

And another use case is, I am using the ADXExcelAppEvents component to do some actions when sheet selection is changed. In that handler how can I get the active workbooks task pane instance?

The only way that I can think is, when I am opening that Task Pane instance or popup window, I should pass it the current context so that it works in that context.

Please suggest if there any other way that is already there in the Add-In Express.

Regards,
Jamil
Posted 12 Jul, 2018 06:38:10 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Jamil Nawaz writes:
Now the question is, how would I determine the context when I am in the Task Pane control? or When I am in the custom popup window.


Context is a term from the Office Ribbon API. When the popup window opens, it opens by clicking a Ribbon control; you can retrieve that Ribbon control's context.

Jamil Nawaz writes:
I am using the ADXExcelAppEvents component to do some actions when sheet selection is changed. In that handler how can I get the active workbooks task pane instance?


You can on;y select in the active window; use adxColumnMappingTaskPane[{an Excel window object}].


Andrei Smolin
Add-in Express Team Leader
Posted 12 Jul, 2018 07:24:09 Top
Jamil Nawaz




Posts: 22
Joined: 2018-02-10

You can on;y select in the active window; use adxColumnMappingTaskPane[{an Excel window object}].


How to get active excel window? I am using this way.
(HostApplication as ComExcel._Application).ActiveWindow

Is this correct?

Regards,
Jamil
Posted 12 Jul, 2018 07:31:17 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Yes. If you have the ExcelApp property on the add-in module, you can use ExcelApp.ActiveWindow.


Andrei Smolin
Add-in Express Team Leader

        public static new AddinModule CurrentInstance 
        {
            get
            {
                return AddinExpress.MSO.ADXAddinModule.CurrentInstance as AddinModule;
            }
        }

        public Excel._Application ExcelApp
        {
            get
            {
                return (HostApplication as Excel._Application);
            }
        }
Posted 12 Jul, 2018 07:42:25 Top
Jamil Nawaz




Posts: 22
Joined: 2018-02-10
Thanks! Andrei.

Regarding my question in previous posts:


eg: We have an excel table, we define table column mapping with a database table columns. When all done, we upload the file to the server so that all data can be imported to the database. For that I have a model popup window, that opens when user click on Upload button. When file upload is completed and server is taking some time to process the request, we need to lock the excel. Lock the excel means, we are hiding the active window's task pane instance and also disable the ribbon buttons for that active workbook, so that no more changes can be made until the server completes it's processing. But meanwhile, the user can continue to define mapping on another workbook.


To handle the section in bold, I need to follow this way?
https://www.add-in-express.com/docs/net-ribbon-components.php#properties-events

How will it differentiate the active window? I am assuming the ribbon controls are shared across multiple workbooks. So I am trying to manage the ribbon button's state according to active workbook as I mention in my above use case.

Please suggest?

Regards,
Jamil
Posted 12 Jul, 2018 07:54:48 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Jamil,

Jamil Nawaz writes:
To handle the section in bold, I need to follow this way?


Yes.

A ribbon control's context is typically a Window object; you need to compare it with the window object returned via ExcelApp.ActiveWindow.

Please note that although widely used the term Ribbon Control is not exactly precise. Your add-in supplies Office with a Ribbon XML (see e.Xml in the OnRibbonBeforeLoad event of your add-in module) that specifies what "controls" to create and a number of callback functions that specify its behavior. Add-in Express provides all the callbacks for you and maps Office calls to the Ribbon components used in your code.

That is, there's no such thing as a Ribbon control shared across several windows; there is the Ribbon XML that specify what how Office draws your control and there are Add-in Express properties and events that let you define how that "control" behaves using the properties/methods/events of the corresponding ribbon component.


Andrei Smolin
Add-in Express Team Leader
Posted 13 Jul, 2018 05:52:24 Top