Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to control the excel application via WPF project.

var xla = new Microsoft.Office.Interop.Excel.Application();

xla.Width = 400; // This line is throwing the below exception.

System.Runtime.InteropServices.COMException was unhandled
  HResult=-2146827284
  Message=Exception from HRESULT: 0x800A03EC
  Source=Microsoft.Office.Interop.Excel
  ErrorCode=-2146827284
  StackTrace:
       at Microsoft.Office.Interop.Excel.ApplicationClass.set_Width(Double RHS)
       at EmbedExcel1.Form1.button1_Click(Object sender, EventArgs e) in d:\Test Projects\EmbedExcel1\EmbedExcel1\Form1.cs:line 27
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at EmbedExcel1.Program.Main() in d:\Test Projects\EmbedExcel1\EmbedExcel1\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
thanks in advance.


What I have tried:

I am trying to control the excel application via WPF project.

var xla = new Microsoft.Office.Interop.Excel.Application();

xla.Width = 400;
Posted
Updated 30-May-17 5:58am
Comments
Mehdi Gholam 30-May-17 1:08am    
I don't think it has a "Width" property.
kaliprasad123 30-May-17 1:21am    
I am sure it has width property, it works fine for few times, after few days the same line gives exception. Logging off and logging on to the system fixes issue temporarily.
madhav_jain 30-May-17 2:41am    
you can not set the width because it is read only property... If you wanna update the with u need to implement _Application interface to update the width
kaliprasad123 30-May-17 2:53am    
hi Madhav,

I am pretty sure that the width is not read only because it works few times. I wonder how to implement _Application interface. Could you please write some code wrt to it.
Patrice T 30-May-17 3:29am    
I used 'Width' in columns, not in application

Before setting Width property you should set xla.WindowState = xlNormal
 
Share this answer
 
Application.Width is a ReadOnly property as clearly stated in the documentation: _Application.Width property (Microsoft.Office.Interop.Excel)[^].
 
Share this answer
 
v2
Comments
kaliprasad123 30-May-17 5:17am    
hi Richard,

the link you provided clearly says that it has get and set.
double Width { get; set; }

any other suggestion?
Richard MacCutchan 30-May-17 5:21am    
Sorry, I misread.
Richard MacCutchan 30-May-17 5:24am    
The best I can suggest is to Google that error code and see if anyone has any ideas.
kaliprasad123 30-May-17 5:33am    
Hi Richard,

thanks for reply, that is the first thing that I did when I got the error. None has given the solution. After the user has logged off and log on it works as expected for short duration.

thanks
kaliprasad

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