I've created an excel plugin using Add-In Express for .NET, but can't seem to figure out how to only show my ribbon when there is a certain set of data on the "Active" sheet.
If the worksheet doesn't contain a certain set of data in certain row of cells, I want to hide my ribbon since the buttons on the ribbon don't apply to all worksheets. When the user switches between different worksheets, I'd like to hide/show the ribbon as appropriate.
I tried using the AddinInitialize
event, but this only fires once. I don't want to force the user to open the Excel file directly. They should be able to open Excel, then select the file from the File menu.
private void OnAddinInitialize(object sender, EventArgs e)
{
// note: this does not work all the time!
adxRibbonTab1.Visible = IsRibbonVisible();
}
private bool IsRibbonVisible()
{
var worksheet = ActiveSheet;
if (worksheet == null)
return false;
// only show ribbon when top row has certain column headings
var reader = new WorksheetReader(worksheet);
return reader.HasColumns(TopLeftCell, RequiredColumnNames);
}
I've tried creating an ADXExcelWorksheetEvents
instance and overriding some of the events, but I'm not having much luck so far. I've not been able to find anything on their website for this type of workflow either.
I'd appreciate any help!
I found the answer. On the AddinModule
designer, there is an "Events" item that I had to reference and then I was able to trap the following with my IsRibbonVisible()
function:
WorksheetActivated
WorksheetDeactivated
WorkbookActivated
Problem solved!