Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor C# Wrapper for Office.js #4247

Closed
robertmclaws opened this issue Mar 13, 2024 · 4 comments
Closed

Blazor C# Wrapper for Office.js #4247

robertmclaws opened this issue Mar 13, 2024 · 4 comments
Assignees
Labels
Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP

Comments

@robertmclaws
Copy link

It would be amazing if the team could ship a C# wrapper for Office.js that would let us code C# directly against the Office APIs in a Blazor app without having to build our own JSinterop.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP label Mar 13, 2024
@gergzk
Copy link

gergzk commented Mar 15, 2024

Hi @robertmclaws -
Blazor is new to me, but I wanted to get your thoughts on how it would/could integrate with office.js. I'm starting with the top-level docs: https://learn.microsoft.com/en-us/aspnet/core/blazor/?view=aspnetcore-8.0&WT.mc_id=dotnet-35129-website

From my reading, the technology is server-rendered. This suggests the model would be that the manifest would point to an index.html that is rendered from a service owned by the add-in developer (eg: devserver.com/index.html). The implementation is in Blazor. So far so good.

The next hurdle is how and where office.js loads and runs vs where Blazor intends behavior to happen. The docs above say Blazor processes actions in the service. office.js needs to be present on the page in the iframe runtime of the host application. Suppose a user clicks a button to highlight the current selection.

The underlying code that needs to run is something like:

await Excel.run(context => {
const range = context.workbook.getSelectedRange();
range.format.fill.color = "yellow";
return context.sync();
});

This needs to run in the iframe though, because that's where we'd need to be able to post to the host from. From what I can tell, the point of Blazor is that the click would propagate back to the service and be processed by a C# handler, the page updated, and then sent back down and re-rendered.

How would the C# running in the service invoke the Excel.run in the iframe?

@gergzk
Copy link

gergzk commented Apr 3, 2024

Closing as not planned - technical feasibility seems unlikely.

@gergzk gergzk closed this as completed Apr 3, 2024
@gergzk gergzk reopened this Apr 3, 2024
@gergzk gergzk closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
@robertmclaws
Copy link
Author

So, Blazor server rendering is just one option. However the Blazor stack has a unified way of invoking JS commands, no matter where it is happening. Blazor handles registering the Javascript and triggering the iframe loading and what-not.

Blazor can also be exclusively front-end through WebAssembly where the execution context and interop are running in the same process.

The point being is that you don't need to worry about "How would the C# running in the service invoke the Excel.run in the iframe?" as the Blazor runtime already handles that for you.

There are already examples of how to use Office.js in Blazor, and most of those examples involve people still writing their own extensive Javascript and just invoking the JS methods from C#.

What I am suggesting is a native wrapper that would use a TypeScript to C# generator to re-create all of these objects in C#, and then leverage the Blazor JSInvoke infrastructure to translate these calls into invoked Javascript commands.

Since it has been done before, it is technically feasible. It would need a commitment from Microsoft and some budget to spend time on it.

Since WASM is the future of the web, I'm honestly surprised that Microsoft hasn't prioritized this more, because packaging Excel for the web as a WASM desktop app seems like a no-brainer.

@4tti
Copy link

4tti commented Apr 4, 2024

I agree this would be awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP
Projects
None yet
Development

No branches or pull requests

3 participants