Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor as a Office add-in?

I have a few questions about Office plug-ins and Blazor:

  1. Is it possible (now or in the close future) to get Blazor working as an Office add-in?
  2. Is there any work being done on this at all (where)?
  3. Is there something (in Blazor?) stopping it from working, other than just commitment (effort/etc.)?

[Edit] I found the office-js GitHub repo and asked the question there also.

p.s I was routed here after I asked this question at the aspnetcore repo.

like image 686
Sturla Avatar asked Nov 16 '25 00:11

Sturla


2 Answers

a little late to the party but Blazor Server and WASM works for Office addins. I have created an Outlook addin using the task pane as well as custom Excel functions utilizing the DotnetRef object to get the results of the functions from the Blazor part of the application.

Your Javascript function in the file you point to from the manifest:

async function blazor(name) {
return await helloBlazor(name);}

CustomFunctions.associate("Blazor", blazor);

Then you can have a "shared" Javascript file where your DotnetRefrence Object lives:

var dotnetObjectRef;
window.datafeeds = { 
setDotNetRef: function (dotNetObject) {
    dotnetObjectRef = dotNetObject;
    console.log("Ref created");
},
destroy: function (dotNetObject) {
    console.log("Ref destroyed");
}}

async function helloBlazor(name) {
var blazorResult = await dotnetObjectRef.invokeMethodAsync('HELLOBLAZOR',name);
return blazorResult;}

In you Blazor project:

 [JSInvokable("HELLOBLAZOR")]
    public async Task<string> Hello(string name)
    {
        return $"Welcome to Blazor,{name}!";
    }

enter image description here

As of late there are some other Blazor examples in the Office addins git... https://github.com/OfficeDev/Office-Add-in-samples/tree/main/Samples/blazor-add-in

like image 125
Kaptein Babbalas Avatar answered Nov 17 '25 22:11

Kaptein Babbalas


With the new ASP.NET Core 6 coming up, the future of Blazor wasm looks even more promising, especially with features like React and Angular component generation, which will be a perfect fit for Office add-ins in the meantime. https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-rc-1/#generate-angular-and-react-components-using-blazor

like image 35
Fanie Reynders Avatar answered Nov 17 '25 20:11

Fanie Reynders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!