0

I'm facing a strange problem with the IIS Local. I've developed a webapi Controller that, at some point, opens Excel, makes some processing with macros and then closes. Here's the piece of code that opens Excel with several parameters:

var procStartInfo = new ProcessStartInfo(
this.Parameters[ConsoleExecutionParameters.FileToExecute],
this.ParametersProcessed)
    {
        CreateNoWindow = false,
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        RedirectStandardInput = true,
        WindowStyle = ProcessWindowStyle.Maximized,
        WorkingDirectory = workingDirectory
    };

using (var proc = new Process { StartInfo = procStartInfo })
{
    try
    {
        proc.EnableRaisingEvents = true;
        proc.Start();
        proc.WaitForExit(60000);
        proc.StandardInput.Flush();

        if (!proc.HasExited)
        ....

Gotta say that this piece of code WORKS (and opens the excel correctly) if the WebAPI is run under IIS Express. However, when running it under a local IIS, an Excel process is opened (at least it is shown in the task manager) but no Excel window appears, the application seems to hang when "proc.WaitForExit" instruction is called, and EXCEL.EXE process stays like in a "zombie" state. After some time (60 seconds) my application times out and the Excel.EXE process is still hung.

Does someone have any idea about why it works on IIS express and doesn't in Local IIS?

Thanks and kind regards.

David Jiménez Martínez
  • 3,053
  • 5
  • 23
  • 43
  • I've stopped answering these types of questions, aka: *Why doesn't Excel/Word/PowerPoint work on my production web server?*. There's a whole heap of security and some licensing reasons why trying to do this is always going to end in tears (http://stackoverflow.com/a/21035746/419). Shell out for a copy of http://www.aspose.com/.net/total-component.aspx or grab one of the open source libs instead: http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c-sharp – Kev Feb 16 '15 at 16:40
  • AS far as I've seen, Aspose cannot execute macros, and I really need that: http://www.aspose.com/community/forums/thread/435969/can-aspose.cells-execute-macro-from-excel-file.aspx – David Jiménez Martínez Feb 17 '15 at 09:49
  • Extract your macro logic to C# code. See also: http://support.microsoft.com/kb/257757 - seriously, don't waste time trying to solve your problem this way, it simply won't work, trust me. – Kev Feb 17 '15 at 11:22

0 Answers0