Last post Oct 29, 2018 08:00 PM by nadhimer
Apr 03, 2017 08:49 PM|guitarmaestro69|LINK
I have been programming windows forms and various other environments and languages for quite a while, but am new to MVC and web applications in general.
Issue: I have some code that creates and excel object, opens a files, and inserts a picture, like this
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = null;
Excel.Worksheet xlWorksheet = null;
xlWorkbook = xlApp.Workbooks.Open(Server.MapPath(Properties.Settings.Default.A3DownloadTemplatePath) + "A3-" + id + ".xlsx");
xlWorksheet = xlWorkbook.Worksheets.get_Item(1);
... (lots of cell data entry; all works fine)
Then this line fails ONLY ON THE SERVER (it works find from my dev machine in debug mode). The page churns and churns waiting on the server to do something and it never does - it is supposed to return an excel file.
xlWorksheet.Shapes.AddPicture(Path.Combine(Server.MapPath(Properties.Settings.Default.A3AttachmentPath), ProblemClarificationImages.FileName), Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 630, 177, 417, 254); //Left, Top, Width, Height (used to be 648 and 431)
I have verified the path is correct (i wrote the path to an excel cell instead of inserting the picture and it was correct. I copied the path to the same server in question and it opened the picture fine).
I considered that it may be an issue with the reference to the Office tristate reference, but that is also fine. i converted this to (int) and wrote it to an excel cell, no issues.
To get the download to work at all, I had to add the folder "C:\Windows\SysWOW64\config\systemprofile\Desktop" since excel runs under the system user I assume? either way, this it not the issue either.
The download works perfectly until it tries to execute the addpicture method. I'm at a loss. any suggestions?
The fact that this works on my dev machine and not the live server says to me that it's deeper than MVC, a server setting or such, maybe permissions?
Edit @17:36 03-apr-2017
I have ran the application pool under my admin credentials - no dice. That indicates that it is not an Excel modal window nor a permissions issue.
I see the excel process running that is hung on the web server. when I end it, the page responds with an error. otherwise it just sits there churning.
Apr 03, 2017 11:02 PM|guitarmaestro69|LINK
I've found what seems to be a group policy enforcement on excel on the web server in question. I cannot open the VBA editor, record a macro, nor successfully open an excel file with macro code in it on this server. Perhaps the shapes.addpicture executes
in the same manor as a macro?
Oct 29, 2018 08:00 PM|nadhimer|LINK
This code is tested and works:
Dim fNameAndPath As String
Dim img As Object
fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
'Move and Resize Image
.ShapeRange.LockAspectRatio = msoFalse
.Left = ActiveSheet.Range("H10").Left
.Top = ActiveSheet.Range("H10").Top
.Width = ActiveSheet.Range("H10:O10").Width
.Height = ActiveSheet.Range("H10:O24").Heighthttps://bluestacks.vip/https://textnow.vip/https://downloader.vip/vpn/