Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs()
method is working fine on Windows server 2003 and also on XP but not on Windows server 2008. I copied it a
It 'a permission problem when IIS is running I had this problem and I solved it in this way
I went on folders
C:\Windows\ System32\config\SystemProfile
and
C:\Windows\SysWOW64\config\SystemProfile
are protected system folders, they usually have the lock.
Right-click-> Card security-> Click on Edit-> Add untente "Autenticadet User" and assign permissions.
At this point everything is solved, if you still have problems try to give all permissions to "Everyone"
For all of those, who still experiencing this problem, I just spent 2 days tracking down the bloody thing. I was getting the same error when there was no rows in dataset. Seems obvious, but error message is very obscure, hence 2 days.
Some googling reveals that potentially you've got a corrupt file:
http://bitterolives.blogspot.com/2009/03/excel-interop-comexception-hresult.html
and that you can tell excel to open it anyway with the CorruptLoad parameter, with something like...
Workbook workbook = excelApplicationObject.Workbooks.Open(path, CorruptLoad: true);
In my case, the problem was styling header as "Header 1" but that style was not exist in the Word that I get the error because it was not an Office in English Language.
Try this as it worked for me...
courtesy of Last paragraph mentioned in here
I was seeing this same error when trying to save an excel file. The code worked fine when I was using MS Office 2003, but after upgrading to MS Office 2007 I started seeing this. It would happen anytime I tried to save an Excel file to a server or remote fie share.
My solution, though rudimentary, worked well. I just had the program save the file locally, like to the user's C:\ drive. Then use the "System.IO.File.Copy(File, Destination, Overwrite)" method to move the file to the server. Then you can delete the file on the C:\ drive.
Works great, and simple. But admittedly not the most elegant approach.
Hope this helps! I was having a ton of trouble finding any solutions on the web till this idea popped into my head.