Excel Interop (Insert Image) in Windows Server 2012 R2

We are migrating our web application from Windows 2003 to Windows 2012 R2.

The app has an Excel report function. We open excel (template file) with Interop and write some data and paste an image from a specific folder on the server.

MS Office version - 2007. The weird thing is that the image insertion functionality only works when the image size is less than 20 kb, as soon as the application tries to insert an image larger than 20 kb, for example 250 kb, the system freezes as if it does not have enough memory to complete the task, and excel.exe hangs in task manager.

In Dcomcnfg, excel runs under the "Start User" identity.

The IIS application pool uses a network service to run the application.

The code to embed the image is shown below, however, since it works on Windows 2003, we haven't changed anything

public void InsertImage(string imagePath, float leftPosition, float topPosition, float   imageWidth, float heightImage)
    {
        if (!File.Exists(imagePath))
            throw new   OfficeHelperException(OfficeHelperException.ExceptionType.ImageFileNotFound);

        WorkingSheet.Shapes.AddPicture(
            imagePath,
            Microsoft.Office.Core.MsoTriState.msoFalse,
            Microsoft.Office.Core.MsoTriState.msoCTrue,
            leftPosition,
            topPosition,
            imageWidth,
            heightImage);
    }

      

Is there any memory allocation setting in new windows 2012 R2? The web app has other Excel reports that don't have image exports and they work fine.

We tried to remove this inset image functionality by placing a macro inside the template file that will embed the image and call the macro from interop. It works on the local machine, but hangs on the server again when the image size is greater than 20kb.

We are stuck with this and are not sure about any known interel interel-related Windows Server 2012 R2 issue. Any suggestion would be appreciated.

+3


source to share


2 answers


I set the MsoTriState LinkToFile parameter value and it works great! I am using Win 2012 R2 and Excel 2010 x64.

Example:



oHoja.Shapes.AddPicture(HttpContext.Current.Server.MapPath("~/images/logos/57/teix.png", 
     MsoTriState.msoCTrue, MsoTriState.msoCTrue,float.Parse(3.ToString()), 
     float.Parse(65.ToString()), 
     float.Parse("113"), 
     float.Parse("54"));

      

Good luck!

0


source


We had the same problem. I fixed it by installing MS Office 2013.



0


source







All Articles