0

I have a Windows Server 2019. And I have a website hosted there on IIS. On the website, there's a button that fetches information from a database (sql server), and then creates an Excel worksheet with that information. Once it is done, it opens the Excel file to the user, so that he can save it, or whatever.

Simple VB code using Microsoft.Office.Interop.Excel to create the application.

(Only showing relevant code)

Dim appXL As Excel.Application
Dim wbXl As Excel.Workbook
Dim shXL As Excel.Worksheet
Dim raXL As Excel.Range

appXL = CreateObject("Excel.Application")

wbXl = appXL.Workbooks.Add
shXL = wbXl.ActiveSheet

appXL.Visible = True
appXL.UserControl = True

Now, testing this locally has no issue whatsoever. I click the button, and it generates the Excel file, and opens it. However, when I bring the site onto my Windows Server2019, it has issues.

  • At first, Microsoft Office wasn't installed, so I was getting ActiveX problems. That was solved by installing Office, thus Excel.
  • After, I had to go in the Service Components, into the DCOM configs to enable the NETWORK SERVICE user to access the Excel Application (following this link).

The problem I have now, is that clicking the button will go through the steps of fetching the database info, and building the entire Excel file in the backend. This is shown by the fact that the Excel process in the Task Manager is running when I click the button. However, this entry in the Task Manager is in the Background processes, rather than Applications. The Excel Process in Task Manager

The site doesn't display any errors, it simply rolls through the code, and just never shows the Excel file. It's not in the taskbar, or anything. I tried some things to show it, such as:

  • appXL.Windows(wbXL.Name).visible = true doesn't work
  • Maximizing the Window

So far, no shot. It works fine on my station obviously, Excel opens, but it doesn't on the Server. I'm wondering if it has something to do with certain rights that I haven't configured? I did just install Microsoft Office on the server this morning. Maybe there's something else to do?

Thank you very much.

  • 2
    Have you read this? https://support.microsoft.com/en-us/topic/considerations-for-server-side-automation-of-office-48bcfe93-8a89-47f1-0bce-017433ad79e2 – Dai Apr 12 '23 at 17:39
  • 1
    Unfortunately, Interop.Excel is neither recommended nor supported in the usage case that you've described (as described in a post a previous commenter posted). – Tu deschizi eu inchid Apr 12 '23 at 17:55
  • @Dai Huh, no I had not! Thank for you that. It seems like my idea of using Excel is not a good one. – snowyphoenix Apr 12 '23 at 18:06
  • @user09938 Thanks a lot for the answer, it sure seems that way, I'll have to find an alternative to my method. Maybe creating an SSRS report or something. Thank you again. – snowyphoenix Apr 12 '23 at 18:07
  • You may consider NuGet package [DocumentFormat.OpenXml](https://github.com/dotnet/Open-XML-SDK#open-xml-sdk) or [ClosedXml](https://github.com/closedxml/closedxml) – Tu deschizi eu inchid Apr 12 '23 at 18:15

0 Answers0