Sturla
Sturla

Reputation: 3626

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.

Upvotes: 4

Views: 2141

Answers (2)

Kaptein Babbalas
Kaptein Babbalas

Reputation: 1108

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

Upvotes: 2

Fanie Reynders
Fanie Reynders

Reputation: 580

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

Upvotes: 1

Related Questions