none
Save a xlsx file took a long long time? RRS feed

  • Question

  • It took a long time. Something wrong. Please see my code.
    saveFileDialog1.Filter = "(*.xls)|*.xls|(*.xlsx)|*.xlsx";
            saveFileDialog1.Title = "Where do you want to save the file?";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
              MessageBox.Show("You selected the file: " + saveFileDialog1.FileName);
              string sname = saveFileDialog1.FileName;
              //object misValue = System.Reflection.Missing.Value;
              xlWorkBook.SaveAs(sname, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
              xlWorkBook.Close(true, misValue, misValue);
              xlApp.Quit();
              releaseObject(xlWorkSheet1);
              releaseObject(xlWorkBook);
              releaseObject(xlApp);
              this.Close();
            }
    But if I save it as a xls file, it quickly.
    Friday, March 4, 2011 10:24 PM

Answers

  • I copied the code from somewhere, don't remember where. So how to modify it?

    Resloved it by myself.

    • Edited by ardmore Saturday, March 5, 2011 3:16 AM add
    • Marked as answer by ardmore Saturday, March 5, 2011 3:24 AM
    Saturday, March 5, 2011 3:15 AM

All replies

  • And eventually got an exception.

    System.Runtime.InteropServices.COMException was unhandled
     Message="Exception from HRESULT: 0x800A03EC"
     Source="Microsoft.Office.Interop.Excel"
     ErrorCode=-2146827284
     StackTrace:
        at Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local)
        at MarkExcelCells.Form1.button1_Click(Object sender, EventArgs e) in \\2170-mars\groupdata\Code\201103\Hui\MarkExcelCells\Form1.cs:line 181
        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(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 System.Windows.Forms.Application.Run(Form mainForm)
        at MarkExcelCells.Program.Main() in \\2170-mars\groupdata\Code\201103\Hui\MarkExcelCells\Program.cs:line 18
        at System.AppDomain._nExecuteAssembly(Assembly 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.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
        at System.Threading.ThreadHelper.ThreadStart()
     InnerException: 
    
    Friday, March 4, 2011 10:26 PM
  • Why are you saving an Access file with XLS file extension?
    jdweng
    Saturday, March 5, 2011 1:47 AM
  • I copied the code from somewhere, don't remember where. So how to modify it?

    Resloved it by myself.

    • Edited by ardmore Saturday, March 5, 2011 3:16 AM add
    • Marked as answer by ardmore Saturday, March 5, 2011 3:24 AM
    Saturday, March 5, 2011 3:15 AM