This example shows how to build a .NET Framework COM add-in that embeds DotNetBrowser in an Excel task pane and lets a web page read and write spreadsheet data through a JavaScript bridge.
- Windows
- .NET Framework 4.7.2
- Microsoft Excel
- A DotNetBrowser license key
AddIn/Connect.csis the COM entry point Excel loads at startup. It implements the add-in lifecycle, supplies the ribbon XML, and creates the task pane.AddIn/ComRegistration.cswrites and removes the registry keys that register the add-in with Excel.Interop/ComConstants.csholds the ProgId and GUID that identify the COM class.Ribbon/RibbonController.csowns the ribbon XML and handles the "Open Panel" button callback.Browser/EngineManager.cscreates the DotNetBrowser engine and registers theapp://scheme used to serve the bundled web page.TaskPane/BrowserHostControl.csis the COM-visible WinForms control that hosts the browser inside the task pane. It exposesreadFromExcelandwriteToExcelto JavaScript aswindow.excelBridge.TaskPane/TaskPaneManager.cscoordinates the task pane and engine lifecycle and implements the Excel cell read/write logic.Web/index.htmlis the web UI bundled with the add-in.
Open Browser/EngineManager.cs and set your license key:
var builder = new EngineOptions.Builder
{
LicenseKey = "<your_license_key>",
...
};Build the project with MSBuild:
msbuild src/ExcelComAddin/ExcelComAddin.csproj /p:Configuration=DebugOr open ExcelComAddin.sln in Visual Studio and build from there.
Then register the add-in using the provided script (requires an elevated PowerShell prompt):
.\scripts\com-registration.ps1 -Action registerTo unregister:
.\scripts\com-registration.ps1 -Action unregisterTo check the current registration status without making any changes:
.\scripts\com-registration.ps1 -Action statusIf you use Visual Studio, you can alternatively enable Register for COM Interop in Project Properties → Build for the Debug configuration and the registration will run automatically on each build.
After a successful build, open Excel. A Sales Lead Add-in tab appears in the ribbon. Click Open Panel to open the task pane with the browser UI loaded.
- Click Read from Excel to display the current value of cell A1.
- Type a value and click Write to Excel to write it directly to the cell.