Reputation: 3626
I have a few questions about Office plug-ins and Blazor:
[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
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}!";
}
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
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