How many excel process i can invoke using c# - excel

I have an application (web) which suppose to open separate excel process for each session. When i try this, server opened only 20 process, is it a restriction or is their a way to open more than 20 Excel.exe process.
Thanks

I think this depends on your system resources.
However I can tell you from personal experience that Excel Interop is not a recommended solution to web applications e.g. C# ASP.NET. See here even: https://support.microsoft.com/kb/257757?wa=wsignin1.0
Why else?:
Excel Interop uses a lot of system resources and your web application will soon run into many performance issues.
Excel Interop has to be installed on the server and there are also issues with the process identity. Installation and configuration is sometimes hard and differes for 32 bit and 64 bit systems.
Sometimes for, God knows what, reasons Excel Interop processes will not close immediately (not only if some Interop resources are unreleased). Then you will have to close these processes yourself which is a real pain.
Why not use OpenXML or even better ClosedXML? You will see your code running even 100x faster with Excel files as OpenXML/ClosedXML treats Excel files as XML files and does not create additional processes for intermediary operations.
CloseXML link: https://closedxml.codeplex.com/

Related

Using Excel Office Scripts for Engineering Application

When I first looked at Office Scripts I was thinking it is good for simple formatting. I have an Excel VBA addin (.xlam) engineering app that does estimation and optimization for a product. I'm wondering how extensive an app you can create in Office Scripts. It has interesting opportunities for collaboration. Questions:
Is there a runtime limit for a script? I envision some optimizations taking 20-30 minutes.
Is there a size limit on scripts? My VBA addin is 2500 lines.
Is there a good way to manage large Typescript files?
Is there a runtime memory limit?
Is there a limit on JSON fetch data size/number limits? My addin uses a local Access database to hold engineering data. I envision creating a lot of JSON files from the database.
Is there any way to use GIT or Devops for backing up scripts.
Is there a way to use Visual Studio or VSCode?
It may be a good idea to look into Office.Js add-ins. Office Scripts is built on top of Office.js. You can see the differences here.
Office.js was designed with developers in mind. And it will give you many of the options that you're seeking (git support, use of VSCode, the ability to manage several typescript files, etc.) You can read more about using the Excel JavaScript API within Office.js here.
For your application I would recommend looking at Script Lab. Script Lab will let you prototype and save your prototype to GitHub as a gist.
Is there a runtime limit for a script? I envision some optimizations taking 20-30 minutes.
There is no runtime limit on your local machine.
Is there a size limit on scripts? My VBA addin is 2500 lines.
There is no size limit on scripts. note: scripts are currently limited to a single file.
Is there a good way to manage large Typescript files?
Scripts are currently limited to a single file.
Is there a runtime memory limit?
How much memory are you anticipating your program needing?
Is there a limit on JSON fetch data size/number limits? My addin uses a local Access database to hold engineering data. I envision creating a lot of JSON files from the database.
See the fetch API
Is there any way to use GIT or Devops for backing up scripts.
Not easily.
Is there a way to use Visual Studio or VSCode?
Yes. You can use vscode.dev (The Web version of Visual Studio Code).

When closing an Excel file on a terminal server it saves to a different location than it was in

In our organisation a problem occurs when saving Excel files.
Whenever we close a file there is a 50/50 chance that it saves in the location it was already in, but the other times it saves where another file was last saved.
We are all working on a Terminal Server (Windows 2019) using Office 2019.
Did anyone else stumble upon this as well? And perhaps found a solution?
The Considerations for server-side Automation of Office article states the following:
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 are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
I'd suggest using the Open XML SDK instead if you deal with open XML documents only, see Welcome to the Open XML SDK 2.5 for Office for more information.

How to identify which application is used to start excel process in task manager

My vb application is used to generate the excel reports.During the last run it got failed in between but the excel process still running in the background on server.
The problem is there are some other applications that uses excel process to generate reports. I need to terminate the particular instance of excel which was still running at the background.
I don't know about the task manager but Sysinternals Process Explorer would give you that information. It lists all processes in a tree view displaying parent/child process hierarchies. http://technet.microsoft.com/en-gb/sysinternals/bb896653.aspx
I asked this question before and the bad news is, that there is no straightforward way to do that.
What can be done: When you start up excel in your application store the PID (if available, I am not sure) and / or the path of the created document. In case of an error, terminate the specific excel process by PID. Or if that is not possible: iterate over all open excel instances and find the one which has opened the path - than kill that instance. The latter approach is problematic in multi user environments, as Excel does not react well when used by multiple applications.
The best way would be to get rid of excel on the server altogether and move to an independent excel-writing library like EPPLUS or Aspose.Cells or other alternatives. But I do not know, if these libraries are still available for VB6. Please note, that Microsoft advises against using Office on a server

VBA Calendar Control Different Versions Issue

I've built a simple Excel tool that uses the additional Calendar Control(mscal.ocx). Everything worked out fine, on different systems, however, the calendar seems not to be implemented and instead of just not showing the date picker, the whole form crashes.
Is there a way to implement the calendar control so that it runs on every system? Or do I have to code a datepicker myself?
(Office12)
Whenever you're using controls that aren't native to all operating systems and versions of excel, you're asking for trouble on other computers. Often, when developing, you'll have access to forms that don't exist on most systems, and only exist on yours because you have Visual Studio installed, or a special Microsoft Office package. Whenever such a problem occurs you have 3 choices:
Work your ass of to try and package the missing controls (mscal.ocx), and try to create a deployment script for your users which will copy it to the System32 directory and register it. This is a pain because there is usually a large chain of dependencies for a single control.
Deal with the fact that some systems won't support your tool and warn users upfront or provide a virtual machine that they can access that and that your tool will run on.
Reinvent whatever fancy control you're using with basic buttons, list-boxes, drop-downs, images, etc, which is the biggest pain of all and often requires you to compromise some nice functionality.
I've had to do number 3 countless times for excel 2007 tools that work on XP systems, but not Vista+ where certain ActiveX controls (i.e. Datagrid) are no longer supported.
i would build against Excel 10 (2003) as not everyone might have new Office 12 (2010).
or see if you can reference that ocx locally and deploy with your excel file
You can do this without the calendar controls.
Like this example here

Access to excel file in the server without installing excel

I've created a library to pass/get data to/from excel.
To execute in my machine i modified the access permisions in COM+ console.
The thing is that im interested in upload this component to my online server, but there i havent installed excel.
Are there any way to register excel in COM+ without install excel?
Thanks in advance.
Best Regards.
Jose
If your library uses Office Interops to manipulate Excel, then no you can't register Excel in COM+ without installing Excel, since there would be nothing to register against, or interop for that matter.
Even if you use late binding in your code, so that it compiles, you will experience runtime errors if the Excel components are not installed.
"All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended." - http://support.microsoft.com/kb/257757

Resources