Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Hello to everybody.
The task is next: the server creates nice charts (bars, pies, lines) from brut data from Database by using Microsoft.Office.Excel.Interop library and by the COM objects in Microsoft Office Object library 14. But there is a restriction to install Office on the server machine.

There is an idea to have Office installed on a remote machine, not on the server, and to access it from the server.
How can it be implemented? (via what and how).Any ideas?
Thank you in advance, any help is highly appreciated!
Posted
Comments
jk0391 29-May-15 11:27am    
Use google.
Sergey Alexandrovich Kryukov 29-May-15 11:46am    
It doesn't sound like a good idea for me. Why? Not only Office is restricted for server work, it's also not designed for that. It sounds like non-programming thinking.
—SA
Dzianis Igaravich Leanenka 29-May-15 12:45pm    
So, "Office is restricted for server work" - exactly, so that is why I am looking for another way to use Excel not installed on the server. The question is how?
Sergey Alexandrovich Kryukov 29-May-15 15:18pm    
I just say it does not look like a good idea. This is not what Office normally does. It's a typical end-client thing.
Those "nice charts" is really nothing from the service standpoint. What nice feature could it possibly serve?
—SA
RedDk 29-May-15 13:18pm    
Huh ...

"... server creates nice charts (bars, pies, lines) from brute data"

My doubt is with this statement because the server isn't doing any of this, a program on the server is doing this. Presumeably the one using the interop assembly. the bruteforcedness comes in the form of outputting .bmp or .jpg or .png. So I think this problem is trivial.


Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you install Office on the server, you'll struggle to make it work. If you do get it to work, you'll have to be prepared for the fact that it could stop working again at any time without warning.

Whilst you might be able to use something like Remoting[^] or WCF[^] to drive Office on a different computer, you'd still need a non-interactive process on that computer to automate the Office application.

You'd be better off looking at a library which doesn't require Office at all. For example, EPPlus[^] can generate Excel workbooks, including charts. Or, if you just want charts, something like Chartist[^] or Chart.js[^] would do the trick.
 
Share this answer
 
Comments
Dzianis Igaravich Leanenka 30-May-15 6:42am    
Oh, thanks a lot! It sounds quite reasonable. But could you explain or give a hint about how .js code can be used via C#.
The situation is like this one: there is a POST request from the client's side and an MVC controller catches it and then processes. So the code in this controller should export some data in .xlsx format and somehow build charts automatically. Is it possible to use .js in C#?

But your piece of advice about EPPlus[^] is worth implementing, it seems to me) Thanks again!
Richard Deeming 1-Jun-15 7:48am    
From your question, I thought you were just generating charts to display to the user within a web page, which would work best with a js solution.

If you're processing .xlsx files, then you'll need something like EPPlus.
Dzianis Igaravich Leanenka 30-May-15 6:49am    
Actually I was aimed to use NPOI library but it turned out that it did not allow to create any types of line- bar- pie- charts. But EPPlus sounds really reasonable.
How is it accessed now? Was the Excel dll added as a reference?

I suppose you might be able to use Reflection to the load the dll over a network share but I believe you will be violating Microsoft's license agreement if you do it that way. Best to get a license and do it correctly and legally.
 
Share this answer
 
Comments
Dzianis Igaravich Leanenka 29-May-15 12:43pm    
Now the only way to access Office is to have it installed on the server.
Microsoft.Office.Interop.Excel.dll is added as a reference.
Yeah, you are right about the license but actually I need a walk around way)
Dzianis Igaravich Leanenka 29-May-15 12:46pm    
Sorry, but having license is not a solution)
Philippe Mori 29-May-15 21:44pm    
You don't want to install Office on a server even if you can. See my solution. It is very well known that Office interop is not designed for server usage. Search Google and you will see.
If you want to create Excel files:

Uses Open XML SDK or any third party product. Office interop is not designed to be used on server. It is slow and single-user.

Office interop is intended to be used locally by desktop application to automate some task on that computer.

With Open XML SDK, you can generate Excel files containing charts.


If you want to create chart images:

Use any third-party chart Library.

If you want to interact with the user on a web page, then use a chart based on jQuery.

There are a lot of options. Some free. Some commercials. With most package, you can get quite nice charts by some make it easier than others.
 
Share this answer
 
Comments
Dzianis Igaravich Leanenka 30-May-15 6:54am    
Oh yes, I have heard about the variant of usage of XML SDK, but it is so complicated and it does not allow to create a great part of what POI API (JAVA) is able to do, for instance. But maybe I am wrong...
But thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900