+ Reply to Thread
Results 1 to 2 of 2

Export into excel hangs all application/keyboard inaccessible/halts the system

  1. #1
    Registered User
    Join Date
    06-15-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    1

    Post Export into excel hangs all application/keyboard inaccessible/halts the system

    Hi,

    Our Project using Export functionality from .net 2.0 windows forms application. And it was working great in all OS and in MS Office versions except MS Office 2007 (Windows 7 OS, 64 bit).

    When export excel event is fired from our application and after the report opened in MS Excel, that movement onwards none of the application can be editable.

    Enclosed Complete source code here...

    public partial class ExportExcelIssue : Form
    {
    public static int Counter=0;
    public String strPath = "";

    public void CreateExcel()
    {
    Counter = Counter + 1;

    Excel.Application xlApp;
    Excel.Workbook xlWorkBook;
    Excel.Worksheet xlWorkSheet;
    object misValue = System.Reflection.Missing.Value;

    xlApp = new Excel.ApplicationClass();
    xlWorkBook = xlApp.Workbooks.Add(misValue);

    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    xlWorkSheet.Cells[1, 1] = "TEST";

    string strTempPath = System.Environment.GetEnvironmentVariable("TEMP");
    DirectoryInfo objInfo = new DirectoryInfo(strTempPath);

    strPath = strTempPath + "\\Excel" + Counter + ".xls";

    xlWorkBook.SaveAs(strPath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
    xlWorkBook.Close(true, misValue, misValue);
    xlApp.Quit();

    object Delete;
    Delete = xlApp;

    if (!WithoutCom.Checked)
    {
    ReleaseComObject(ref Delete);
    }

    if (!WithoutGC.Checked)
    {
    GC.Collect();
    }

    if ((GCWithWFPF.Checked & WithoutGC.Checked) || (GCWithWFPF.Checked & !WithoutGC.Checked))
    {

    GC.WaitForPendingFinalizers();
    }

    try
    {
    System.Diagnostics.Process.Start(strPath);
    }

    catch (Exception ex)
    { MessageBox.Show(ex.Message); }

    }

    private void ReleaseComObject(ref Object o)
    {
    int releaseObject = 1;
    while (releaseObject > 0)
    {
    releaseObject = System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
    };
    }

    private void button1_Click(object sender, EventArgs e)
    {
    CreateExcel();
    }


    private void checkBox2_CheckedChanged(object sender, EventArgs e)
    {
    if (GCWithWFPF.Checked)
    {
    WithoutGC.Checked = false;
    WithoutGC.Enabled = false;
    }

    else {

    WithoutGC.Enabled = true;
    }
    }

    private void WithoutGC_CheckedChanged(object sender, EventArgs e)
    {
    if (WithoutGC.Checked)
    {
    GCWithWFPF.Checked = false;
    GCWithWFPF.Enabled = false;
    }

    else
    {

    GCWithWFPF.Enabled = true;
    }

    }
    }

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Export into excel hangs all application/keyboard inaccessible/halts the system

    Put your code in code tags
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1