Click here to Skip to main content
15,887,446 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using a Windows based application which uses COM Interop Excel in which the excel exports fails. This works in the development environment. But it fails when promoted to other environment.

Also the problem is it is not reproducible in local environment.

We are using Microsoft.Interop.Excel for opening the excel and updating the data.

While trying to add the workbook using Workbooks.Add method we are getting the following
error :


System.Runtime.InteropServices.COMException.Exception from HRESULT:0X800A03EC
at Microsoft.Office.Interop.Excel.Workbooks.Add(Object Template)

Code :

thisWorkbook = OpenTemplate(new System.IO.FileInfo("XLSTemplate\\Test.xlsx"));


public Workbook OpenTemplate(FileInfo xlsFile)
{
Workbook wb = null;

try
{
wb = Workbooks.Add(xlsFile.FullName);
template = xlsFile;

if (wb != null)

{
if (!DebugOut.IsDebug & wb.Worksheets.Count > 0)
((_Worksheet)wb.Worksheets[1]).Activate();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
throw new Exception("Error in OpenTemplate",ex);
}
return wb;
}

Any help and solution would be much appreaciated.
Posted
Updated 23-Sep-16 8:48am

1 solution

Are the OS different in both environment? Is it Window 2008 Server? If so try creating Desktop folder as below if not present already in the environment where this is failing.

Windows 2008 Server (64 Bit): C:\Windows\SysWOW64\config\systemprofile\Desktop
Windows 2008 Server (32 Bit): C:\Windows\System32\config\systemprofile\Desktop
 
Share this answer
 
Comments
rajaron 9-Apr-13 5:57am    
This is Windows Vista 32 bit OS
rajaron 9-Apr-13 6:28am    
Hi Prashanth,

The Operation System is Windows Vista - 32 Bit.

But can you say me as how the 32 bit/ 64 bit is associated with Interop excel
PrashantSonewane 9-Apr-13 6:35am    
Its not related to Interop exel. I was check checking if your OS is server and 64 bit. If it is 64 bit, there is another folder for system files SysWOW64 unlike 32 bit. Hence you need to create Desktop folder both the places. Bit here is not related to Excel interop but with OS. Anyway yours is 32 bit. Will reply if find breakthrough or clue.
Manju0520 23-Sep-16 15:03pm    
I faced Exact same issue on a Windows 2008 Server (64 Bit). Creating a Desktop folder as mentioned by Prashanth resolved my issue. Thanks for this Question and Answer :)
Member 10085182 18-May-18 16:28pm    
This also worked for me on Windows Server 2012 R2 standard (64 bit)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900