opening an exel file in a c# program

Discussion in 'C#' started by arian, Aug 31, 2010.

  1. arian

    arian New Member

    Joined:
    Aug 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi

    I am getting the following error while opening the exel file. I am sure the path and the file name is correct.

    'G:\myCodeProgram\swiming\beforeMatch\Files\Input\arrange.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct.

    If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted.

    System.Runtime.InteropServices.COMException was unhandled
    HelpLink="C:\\Program Files (x86)\\Microsoft Office\\Office12\\1033\\XLMAIN11.CHM"
    Message="'G:\\myCodeProgram\\swiming\\beforeMatch\\Files\\Input\arrange.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct.\n\nIf you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted."
    Source="Microsoft Office Excel"
    ErrorCode=-2146827284
    StackTrace:
    at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
    at matchProvider.mainInfo.button1_Click(Object sender, EventArgs e) in G:\myCodeProgram\swiming\beforeMatch\1\matchProvider\matchProvider\mainInfo.cs:line 116
    at System.Windows.Forms.Control.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.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(Int32 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 matchProvider.Program.Main() in G:\myCodeProgram\swiming\beforeMatch\1\matchProvider\matchProvider\Program.cs:line 18
    at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()
    InnerException:
    I use visual Studio 2008 , win7 (86X)

    and here is the code
    Code:
     	object opt = System.Reflection.Missing.Value;
                    Excel.Application excel = new Excel.ApplicationClass();
                    Excel.Sheets Sheets;
                    Excel.Workbook wArrange;
    
                    wArrange = excel.Workbooks.Open(path+"\arrange.xlsx", opt, false, opt, opt, opt, true, opt, opt, opt, opt, opt, opt, opt, opt);
                    Sheets = wArrange.Worksheets;
                    teamNum = wArrange.Sheets.Count;
    
                    wArrange.Close(true, opt, opt); 
    
    Can you plz tell me what is wrong?

    Tnx
    arian
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice