Why would the Excel Interop remove an image after processing a file?

前端 未结 5 1921
南笙
南笙 2020-12-11 20:53

Excel Interop is removing images from processed files.

I’m using the Excel Interop, no third-party components are present (that I\'m aware of). The workflow is -- cr

相关标签:
5条回答
  • 2020-12-11 21:03

    You're probably on your own, since Excel isn't supported in a server environment as @Yahia correctly points out.

    Your mention of ActiveX controls is a red flag - maybe some of your ActiveX controls require Excel to run under an account with a profile?

    All you can do is debug this yourself, probably best to proceed by eliminating the possible sources of different behaviour in your dev and production environments.

    • Try using the same Office version in both environments
    • Are you using Cassini in your dev environment? (i.e. running under your own login) If so, perhaps try with IIS running under a service account with no profile
    • Try removing the ActiveX components one by one to see if one of those is having an impact ... etc ...
    0 讨论(0)
  • 2020-12-11 21:05

    I'm facing the same issue with powerpoint on Desktop (not a service) by copying a slide with picture from a template. (when getting about 200 copy paste in 1 presentation, but 1300 slides with same picture works fine ???)

    It is hard to get this issue, I think it is hardware related, like RAM errors, but not sure

    only 1 client of hundred get this error, so i think it is hardware related.

    Note that i have a website that provide an Excel automataion and it works PERFECTLY, even "it is not supported by MS blah blah...." !

    Your excel file seems to be corrupted, you have to find how.

    0 讨论(0)
  • 2020-12-11 21:06

    (a) Not supported, don't do it https://support.microsoft.com/en-gb/kb/257757

    (b) Anyway, if you have to do it (and cannot give desktop access to your process, as suggested in the accepted answer), you can mess with the contents and permissions in C:\Windows\System32\config\systemprofile, as suggested by this answer.

    I had to create and allow permissions to the Desktop and to the INetCache folders. Checking (and solving) failed access attempts in paths beginning with C:\Windows\System32\config\systemprofile with the help of Process Monitor was what got me out of the annoying problem and pointed out at INetCache permissions as the reason of the failed insertion of images.

    You just have to add permisions to C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache or C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache(depends on your system version) folder and images will shown

    0 讨论(0)
  • 2020-12-11 21:13

    As explained in comments (and eventually in an edit to the question), the code was running in production as a service, with the Local Service account.

    I am now unsure why I picked this account -- something I found in passing during my research on getting the Interop to run correctly as a service?

    However, once I switched from the Local Service account to the Local System account (and checked "Allow service to interact with desktop") it worked. Automagically.

    1. services.msc
    2. select the service
    3. right-click, select "Properties"
    4. select the "Log On" tab
    5. select "Local System account" and check "Allow service to interact with desktop"

    "Allow service to interact with desktop" might not be required; Other notes on automating the Interop suggest that other desktop settings are required, however I did an install where those pre-requisites were set but THIS value unchecked; app still worked...

    http://i.imgur.com/k6Qwy.png

    0 讨论(0)
  • 2020-12-11 21:18

    Interop is not supported in sever-scenarios by MS.

    There are many options to read/edit/create Excel files without Interop:

    MS provides the free OpenXML SDK V 2.0 - see http://msdn.microsoft.com/en-us/library/bb448854%28office.14%29.aspx (XLSX only)

    This can read+write MS Office files (including Excel).

    Another free option see http://www.codeproject.com/KB/office/OpenXML.aspx (XLSX only)

    IF you need more like handling older Excel versions (like XLS, not only XLSX), rendering, creating PDFs, formulas etc. then there are different free and commercial libraries like ClosedXML (free, XLSX only), EPPlus (free, XLSX only), Aspose.Cells, SpreadsheetGear, LibXL and Flexcel etc.

    It is hard to say whether your specific case (ActiveX controls) is fully supported by any of the above... that is something you need to test...

    Even if the ActiveX controls are supported by any of the libraries there is a chance that the ActiveX controls themselves don't work within a Windows Service (permissions etc.).

    EDIT - as per comment:

    I understand the ActiveX problem and I addressed it from 2 points:

    • Have you really tested all above mentioned libraries ?
    • Have you checked with the implementor(s) of the ActiveX controls whether the ActiveX controls could even theoretically work in a Windows Service scenario ?

    EDIT 3 - after the UPDATE from the OP:

    .emf is a vector file format... IIRC GDI+ is used to render it on current Windows versions... .emf has evolved a bit over time so older OS and/or Office versions can sometimes have problems rendering newer .emf files... which in turn means the problem is the "missing desktop" in the Windows Service AND/OR that your .emf files are "too new" for the production machine.

    0 讨论(0)
提交回复
热议问题